summaryrefslogtreecommitdiff
path: root/src/backend/replication/basebackup_copy.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2021-11-16 15:20:50 -0500
committerRobert Haas <rhaas@postgresql.org>2022-01-20 10:46:33 -0500
commit3500ccc39b0dadd1068a03938e4b8ff562587ccc (patch)
tree1c5d639bebf9c9f493a4cebffd59baa4c7dafbb9 /src/backend/replication/basebackup_copy.c
parentf80900be06f784a6bda705800305c550e05d6edf (diff)
Support base backup targets.
pg_basebackup now has a --target=TARGET[:DETAIL] option. If specfied, it is sent to the server as the value of the TARGET option to the BASE_BACKUP command. If DETAIL is included, it is sent as the value of the new TARGET_DETAIL option to the BASE_BACKUP command. If the target is anything other than 'client', pg_basebackup assumes that it will now be the server's job to write the backup in a location somehow defined by the target, and that it therefore needs to write nothing locally. However, the server will still send messages to the client for progress reporting purposes. On the server side, we now support two additional types of backup targets. There is a 'blackhole' target, which just throws away the backup data without doing anything at all with it. Naturally, this should only be used for testing and debugging purposes, since you will not actually have a backup when it finishes running. More usefully, there is also a 'server' target, so you can now use something like 'pg_basebackup -Xnone -t server:/SOME/PATH' to write a backup to some location on the server. We can extend this to more types of targets in the future, and might even want to create an extensibility mechanism for adding new target types. Since WAL fetching is handled with separate client-side logic, it's not part of this mechanism; thus, backups with non-default targets must use -Xnone or -Xfetch. Patch by me, with a bug fix by Jeevan Ladhe. The patch set of which this is a part has also had review and/or testing from 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_copy.c')
-rw-r--r--src/backend/replication/basebackup_copy.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/backend/replication/basebackup_copy.c b/src/backend/replication/basebackup_copy.c
index 8dfdff06449..938e19a6a43 100644
--- a/src/backend/replication/basebackup_copy.c
+++ b/src/backend/replication/basebackup_copy.c
@@ -44,6 +44,9 @@ typedef struct bbsink_copystream
/* Common information for all types of sink. */
bbsink base;
+ /* Are we sending the archives to the client, or somewhere else? */
+ bool send_to_client;
+
/*
* Protocol message buffer. We assemble CopyData protocol messages by
* setting the first character of this buffer to 'd' (archive or manifest
@@ -131,11 +134,12 @@ const bbsink_ops bbsink_copytblspc_ops = {
* Create a new 'copystream' bbsink.
*/
bbsink *
-bbsink_copystream_new(void)
+bbsink_copystream_new(bool send_to_client)
{
bbsink_copystream *sink = palloc0(sizeof(bbsink_copystream));
*((const bbsink_ops **) &sink->base.bbs_ops) = &bbsink_copystream_ops;
+ sink->send_to_client = send_to_client;
/* Set up for periodic progress reporting. */
sink->last_progress_report_time = GetCurrentTimestamp();
@@ -212,8 +216,12 @@ bbsink_copystream_archive_contents(bbsink *sink, size_t len)
StringInfoData buf;
uint64 targetbytes;
- /* Send the archive content to the client (with leading type byte). */
- pq_putmessage('d', mysink->msgbuffer, len + 1);
+ /* Send the archive content to the client, if appropriate. */
+ if (mysink->send_to_client)
+ {
+ /* Add one because we're also sending a leading type byte. */
+ pq_putmessage('d', mysink->msgbuffer, len + 1);
+ }
/* Consider whether to send a progress report to the client. */
targetbytes = mysink->bytes_done_at_last_time_check
@@ -294,8 +302,11 @@ bbsink_copystream_manifest_contents(bbsink *sink, size_t len)
{
bbsink_copystream *mysink = (bbsink_copystream *) sink;
- /* Send the manifest content to the client (with leading type byte). */
- pq_putmessage('d', mysink->msgbuffer, len + 1);
+ if (mysink->send_to_client)
+ {
+ /* Add one because we're also sending a leading type byte. */
+ pq_putmessage('d', mysink->msgbuffer, len + 1);
+ }
}
/*