Re: [SQL] How to check postgres running or not ?

2004-09-20 Thread Reiner Dassing
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

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [SQL] How to check postgres running or not ?

2004-09-20 Thread Gaetano Mendola
-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!
|
| [EMAIL PROTECTED]:~$ ps aux | grep /usr/bin/postmaster | grep -v grep
| [EMAIL PROTECTED]:~$ ps aux | grep postmaster | grep -v grep
| postgres   670  0.1  0.6  8544 1688 pts/1S12:33   0:00
| /usr/lib/postgresql/bin/postmaster
| [EMAIL PROTECTED]:~$
|
| 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-
---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [SQL] How to check postgres running or not ?

2004-09-20 Thread Peter Eisentraut
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
UIDPID  PPID  CSZ  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/

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [SQL] How to check postgres running or not ?

2004-09-20 Thread Theodore Petrosky
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 [EMAIL PROTECTED] 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

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Geoffrey
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
ATT Certified UNIX System Programmer - 1995
---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Tom Lane
Geoffrey [EMAIL PROTECTED] 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

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Andrew Sullivan
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  | [EMAIL PROTECTED]
In the future this spectacle of the middle classes shocking the avant-
garde will probably become the textbook definition of Postmodernism. 
--Brad Holland

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


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Tom Lane
Andrew Sullivan [EMAIL PROTECTED] 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

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Gaetano Mendola
Jeff Eckermann wrote:
--- Christopher Browne [EMAIL PROTECTED] wrote:

In an attempt to throw the authorities off his
trail, [EMAIL PROTECTED] (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

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Gaetano Mendola
Tom Lane wrote:
Geoffrey [EMAIL PROTECTED] 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




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


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Andrew Sullivan
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  | [EMAIL PROTECTED]
The fact that technology doesn't work is no bar to success in the marketplace.
--Philip Greenspun

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Worik

[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!
[EMAIL PROTECTED]:~$ ps aux | grep /usr/bin/postmaster | grep -v grep
[EMAIL PROTECTED]:~$ ps aux | grep postmaster | grep -v grep
postgres   670  0.1  0.6  8544 1688 pts/1S12:33   0:00 
/usr/lib/postgresql/bin/postmaster
[EMAIL PROTECTED]:~$

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

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Worik
Perhaps I have a bug in pg_ctrl?
This is what I get...
[EMAIL PROTECTED]:~$ ps aux | grep postmaster | grep -v grep 
;/usr/lib/postgresql/bin/pg_ctl status
postgres   670  0.0  0.6  8544 1688 pts/1S12:33   0:00 
/usr/lib/postgresql/bin/postmaster
pg_ctl: postmaster or postgres is not running
[EMAIL PROTECTED]:~$

cheers
Worik
Jeff Eckermann wrote:
--- Christopher Browne [EMAIL PROTECTED] wrote:

In an attempt to throw the authorities off his
trail, [EMAIL PROTECTED] (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:
[EMAIL PROTECTED]:/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
[EMAIL PROTECTED])



___
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

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Tom Lane
Worik [EMAIL PROTECTED] 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

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


Re: [SQL] How to check postgres running or not ?

2004-09-19 Thread Arne Stoelck
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


[SQL] How to check postgres running or not ?

2004-09-18 Thread Sandeep Gaikwad
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


Re: [SQL] How to check postgres running or not ?

2004-09-18 Thread Christopher Browne
In an attempt to throw the authorities off his trail, [EMAIL PROTECTED] (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:

[EMAIL PROTECTED]:/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 [EMAIL PROTECTED])


Re: [SQL] How to check postgres running or not ?

2004-09-18 Thread Gaetano Mendola
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

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [SQL] How to check postgres running or not ?

2004-09-18 Thread Worik
Assuming it is unix  The command
ps xau|grep post
If it is running it will produce output like...
[EMAIL PROTECTED]:~$ ps xau|grep post
postgres   880  0.0  0.2  8580  740 ?SSep07   0:31 
/usr/lib/postgresql/bin/postmaster
postgres   887  0.0  0.2  9536  612 ?SSep07   0:02 postgres: 
stats buffer process
postgres   889  0.0  0.2  8624  632 ?SSep07   0:05 postgres: 
stats collector process
worik25927  0.0  0.2  1612  540 pts/10   S13:54   0:00 grep post
[EMAIL PROTECTED]:~$

If it is not running it will produce output like...
[EMAIL PROTECTED]:~$ ps xau|grep post
worik26094  0.0  0.2  1608  528 pts/10   S13: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
---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
  http://www.postgresql.org/docs/faqs/FAQ.html