Re: Catching server shutdown in C

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Graeme Hinchliffe <graeme(dot)hinchliffe(at)zeninternet(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Catching server shutdown in C
Date: 2004-08-23 13:35:38
Message-ID: 20040823133537.GD4765@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ennio-Sr 2004-08-23 13:59:40 Checking whether postgresql is running
Previous Message Martijn van Oosterhout 2004-08-23 13:29:08 Re: Greatest/Least functions?