@@ -9768,8 +9768,8 @@ XLogFileNameP(TimeLineID tli, XLogSegNo segno)
9768
9768
*/
9769
9769
XLogRecPtr
9770
9770
do_pg_start_backup (const char * backupidstr , bool fast , TimeLineID * starttli_p ,
9771
- char * * labelfile , DIR * tblspcdir , List * * tablespaces ,
9772
- char * * tblspcmapfile , bool infotbssize ,
9771
+ StringInfo labelfile , DIR * tblspcdir , List * * tablespaces ,
9772
+ StringInfo tblspcmapfile , bool infotbssize ,
9773
9773
bool needtblspcmapfile )
9774
9774
{
9775
9775
bool exclusive = (labelfile == NULL );
@@ -9783,8 +9783,6 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
9783
9783
XLogSegNo _logSegNo ;
9784
9784
struct stat stat_buf ;
9785
9785
FILE * fp ;
9786
- StringInfoData labelfbuf ;
9787
- StringInfoData tblspc_mapfbuf ;
9788
9786
9789
9787
backup_started_in_recovery = RecoveryInProgress ();
9790
9788
@@ -9981,7 +9979,8 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
9981
9979
/*
9982
9980
* Construct tablespace_map file
9983
9981
*/
9984
- initStringInfo (& tblspc_mapfbuf );
9982
+ if (exclusive )
9983
+ tblspcmapfile = makeStringInfo ();
9985
9984
9986
9985
datadirpathlen = strlen (DataDir );
9987
9986
@@ -10054,7 +10053,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
10054
10053
if (tablespaces )
10055
10054
* tablespaces = lappend (* tablespaces , ti );
10056
10055
10057
- appendStringInfo (& tblspc_mapfbuf , "%s %s\n" , ti -> oid , ti -> path );
10056
+ appendStringInfo (tblspcmapfile , "%s %s\n" , ti -> oid , ti -> path );
10058
10057
10059
10058
pfree (buflinkpath .data );
10060
10059
#else
@@ -10073,23 +10072,24 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
10073
10072
/*
10074
10073
* Construct backup label file
10075
10074
*/
10076
- initStringInfo (& labelfbuf );
10075
+ if (exclusive )
10076
+ labelfile = makeStringInfo ();
10077
10077
10078
10078
/* Use the log timezone here, not the session timezone */
10079
10079
stamp_time = (pg_time_t ) time (NULL );
10080
10080
pg_strftime (strfbuf , sizeof (strfbuf ),
10081
10081
"%Y-%m-%d %H:%M:%S %Z" ,
10082
10082
pg_localtime (& stamp_time , log_timezone ));
10083
- appendStringInfo (& labelfbuf , "START WAL LOCATION: %X/%X (file %s)\n" ,
10083
+ appendStringInfo (labelfile , "START WAL LOCATION: %X/%X (file %s)\n" ,
10084
10084
(uint32 ) (startpoint >> 32 ), (uint32 ) startpoint , xlogfilename );
10085
- appendStringInfo (& labelfbuf , "CHECKPOINT LOCATION: %X/%X\n" ,
10085
+ appendStringInfo (labelfile , "CHECKPOINT LOCATION: %X/%X\n" ,
10086
10086
(uint32 ) (checkpointloc >> 32 ), (uint32 ) checkpointloc );
10087
- appendStringInfo (& labelfbuf , "BACKUP METHOD: %s\n" ,
10087
+ appendStringInfo (labelfile , "BACKUP METHOD: %s\n" ,
10088
10088
exclusive ? "pg_start_backup" : "streamed" );
10089
- appendStringInfo (& labelfbuf , "BACKUP FROM: %s\n" ,
10089
+ appendStringInfo (labelfile , "BACKUP FROM: %s\n" ,
10090
10090
backup_started_in_recovery ? "standby" : "master" );
10091
- appendStringInfo (& labelfbuf , "START TIME: %s\n" , strfbuf );
10092
- appendStringInfo (& labelfbuf , "LABEL: %s\n" , backupidstr );
10091
+ appendStringInfo (labelfile , "START TIME: %s\n" , strfbuf );
10092
+ appendStringInfo (labelfile , "LABEL: %s\n" , backupidstr );
10093
10093
10094
10094
/*
10095
10095
* Okay, write the file, or return its contents to caller.
@@ -10123,7 +10123,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
10123
10123
(errcode_for_file_access (),
10124
10124
errmsg ("could not create file \"%s\": %m" ,
10125
10125
BACKUP_LABEL_FILE )));
10126
- if (fwrite (labelfbuf . data , labelfbuf . len , 1 , fp ) != 1 ||
10126
+ if (fwrite (labelfile -> data , labelfile -> len , 1 , fp ) != 1 ||
10127
10127
fflush (fp ) != 0 ||
10128
10128
pg_fsync (fileno (fp )) != 0 ||
10129
10129
ferror (fp ) ||
@@ -10132,10 +10132,12 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
10132
10132
(errcode_for_file_access (),
10133
10133
errmsg ("could not write file \"%s\": %m" ,
10134
10134
BACKUP_LABEL_FILE )));
10135
- pfree (labelfbuf .data );
10135
+ /* Allocated locally for exclusive backups, so free separately */
10136
+ pfree (labelfile -> data );
10137
+ pfree (labelfile );
10136
10138
10137
10139
/* Write backup tablespace_map file. */
10138
- if (tblspc_mapfbuf . len > 0 )
10140
+ if (tblspcmapfile -> len > 0 )
10139
10141
{
10140
10142
if (stat (TABLESPACE_MAP , & stat_buf ) != 0 )
10141
10143
{
@@ -10159,7 +10161,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
10159
10161
(errcode_for_file_access (),
10160
10162
errmsg ("could not create file \"%s\": %m" ,
10161
10163
TABLESPACE_MAP )));
10162
- if (fwrite (tblspc_mapfbuf . data , tblspc_mapfbuf . len , 1 , fp ) != 1 ||
10164
+ if (fwrite (tblspcmapfile -> data , tblspcmapfile -> len , 1 , fp ) != 1 ||
10163
10165
fflush (fp ) != 0 ||
10164
10166
pg_fsync (fileno (fp )) != 0 ||
10165
10167
ferror (fp ) ||
@@ -10170,13 +10172,9 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
10170
10172
TABLESPACE_MAP )));
10171
10173
}
10172
10174
10173
- pfree (tblspc_mapfbuf .data );
10174
- }
10175
- else
10176
- {
10177
- * labelfile = labelfbuf .data ;
10178
- if (tblspc_mapfbuf .len > 0 )
10179
- * tblspcmapfile = tblspc_mapfbuf .data ;
10175
+ /* Allocated locally for exclusive backups, so free separately */
10176
+ pfree (tblspcmapfile -> data );
10177
+ pfree (tblspcmapfile );
10180
10178
}
10181
10179
}
10182
10180
PG_END_ENSURE_ERROR_CLEANUP (pg_start_backup_callback , (Datum ) BoolGetDatum (exclusive ));
@@ -10283,7 +10281,16 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
10283
10281
*/
10284
10282
WALInsertLockAcquireExclusive ();
10285
10283
if (exclusive )
10284
+ {
10285
+ if (!XLogCtl -> Insert .exclusiveBackup )
10286
+ {
10287
+ WALInsertLockRelease ();
10288
+ ereport (ERROR ,
10289
+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
10290
+ errmsg ("exclusive backup not in progress" )));
10291
+ }
10286
10292
XLogCtl -> Insert .exclusiveBackup = false;
10293
+ }
10287
10294
else
10288
10295
{
10289
10296
/*
0 commit comments