Page 1 of 1

Example of cron job for database maintenance?

PostPosted: Sun Jul 13, 2008 9:17 am
by Guest
Question to the group: Does anybody have an example for me for a job that automatically performs database management every night?

I have the postgresql database running on a Linux server so running cron jobs is a part of life. But I have no idea how to start a PL/pgSQL job that runs the vacuum, cluster and analyze commands. And since it might help the performance to do these commands during the night a few times a week I am looking for a way to do this.

Anybody happen to have an example of such a job? Both the cron command as well as the PL/pgSQL script I would need?

Re: Example of cron job for database maintenance?

PostPosted: Sat Jul 19, 2008 6:14 am
by Guest
Well, since nobody seems to have this readily available I have tried something myself.

So, I switched to the postgres user, used crontab -e to make a new one and put the following text in the crontab:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/opt/data/postgres

00 3 * * * /usr/bin/vacuumdb --full --analyze "PT3 DB"

Every day at 03:00 I run the vacuum job with analysis included. And it seems to work.

Enjoy.

Re: Example of cron job for database maintenance?

PostPosted: Sat Jul 26, 2008 11:05 am
by driemekasten

Re: Example of cron job for database maintenance?

PostPosted: Sun Jul 27, 2008 1:52 pm
by Guest
That is also my own thread :)

highfalutin