Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit - Mailing list pgsql-bugs

From Rick Gabriel
Subject Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit
Date
Msg-id CACvJEPYbk6_YBpTbub6TVCOjKG32RCf=64xv2MQ3mH8rpBMbPg@mail.gmail.com
Whole thread Raw
In response to Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Thank you for investigating! After digging further, I think I found the problem. It is not technically a bug, but I do have a suggestion to prevent others from running into the same problem.

First, I forgot to mention that I am sending async queries (PQsendQuery). libpq documentation states that PQgetResult() must be called repeatedly until it returns a null pointer. Unfortunately, there is nothing about this requirement in the official docs for PHP's libpq wrapper extension. If I don't call PQgetResult() one more time than I really need, the transaction and connection statuses remain active/busy. Even though PG reports its status as "busy", subsequent queries succeed normally.

I suggest that the connection and transaction states should be updated when all queued async queries are completed, without the extra call to PQgetResult(). What do you think?

On Tue, Apr 24, 2018 at 7:10 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
PG Bug reporting form <noreply@postgresql.org> writes:
> PQtransactionStatus() incorrectly returns PQTRANS_ACTIVE after committing an
> empty transaction block (ie. BEGIN and COMMIT without any other queries).

I do not see that here; for instance, the attached test program prints

Initial PQtransactionStatus: 0
PQtransactionStatus after BEGIN: 2
PQtransactionStatus after COMMIT: 0
PQtransactionStatus after BEGIN; COMMIT: 0

which is what I'd expect (0 is PQTRANS_IDLE, 2 is PQTRANS_INTRANS).
I'd only expect PQTRANS_ACTIVE if libpq thinks a query is still "in
flight", ie the server hasn't returned a command-complete message.

I speculate that either you or PHP have not waited for the commit
response to come back ... but without a concrete example to look at,
it's hard to say more.

                        regards, tom lane


pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #15168: "pg_isready -d" effectively ignores given database name
Next
From: jake
Date:
Subject: Re: BUG #15168: "pg_isready -d" effectively ignores given databasename