aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorTeodor Sigaev <teodor@sigaev.ru>2017-03-24 13:53:40 +0300
committerTeodor Sigaev <teodor@sigaev.ru>2017-03-24 13:53:40 +0300
commit78874531baf99769468dedfff19aa7e2068bc5e5 (patch)
treeab0fc9106324635b142052430035f6dc4de0d576 /src/backend/access/transam/xlog.c
parent457a4448732881b5008f7a3bcca76fc299075ac3 (diff)
downloadpostgresql-78874531baf99769468dedfff19aa7e2068bc5e5.tar.gz
postgresql-78874531baf99769468dedfff19aa7e2068bc5e5.zip
Fix backup canceling
Assert-enabled build crashes but without asserts it works by wrong way: it may not reset forcing full page write and preventing from starting exclusive backup with the same name as cancelled. Patch replaces pair of booleans nonexclusive_backup_running/exclusive_backup_running to single enum to correctly describe backup state. Backpatch to 9.6 where bug was introduced Reported-by: David Steele Authors: Michael Paquier, David Steele Reviewed-by: Anastasia Lubennikova https://commitfest.postgresql.org/13/1068/
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index b99ded5df67..58790e0e96e 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -504,6 +504,12 @@ typedef enum ExclusiveBackupState
} ExclusiveBackupState;
/*
+ * Session status of running backup, used for sanity checks in SQL-callable
+ * functions to start and stop backups.
+ */
+static SessionBackupState sessionBackupState = SESSION_BACKUP_NONE;
+
+/*
* Shared state data for WAL insertion.
*/
typedef struct XLogCtlInsert
@@ -10566,13 +10572,17 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
/*
* Mark that start phase has correctly finished for an exclusive backup.
+ * Session-level locks are updated as well to reflect that state.
*/
if (exclusive)
{
WALInsertLockAcquireExclusive();
XLogCtl->Insert.exclusiveBackupState = EXCLUSIVE_BACKUP_IN_PROGRESS;
WALInsertLockRelease();
+ sessionBackupState = SESSION_BACKUP_EXCLUSIVE;
}
+ else
+ sessionBackupState = SESSION_BACKUP_NON_EXCLUSIVE;
/*
* We're done. As a convenience, return the starting WAL location.
@@ -10628,6 +10638,15 @@ pg_stop_backup_callback(int code, Datum arg)
}
/*
+ * Utility routine to fetch the session-level status of a backup running.
+ */
+SessionBackupState
+get_backup_status(void)
+{
+ return sessionBackupState;
+}
+
+/*
* do_pg_stop_backup is the workhorse of the user-visible pg_stop_backup()
* function.
*
@@ -10794,6 +10813,9 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
}
WALInsertLockRelease();
+ /* Clean up session-level lock */
+ sessionBackupState = SESSION_BACKUP_NONE;
+
/*
* Read and parse the START WAL LOCATION line (this code is pretty crude,
* but we are not expecting any variability in the file format).