My Notepad

  • My Linux Notes
  • My Grid Notes
  • To do List
  • Thursday, November 05, 2009

     

    Use Cron to do daily Vaccumn and backup for postgres

    In order to give best performance to your postgresql database, it's crucial to use vaccum and analyze command to clean up your system regularly. On linux system, this can be easily implemented with help of cron.

    A typical cron script that runs daily has been listed below. It not only clean the database, but also backup the database into a dump file:
    ----------
    #!/bin/sh

    /usr/local/pgsql/bin/vacuumdb --all --analyze

    DATESTAMP=`date +%B_%d_%Y__%H:%M:%S`
    BACKUPDIR=/usr/local/pgsql/backup
    FILENAME=pg_daily_backup__${DATESTAMP}.bz

    /usr/local/pgsql/bin/pg_dumpall | /usr/bin/bzip2 > $BACKUPDIR/$FILENAME
    ---------------
    One thing needs to make sure it whether root the command can be ran as root - normally only the user postgres has the privilege to do so.

    Comments: Post a Comment



    << Home

    Archives

    December 2005   January 2006   February 2006   April 2006   May 2006   June 2006   July 2006   November 2006   February 2007   May 2007   June 2007   November 2007   February 2008   March 2008   April 2008   August 2008   December 2008   March 2009   April 2009   May 2009   June 2009   October 2009   November 2009   December 2009   May 2013  

    This page is powered by Blogger. Isn't yours?