Re: PQstatus does not seem to work

From: Tim Hart <tjhart(at)mac(dot)com>
To: Sam Mason <sam(at)samason(dot)me(dot)uk>, pgsql-general(at)postgresql(dot)org, Juan Backson <juanbackson(at)gmail(dot)com>
Subject: Re: PQstatus does not seem to work
Date: 2009-08-10 18:02:06
Message-ID: C6A5CACE.16CCA%tjhart@mac.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 8/10/09 12:08 PM, "Sam Mason" <sam(at)samason(dot)me(dot)uk> wrote:

> On Tue, Aug 11, 2009 at 12:41:47AM +0800, Juan Backson wrote:
>> I used PQstatus(conn) function to check connection status, but I found that
>> it still returns CONNECTION_OK even after postgres is restarted. Does
>> anyone know if there is another command that I can use to check connection
>> status?
>
> Yes, PQstatus just gives back the last status. It doesn't go off and
> check anything.
>
>> What other solution is available to check whether a connection is still
>> alive?
>
> As a connection can go down at any time, this doesn't seem useful. Just
> send off your request as normal and if it fails because the connection
> was closed then you can open a new one and try again.

Depending on your situation, connection pooling might be a reasonable
option. Instead of managing the connections yourself, you leave that to
another process entirely.

http://www.revsys.com/writings/postgresql-performance.html

Look at the section on "Stateless Applications"

I spend a lot of time writing stateless apps that server many 'users'
concurrently. For me, the pooling idea is much simpler because I only
interact with the 'pool', and the pool manages opening and closing
connections on my behalf.

Of course, this is not a good option if you're writing a stateful app. Your
original email didn't say either way, so this is a take on the other side of
the problem.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim Michaels 2009-08-10 20:03:16 Re: libpq
Previous Message Scott Marlowe 2009-08-10 17:59:56 Re: using COPY and PARTITON