473,388 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Checking whether postgresql is running

[Possible duplicate: original sent to novice never got through! -;(]
Hi all!
Testing a script where I need to make sure that postgresql is running
before passing a <psql dbasename -c "insert into ..." > instruction I
faced this curious behaviour:

This is the relevant content of the script:
------------------
#!/bin/bash
/usr/lib/postgresql/bin/pg_ctl status -D /var/lib/postgres/data >/dev/null 2>&1
rtn=$?
if [ $rtn -ne 0 ]; then
echo "not running"
else
echo "ok ok"
fi

Now, if I run the script as root, I get:

ok ok

(or, commenting the script if condition:
pg_ctl: postmaster is running (pid: 18658)
Command line was:
/usr/lib/postgresql/bin/postmasteir)

whereas, if I run the same script as ordinary user, the answer is:

not running

(or, commenting the if lines:
pg_ctl: postmaster or postgres is not running)

--------------
Everything is being tested on the same PC [running PG 7.2.1-2Woody5
under GNU/Linux, k. 2.2.22], root being on /dev/tty1, user on
/dev/tty2, and postgresql not being stopped while switching from root
to user :-).
Could anybody throw some light on this issue?
Thanks for your attention,
Ennio.
--
[Perche' usare Win$ozz (dico io) se ..."anche uno sciocco sa farlo. \\?//
Fa' qualche cosa di cui non sei capace!" (diceva Henry Miller) ] (°|°)
[Why to use Win$ozz (I say) if ... "even a fool can do that. )=(
Do something you aren't good at!" (used to say Henry Miller) ]

--
[Perche' usare Win$ozz (dico io) se ..."anche uno sciocco sa farlo. \\?//
Fa' qualche cosa di cui non sei capace!" (diceva Henry Miller) ] (°|°)
[Why to use Win$ozz (I say) if ... "even a fool can do that. )=(
Do something you aren't good at!" (used to say Henry Miller) ]

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

Nov 23 '05 #1
1 5740
Ennio-Sr wrote:
[Possible duplicate: original sent to novice never got through! -;(]
Hi all!
Testing a script where I need to make sure that postgresql is running
before passing a <psql dbasename -c "insert into ..." > instruction I
faced this curious behaviour:

This is the relevant content of the script:
------------------
#!/bin/bash
/usr/lib/postgresql/bin/pg_ctl status -D /var/lib/postgres/data >/dev/null 2>&1
rtn=$?
if [ $rtn -ne 0 ]; then
echo "not running"
else
echo "ok ok"
fi

Now, if I run the script as root, I get:

ok ok

(or, commenting the script if condition:
pg_ctl: postmaster is running (pid: 18658)
Command line was:
/usr/lib/postgresql/bin/postmasteir)

whereas, if I run the same script as ordinary user, the answer is:

not running

(or, commenting the if lines:
pg_ctl: postmaster or postgres is not running)

--------------
Everything is being tested on the same PC [running PG 7.2.1-2Woody5
under GNU/Linux, k. 2.2.22], root being on /dev/tty1, user on
/dev/tty2, and postgresql not being stopped while switching from root
to user :-).
Could anybody throw some light on this issue?


Though I don't read Perl at all, so I haven't the
slightest idea about what's in the if, I think I
can shed some light on the issue...

When you execute pg_ctl -D /var/lib/postgres/data,
the command fails -- you can not access the directory
/var/lib/postgres/data to go and pickup the file
postgres.pid (I think that's the filename) to check
if that PID is running. So, without understanding
that gibberish inside the if, I bet that it simply
is returning some error code that is causing the
"not running" part of the if to be executed.

You have to be user postgres or superuser to be
able to use pg_ctl to verify if postmaster is
running.

A "loose check" would be executing the command
"ps -C postgres" and see if there's any output.

Or, simply use the PG client library -- you will
get an error message saying that postmaster is
not running on the specified port.

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

http://archives.postgresql.org

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Deepak Sarda | last post by:
Hello everyone. I have run into something which I believe is a bug or a shortcoming of the threading.Thread module. My program spawns 15 threads. For this I've creating a new class with...
0
by: Bill J. | last post by:
I have to update a PostgreSQL linked server through MSSQL2K. I first configured the connection with ODBC as follows and I can do queries with no problem: EXEC sp_droplinkedsrvlogin @rmtsrvname...
0
by: Bill J. | last post by:
I have to update a PostgreSQL linked server through MSSQL2K. I first configured the connection with ODBC as follows and I can do queries with no problem: EXEC sp_droplinkedsrvlogin @rmtsrvname...
30
by: Michael B Allen | last post by:
I have a general purpose library that has a lot of checks for bad input parameters like: void * linkedlist_get(struct linkedlist *l, unsigned int idx) { if (l == NULL) { errno = EINVAL;...
5
by: kd | last post by:
Hi All, If the name of a process is known, is it possible to check whether it is in execution? What I did was to fetch all the processes running on the system using Process.GetProcesses() and...
1
by: phil campaigne | last post by:
On Mon, 1 Mar 2004, phil campaigne wrote: >> Nigel J. Andrews wrote: >> > > >>> >On Mon, 1 Mar 2004, Phil Campaigne wrote: >>> > >>> >
17
by: Jim Strickland | last post by:
We currently are running a data intensive web service on a Mac using 4D. The developers of our site are looking at converting this web service to PostgreSQL. We will have a backup of our three...
7
by: pradeep_TP | last post by:
hello all, I want to know how can I check whether a web site us running or not. I have used HttpWebRequest but when I give a web site address, It takes few number of seconds to throw exception...
3
by: w.m.gardella.sambeth | last post by:
Hi all, I am more or less new to Python, and currently am making my first "serious" program. The application is a Clinical History manager (for my wife) which stores its data on a sqlite database....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.