@ -42,8 +42,6 @@
*/
*/
static StringInfo label_file ;
static StringInfo label_file ;
static StringInfo tblspc_map_file ;
static StringInfo tblspc_map_file ;
static bool exclusive_backup_running = false ;
static bool nonexclusive_backup_running = false ;
/*
/*
* Called when the backend exits with a running non - exclusive base backup ,
* Called when the backend exits with a running non - exclusive base backup ,
@ -78,10 +76,11 @@ pg_start_backup(PG_FUNCTION_ARGS)
char * backupidstr ;
char * backupidstr ;
XLogRecPtr startpoint ;
XLogRecPtr startpoint ;
DIR * dir ;
DIR * dir ;
SessionBackupState status = get_backup_status ( ) ;
backupidstr = text_to_cstring ( backupid ) ;
backupidstr = text_to_cstring ( backupid ) ;
if ( exclusive_backup_running | | nonexclusive_backup_running )
if ( status = = SESSION_BACKUP_NON_EXCLUSIVE )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
errmsg ( " a backup is already in progress in this session " ) ) ) ;
errmsg ( " a backup is already in progress in this session " ) ) ) ;
@ -96,7 +95,6 @@ pg_start_backup(PG_FUNCTION_ARGS)
{
{
startpoint = do_pg_start_backup ( backupidstr , fast , NULL , NULL ,
startpoint = do_pg_start_backup ( backupidstr , fast , NULL , NULL ,
dir , NULL , NULL , false , true ) ;
dir , NULL , NULL , false , true ) ;
exclusive_backup_running = true ;
}
}
else
else
{
{
@ -113,7 +111,6 @@ pg_start_backup(PG_FUNCTION_ARGS)
startpoint = do_pg_start_backup ( backupidstr , fast , NULL , label_file ,
startpoint = do_pg_start_backup ( backupidstr , fast , NULL , label_file ,
dir , NULL , tblspc_map_file , false , true ) ;
dir , NULL , tblspc_map_file , false , true ) ;
nonexclusive_backup_running = true ;
before_shmem_exit ( nonexclusive_base_backup_cleanup , ( Datum ) 0 ) ;
before_shmem_exit ( nonexclusive_base_backup_cleanup , ( Datum ) 0 ) ;
}
}
@ -147,8 +144,9 @@ Datum
pg_stop_backup ( PG_FUNCTION_ARGS )
pg_stop_backup ( PG_FUNCTION_ARGS )
{
{
XLogRecPtr stoppoint ;
XLogRecPtr stoppoint ;
SessionBackupState status = get_backup_status ( ) ;
if ( nonexclusive_backup_running )
if ( status = = SESSION_BACKUP_NON_EXCLUSIVE )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
errmsg ( " non-exclusive backup in progress " ) ,
errmsg ( " non-exclusive backup in progress " ) ,
@ -156,14 +154,12 @@ pg_stop_backup(PG_FUNCTION_ARGS)
/*
/*
* Exclusive backups were typically started in a different connection , so
* Exclusive backups were typically started in a different connection , so
* don ' t try to verify that exclusive_backup_running is set in this one .
* don ' t try to verify that status of backup is set to
* Actual verification that an exclusive backup is in fact running is
* SESSION_BACKUP_EXCLUSIVE in this function . Actual verification that an
* handled inside do_pg_stop_backup .
* exclusive backup is in fact running is handled inside do_pg_stop_backup .
*/
*/
stoppoint = do_pg_stop_backup ( NULL , true , NULL ) ;
stoppoint = do_pg_stop_backup ( NULL , true , NULL ) ;
exclusive_backup_running = false ;
PG_RETURN_LSN ( stoppoint ) ;
PG_RETURN_LSN ( stoppoint ) ;
}
}
@ -199,6 +195,7 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
bool exclusive = PG_GETARG_BOOL ( 0 ) ;
bool exclusive = PG_GETARG_BOOL ( 0 ) ;
bool waitforarchive = PG_GETARG_BOOL ( 1 ) ;
bool waitforarchive = PG_GETARG_BOOL ( 1 ) ;
XLogRecPtr stoppoint ;
XLogRecPtr stoppoint ;
SessionBackupState status = get_backup_status ( ) ;
/* check to see if caller supports us returning a tuplestore */
/* check to see if caller supports us returning a tuplestore */
if ( rsinfo = = NULL | | ! IsA ( rsinfo , ReturnSetInfo ) )
if ( rsinfo = = NULL | | ! IsA ( rsinfo , ReturnSetInfo ) )
@ -230,7 +227,7 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
if ( exclusive )
if ( exclusive )
{
{
if ( nonexclusive_backup_running )
if ( status = = SESSION_BACKUP_NON_EXCLUSIVE )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
errmsg ( " non-exclusive backup in progress " ) ,
errmsg ( " non-exclusive backup in progress " ) ,
@ -241,14 +238,13 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
* return NULL for both backup_label and tablespace_map .
* return NULL for both backup_label and tablespace_map .
*/
*/
stoppoint = do_pg_stop_backup ( NULL , waitforarchive , NULL ) ;
stoppoint = do_pg_stop_backup ( NULL , waitforarchive , NULL ) ;
exclusive_backup_running = false ;
nulls [ 1 ] = true ;
nulls [ 1 ] = true ;
nulls [ 2 ] = true ;
nulls [ 2 ] = true ;
}
}
else
else
{
{
if ( ! nonexclusive_backup_running )
if ( status ! = SESSION_BACKUP_NON_EXCLUSIVE )
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
errmsg ( " non-exclusive backup is not in progress " ) ,
errmsg ( " non-exclusive backup is not in progress " ) ,
@ -259,7 +255,6 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
* and tablespace map so they can be written to disk by the caller .
* and tablespace map so they can be written to disk by the caller .
*/
*/
stoppoint = do_pg_stop_backup ( label_file - > data , waitforarchive , NULL ) ;
stoppoint = do_pg_stop_backup ( label_file - > data , waitforarchive , NULL ) ;
nonexclusive_backup_running = false ;
cancel_before_shmem_exit ( nonexclusive_base_backup_cleanup , ( Datum ) 0 ) ;
cancel_before_shmem_exit ( nonexclusive_base_backup_cleanup , ( Datum ) 0 ) ;
values [ 1 ] = CStringGetTextDatum ( label_file - > data ) ;
values [ 1 ] = CStringGetTextDatum ( label_file - > data ) ;