diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 641b3b8f4e..ba7b068501 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -18635,16 +18635,15 @@ postgres=# select pg_start_backup('label_goes_here'); - When executed on a primary, the function also creates a backup history file - in the write-ahead log + The function also creates a backup history file in the write-ahead log archive area. The history file includes the label given to - pg_start_backup, the starting and ending write-ahead log locations for - the backup, and the starting and ending times of the backup. The return - value is the backup's ending write-ahead log location (which again - can be ignored). After recording the ending location, the current - write-ahead log insertion - point is automatically advanced to the next write-ahead log file, so that the - ending write-ahead log file can be archived immediately to complete the backup. + pg_start_backup, the starting and ending write-ahead log + locations for the backup, and the starting and ending times of the backup. + The return value is the backup's ending write-ahead log location (which + again can be ignored). When executed on a primary, the current write-ahead + log insertion point is automatically advanced to the next write-ahead log + file after recording the ending location, so that the ending write-ahead + log file can be archived immediately to complete the backup. diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index df4843f409..0bfe73f6a3 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -10894,10 +10894,9 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p) * pg_control. This is harmless for current uses. * * XXX currently a backup history file is for informational and debug - * purposes only. It's not essential for an online backup. Furthermore, - * even if it's created, it will not be archived during recovery because - * an archiver is not invoked. So it doesn't seem worthwhile to write a - * backup history file during recovery. + * purposes only. It's not essential for an online backup. It gets created + * even during recovery as an archiver can be spawned in this case as + * well. */ if (backup_started_in_recovery) { @@ -10942,49 +10941,48 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p) * valid as soon as archiver moves out the current segment file. */ RequestXLogSwitch(false); + } - XLByteToPrevSeg(stoppoint, _logSegNo); - XLogFileName(stopxlogfilename, stoptli, _logSegNo); - - /* Use the log timezone here, not the session timezone */ - stamp_time = (pg_time_t) time(NULL); - pg_strftime(strfbuf, sizeof(strfbuf), - "%Y-%m-%d %H:%M:%S %Z", - pg_localtime(&stamp_time, log_timezone)); + /* Use the log timezone here, not the session timezone */ + stamp_time = (pg_time_t) time(NULL); + pg_strftime(strfbuf, sizeof(strfbuf), + "%Y-%m-%d %H:%M:%S %Z", + pg_localtime(&stamp_time, log_timezone)); - /* - * Write the backup history file - */ - XLByteToSeg(startpoint, _logSegNo); - BackupHistoryFilePath(histfilepath, stoptli, _logSegNo, - (uint32) (startpoint % XLogSegSize)); - fp = AllocateFile(histfilepath, "w"); - if (!fp) - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not create file \"%s\": %m", - histfilepath))); - fprintf(fp, "START WAL LOCATION: %X/%X (file %s)\n", - (uint32) (startpoint >> 32), (uint32) startpoint, startxlogfilename); - fprintf(fp, "STOP WAL LOCATION: %X/%X (file %s)\n", - (uint32) (stoppoint >> 32), (uint32) stoppoint, stopxlogfilename); - /* transfer remaining lines from label to history file */ - fprintf(fp, "%s", remaining); - fprintf(fp, "STOP TIME: %s\n", strfbuf); - if (fflush(fp) || ferror(fp) || FreeFile(fp)) - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not write file \"%s\": %m", - histfilepath))); + /* + * Write the backup history file + */ + XLByteToPrevSeg(stoppoint, _logSegNo); + XLogFileName(stopxlogfilename, stoptli, _logSegNo); + XLByteToSeg(startpoint, _logSegNo); + BackupHistoryFilePath(histfilepath, stoptli, _logSegNo, + (uint32) (startpoint % XLogSegSize)); + fp = AllocateFile(histfilepath, "w"); + if (!fp) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not create file \"%s\": %m", + histfilepath))); + fprintf(fp, "START WAL LOCATION: %X/%X (file %s)\n", + (uint32) (startpoint >> 32), (uint32) startpoint, startxlogfilename); + fprintf(fp, "STOP WAL LOCATION: %X/%X (file %s)\n", + (uint32) (stoppoint >> 32), (uint32) stoppoint, stopxlogfilename); + /* transfer remaining lines from label to history file */ + fprintf(fp, "%s", remaining); + fprintf(fp, "STOP TIME: %s\n", strfbuf); + if (fflush(fp) || ferror(fp) || FreeFile(fp)) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not write file \"%s\": %m", + histfilepath))); - /* - * Clean out any no-longer-needed history files. As a side effect, - * this will post a .ready file for the newly created history file, - * notifying the archiver that history file may be archived - * immediately. - */ - CleanupBackupHistory(); - } + /* + * Clean out any no-longer-needed history files. As a side effect, + * this will post a .ready file for the newly created history file, + * notifying the archiver that history file may be archived + * immediately. + */ + CleanupBackupHistory(); /* * If archiving is enabled, wait for all the required WAL files to be