Re: Connecting to a postgreSQL database with windows CE over wi-fi; failing gracefully

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Connecting to a postgreSQL database with windows CE over wi-fi; failing gracefully
Date: 2009-05-01 14:25:40
Message-ID: 10725.1241187940@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com> writes:
> I'm developing a PostgreSQL application for Windows CE 5 on a PDT/ PDA
> in C++/Qt, using Hiroshi Saito's libpq port for that platform. Since
> the connection is established over wi-fi, and wi-fi connectivity is
> often flaky, I feel that I have to "fail gracefully" to as great an
> extent as possible. The following utility function,
> VerifyDbConnection(), is called before every piece of database work:

> void MainInterface::VerifyDbConnection()
> {
> if (PQstatus(conn) != CONNECTION_OK)
> {
> ... try to recover ...
> }
> }

PQstatus does *not* probe to see if there's a live connection to the
database; it just returns the state left behind by the last operation.
So this code will just fall through and not do anything useful until
after you've already had a failure. The forcible PQreset is probably
not the most graceful way of recovering, either.

What I'd try is a "ping" to the database server, and not initiate any
libpq operation unless the server is answering pings. If you get
a failure due to connectivity loss midway through an operation,
PQreset is appropriate then --- but don't do it to recover from
a momentary network outage.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-05-01 15:04:24 Re: recover corrupt DB?
Previous Message Dimitri Fontaine 2009-05-01 14:03:40 Fwd: triggers and execute...