Installing Postgresql
The following code will install postgresql on an rhel4 server (it would work with a tweak or two for WBEL3/RHEL3).
function installpostgresql() {apt-get update# needed for postgresql-contribapt-get -y install libxslt
apt-get -y remove postgresqlVERSION=8.2.3PV=1PGDG# change rhel-as-4 to rhel-es-3 for rhel3/whitebox3URL=ftp://ftp5.us.postgresql.org/pub/PostgreSQL/binary/v$VERSION/linux/rpms/redhat/rhel-as-4
PACKAGES="postgresql-plpython postgresql-plperl postgresql-libs postgresql-contrib postgresql postgresql-server"for PACKAGE in $PACKAGES; doFILE=$PACKAGE-$VERSION-$PV.i686.rpmif [ -e "$FILE" ] ; thenecho "Skipping $FILE, already have it"continuefiecho "Fetching $URL/$FILE"wget --no-verbose "$URL/$FILE"if [ $? -ne 0 ] ; thenecho "Failed getting $URL/$FILE"return 1fidone# need -i - i.e. keep the old one - on this one to avoid dependency issues with dovecot and php-pgsqlrpm -i postgresql-libs-$VERSION*i686.rpm# the rest can just be -U - i.e. upgrade any other packagesrpm -Uvfh postgresql-plpython-$VERSION-$PV.i686.rpm postgresql-plperl-$VERSION-$PV.i686.rpm postgresql-contrib-$VERSION-$PV.i686.rpm postgresql-$VERSION-$PV.i686.rpm postgresql-server-$VERSION-$PV.i686.rpmif [ $? -ne 0 ] ; thenecho "Failed installing rpms"return 1fichkconfig --level 35 postgresql on/etc/init.d/postgresql startpsql --version}installpostgresql
Backups
The following file will backup a given database to /var/log/. It will create a different file for each day of the week - the %u option in the date command. After that it will overwrite files.
cat /etc/cron.d/backupfsn.sh
#!/bin/bash
backup_dir="/var/log/"
timeslot=`date +%u`
i=dbnametobackup
/usr/bin/pg_dump -U postgres $i | gzip > "$backup_dir/postgresql-$i-$timeslot-database.gz"
Getting a List of Databases
psql -U postgres -q -c "l" dbname | sed -n 4,/eof/p | grep -v rows) | awk {'print $1'}Not sure how to bootstrap this. You need to provide a dbname, but what to use by default? I think dbname could be postgres by default? Not sure.
RHEL4, PostgreSQL 8.1 and Dovecot
The default Dovecot is built against the older PostgreSQL 7.4.x RPMs, and needs to be removed to install 8.1. If you still need Dovecot, use this RPM which is compiled against the PostgreSQL 8.1.x -devel packages.
rpm -Uvh "http://downloads.rimuhosting.com/dovecot-0.99.11-4-pg81.EL4.i386.rpm"