Re: Checking that Pg is running from a shell script

From: "McCaffity, Ray (Contractor)" <McCaffityR(at)epg(dot)lewis(dot)army(dot)mil>
To: 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Vincent Stoessel <vincent(at)xaymaca(dot)com>
Cc: Fran Fabrizio <ffabrizio(at)mmrd(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Checking that Pg is running from a shell script
Date: 2002-06-10 22:15:38
Message-ID: 9669B05099E9D411B6E400B0D0AA476C79CE2B@epg.lewis.army.mil
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This seems to work on UNIX systems. (Tested on Linux and Solaris)
You have to change the path of PIDFILE variable below.

#!/usr/bin/ksh
# $Source$
#*DESCRIPTION:**************************************************************
****
# is_postgres_running:
# This script returns either YES or NO, depending on whether Postgresql is
running.
#

## Hard-code the response for testing:
#echo "YES" #*DEBUG*
#exit #*DEBUG*

# the path to your PID file
PIDFILE=/pgdata/postmaster.pid

if [ -f $PIDFILE ] ; then
PID=`cat $PIDFILE`
if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
STATUS="YES"
else
STATUS="NO"
fi
else
STATUS="NO"
fi

echo $STATUS

-----Original Message-----
From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
Sent: Monday, June 10, 2002 1:51 PM
To: Vincent Stoessel
Cc: Fran Fabrizio; pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Checking that Pg is running from a shell script

Vincent Stoessel <vincent(at)xaymaca(dot)com> writes:
> Can pg_ctl across the network?

No.

> I'd like my middleware server to know
> if my postgres db is up and running OK. I guess I could just make a
> db connection but I was hoping for a more elegant solution.

Making a connection is the only way at present. There was some talk of
writing a "pg_ping" utility that would just send a probe packet to the
postmaster (and not, for example, require you to supply a password).
No one's got round to it, but it's just a small matter of programming...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Browse pgsql-general by date

  From Date Subject
Next Message s 2002-06-10 23:42:04 cascading an insert trigger/rule help
Previous Message Ericson Smith 2002-06-10 21:01:52 Re: Checking that Pg is running from a shell script