This patch looks reasonable to me. Attached is a top-up patch with a few small fixups.
I suggest to wait for the resolution of the "Replication/backup defaults" thread. I would not want to be in a situation where users who have not been trained to use replication slots now have yet another restart-only parameter to set before they can take a backup. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
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;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers