diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index ddff903915..2261f78f81 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -426,7 +426,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)
                                {
