Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icsk9-0003rz-0R for pgsql-general@arkaria.postgresql.org; Thu, 05 Dec 2019 15:08:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1icsk7-0004DR-N9 for pgsql-general@arkaria.postgresql.org; Thu, 05 Dec 2019 15:08:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icsgv-0006QQ-Ej for pgsql-general@lists.postgresql.org; Thu, 05 Dec 2019 15:05:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1icsgt-0004Vp-01 for pgsql-general@postgresql.org; Thu, 05 Dec 2019 15:05:16 +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 xB5F5BxS013188; Thu, 5 Dec 2019 10:05:11 -0500 From: Tom Lane To: M Tarkeshwar Rao cc: "'pgsql-general@postgresql.org'" Subject: Re: We have to close the cursor or rollback the transaction in case of failure? In-reply-to: References: Comments: In-reply-to M Tarkeshwar Rao message dated "Thu, 05 Dec 2019 10:00:03 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13186.1575558311.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 05 Dec 2019 10:05:11 -0500 Message-ID: <13187.1575558311@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk M Tarkeshwar Rao writes: > I am using cursors to fetch the data from table using C++. Initially we= re errors as highlighted as "current transaction isaborted" in /var/logs = during full vacuum. > We are little bit confused in failure handling. In case of any failure o= f following function. > PQexec(connection, myFetchSql) > We have to close the cursor or rollback the transaction? Once the transaction has had an error, you have to issue ROLLBACK before you can do anything else. That will automatically close any cursors opened in the current transaction. There's no point in issuing an explicit CLOSE (and indeed, if you try, it'll just produce the same "current transaction is aborted" error). regards, tom lane