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

Re: Resetting libpq connections after an app error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Resetting libpq connections after an app error
Date: 2012-07-21 16:36:04
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> On Sat, Jul 21, 2012 at 01:08:58AM +0100, Daniele Varrazzo wrote:
>> 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

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

Note that PQreset essentially kills the connection and establishes a new
one, which might not be what Daniele is looking for.  The alternative
approach is to issue PQcancel and then just let the query flush out as
you normally would in an async application, ie PQisBusy/PQconsumeInput
until ready, then PQgetResult (which you throw away), repeat until you
get NULL.

			regards, tom lane

In response to


pgsql-hackers by date

Next:From: Tom LaneDate: 2012-07-21 17:05:16
Subject: Re: 9.2 release schedule
Previous:From: Robert HaasDate: 2012-07-21 16:01:27
Subject: Re: Event Triggers reduced, v1

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