aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/basebackup.c
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2012-01-25 18:02:04 +0000
committerSimon Riggs <simon@2ndQuadrant.com>2012-01-25 18:02:04 +0000
commit8366c7803ec3d0591cf2d1226fea1fee947d56c3 (patch)
tree6cdd97e2f9352127db470507f4e650fde0ad6f86 /src/backend/replication/basebackup.c
parent74ab96a45ef6259aa6a86a781580edea8488511a (diff)
downloadpostgresql-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.c25
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)