aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2021-02-19 22:01:25 +0900
committerFujii Masao <fujii@postgresql.org>2021-02-19 22:01:25 +0900
commitfe06819f105ccea52c12d418c8dbaaaa54377e96 (patch)
treed1cbef17e0709627dd19a6599eed09572ef191e4
parent8a55cb5ba9655ffb1cf0a3042aaa6f5eef8c5a85 (diff)
downloadpostgresql-fe06819f105ccea52c12d418c8dbaaaa54377e96.tar.gz
postgresql-fe06819f105ccea52c12d418c8dbaaaa54377e96.zip
Fix psql's ON_ERROR_ROLLBACK so that it handles COMMIT AND CHAIN.
When ON_ERROR_ROLLBACK is enabled, psql releases a temporary savepoint if it's idle in a valid transaction block after executing a query. But psql doesn't do that after RELEASE or ROLLBACK is executed because a temporary savepoint has already been destroyed in that case. This commit changes psql's ON_ERROR_ROLLBACK so that it doesn't release a temporary savepoint also when COMMIT AND CHAIN is executed. A temporary savepoint doesn't need to be released in that case because COMMIT AND CHAIN also destroys any savepoints defined within the transaction to commit. Otherwise psql tries to release the savepoint that COMMIT AND CHAIN has already destroyed and cause an error "ERROR: savepoint "pg_psql_temporary_savepoint" does not exist". Back-patch to v12 where transaction chaining was added. Reported-by: Arthur Nascimento Author: Arthur Nascimento Reviewed-by: Fujii Masao, Vik Fearing Discussion: https://postgr.es/m/16867-3475744069228158@postgresql.org
-rw-r--r--src/bin/psql/common.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 6f507104f46..925fe34a3fd 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1350,12 +1350,13 @@ SendQuery(const char *query)
/*
* Do nothing if they are messing with savepoints themselves:
- * If the user did RELEASE or ROLLBACK, our savepoint is gone.
- * If they issued a SAVEPOINT, releasing ours would remove
- * theirs.
+ * If the user did COMMIT AND CHAIN, RELEASE or ROLLBACK, our
+ * savepoint is gone. If they issued a SAVEPOINT, releasing
+ * ours would remove theirs.
*/
if (results &&
- (strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 ||
+ (strcmp(PQcmdStatus(results), "COMMIT") == 0 ||
+ strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 ||
strcmp(PQcmdStatus(results), "RELEASE") == 0 ||
strcmp(PQcmdStatus(results), "ROLLBACK") == 0))
svptcmd = NULL;