Re: Checking that Pg is running from a shell script - Mailing list pgsql-general

From McCaffity, Ray (Contractor)
Subject Re: Checking that Pg is running from a shell script
Date
Msg-id 9669B05099E9D411B6E400B0D0AA476C79CE2B@epg.lewis.army.mil
Whole thread Raw
In response to Checking that Pg is running from a shell script  (Fran Fabrizio <ffabrizio@mmrd.com>)
List 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@sss.pgh.pa.us]
Sent: Monday, June 10, 2002 1:51 PM
To: Vincent Stoessel
Cc: Fran Fabrizio; pgsql-general@postgresql.org
Subject: Re: [GENERAL] Checking that Pg is running from a shell script


Vincent Stoessel <vincent@xaymaca.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

pgsql-general by date:

Previous
From: Ericson Smith
Date:
Subject: Re: Checking that Pg is running from a shell script
Next
From: s
Date:
Subject: cascading an insert trigger/rule help