diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 596d2ca5836..64a4cfd4ae0 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -9151,6 +9151,35 @@ get_backup_status(void) return sessionBackupState; } +/* + * XLogBackupStatus + * + * Returns true if any backup is currently in progress on this server (across all sessions), + * and optionally returns the LSN of the latest checkpoint redo location used as a starting + * point for an online backup (if lastBackupStart is not NULL). + * + * Note: We must hold WALInsertLock to read runningBackups and lastBackupStart to ensure + * consistent access to the shared memory values. + */ +bool +XLogBackupStatus(XLogRecPtr *lastBackupStart) +{ + bool result; + XLogRecPtr lsn = InvalidXLogRecPtr; + + WALInsertLockAcquireExclusive(); + result = (XLogCtl->Insert.runningBackups > 0); + if (lastBackupStart) + lsn = XLogCtl->Insert.lastBackupStart; + WALInsertLockRelease(); + + if (lastBackupStart) + *lastBackupStart = lsn; + + return result; +} + + /* * do_pg_backup_stop * diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index adddac6710e..c5a326c98e2 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -299,6 +299,7 @@ extern void do_pg_backup_stop(BackupState *state, bool waitforarchive); extern void do_pg_abort_backup(int code, Datum arg); extern void register_persistent_abort_backup_handler(void); extern SessionBackupState get_backup_status(void); +extern bool XLogBackupStatus(XLogRecPtr *lastBackupStart); /* File path names (all relative to $PGDATA) */ #define RECOVERY_SIGNAL_FILE "recovery.signal"