Skip to content

Commit 0d4513b

Browse files
committed
Remove server support for the previous base backup protocol.
Commit cc333f3 added a new COPY sub-protocol for taking base backups, but retained support for the previous protocol. For the same reasons articulated in the message for commit 9cd28c2, remove support for the previous protocol from the server. Discussion: http://postgr.es/m/CA+TgmoazKcKUWtqVa0xZqSzbKgTH+X-aw4V7GyLD68EpDLMh8A@mail.gmail.com
1 parent d37776e commit 0d4513b

File tree

4 files changed

+21
-197
lines changed

4 files changed

+21
-197
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,13 +2634,8 @@ The commands accepted in replication mode are:
26342634
<term><literal>TARGET</literal> <replaceable>'target'</replaceable></term>
26352635
<listitem>
26362636
<para>
2637-
Tells the server where to send the backup. If not specified,
2638-
the legacy base backup protocol will be used. Otherwise, the new
2639-
protocol will be used, as described below.
2640-
</para>
2641-
2642-
<para>
2643-
If the target is <literal>client</literal>, the backup data is
2637+
Tells the server where to send the backup. If the target is
2638+
<literal>client</literal>, which is the default, the backup data is
26442639
sent to the client. If it is <literal>server</literal>, the backup
26452640
data is written to the server at the pathname specified by the
26462641
<literal>TARGET_DETAIL</literal> option. If it is
@@ -2866,25 +2861,8 @@ The commands accepted in replication mode are:
28662861
</para>
28672862

28682863
<para>
2869-
After the second regular result set, one or more CopyOutResponse results
2870-
will be sent. If the <literal>TARGET</literal> option is not specified,
2871-
the legacy base backup protocol will be used. In this mode,
2872-
there will be one CopyOutResponse for the main directory, one for each
2873-
additional tablespace other than <literal>pg_default</literal> and
2874-
<literal>pg_global</literal>, and one for the backup manifested if
2875-
requested. The main data directory and any additional tablespaces will
2876-
be sent in tar format (following the <quote>ustar interchange
2877-
format</quote> specified in the POSIX 1003.1-2008 standard), and
2878-
the manifest will sent as a plain file. Prior to
2879-
<literal>PostgreSQL</literal> 15, the server omitted the two trailing
2880-
blocks of zeroes specified in the standard, but this is no longer the
2881-
case.
2882-
</para>
2883-
2884-
<para>
2885-
New applications should specify the <literal>TARGET</literal> option.
2886-
When that option is used, a single CopyOutResponse will be sent, and
2887-
the payload of each CopyData message will contain a message in one of
2864+
After the second regular result set, a CopyOutResponse will be sent.
2865+
The payload of each CopyData message will contain a message in one of
28882866
the following formats:
28892867
</para>
28902868

@@ -2898,6 +2876,10 @@ The commands accepted in replication mode are:
28982876
<term>Byte1('n')</term>
28992877
<listitem><para>
29002878
Identifes the messaage as indicating the start of a new archive.
2879+
There will be one archive for the main data directory and one
2880+
for each additional tablespace; each will use tar format
2881+
(following the <quote>ustar interchange format</quote> specified
2882+
in the POSIX 1003.1-2008 standard).
29012883
</para></listitem>
29022884
</varlistentry>
29032885
<varlistentry>

src/backend/replication/basebackup.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
typedef enum
5757
{
5858
BACKUP_TARGET_BLACKHOLE,
59-
BACKUP_TARGET_COMPAT,
6059
BACKUP_TARGET_CLIENT,
6160
BACKUP_TARGET_SERVER
6261
} backup_target_type;
@@ -719,7 +718,7 @@ parse_basebackup_options(List *options, basebackup_options *opt)
719718
bool o_compression_level = false;
720719

721720
MemSet(opt, 0, sizeof(*opt));
722-
opt->target = BACKUP_TARGET_COMPAT;
721+
opt->target = BACKUP_TARGET_CLIENT;
723722
opt->manifest = MANIFEST_OPTION_NO;
724723
opt->manifest_checksum_type = CHECKSUM_TYPE_CRC32C;
725724
opt->compression = BACKUP_COMPRESSION_NONE;
@@ -992,16 +991,11 @@ SendBaseBackup(BaseBackupCmd *cmd)
992991
* protocol. If the target is specifically 'client' then set up to stream
993992
* the backup to the client; otherwise, it's being sent someplace else and
994993
* should not be sent to the client.
995-
*
996-
* If the TARGET option was not specified, we must fall back to the older
997-
* and less capable copy-tablespace protocol.
998994
*/
999995
if (opt.target == BACKUP_TARGET_CLIENT)
1000996
sink = bbsink_copystream_new(true);
1001-
else if (opt.target != BACKUP_TARGET_COMPAT)
1002-
sink = bbsink_copystream_new(false);
1003997
else
1004-
sink = bbsink_copytblspc_new();
998+
sink = bbsink_copystream_new(false);
1005999

10061000
/*
10071001
* If a non-default backup target is in use, arrange to send the data
@@ -1012,7 +1006,6 @@ SendBaseBackup(BaseBackupCmd *cmd)
10121006
case BACKUP_TARGET_BLACKHOLE:
10131007
/* Nothing to do, just discard data. */
10141008
break;
1015-
case BACKUP_TARGET_COMPAT:
10161009
case BACKUP_TARGET_CLIENT:
10171010
/* Nothing to do, handling above is sufficient. */
10181011
break;

src/backend/replication/basebackup_copy.c

Lines changed: 11 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@
33
* basebackup_copy.c
44
* send basebackup archives using COPY OUT
55
*
6-
* We have two different ways of doing this.
6+
* We send a result set with information about the tabelspaces to be included
7+
* in the backup before starting COPY OUT. Then, we start a single COPY OUT
8+
* operation and transmits all the archives and the manifest if present during
9+
* the course of that single COPY OUT. Each CopyData message begins with a
10+
* type byte, allowing us to signal the start of a new archive, or the
11+
* manifest, by some means other than ending the COPY stream. This also allows
12+
* for future protocol extensions, since we can include arbitrary information
13+
* in the message stream as long as we're certain that the client will know
14+
* what to do with it.
715
*
8-
* 'copytblspc' is an older method still supported for compatibility
9-
* with releases prior to v15. In this method, a separate COPY OUT
10-
* operation is used for each tablespace. The manifest, if it is sent,
11-
* uses an additional COPY OUT operation.
12-
*
13-
* 'copystream' sends a starts a single COPY OUT operation and transmits
14-
* all the archives and the manifest if present during the course of that
15-
* single COPY OUT. Each CopyData message begins with a type byte,
16-
* allowing us to signal the start of a new archive, or the manifest,
17-
* by some means other than ending the COPY stream. This also allows
18-
* this protocol to be extended more easily, since we can include
19-
* arbitrary information in the message stream as long as we're certain
20-
* that the client will know what to do with it.
21-
*
22-
* Regardless of which method is used, we sent a result set with
23-
* information about the tabelspaces to be included in the backup before
24-
* starting COPY OUT. This result has the same format in every method.
16+
* An older method that sent each archive using a separate COPY OUT
17+
* operation is no longer supported.
2518
*
2619
* Portions Copyright (c) 2010-2022, PostgreSQL Global Development Group
2720
*
@@ -87,20 +80,7 @@ static void bbsink_copystream_end_backup(bbsink *sink, XLogRecPtr endptr,
8780
TimeLineID endtli);
8881
static void bbsink_copystream_cleanup(bbsink *sink);
8982

90-
static void bbsink_copytblspc_begin_backup(bbsink *sink);
91-
static void bbsink_copytblspc_begin_archive(bbsink *sink,
92-
const char *archive_name);
93-
static void bbsink_copytblspc_archive_contents(bbsink *sink, size_t len);
94-
static void bbsink_copytblspc_end_archive(bbsink *sink);
95-
static void bbsink_copytblspc_begin_manifest(bbsink *sink);
96-
static void bbsink_copytblspc_manifest_contents(bbsink *sink, size_t len);
97-
static void bbsink_copytblspc_end_manifest(bbsink *sink);
98-
static void bbsink_copytblspc_end_backup(bbsink *sink, XLogRecPtr endptr,
99-
TimeLineID endtli);
100-
static void bbsink_copytblspc_cleanup(bbsink *sink);
101-
10283
static void SendCopyOutResponse(void);
103-
static void SendCopyData(const char *data, size_t len);
10484
static void SendCopyDone(void);
10585
static void SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli);
10686
static void SendTablespaceList(List *tablespaces);
@@ -118,18 +98,6 @@ const bbsink_ops bbsink_copystream_ops = {
11898
.cleanup = bbsink_copystream_cleanup
11999
};
120100

121-
const bbsink_ops bbsink_copytblspc_ops = {
122-
.begin_backup = bbsink_copytblspc_begin_backup,
123-
.begin_archive = bbsink_copytblspc_begin_archive,
124-
.archive_contents = bbsink_copytblspc_archive_contents,
125-
.end_archive = bbsink_copytblspc_end_archive,
126-
.begin_manifest = bbsink_copytblspc_begin_manifest,
127-
.manifest_contents = bbsink_copytblspc_manifest_contents,
128-
.end_manifest = bbsink_copytblspc_end_manifest,
129-
.end_backup = bbsink_copytblspc_end_backup,
130-
.cleanup = bbsink_copytblspc_cleanup
131-
};
132-
133101
/*
134102
* Create a new 'copystream' bbsink.
135103
*/
@@ -338,115 +306,6 @@ bbsink_copystream_cleanup(bbsink *sink)
338306
/* Nothing to do. */
339307
}
340308

341-
/*
342-
* Create a new 'copytblspc' bbsink.
343-
*/
344-
bbsink *
345-
bbsink_copytblspc_new(void)
346-
{
347-
bbsink *sink = palloc0(sizeof(bbsink));
348-
349-
*((const bbsink_ops **) &sink->bbs_ops) = &bbsink_copytblspc_ops;
350-
351-
return sink;
352-
}
353-
354-
/*
355-
* Begin backup.
356-
*/
357-
static void
358-
bbsink_copytblspc_begin_backup(bbsink *sink)
359-
{
360-
bbsink_state *state = sink->bbs_state;
361-
362-
/* Create a suitable buffer. */
363-
sink->bbs_buffer = palloc(sink->bbs_buffer_length);
364-
365-
/* Tell client the backup start location. */
366-
SendXlogRecPtrResult(state->startptr, state->starttli);
367-
368-
/* Send client a list of tablespaces. */
369-
SendTablespaceList(state->tablespaces);
370-
371-
/* Send a CommandComplete message */
372-
pq_puttextmessage('C', "SELECT");
373-
}
374-
375-
/*
376-
* Each archive is set as a separate stream of COPY data, and thus begins
377-
* with a CopyOutResponse message.
378-
*/
379-
static void
380-
bbsink_copytblspc_begin_archive(bbsink *sink, const char *archive_name)
381-
{
382-
SendCopyOutResponse();
383-
}
384-
385-
/*
386-
* Each chunk of data within the archive is sent as a CopyData message.
387-
*/
388-
static void
389-
bbsink_copytblspc_archive_contents(bbsink *sink, size_t len)
390-
{
391-
SendCopyData(sink->bbs_buffer, len);
392-
}
393-
394-
/*
395-
* The archive is terminated by a CopyDone message.
396-
*/
397-
static void
398-
bbsink_copytblspc_end_archive(bbsink *sink)
399-
{
400-
SendCopyDone();
401-
}
402-
403-
/*
404-
* The backup manifest is sent as a separate stream of COPY data, and thus
405-
* begins with a CopyOutResponse message.
406-
*/
407-
static void
408-
bbsink_copytblspc_begin_manifest(bbsink *sink)
409-
{
410-
SendCopyOutResponse();
411-
}
412-
413-
/*
414-
* Each chunk of manifest data is sent using a CopyData message.
415-
*/
416-
static void
417-
bbsink_copytblspc_manifest_contents(bbsink *sink, size_t len)
418-
{
419-
SendCopyData(sink->bbs_buffer, len);
420-
}
421-
422-
/*
423-
* When we've finished sending the manifest, send a CopyDone message.
424-
*/
425-
static void
426-
bbsink_copytblspc_end_manifest(bbsink *sink)
427-
{
428-
SendCopyDone();
429-
}
430-
431-
/*
432-
* Send end-of-backup wire protocol messages.
433-
*/
434-
static void
435-
bbsink_copytblspc_end_backup(bbsink *sink, XLogRecPtr endptr,
436-
TimeLineID endtli)
437-
{
438-
SendXlogRecPtrResult(endptr, endtli);
439-
}
440-
441-
/*
442-
* Cleanup.
443-
*/
444-
static void
445-
bbsink_copytblspc_cleanup(bbsink *sink)
446-
{
447-
/* Nothing to do. */
448-
}
449-
450309
/*
451310
* Send a CopyOutResponse message.
452311
*/
@@ -461,15 +320,6 @@ SendCopyOutResponse(void)
461320
pq_endmessage(&buf);
462321
}
463322

464-
/*
465-
* Send a CopyData message.
466-
*/
467-
static void
468-
SendCopyData(const char *data, size_t len)
469-
{
470-
pq_putmessage('d', data, len);
471-
}
472-
473323
/*
474324
* Send a CopyDone message.
475325
*/

src/include/replication/basebackup_sink.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ extern void bbsink_forward_cleanup(bbsink *sink);
283283

284284
/* Constructors for various types of sinks. */
285285
extern bbsink *bbsink_copystream_new(bool send_to_client);
286-
extern bbsink *bbsink_copytblspc_new(void);
287286
extern bbsink *bbsink_gzip_new(bbsink *next, int compresslevel);
288287
extern bbsink *bbsink_progress_new(bbsink *next, bool estimate_backup_size);
289288
extern bbsink *bbsink_server_new(bbsink *next, char *pathname);

0 commit comments

Comments
 (0)