Given the following libpq code:
PGconn * internalConnection = PQconnectdb("my connection string");
if (PQstatus(internalConnection) != CONNECTION_OK)
{
// return error on failure
}
// Kill all connections
if(0 == PQsendQuery(internalConnection, "SELECT pid, (SELECT pg_terminate_backend(pid)) as killed from pg_stat_activity"))
{
// return error on failure
}
Which does the following:
- Makes a connection to a server.
- Executes a query, killing all of the connections (including this connection).
How can I tell via the client side that the connection has been killed? If I run the following again:
PQstatus(internalConnection)
I still gets CONNECTION_OK
as my result.
Using the MySQL API I can check mysql_ping
on a connection to see if a connection is still open, but on Postgres, there does not seem to be a similar method call (that I could find).
Any suggestions as to how I can determine from the client side if a connection has been killed?