diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2012-01-25 18:02:04 +0000 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2012-01-25 18:02:04 +0000 |
commit | 8366c7803ec3d0591cf2d1226fea1fee947d56c3 (patch) | |
tree | 6cdd97e2f9352127db470507f4e650fde0ad6f86 /src/backend/replication/basebackup.c | |
parent | 74ab96a45ef6259aa6a86a781580edea8488511a (diff) | |
download | postgresql-8366c7803ec3d0591cf2d1226fea1fee947d56c3.tar.gz postgresql-8366c7803ec3d0591cf2d1226fea1fee947d56c3.zip |
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
Diffstat (limited to 'src/backend/replication/basebackup.c')
-rw-r--r-- | src/backend/replication/basebackup.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 2fa1f546135..81203c9f5ac 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) |