Given the requirement for having to know PGDATA in order to get pg_ctl to
work, and to offer flexibility for cases where the server will live on a
different machine, I prefer checking status of $?
bash-2.05$ psql quickview -c '\q';
bash-2.05$ echo $?
0
bash-2.05$ export PGPORT=9999
bash-2.05$ psql quickview -c '\q';
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.9999"?
bash-2.05$ echo $?
2
-ron
> -----Original Message-----
> From: Lamar Owen [mailto:lamar.owen@wgcr.org]
> Sent: Monday, June 10, 2002 10:57 AM
> To: Fran Fabrizio; pgsql-general@postgresql.org
> Subject: Re: [GENERAL] Checking that Pg is running from a shell script
>
>
> On Monday 10 June 2002 10:29 am, Fran Fabrizio wrote:
> > What's the best way to ensure that Pg is running from a
> shell script?
> > I'm crafting a few RPMs for my projects, one of which will
> attempt to
> > load data into a database, but I want to check that it's
> running first
> > before I try this.
>
> See the man page for pg_ctl. There is, IIRC, a status
> option, but you have to
> know the location of PGDATA (which, in a vanilla RPM install is
> /var/lib/pgsql/data).
> --
> Lamar Owen
> WGCR Internet Radio
> 1 Peter 4:11
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>