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