Here is a perl script I use for vacuuming.  It's
in my postgres crontab, so that it runs with the
proper environment variables.  There's probably
a more elegant solution, but this works okay for
me.

--Keith
[EMAIL PROTECTED]


--------------------------------------------------------

#!/usr/bin/perl
### vacuum.plx
### Copyright K. Keller 07/24/1999
### This script can be distributed under the GNU GPL.
### Look at their web site for details: www.gnu.org
### No warranty for any purpose whatsoever; caveat user.

use strict;
use Pg;

# Useful to do autoflushing on stdout, but not necessary
use FileHandle;
autoflush STDOUT 1;

# Every PostgreSQL installation should have template1
my $conn=Pg::connectdb("dbname=template1");

# Get the list of databases from the Postgres master list
my $sql="select datname from pg_database";
my $result=$conn->exec($sql);

print "Vacumming databases... ";

my @row;
while (@row=$result->fetchrow)
{
        # Connect to the database
        my $conn=Pg::connectdb("dbname=$row[0]");
        # Make sure it's the right one, and print the name
        my $dbname=$conn->db;
        print "$dbname ";
        # Issue the vacuum sql command
        my $sql="vacuum";
        my $result=$conn->exec($sql);
}

print "\n";

************

Reply via email to