PQstatus() detect change in connection...

From: Matthew Hagerty <mhagerty(at)voyager(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PQstatus() detect change in connection...
Date: 2001-10-18 00:47:09
Message-ID: 5.1.0.14.2.20011017203421.01daad60@pop.voyager.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greetings,

PostgreSQL 7.1.3, FreeBSD-4.3-RELEASE, gcc 2.95.3

I'm trying to attempt to detect a failed backend connection, but a call to
PQstatus() always returns the state of the backend when the call was
made. For example, take this test code:

PGconn *pgConn;
PGresult *pgRes;
int fdPGconn;

int i = 0;
int iNewState = 0;
int iOldState = 60;

pgConn = PQconnectdb("dbname=pglogd user=postgres");

while ( i == 0 )
{
iNewState = PQstatus(pgConn);

if ( iNewState != iOldState )
{
iOldState = iNewState;
printf("Connection State [%d]\n", iNewState);

fdPGconn = PQsocket(pgConn);
printf("Connection Socket [%d]\n", fdPGconn);
}

sleep(1);
}

PQfinish(pgConn);

If you start this with the backend running, the status is CONNECTION_OK,
then pull the plug on the backend, the call to PQstatus() will still return
CONNECTION_OK, even though the backend is not running. Start this program
with the backend not running, then start the backend, PQstatus() never sees
the backend come to life...

Am I reading PQstatus() wrong? Is there any way to detect when the backend
goes down or comes back up?

Thanks,
Matthew

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Korshunov Ilya 2001-10-18 00:48:58 may be bug in pg_dumpall in 7.0.3
Previous Message Bruce Momjian 2001-10-17 22:34:34 Re: To Postgres Devs : Wouldn't changing the select limit