pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix psql's single transaction mode on client-side errors with -c
Date: Mon, 06 Jun 2022 02:08:46 +0000
Message-ID: <E1ny2Af-002uou-UC@gemulon.postgresql.org> (raw)

Fix psql's single transaction mode on client-side errors with -c/-f switches

psql --single-transaction is able to handle multiple -c and -f switches
in a single transaction since d5563d7d, but this had the surprising
behavior of forcing a transaction COMMIT even if psql failed with an
error in the client (for example incorrect path given to \copy), which
would generate an error, but still commit any changes that were already
applied in the backend.  This commit makes the behavior more consistent,
by enforcing a transaction ROLLBACK if any commands fail, both
client-side and backend-side, so as no changes are applied if one error
happens in any of them.

Some tests are added on HEAD to provide some coverage about all that.
Backend-side errors are unreliable as IPC::Run can complain on SIGPIPE
if psql quits before reading a query result, but that should work
properly in the case where any errors come from psql itself, which is
what the original report is about.

Reported-by: Christoph Berg
Author: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/17504-76b68018e130415e@postgresql.org
Backpatch-through: 10

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/157f8739ad18278ca946758b2f274a8109a0aa08

Modified Files
--------------
doc/src/sgml/ref/psql-ref.sgml |  6 ++--
src/bin/psql/startup.c         |  4 ++-
src/bin/psql/t/001_basic.pl    | 64 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 3 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1ny2Af-002uou-UC@gemulon.postgresql.org>
Permalink:  ../E1ny2Af-002uou-UC@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ny2Af-002uou-UC@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Fix psql's single transaction mode on client-side errors with -c
  In-Reply-To: <E1ny2Af-002uou-UC@gemulon.postgresql.org>
  References: <E1ny2Af-002uou-UC@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox