From 8366c7803ec3d0591cf2d1226fea1fee947d56c3 Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Wed, 25 Jan 2012 18:02:04 +0000 Subject: Allow pg_basebackup from standby node with safety checking. Base backup follows recommended procedure, plus goes to great lengths to ensure that partial page writes are avoided. Jun Ishizuka and Fujii Masao, with minor modifications --- src/backend/replication/basebackup.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/backend/replication') diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 2fa1f54613..81203c9f5a 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -180,6 +180,22 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir) ti->path == NULL ? 1 : strlen(ti->path), false); + /* In the main tar, include pg_control last. */ + if (ti->path == NULL) + { + struct stat statbuf; + + if (lstat(XLOG_CONTROL_FILE, &statbuf) != 0) + { + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not stat control file \"%s\": %m", + XLOG_CONTROL_FILE))); + } + + sendFile(XLOG_CONTROL_FILE, XLOG_CONTROL_FILE, &statbuf); + } + /* * If we're including WAL, and this is the main data directory we * don't terminate the tar stream here. Instead, we will append @@ -361,11 +377,6 @@ SendBaseBackup(BaseBackupCmd *cmd) MemoryContext old_context; basebackup_options opt; - if (am_cascading_walsender) - ereport(FATAL, - (errcode(ERRCODE_CANNOT_CONNECT_NOW), - errmsg("recovery is still in progress, can't accept WAL streaming connections for backup"))); - parse_basebackup_options(cmd->options, &opt); backup_context = AllocSetContextCreate(CurrentMemoryContext, @@ -609,6 +620,10 @@ sendDir(char *path, int basepathlen, bool sizeonly) strcmp(pathbuf, "./postmaster.opts") == 0) continue; + /* Skip pg_control here to back up it last */ + if (strcmp(pathbuf, "./global/pg_control") == 0) + continue; + if (lstat(pathbuf, &statbuf) != 0) { if (errno != ENOENT) -- cgit v1.2.1