postgresql start/stop/status script

From: Baldur Norddahl <bbn-pgsql(dot)general(at)clansoft(dot)dk>
To: pgsql-general(at)postgresql(dot)org
Subject: postgresql start/stop/status script
Date: 2005-04-19 22:34:30
Message-ID: 42658776.9020500@clansoft.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I am working on making a postgresql/drbd/heartbeat high availability
cluster. I need a script for heartbeat to start, stop and query the
service. I wrote the following:

pgStart() {
su - pg0 -c "cd data ; /mnt/data0/postgresql/bin/pg_ctl start -D
/mnt/data0/postgresql/data -w -o '-i -h 192.168.2.50'"
}

pgStop () {
su - pg0 -c "cd data ; /mnt/data$user/postgresql/bin/pg_ctl stop
-D /mnt/data0/postgresql/data -m fast -w"
}

pgStatus () {
if su - pg0 -c "cd data ; /mnt/data0/postgresql/bin/pg_ctl
status -D /mnt/data0/postgresql/data" | grep -q "postmaster is running"
then
echo running
else
echo stopped
fi
}

This works fine. The only problem is that status - it seems to only
check for the existance of the PID file. If the file is there, it
assumes that postgresql is running. In the case of a failover, the PID
file will of course still be there, but it will be stale. The effect is
that heartbeat never starts postgresql because my pgStatus claims it is
already running, even though it is not.

Is there a better way to query the status of postgresql? I would expect
it to at least check that the process in the PID is actually running and
that it is a postgresql process.

I am also confused by the need to specify "-h 192.168.2.50" - that is
already in the postgres.conf file, but "pg_ctl start" ignores it.

Thanks,

Baldur

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Russell Smith 2005-04-19 23:06:45 Re: pg_dump fails
Previous Message Dan Sugalski 2005-04-19 19:24:47 Re: Simplified (a-la [G|N]DBM) DB access