Re: Catching server shutdown in C - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Catching server shutdown in C
Date
Msg-id 20040823133537.GD4765@svana.org
Whole thread Raw
In response to Catching server shutdown in C  (Graeme Hinchliffe <graeme.hinchliffe@zeninternet.co.uk>)
List pgsql-general
On Mon, Aug 23, 2004 at 09:53:43AM +0100, Graeme Hinchliffe wrote:
> Hiya
>     I am writing a daemon in C which monitors a table stored in postgres.
> I would ideally like the daemon to be able to withstand things such as
> the db connection going away or the db being shutdown, and simply keep
> trying to connect rather than just fall on it's face.
>
>     Is there a way that I can catch a server shutdown/connection loss
> cleanly?  I did a quick search of the mailling list but didn't see
> anything.

Normally when the database exits, clients receive an error on the next
transaction usually. I create a wrapper for query executations which,
when noticing the database has gone, tries to reopen the connection. It
returns unknown if it fails. Not exactly compatable with transactions
though...

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Greatest/Least functions?
Next
From: Christopher Browne
Date:
Subject: Re: postgres replication only some datas