PQstatus() detect change in connection... - Mailing list pgsql-hackers

From Matthew Hagerty
Subject PQstatus() detect change in connection...
Date
Msg-id 5.1.0.14.2.20011017203421.01daad60@pop.voyager.net
Whole thread Raw
Responses Re: PQstatus() detect change in connection...
List 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



pgsql-hackers by date:

Previous
From: Dan
Date:
Subject: Re: compiling libpq++ on Solaris with Sun SPRO6U2 (fixed
Next
From: "Christopher Kings-Lynne"
Date:
Subject: Re: pg_sorttemp files