43
43
*/
44
44
static StringInfo label_file ;
45
45
static StringInfo tblspc_map_file ;
46
- static bool exclusive_backup_running = false;
47
- static bool nonexclusive_backup_running = false;
48
46
49
47
/*
50
48
* Called when the backend exits with a running non-exclusive base backup,
@@ -79,10 +77,11 @@ pg_start_backup(PG_FUNCTION_ARGS)
79
77
char * backupidstr ;
80
78
XLogRecPtr startpoint ;
81
79
DIR * dir ;
80
+ SessionBackupState status = get_backup_status ();
82
81
83
82
backupidstr = text_to_cstring (backupid );
84
83
85
- if (exclusive_backup_running || nonexclusive_backup_running )
84
+ if (status == SESSION_BACKUP_NON_EXCLUSIVE )
86
85
ereport (ERROR ,
87
86
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
88
87
errmsg ("a backup is already in progress in this session" )));
@@ -97,7 +96,6 @@ pg_start_backup(PG_FUNCTION_ARGS)
97
96
{
98
97
startpoint = do_pg_start_backup (backupidstr , fast , NULL , NULL ,
99
98
dir , NULL , NULL , false, true);
100
- exclusive_backup_running = true;
101
99
}
102
100
else
103
101
{
@@ -114,7 +112,6 @@ pg_start_backup(PG_FUNCTION_ARGS)
114
112
115
113
startpoint = do_pg_start_backup (backupidstr , fast , NULL , label_file ,
116
114
dir , NULL , tblspc_map_file , false, true);
117
- nonexclusive_backup_running = true;
118
115
119
116
before_shmem_exit (nonexclusive_base_backup_cleanup , (Datum ) 0 );
120
117
}
@@ -148,23 +145,22 @@ Datum
148
145
pg_stop_backup (PG_FUNCTION_ARGS )
149
146
{
150
147
XLogRecPtr stoppoint ;
148
+ SessionBackupState status = get_backup_status ();
151
149
152
- if (nonexclusive_backup_running )
150
+ if (status == SESSION_BACKUP_NON_EXCLUSIVE )
153
151
ereport (ERROR ,
154
152
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
155
153
errmsg ("non-exclusive backup in progress" ),
156
154
errhint ("Did you mean to use pg_stop_backup('f')?" )));
157
155
158
156
/*
159
157
* Exclusive backups were typically started in a different connection, so
160
- * don't try to verify that exclusive_backup_running is set in this one.
161
- * Actual verification that an exclusive backup is in fact running is
162
- * handled inside do_pg_stop_backup.
158
+ * don't try to verify that status of backup is set to
159
+ * SESSION_BACKUP_EXCLUSIVE in this function. Actual verification that an
160
+ * exclusive backup is in fact running is handled inside do_pg_stop_backup.
163
161
*/
164
162
stoppoint = do_pg_stop_backup (NULL , true, NULL );
165
163
166
- exclusive_backup_running = false;
167
-
168
164
PG_RETURN_LSN (stoppoint );
169
165
}
170
166
@@ -192,6 +188,7 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
192
188
193
189
bool exclusive = PG_GETARG_BOOL (0 );
194
190
XLogRecPtr stoppoint ;
191
+ SessionBackupState status = get_backup_status ();
195
192
196
193
/* check to see if caller supports us returning a tuplestore */
197
194
if (rsinfo == NULL || !IsA (rsinfo , ReturnSetInfo ))
@@ -223,7 +220,7 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
223
220
224
221
if (exclusive )
225
222
{
226
- if (nonexclusive_backup_running )
223
+ if (status == SESSION_BACKUP_NON_EXCLUSIVE )
227
224
ereport (ERROR ,
228
225
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
229
226
errmsg ("non-exclusive backup in progress" ),
@@ -234,14 +231,13 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
234
231
* return NULL for both backup_label and tablespace_map.
235
232
*/
236
233
stoppoint = do_pg_stop_backup (NULL , true, NULL );
237
- exclusive_backup_running = false;
238
234
239
235
nulls [1 ] = true;
240
236
nulls [2 ] = true;
241
237
}
242
238
else
243
239
{
244
- if (! nonexclusive_backup_running )
240
+ if (status != SESSION_BACKUP_NON_EXCLUSIVE )
245
241
ereport (ERROR ,
246
242
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
247
243
errmsg ("non-exclusive backup is not in progress" ),
@@ -252,7 +248,6 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
252
248
* and tablespace map so they can be written to disk by the caller.
253
249
*/
254
250
stoppoint = do_pg_stop_backup (label_file -> data , true, NULL );
255
- nonexclusive_backup_running = false;
256
251
cancel_before_shmem_exit (nonexclusive_base_backup_cleanup , (Datum ) 0 );
257
252
258
253
values [1 ] = CStringGetTextDatum (label_file -> data );
0 commit comments