diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 86c8b84223b..afad0025699 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -592,8 +592,10 @@ EOF
psql to issue a BEGIN command
before the first such option and a COMMIT command after
the last one, thereby wrapping all the commands into a single
- transaction. This ensures that either all the commands complete
- successfully, or no changes are applied.
+ transaction. If any of the commands fails, a
+ ROLLBACK command is sent instead. This ensures that
+ either all the commands complete successfully, or no changes are
+ applied.
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 67653ae75f8..2f870921ed3 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -416,7 +416,9 @@ main(int argc, char *argv[])
if (options.single_txn)
{
- if ((res = PSQLexec("COMMIT")) == NULL)
+ res = PSQLexec((successResult == EXIT_SUCCESS) ?
+ "COMMIT" : "ROLLBACK");
+ if (res == NULL)
{
if (pset.on_error_stop)
{