Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fB74x-00077Y-Rr for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Apr 2018 23:10:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fB74u-0001gL-Ir for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Apr 2018 23:10:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fB74u-0001gB-9H for pgsql-bugs@lists.postgresql.org; Tue, 24 Apr 2018 23:10:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fB74r-0001R7-2m for pgsql-bugs@lists.postgresql.org; Tue, 24 Apr 2018 23:10:26 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w3ONAMMj016963; Tue, 24 Apr 2018 19:10:22 -0400 From: Tom Lane To: klaxian@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15170: PQtransactionStatus returns ACTIVE after Empty Commit In-reply-to: <152458855796.19803.13664386145754757782@wrigleys.postgresql.org> References: <152458855796.19803.13664386145754757782@wrigleys.postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Tue, 24 Apr 2018 16:49:17 -0000" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <16903.1524611361.0@sss.pgh.pa.us> Date: Tue, 24 Apr 2018 19:10:22 -0400 Message-ID: <16961.1524611422@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16903.1524611361.1@sss.pgh.pa.us> =?utf-8?q?PG_Bug_reporting_form?= 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 ------- =_aaaaaaaaaa0 Content-Type: text/x-c; name="trans-status-test.c"; charset="us-ascii" Content-ID: <16903.1524611361.2@sss.pgh.pa.us> Content-Description: trans-status-test.c #include #include #include "libpq-fe.h" static void exit_nicely(PGconn *conn) { PQfinish(conn); exit(1); } int main(int argc, char **argv) { const char *conninfo; PGconn *conn; PGresult *res; if (argc > 1) conninfo = argv[1]; else conninfo = "dbname = postgres user = postgres"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); /* Check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn)); exit_nicely(conn); } printf("Initial PQtransactionStatus: %d\n", PQtransactionStatus(conn)); res = PQexec(conn, "BEGIN"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "BEGIN failed: %s", PQerrorMessage(conn)); PQclear(res); exit_nicely(conn); } PQclear(res); printf("PQtransactionStatus after BEGIN: %d\n", PQtransactionStatus(conn)); res = PQexec(conn, "COMMIT"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "COMMIT failed: %s", PQerrorMessage(conn)); PQclear(res); exit_nicely(conn); } PQclear(res); printf("PQtransactionStatus after COMMIT: %d\n", PQtransactionStatus(conn)); res = PQexec(conn, "BEGIN; COMMIT"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "BEGIN; COMMIT failed: %s", PQerrorMessage(conn)); PQclear(res); exit_nicely(conn); } PQclear(res); printf("PQtransactionStatus after BEGIN; COMMIT: %d\n", PQtransactionStatus(conn)); /* close the connection to the database and cleanup */ PQfinish(conn); return 0; } ------- =_aaaaaaaaaa0--