Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd831af

Browse files
committed
Prevent BASE_BACKUP in the middle of another backup in the same session.
Multiple non-exclusive backups are able to be run conrrently in different sessions. But, in the same session, only one non-exclusive backup can be run at the same moment. If pg_backup_start (pg_start_backup in v14 or before) is called in the middle of another non-exclusive backup in the same session, an error is thrown. However, previously, in logical replication walsender mode, even if that walsender session had already called pg_backup_start and started a non-exclusive backup, it could execute BASE_BACKUP command and start another non-exclusive backup. Which caused subsequent pg_backup_stop to throw an error because BASE_BACKUP unexpectedly reset the session state marked by pg_backup_start. This commit prevents BASE_BACKUP command in the middle of another non-exclusive backup in the same session. Back-patch to all supported branches. Author: Fujii Masao Reviewed-by: Kyotaro Horiguchi, Masahiko Sawada, Michael Paquier, Robert Haas Discussion: https://postgr.es/m/[email protected]
1 parent 26c9e1b commit dd831af

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/backend/replication/basebackup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,12 @@ SendBaseBackup(BaseBackupCmd *cmd)
705705
{
706706
DIR *dir;
707707
basebackup_options opt;
708+
SessionBackupState status = get_backup_status();
709+
710+
if (status == SESSION_BACKUP_NON_EXCLUSIVE)
711+
ereport(ERROR,
712+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
713+
errmsg("a backup is already in progress in this session")));
708714

709715
parse_basebackup_options(cmd->options, &opt);
710716

0 commit comments

Comments
 (0)