Re: Check PostgreSQL status using MS-DOS bat file?

From: Dave Page <dpage(at)pgadmin(dot)org>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: "Loughrey, Hugh" <Hugh(dot)Loughrey(at)hoopleltd(dot)co(dot)uk>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Check PostgreSQL status using MS-DOS bat file?
Date: 2012-08-15 15:29:43
Message-ID: CA+OCxozvD=Nb+V3-w8aBwT-X_MfjDeZ_0eCd4_s1D_wcqQKgEw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Aug 15, 2012 at 4:04 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> On Wed, Aug 15, 2012 at 09:52:17AM +0000, Loughrey, Hugh wrote:
>> Hi All,
>>
>> I want to write a MS-DOS command to check that the PostgreSQL database is up
>> and running and able to accept data being pushed to it. From a bit of reading
>> I’ve identified the pg_ctl status command, but can this be incorporated into a
>> *.bat file and can the resulting status be recorded in a *.txt file? If so does
>> anyone have a command which would enable this?
>
> As I remember it is pretty tricky to call pg_ctl from a Windows batch
> file. I know the Windows installers do it somehow --- you might want to
> downlaod it and see if you can find the shell script they use. Dave
> Page might know more --- CC'ing him.

You shouldn't try to start/stop the server with pg_ctl if it's
configured to run as a service (use "net start xxx", "net stop xxx"
for that), but you can check the status:

C:\>"C:\Program Files\PostgreSQL\9.2\bin\pg_ctl.exe" -D "C:\Program
Files\PostgreSQL\9.2\data" status
pg_ctl: server is running (PID: 1040)
C:/Program Files/PostgreSQL/9.2/bin/postgres.exe "-D" "C:/Program
Files/PostgreSQL/9.2/data"

C:\>net stop postgresql-x64-9.2
The postgresql-x64-9.2 service is stopping.
The postgresql-x64-9.2 service was stopped successfully.

C:\>"C:\Program Files\PostgreSQL\9.2\bin\pg_ctl.exe" -D "C:\Program
Files\PostgreSQL\9.2\data" status
pg_ctl: no server running

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Angel Zúñiga 2012-08-15 15:34:53 ProblemWithCharsOSX
Previous Message Bruce Momjian 2012-08-15 15:04:27 Re: Check PostgreSQL status using MS-DOS bat file?