Skip site navigation (1) Skip section navigation (2)

Re: Resetting libpq connections after an app error

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Resetting libpq connections after an app error
Date: 2012-07-21 08:55:57
Message-ID: 20120721085557.GA23125@svana.org (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-hackers
On Sat, Jul 21, 2012 at 01:08:58AM +0100, Daniele Varrazzo wrote:
> Hello,
> 
> apologize for bumping the question to -hackers but I got no answer
> from -general. If there is a better ML to post it let me know.
> 
> In a libpq application, if there is an application error between
> PQsendQuery and PQgetResult, is there a way to revert a connection
> back to an usable state (i.e. from transaction status ACTIVE to IDLE)
> without using the network in a blocking way? We are currently doing
> 
>     while (NULL != (res = PQgetResult(conn->pgconn))) {
>         PQclear(res);
>     }
> 
> but this is blocking, and if the error had been caused by the network
> down, we'll just get stuck in a poll() waiting for a timeout.

There is PQreset(), which also exists in a non-blocking variant.

Hope this helps,
-- 
Martijn van Oosterhout   <kleptog(at)svana(dot)org>   http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
   -- Arthur Schopenhauer

In response to

Responses

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2012-07-21 12:57:36
Subject: Re: Using pg_upgrade on log-shipping standby servers
Previous:From: Peter EisentrautDate: 2012-07-21 08:24:21
Subject: Re: Using pg_upgrade on log-shipping standby servers

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group