Re: How to check postgres running or not ?

Lists: pgsql-sql
From: "Sandeep Gaikwad" <sgaikwad(at)vertex(dot)co(dot)in>
To: pgsql-sql(at)postgresql(dot)org
Subject: How to check postgres running or not ?
Date: 2004-09-17 05:18:13
Message-ID: 414A7395.8070503@vertex.co.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql


Hello Sir,
I want to know how to check whether postgres database is
running or not ? when I give command like ./postmaster -i &, whether
all databases in that postgres will run or any one [default] ? If any
one, then how to detect that database ?

Thanks and regards,
Sandeep.

Attachment Content-Type Size
unknown_filename text/plain 823 bytes

From: Christopher Browne <cbbrowne(at)acm(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-18 17:20:15
Message-ID: m3r7ozqysw.fsf@wolfe.cbbrowne.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

In an attempt to throw the authorities off his trail, sgaikwad(at)vertex(dot)co(dot)in ("Sandeep Gaikwad") transmitted:
> Hello Sir,
> I want to know how to check whether postgres database
> is running or not ? when I give command like ./postmaster -i &,
> whether all databases in that postgres will run or any one [default] ?
> If any one, then how to detect that database ?

Well, the way I usually check on what databases are running is thus:

cbbrowne(at)wolfe:/tmp/mm5/doc> netstat -an | grep PG Saturday 13:18:30
unix 2 [ ACC ] STREAM LISTENING 2793 /var/run/postgresql/.s.PGSQL.5432

One could presumably script things further to get more out of that; it
doesn't normally seem worthwhile to do so...
--
output = ("cbbrowne" "@" "ntlug.org")
http://www.ntlug.org/~cbbrowne/postgresql.html
"As long as war is regarded as wicked, it will always have
its fascination. When it is looked upon as vulgar,
it will cease to be popular."
--Oscar Wilde


From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-18 18:36:47
Message-ID: cihv80$mb2$1@floppy.pyrenet.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Sandeep Gaikwad wrote:
>
> Hello Sir,
> I want to know how to check whether postgres database is
> running or not ? when I give command like ./postmaster -i &, whether
> all databases in that postgres will run or any one [default] ? If any
> one, then how to detect that database ?

Well, in the $DATADIR you habe postmaster.pid that contains the supposed pid...

Regards
Gaetano Mendola


From: Worik <worik(at)noggon(dot)com>
To: Sandeep Gaikwad <sgaikwad(at)vertex(dot)co(dot)in>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-19 01:57:02
Message-ID: 414CE76E.2050405@noggon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Assuming it is unix.... The command

ps xau|grep post

If it is running it will produce output like...

worik(at)stolberg:~$ ps xau|grep post
postgres 880 0.0 0.2 8580 740 ? S Sep07 0:31
/usr/lib/postgresql/bin/postmaster
postgres 887 0.0 0.2 9536 612 ? S Sep07 0:02 postgres:
stats buffer process
postgres 889 0.0 0.2 8624 632 ? S Sep07 0:05 postgres:
stats collector process
worik 25927 0.0 0.2 1612 540 pts/10 S 13:54 0:00 grep post
worik(at)stolberg:~$

If it is not running it will produce output like...

worik(at)stolberg:~$ ps xau|grep post
worik 26094 0.0 0.2 1608 528 pts/10 S 13:55 0:00 grep post

Sandeep Gaikwad wrote:
>
> Hello Sir,
> I want to know how to check whether postgres database is
> running or not ? when I give command like ./postmaster -i &, whether
> all databases in that postgres will run or any one [default] ? If any
> one, then how to detect that database ?
>
> Thanks and regards,
> Sandeep.
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------
>
> Disclaimer:
>
> The contents of this message are confidential and intended to the addressee at the specified e-mail address only. Its contents may not be copied or disclosed to anyone other than the intended recipient. If this e-mail is received in error, please contact Vertex Software Pvt. Ltd immediately on +91 20 4041500 with details of the sender and addressee and delete the e-mail. Vertex Software Pvt. Ltd accepts no responsibility in the event that the onward transmission, opening or use of this message and/or any attachments adversely affects the recipient's systems or data. It is the recipient's responsibility to carry out such virus and other checks as the recipient considers appropriate.
>
> ---------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings


From: Geoffrey <esoteric(at)3times25(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-19 12:01:55
Message-ID: 414D7533.10708@3times25.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Worik wrote:
> Assuming it is unix.... The command
>
> ps xau|grep post

You might want to change that to:

ps aux|grep postgres

As your suggestion will pick up extraneous data if one is running
postfix on the same box.

--
Until later, Geoffrey Registered Linux User #108567
AT&T Certified UNIX System Programmer - 1995


From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-19 16:08:18
Message-ID: 20040919160818.58480.qmail@web20825.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql


--- Christopher Browne <cbbrowne(at)acm(dot)org> wrote:

> In an attempt to throw the authorities off his
> trail, sgaikwad(at)vertex(dot)co(dot)in ("Sandeep Gaikwad")
> transmitted:
> > Hello Sir,
> > I want to know how to check
> whether postgres database
> > is running or not ? when I give command like
> ./postmaster -i &,
> > whether all databases in that postgres will run or
> any one [default] ?
> > If any one, then how to detect that database ?

The "standard" way would be "pg_ctl status". "man
pg_ctl" is recommended reading for anyone
administering a PostgreSQL setup.

>
> Well, the way I usually check on what databases are
> running is thus:
>
> cbbrowne(at)wolfe:/tmp/mm5/doc> netstat -an | grep PG
>
> Saturday 13:18:30
> unix 2 [ ACC ] STREAM LISTENING
> 2793 /var/run/postgresql/.s.PGSQL.5432
>
> One could presumably script things further to get
> more out of that; it
> doesn't normally seem worthwhile to do so...
> --
> output = ("cbbrowne" "@" "ntlug.org")
> http://www.ntlug.org/~cbbrowne/postgresql.html
> "As long as war is regarded as wicked, it will
> always have
> its fascination. When it is looked upon as vulgar,
> it will cease to be popular."
> --Oscar Wilde
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the
> unregister command
> (send "unregister YourEmailAddressHere" to
> majordomo(at)postgresql(dot)org)
>


_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Geoffrey <esoteric(at)3times25(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-19 16:25:00
Message-ID: 19430.1095611100@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Geoffrey <esoteric(at)3times25(dot)net> writes:
> Worik wrote:
>> Assuming it is unix.... The command
>> ps xau|grep post

> You might want to change that to:
> ps aux|grep postgres
> As your suggestion will pick up extraneous data if one is running
> postfix on the same box.

Actually I'd recommend grepping for "postmaster". If your PG user is
named "postgres" then the above command will find any program the PG
user is running --- which might only be a shell, for instance. If your
PG user is not named "postgres" then the above might find nothing at
all, even though the postmaster is alive (since depending on the details
of your local ps command, it might report all the server processes as
"postmaster").

There is even another gotcha, which is that the "grep postmaster"
command could easily find itself in the ps output. So what really
works is
ps aux | grep postmaster | grep -v grep
(or use "ps -ef" if using a SysV-ish ps).

Obviously none of this matters if you are just going to eyeball the
output, but if you want something suitable for a test in a script,
you'd better use something like the last one.

regards, tom lane


From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-19 16:57:48
Message-ID: 20040919165748.GB15746@phlogiston.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

On Sun, Sep 19, 2004 at 12:25:00PM -0400, Tom Lane wrote:
> ps aux | grep postmaster | grep -v grep
> (or use "ps -ef" if using a SysV-ish ps).

Except that on Solaris, ps -ef _always_ shows "postmaster", even for
the individual back ends.

A

--
Andrew Sullivan | ajs(at)crankycanuck(dot)ca
In the future this spectacle of the middle classes shocking the avant-
garde will probably become the textbook definition of Postmodernism.
--Brad Holland


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-19 17:12:07
Message-ID: 19876.1095613927@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Andrew Sullivan <ajs(at)crankycanuck(dot)ca> writes:
> On Sun, Sep 19, 2004 at 12:25:00PM -0400, Tom Lane wrote:
>> ps aux | grep postmaster | grep -v grep
>> (or use "ps -ef" if using a SysV-ish ps).

> Except that on Solaris, ps -ef _always_ shows "postmaster", even for
> the individual back ends.

Right, but if you see a backend then you can figure the system is up.

If you are concerned about the case where the postmaster has crashed and
yet there are still backends laying about, then the whole "ps" approach
is probably wrong anyway. It would make more sense to check whether the
postmaster is answering the doorbell --- ie, send a connection request
and see what happens.

At one time there was discussion of writing a "pg_ping" utility program
to do exactly this, but it still hasn't got done. You can fake it to
some extent by just running "psql -l >/dev/null" and checking the exit
code, but this does require supplying a valid username and possibly a
password (because psql's exit code doesn't distinguish "could not
connect" from authentication errors).

BTW, "pg_ctl status" doesn't answer this need because it only looks for
a postmaster.pid file, it doesn't attempt to verify that the postmaster
is really alive.

regards, tom lane


From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: How to check postgres running or not ?
Date: 2004-09-19 20:57:57
Message-ID: 414DF2D5.5040509@bigfoot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Tom Lane wrote:
> Geoffrey <esoteric(at)3times25(dot)net> writes:
>
>>Worik wrote:
>>
>>>Assuming it is unix.... The command
>>>ps xau|grep post
>
>
>>You might want to change that to:
>>ps aux|grep postgres
>>As your suggestion will pick up extraneous data if one is running
>>postfix on the same box.
>
>
> Actually I'd recommend grepping for "postmaster". If your PG user is
> named "postgres" then the above command will find any program the PG
> user is running --- which might only be a shell, for instance. If your
> PG user is not named "postgres" then the above might find nothing at
> all, even though the postmaster is alive (since depending on the details
> of your local ps command, it might report all the server processes as
> "postmaster").
>
> There is even another gotcha, which is that the "grep postmaster"
> command could easily find itself in the ps output. So what really
> works is
> ps aux | grep postmaster | grep -v grep
> (or use "ps -ef" if using a SysV-ish ps).

Just to enforce the test is better looking for the entire executable path:

ps aux | grep /usr/bin/postmaster | grep -v grep

Regards
Gaetano Mendola


From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
Subject: Re: How to check postgres running or not ?
Date: 2004-09-19 21:01:01
Message-ID: 414DF38D.2040307@bigfoot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Jeff Eckermann wrote:
> --- Christopher Browne <cbbrowne(at)acm(dot)org> wrote:
>
>
>>In an attempt to throw the authorities off his
>>trail, sgaikwad(at)vertex(dot)co(dot)in ("Sandeep Gaikwad")
>>transmitted:
>>
>>>Hello Sir,
>>> I want to know how to check
>>
>>whether postgres database
>>
>>>is running or not ? when I give command like
>>
>>./postmaster -i &,
>>
>>>whether all databases in that postgres will run or
>>
>>any one [default] ?
>>
>>>If any one, then how to detect that database ?
>
>
> The "standard" way would be "pg_ctl status". "man
> pg_ctl" is recommended reading for anyone
> administering a PostgreSQL setup.

Is not enough because it check only for the postmaster.pid
and not if the engine is really up.

Regards
Gaetano Mendola


From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 00:20:54
Message-ID: 20040920002054.GC15746@phlogiston.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

On Sun, Sep 19, 2004 at 01:12:07PM -0400, Tom Lane wrote:
> > Except that on Solaris, ps -ef _always_ shows "postmaster", even for
> > the individual back ends.
>
> Right, but if you see a backend then you can figure the system is up.

Oops, good point. (And in any case, on Solaris you also have the ucb
ps, so it makes no difference.)

A

--
Andrew Sullivan | ajs(at)crankycanuck(dot)ca
The fact that technology doesn't work is no bar to success in the marketplace.
--Philip Greenspun


From: Worik <worik(at)noggon(dot)com>
To: Gaetano Mendola <mendola(at)bigfoot(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 00:34:59
Message-ID: 414E25B3.9070309@noggon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

[snip]
>
>
> Just to enforce the test is better looking for the entire executable path:
>
> ps aux | grep /usr/bin/postmaster | grep -v grep
>

Does not work for me!

worik(at)stolberg:~$ ps aux | grep /usr/bin/postmaster | grep -v grep
worik(at)stolberg:~$ ps aux | grep postmaster | grep -v grep
postgres 670 0.1 0.6 8544 1688 pts/1 S 12:33 0:00
/usr/lib/postgresql/bin/postmaster
worik(at)stolberg:~$

So...
" ps aux | grep postmaster | grep -v grep "
is more reliable(?)

cheers
Worik

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


From: Worik <worik(at)noggon(dot)com>
To: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 01:04:02
Message-ID: 414E2C82.6050208@noggon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Perhaps I have a bug in pg_ctrl?

This is what I get...

worik(at)stolberg:~$ ps aux | grep postmaster | grep -v grep
;/usr/lib/postgresql/bin/pg_ctl status
postgres 670 0.0 0.6 8544 1688 pts/1 S 12:33 0:00
/usr/lib/postgresql/bin/postmaster
pg_ctl: postmaster or postgres is not running
worik(at)stolberg:~$

cheers
Worik

Jeff Eckermann wrote:
> --- Christopher Browne <cbbrowne(at)acm(dot)org> wrote:
>
>
>>In an attempt to throw the authorities off his
>>trail, sgaikwad(at)vertex(dot)co(dot)in ("Sandeep Gaikwad")
>>transmitted:
>>
>>>Hello Sir,
>>> I want to know how to check
>>
>>whether postgres database
>>
>>>is running or not ? when I give command like
>>
>>./postmaster -i &,
>>
>>>whether all databases in that postgres will run or
>>
>>any one [default] ?
>>
>>>If any one, then how to detect that database ?
>
>
> The "standard" way would be "pg_ctl status". "man
> pg_ctl" is recommended reading for anyone
> administering a PostgreSQL setup.
>
>
>>Well, the way I usually check on what databases are
>>running is thus:
>>
>>cbbrowne(at)wolfe:/tmp/mm5/doc> netstat -an | grep PG
>>
>> Saturday 13:18:30
>>unix 2 [ ACC ] STREAM LISTENING
>>2793 /var/run/postgresql/.s.PGSQL.5432
>>
>>One could presumably script things further to get
>>more out of that; it
>>doesn't normally seem worthwhile to do so...
>>--
>>output = ("cbbrowne" "@" "ntlug.org")
>>http://www.ntlug.org/~cbbrowne/postgresql.html
>>"As long as war is regarded as wicked, it will
>>always have
>> its fascination. When it is looked upon as vulgar,
>> it will cease to be popular."
>> --Oscar Wilde
>>
>>---------------------------(end of
>>broadcast)---------------------------
>>TIP 2: you can get off all lists at once with the
>>unregister command
>> (send "unregister YourEmailAddressHere" to
>>majordomo(at)postgresql(dot)org)
>>
>
>
>
>
>
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match
>
>
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Worik <worik(at)noggon(dot)com>
Cc: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 01:11:31
Message-ID: 1197.1095642691@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Worik <worik(at)noggon(dot)com> writes:
> Perhaps I have a bug in pg_ctrl?

More likely you have the wrong value of PGDATA in your environment
(where "wrong" means "not what that postmaster is using").

regards, tom lane


From: Christopher Browne <cbbrowne(at)acm(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 01:33:00
Message-ID: m3llf5pvw3.fsf@wolfe.cbbrowne.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Clinging to sanity, worik(at)noggon(dot)com (Worik) mumbled into her beard:
> [snip]
>> Just to enforce the test is better looking for the entire executable
>> path:
>> ps aux | grep /usr/bin/postmaster | grep -v grep
>>
>
> Does not work for me!
>
> worik(at)stolberg:~$ ps aux | grep /usr/bin/postmaster | grep -v grep
> worik(at)stolberg:~$ ps aux | grep postmaster | grep -v grep
> postgres 670 0.1 0.6 8544 1688 pts/1 S 12:33 0:00
> /usr/lib/postgresql/bin/postmaster
> worik(at)stolberg:~$
>
> So...
> " ps aux | grep postmaster | grep -v grep "
> is more reliable(?)

There's a very slightly clever modification that gets rid of the extra
grep...

Try..

[appropriate ps command for your platform] | egrep '[p]ostmaster'

That egrep _won't_ match its own command line.
--
let name="cbbrowne" and tld="ntlug.org" in String.concat "@" [name;tld];;
http://www3.sympatico.ca/cbbrowne/multiplexor.html
He doesn't have much of a reputation, or so I've heard.


From: Arne Stoelck <stolck(at)web(dot)de>
To: Sandeep Gaikwad <sgaikwad(at)vertex(dot)co(dot)in>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 02:33:03
Message-ID: Pine.LNX.4.60.0409200431110.3425@aspire
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql


How about a simple

" telnet localhost 5432 " ?

assuming postmaster is listening on that host and port

On Fri, 17 Sep 2004, Sandeep Gaikwad wrote:

>
> Hello Sir,
> I want to know how to check whether postgres database is
> running or not ? when I give command like ./postmaster -i &, whether all
> databases in that postgres will run or any one [default] ? If any one, then
> how to detect that database ?
>
> Thanks and regards,
> Sandeep.
>


From: "Richard Sydney-Smith" <richard(at)ibisaustralia(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Test for file exists?
Date: 2004-09-20 03:16:47
Message-ID: 002a01c49ec0$4527eb50$630736cb@athlon2000
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

I want to use pgsql to send the command:

Copy sometable from 'sometable.csv';

But only if 'sometable.csv' exists;

If 'sometable.csv' does not exist as an input table I want to continue
the next command.

My full procedure is as follows and any help is greatly appreciated.

Thanks

Richard

CREATE OR REPLACE FUNCTION restore_database(text)
RETURNS text AS
$BODY$
declare
tblname record;
cnt record;
tname varchar :='';
tquery varchar :='';
filename varchar :='';

begin
tname := '';
for tblname in select tablename from pg_tables WHERE not(tablename like
'pg_%') and not(tablename like 't_%')
and not(tablename like '%_list') order by tablename loop
raise notice '%',tblname.tablename;
tquery := 'delete from ' || tblname.tablename ;
execute tquery;
filename := '/'||$1||'/'|| lower(tblname.tablename)||'.csv';
tquery := 'copy ' || tblname.tablename || ' from ' ||
quote_literal(filename);
execute tquery;
end loop;

return tquery;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004


From: Reiner Dassing <dassing(at)wettzell(dot)ifag(dot)de>
To: Sandeep Gaikwad <sgaikwad(at)vertex(dot)co(dot)in>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 07:20:03
Message-ID: 414E84A3.8020200@wettzell.ifag.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Hello!

Our check procedure on TRU64 UNIX is:

checkmasterdaemon
if [ $? -eq 1 ]; then
# Try to connect to postgres by selecting tables
TABELLEN=`/pg/postgresql-7.4.3/bin/psql -h postgres -c 'select datname from pg_database' postgres postgres 2>/dev/null`
if [[ "X$TABELLEN" = "X" ]];then
echo "check failed for postmaster"
exit 1
else
# echo "postmaster is running"
fi
else
echo "check failed for postmaster"
exit 1
fi

where :

checkmasterdaemon () {
MASTER_PID=$(getmasterpid)

if [ "X$MASTER_PID" = "X" ]; then
#echo "Postmaster is not running"
ret=0
else
PS_OUT=`ps -o comm,pid -p "${MASTER_PID}"`
PID=`echo $PS_OUT | awk '/postgres/ {print $4}'`
#echo $PID
if [ "X$MASTER_PID" != "X$PID" ]
then
#echo "Postmaster (${MASTER_PID}) does not exist (any more)"
ret=0
else
ret=1
fi
fi
return $ret
}

getmasterpid () {
if [[ -r ${PIDFILE} ]]
then
MASTER_PID=`head -n 1 ${PIDFILE}`
echo $MASTER_PID
else
echo ""
fi
}

--

Mit freundlichen Gruessen / With best regards
Reiner Dassing


From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: Worik <worik(at)noggon(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 10:05:55
Message-ID: 414EAB83.3060600@bigfoot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Worik wrote:
|
|
| [snip]
|
|>
|>
|> Just to enforce the test is better looking for the entire executable
|> path:
|>
|> ps aux | grep /usr/bin/postmaster | grep -v grep
|>
|
| Does not work for me!
|
| worik(at)stolberg:~$ ps aux | grep /usr/bin/postmaster | grep -v grep
| worik(at)stolberg:~$ ps aux | grep postmaster | grep -v grep
| postgres 670 0.1 0.6 8544 1688 pts/1 S 12:33 0:00
| /usr/lib/postgresql/bin/postmaster
| worik(at)stolberg:~$
|
| So...
| " ps aux | grep postmaster | grep -v grep "
| is more reliable(?)

It only depends on your distribution, in your case:

ps aux | grep /usr/lib/postgresql/bin/postmaster | grep -v grep

consider also the if you run different postmaster version in different
location this is the only way I believe

Regards
Gaetano Mendola

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBTquC7UpzwH2SGd4RAiouAKCpvuLSspsTVXCjSLgDZ2ZKQ3gfywCg7rzl
gXkPlq9UanBNjIWpBvPXNwo=
=ZNAY
-----END PGP SIGNATURE-----


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Gaetano Mendola <mendola(at)bigfoot(dot)com>
Cc: Worik <worik(at)noggon(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 11:47:44
Message-ID: 200409201347.44410.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Am Montag, 20. September 2004 12:05 schrieb Gaetano Mendola:
> It only depends on your distribution, in your case:
>
> ps aux | grep /usr/lib/postgresql/bin/postmaster | grep -v grep
>
> consider also the if you run different postmaster version in different
> location this is the only way I believe

Or maybe simply:

$ ps -C postmaster -F
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
postgres 1172 1 0 4339 2160 0 09:14 ? 00:00:00 /usr/lib/postgresql/bin/postmaster -D /var/lib/postgres/data
postgres 1177 1172 0 2039 2776 0 09:14 ? 00:00:00 postgres: stats buffer process
postgres 1178 1177 0 1826 2048 0 09:14 ? 00:00:00 postgres: stats collector process
postgres 9935 1172 0 4443 2848 0 13:46 ? 00:00:00 postgres: pei template1 [local] idle

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 12:19:27
Message-ID: 200409201219.i8KCJRp05291@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Tom Lane wrote:
> At one time there was discussion of writing a "pg_ping" utility program
> to do exactly this, but it still hasn't got done. You can fake it to
> some extent by just running "psql -l >/dev/null" and checking the exit
> code, but this does require supplying a valid username and possibly a
> password (because psql's exit code doesn't distinguish "could not
> connect" from authentication errors).
>
> BTW, "pg_ctl status" doesn't answer this need because it only looks for
> a postmaster.pid file, it doesn't attempt to verify that the postmaster
> is really alive.

Is improving this a TODO item for pg_ctl?

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Theodore Petrosky <tedpet5(at)yahoo(dot)com>
To: Arne Stoelck <stolck(at)web(dot)de>, Sandeep Gaikwad <sgaikwad(at)vertex(dot)co(dot)in>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to check postgres running or not ?
Date: 2004-09-20 13:46:07
Message-ID: 20040920134607.75051.qmail@web41004.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Funny... I set up a little program on my development
machine that queries for the rendezvous name. This way
I know my development machine is running before I try
to connect.

I think zeroconf could be used for this quite
easily...

JMHO

Ted

--- Arne Stoelck <stolck(at)web(dot)de> wrote:

>
> How about a simple
>
> " telnet localhost 5432 " ?
>
> assuming postmaster is listening on that host and
> port
>
>
> On Fri, 17 Sep 2004, Sandeep Gaikwad wrote:
>
> >
> > Hello Sir,
> > I want to know how to check whether
> postgres database is
> > running or not ? when I give command like
> ./postmaster -i &, whether all
> > databases in that postgres will run or any one
> [default] ? If any one, then
> > how to detect that database ?
> >
> > Thanks and regards,
> > Sandeep.
> >
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose
> an index scan if your
> joining column's datatypes do not match
>


__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Test for file exists?
Date: 2004-09-20 16:30:44
Message-ID: 200409200930.44193.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Richard,

> But only if 'sometable.csv' exists;
>
> If 'sometable.csv' does not exist as an input table I want to continue
> the next command.

Sorry, can't be done in plpgsql. Regular procedural languages are
deliberately kept ignorant of the host filesystem in order to prevent
database users from being able to compromise it. It's a security thing.

You could easily write a function in an "untrusted" language, like PL/PerlU or
PL/PythonU, which would test for file existence and return a true/false
value.

--
Josh Berkus
Aglio Database Solutions
San Francisco