@@ -103,6 +103,7 @@ intwal_level = WAL_LEVEL_MINIMAL;
103103int CommitDelay = 0 ;/* precommit delay in microseconds */
104104int CommitSiblings = 5 ;/* # concurrent xacts needed to sleep */
105105int wal_retrieve_retry_interval = 5000 ;
106+ bool cfs_lock_taken = false;
106107
107108TransactionId start_xid = 0 ;
108109MultiXactId start_mx_id = 0 ;
@@ -9894,6 +9895,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
98949895WALInsertLockRelease ();
98959896
98969897cfs_control_gc_lock ();/* disable GC during backup */
9898+ cfs_lock_taken = true;
98979899
98989900/* Ensure we release forcePageWrites if fail below */
98999901PG_ENSURE_ERROR_CLEANUP (pg_start_backup_callback , (Datum )BoolGetDatum (exclusive ));
@@ -10272,7 +10274,11 @@ pg_start_backup_callback(int code, Datum arg)
1027210274}
1027310275WALInsertLockRelease ();
1027410276
10275- cfs_control_gc_unlock ();/* Restore CFS GC activity */
10277+ if (cfs_lock_taken )
10278+ {
10279+ cfs_lock_taken = false;
10280+ cfs_control_gc_unlock ();/* Restore CFS GC activity */
10281+ }
1027610282}
1027710283
1027810284/*
@@ -10472,6 +10478,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
1047210478/* Clean up session-level lock */
1047310479sessionBackupState = SESSION_BACKUP_NONE ;
1047410480
10481+ cfs_lock_taken = false;
1047510482cfs_control_gc_unlock ();/* Restore CFS GC activity */
1047610483
1047710484/*
@@ -10717,7 +10724,11 @@ do_pg_abort_backup(void)
1071710724}
1071810725WALInsertLockRelease ();
1071910726
10720- cfs_control_gc_unlock ();/* Restore CFS GC activity */
10727+ if (cfs_lock_taken )
10728+ {
10729+ cfs_lock_taken = false;
10730+ cfs_control_gc_unlock ();/* Restore CFS GC activity */
10731+ }
1072110732}
1072210733
1072310734/*