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


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to