aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/basebackup.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-01-18 13:47:26 -0500
committerRobert Haas <rhaas@postgresql.org>2022-01-18 13:47:49 -0500
commitcc333f32336f5146b75190f57ef587dff225f565 (patch)
tree8bcc3bf1b50cf4cbfe597a519b37e7aa8fcc5bde /src/backend/replication/basebackup.c
parent3414099c338bf619c00dd82d96f29a9668a3bf07 (diff)
downloadpostgresql-cc333f32336f5146b75190f57ef587dff225f565.tar.gz
postgresql-cc333f32336f5146b75190f57ef587dff225f565.zip
Modify pg_basebackup to use a new COPY subprotocol for base backups.
In the new approach, all files across all tablespaces are sent in a single COPY OUT operation. The CopyData messages are no longer raw archive content; rather, each message is prefixed with a type byte that describes its purpose, e.g. 'n' signifies the start of a new archive and 'd' signifies archive or manifest data. This protocol is significantly more extensible than the old approach, since we can later create more message types, though not without concern for backward compatibility. The new protocol sends a few things to the client that the old one did not. First, it sends the name of each archive explicitly, instead of letting the client compute it. This is intended to make it easier to write future patches that might send archives in a format other that tar (e.g. cpio, pax, tar.gz). Second, it sends explicit progress messages rather than allowing the client to assume that progress is defined by the number of bytes received. This will help with future features where the server compresses the data, or sends it someplace directly rather than transmitting it to the client. The old protocol is still supported for compatibility with previous releases. The new protocol is selected by means of a new TARGET option to the BASE_BACKUP command. Currently, the only supported target is 'client'. Support for additional targets will be added in a later commit. Patch by me. The patch set of which this is a part has had review and/or testing from Jeevan Ladhe, Tushar Ahuja, Suraj Kharage, Dipesh Pandit, and Mark Dilger. Discussion: http://postgr.es/m/CA+TgmoaYZbz0=Yk797aOJwkGJC-LK3iXn+wzzMx7KdwNpZhS5g@mail.gmail.com
Diffstat (limited to 'src/backend/replication/basebackup.c')
-rw-r--r--src/backend/replication/basebackup.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 53dedc73c2a..3afbbe7e02e 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -53,6 +53,12 @@
*/
#define SINK_BUFFER_LENGTH Max(32768, BLCKSZ)
+typedef enum
+{
+ BACKUP_TARGET_COMPAT,
+ BACKUP_TARGET_CLIENT
+} backup_target_type;
+
typedef struct
{
const char *label;
@@ -62,6 +68,7 @@ typedef struct
bool includewal;
uint32 maxrate;
bool sendtblspcmapfile;
+ backup_target_type target;
backup_manifest_option manifest;
pg_checksum_type manifest_checksum_type;
} basebackup_options;
@@ -694,8 +701,10 @@ parse_basebackup_options(List *options, basebackup_options *opt)
bool o_noverify_checksums = false;
bool o_manifest = false;
bool o_manifest_checksums = false;
+ bool o_target = false;
MemSet(opt, 0, sizeof(*opt));
+ opt->target = BACKUP_TARGET_COMPAT;
opt->manifest = MANIFEST_OPTION_NO;
opt->manifest_checksum_type = CHECKSUM_TYPE_CRC32C;
@@ -836,6 +845,22 @@ parse_basebackup_options(List *options, basebackup_options *opt)
optval)));
o_manifest_checksums = true;
}
+ else if (strcmp(defel->defname, "target") == 0)
+ {
+ char *optval = defGetString(defel);
+
+ if (o_target)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("duplicate option \"%s\"", defel->defname)));
+ if (strcmp(optval, "client") == 0)
+ opt->target = BACKUP_TARGET_CLIENT;
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("unrecognized target: \"%s\"", optval)));
+ o_target = true;
+ }
else
ereport(ERROR,
errcode(ERRCODE_SYNTAX_ERROR),
@@ -881,8 +906,15 @@ SendBaseBackup(BaseBackupCmd *cmd)
set_ps_display(activitymsg);
}
- /* Create a basic basebackup sink. */
- sink = bbsink_copytblspc_new();
+ /*
+ * If the TARGET option was specified, then we can use the new copy-stream
+ * protocol. If not, we must fall back to the old and less capable
+ * copy-tablespace protocol.
+ */
+ if (opt.target != BACKUP_TARGET_COMPAT)
+ sink = bbsink_copystream_new();
+ else
+ sink = bbsink_copytblspc_new();
/* Set up network throttling, if client requested it */
if (opt.maxrate > 0)