Need help on Shell script for database maintainace..

Hi All,

                   I have to perform some tasks for database maintainace. I am using postgresql on RHEL 4.4.

1) I have to run "vacuumedb" on the database as postgres user.
2) I have to reindex the database as postgres user.

Now i want to write shell script to do these tasks one after another. Please any one suggest me, how to write a shell script..

Thanks in advance..:slight_smile:

What is the big deal in that ?

Call the commands, one by one !
-- What help you are looking for ?

Is the problem that you are not a postgres user?

su postgresuser commands

does that if you are root.

You could also use "sudo" to allow another user to be the postgres user for these commands; see Using sudo

Hi,

             Thanks for the reply, My senario is given below..
[postgres@sys3 bin]$ ./postgres -D /usr/local/pgsql/data -O -P mydb
LOG:  database system was shut down at 2009-11-11 13:44:47 IST
LOG:  checkpoint record is at 0/AE63A0
LOG:  redo record is at 0/AE63A0; undo record is at 0/0; shutdown TRUE
LOG:  next transaction id: 2254; next oid: 17058
LOG:  database system is ready

POSTGRES backend interactive interface
$Revision: 1.307.2.1 $ $Date: 2003/01/01 21:57:18 $

backend> Reindex Database mydb
NOTICE:  relation 16416 was reindexed
NOTICE:  relation 1255 was reindexed
NOTICE:  relation 16410 was reindexed
NOTICE:  relation 1247 was reindexed
NOTICE:  relation 1249 was reindexed
NOTICE:  relation 1259 was reindexed
NOTICE:  relation 16388 was reindexed
NOTICE:  relation 16390 was reindexed
NOTICE:  relation 16392 was reindexed
NOTICE:  relation 16394 was reindexed
NOTICE:  relation 16396 was reindexed
NOTICE:  relation 16398 was reindexed
NOTICE:  relation 16400 was reindexed
NOTICE:  relation 16402 was reindexed
NOTICE:  relation 16404 was reindexed
NOTICE:  relation 16406 was reindexed
NOTICE:  relation 16412 was reindexed
NOTICE:  relation 16418 was reindexed
NOTICE:  relation 16594 was reindexed
NOTICE:  relation 16596 was reindexed
NOTICE:  relation 16598 was reindexed
NOTICE:  relation 16384 was reindexed
NOTICE:  relation 16386 was reindexed
NOTICE:  relation 16408 was reindexed
backend> LOG:  shutting down
LOG:  database system is shut down
       In the above activity there is an interactive command "Reindex Database", I can't call this command in to a shell script. I want to do this activity without my interaction. Please suggest me what to do...