PostgreSQL Restart
#!/bin/sh
# restart postgres
# the ( ) makes all of this run in a subshell
# the advantage of this it that when it finishes nothing mysterious like being in
# another directory has happened
(
# run from the home directory
cd
# sometimes this fails because the postgres process isn't running, and something else took the pid
# usually this pid is owned by another user, and thus can't, and shouldn't be killed.
/usr/local/pgsql-8.0/bin/pg_ctl stop -D ~/pgdata/ -l ~/logs/postgres.log
# If the previous line failed this one will succeed,
# if it succeeded this one will fail
/bin/rm ~/pgdata/postmaster.pid
# start postgres
/usr/local/pgsql-8.0/bin/pg_ctl start -D ~/pgdata/ -l ~/logs/postgres.log
)