Lists: | pgsql-general |
---|
From: | Michael Kichanov <mike(at)nordlink(dot)ru> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | connection watchdog |
Date: | 2002-10-10 14:45:18 |
Message-ID: | 200210101445.SAA23167@mix.nordlink.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hi Postgres gurus!
How can I check from C-program whether connection to pgsql
engine still works or already lost?
PQstatus() returns CONNECTION_OK even when backend process is killed
by hands after connection is made.
ps: Searching through pgsql-mail-lists archive and Faq gave nothing.
thanx in advance,
mike
From: | "Shridhar Daithankar" <shridhar_daithankar(at)persistent(dot)co(dot)in> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: connection watchdog |
Date: | 2002-10-10 14:52:17 |
Message-ID: | 3DA5E179.1343.527B6FC@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On 10 Oct 2002 at 18:45, Michael Kichanov wrote:
> Hi Postgres gurus!
>
> How can I check from C-program whether connection to pgsql
> engine still works or already lost?
> PQstatus() returns CONNECTION_OK even when backend process is killed
> by hands after connection is made.
There is a function which returns fd of the connection to postgresql database.
If you install a SIGPIPE handler on that connections, perhaps you can catch the
signal that backend is killed. But you will get that signal only when you
attempt to write to the fd, according to 'man 7 signal' on my mandrake box.
Just theory. Try it out and let us know if it works..
HTH
Bye
Shridhar
--
Preudhomme's Law of Window Cleaning: It's on the other side.
From: | frbn <frbn(at)efbs-seafrigo(dot)fr> |
---|---|
To: | Michael Kichanov <mike(at)nordlink(dot)ru>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: connection watchdog |
Date: | 2002-10-10 15:02:54 |
Message-ID: | 3DA5969E.2050000@efbs-seafrigo.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Michael Kichanov wrote:
> Hi Postgres gurus!
>
> How can I check from C-program whether connection to pgsql
> engine still works or already lost?
> PQstatus() returns CONNECTION_OK even when backend process is killed
> by hands after connection is made.
> ps: Searching through pgsql-mail-lists archive and Faq gave nothing.
I think you can't know if a connection is ok before trying to send
a query to the server (IMHO)
If you really want to know before, you can send a simple query (select '1')
and test the PGResult
(!= PGRES_COMMAND_OK or !=PGRES_TUPLES_OK or ==PGRES_BAD_RESPONSE or ==PGRES_FATAL_ERROR)
From: | Michael Kichanov <mike(at)nordlink(dot)ru> |
---|---|
To: | |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: connection watchdog |
Date: | 2002-10-10 15:28:59 |
Message-ID: | 200210101528.TAA29458@mix.nordlink.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
> > How can I check from C-program whether connection to pgsql
> > engine still works or already lost?
> > PQstatus() returns CONNECTION_OK even when backend process is killed
> > by hands after connection is made.
>
> There is a function which returns fd of the connection to postgresql database.
> If you install a SIGPIPE handler on that connections, perhaps you can catch the
> signal that backend is killed. But you will get that signal only when you
> attempt to write to the fd, according to 'man 7 signal' on my mandrake box.
>
> Just theory. Try it out and let us know if it works..
The point is that I don't want to use an interface level lower
than libpq interface level. At present I using a common "select 1" query
(via PQexec()) with check it reslut for this purpose. But this method
results in growing pgsql log and needless load of PG engine.
> Bye
> Shridhar
mike
From: | "Shridhar Daithankar" <shridhar_daithankar(at)persistent(dot)co(dot)in> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: connection watchdog |
Date: | 2002-10-10 15:34:58 |
Message-ID: | 3DA5EB7A.16957.54EC90F@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
On 10 Oct 2002 at 19:28, Michael Kichanov wrote:
> > > How can I check from C-program whether connection to pgsql
> > > engine still works or already lost?
> > > PQstatus() returns CONNECTION_OK even when backend process is killed
> > > by hands after connection is made.
> >
> > There is a function which returns fd of the connection to postgresql database.
> > If you install a SIGPIPE handler on that connections, perhaps you can catch the
> > signal that backend is killed. But you will get that signal only when you
> > attempt to write to the fd, according to 'man 7 signal' on my mandrake box.
> >
> > Just theory. Try it out and let us know if it works..
>
> The point is that I don't want to use an interface level lower
> than libpq interface level. At present I using a common "select 1" query
> (via PQexec()) with check it reslut for this purpose. But this method
> results in growing pgsql log and needless load of PG engine.
Well, I don't see any other way out. So if you want it, you should try this
out. Or dig aroung libpq source code to check what exact error it would throw
if the server side socket is closed.
HTH
Bye
Shridhar
--
He's dead, Jim. -- McCoy, "The Devil in the Dark", stardate 3196.1
From: | Michael Kichanov <mike(at)nordlink(dot)ru> |
---|---|
To: | frbn(at)efbs-seafrigo(dot)fr (frbn) |
Cc: | mike(at)nordlink(dot)ru, pgsql-general(at)postgresql(dot)org |
Subject: | Re: connection watchdog |
Date: | 2002-10-10 15:43:06 |
Message-ID: | 200210101543.TAA02419@mix.nordlink.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
> > How can I check from C-program whether connection to pgsql
> > engine still works or already lost?
> > PQstatus() returns CONNECTION_OK even when backend process is killed
> > by hands after connection is made.
>
> > ps: Searching through pgsql-mail-lists archive and Faq gave nothing.
>
> I think you can't know if a connection is ok before trying to send
> a query to the server (IMHO)
>
> If you really want to know before, you can send a simple query (select '1')
> and test the PGResult
> (!= PGRES_COMMAND_OK or !=PGRES_TUPLES_OK or ==PGRES_BAD_RESPONSE or ==PGRES_FATAL_ERROR)
thanx, but now I doing just this thing :)
and I would need something like PQping() ;)
mike
From: | "Magnus Naeslund(f)" <mag(at)fbab(dot)net> |
---|---|
To: | "frbn" <frbn(at)efbs-seafrigo(dot)fr>, "Michael Kichanov" <mike(at)nordlink(dot)ru> |
Cc: | <mike(at)nordlink(dot)ru>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: connection watchdog |
Date: | 2002-10-10 18:15:05 |
Message-ID: | 08fb01c27088$f564c3c0$f80c0a0a@mnd |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Michael Kichanov <mike(at)nordlink(dot)ru> wrote:
>
> thanx, but now I doing just this thing :)
> and I would need something like PQping() ;)
>
> mike
>
In our listen/notify cache i just collect the socket and select() on it.
When it returns we do a PQconsumeInput(conn); i think that catches a
backend being killed for example.
Magnus
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Programmer/Networker [|] Magnus Naeslund
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-