pg_basebackup_temp_slot2-fixups.patch
text/x-patch
Filename: pg_basebackup_temp_slot2-fixups.patch
Type: text/x-patch
Part: 0
Message:
Re: pg_basebackups and slots
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/pg_basebackup.sgml | 12 | 1 |
| src/bin/pg_basebackup/pg_basebackup.c | 1 | 7 |
| src/bin/pg_basebackup/receivelog.c | 1 | 1 |
diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml
index 5f0efe2239..5c2db2581c 100644
--- a/doc/src/sgml/ref/pg_basebackup.sgml
+++ b/doc/src/sgml/ref/pg_basebackup.sgml
@@ -240,6 +240,11 @@ <title>Options</title>
the server does not remove any necessary WAL data in the time between
the end of the base backup and the start of streaming replication.
</para>
+ <para>
+ If this option is not specified and the server supports temporary
+ replication slots (version 10 and later), then a temporary replication
+ slot is automatically used for WAL streaming.
+ </para>
</listitem>
</varlistentry>
@@ -252,7 +257,13 @@ <title>Options</title>
</para>
<para>
Temporary replication slots are created by default if no slot name
- is given with the <literal>-S</literal> when using log streaming.
+ is given with the option <option>-S</option> when using log streaming.
+ </para>
+ <para>
+ The main purpose of this option is to allow taking a base backup when
+ the server is out of free replication slots. Using replication slots
+ is almost always preferred, because it prevents needed WAL from being
+ removed by the server during the backup.
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 111d113bbf..f443aee631 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -482,13 +482,7 @@ LogStreamerMain(logstreamer_param *param)
stream.replication_slot = replication_slot;
stream.temp_slot = param->temp_slot;
if (stream.temp_slot && !stream.replication_slot)
- {
- /* Generate a name for the temporary slot */
- char name[32];
-
- snprintf(name, sizeof(name), "pg_basebackup_%d", getpid());
- stream.replication_slot = pstrdup(name);
- }
+ stream.replication_slot = psprintf("pg_basebackup_%d", (int) getpid());
if (format == 'p')
stream.walmethod = CreateWalDirectoryMethod(param->xlog, do_sync);
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 72f3339c91..55612832a6 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -519,7 +519,7 @@ ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
res = PQexec(conn, query);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr, _("%s: could not create temporary replication slot \"%s\": %s\n"),
+ fprintf(stderr, _("%s: could not create temporary replication slot \"%s\": %s"),
progname, stream->replication_slot, PQerrorMessage(conn));
PQclear(res);
return false;