Hi,
per suggestion from my colleague Christoph Berg, it seems to make sense
to allow setting the (permanent) replication slot in recovery.conf even
if we don't stream WAL, i.e. allow
pg_basebackup -D foo -R --slot=foo -C -X none
Currently you get an error message "replication slots can only be used
with WAL streaming". If we don't write a recovery.conf, it indeed seems
a bit pointless to allow --slot with -X none, but it should not hurt
either I think.
As physical replication slots are currently created (if requested via
the -C option) in the walstreamer connection, their creation would have
to be moved to the main connection in BaseBackup(), while the temporary
slot creation needs to stay with the walstreamer connection. Peter
Eisentraut also suggested splitting it up like that in 6f0d2862-d33c-9ed
e-1fd2-fc99fc51a...@2ndquadrant.com
The attached patch does that, and relaxes the check to allow --slot with
-X none as long as a recovery.conf is written.
Michael
--
Michael Banck
Projektleiter / Senior Berater
Tel.: +49 2166 9901-171
Fax: +49 2166 9901-100
Email: michael.ba...@credativ.de
credativ GmbH, HRB Mönchengladbach 12080
USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 Mönchengladbach
Geschäftsführung: Dr. Michael Meskes, Jörg Folz, Sascha Heuer
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 1b32592063..e160b21560 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -589,26 +589,19 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
if (PQserverVersion(conn) < MINIMUM_VERSION_FOR_TEMP_SLOTS)
temp_replication_slot = false;
- /*
- * Create replication slot if requested
- */
- if (temp_replication_slot && !replication_slot)
- replication_slot = psprintf("pg_basebackup_%d", (int) PQbackendPID(param->bgconn));
- if (temp_replication_slot || create_slot)
+ /* Create temporary replication slot */
+ if (temp_replication_slot)
{
+ if (!replication_slot)
+ replication_slot = psprintf("pg_basebackup_%d", (int) PQbackendPID(param->bgconn));
+
if (!CreateReplicationSlot(param->bgconn, replication_slot, NULL,
temp_replication_slot, true, true, false))
disconnect_and_exit(1);
if (verbose)
- {
- if (temp_replication_slot)
- fprintf(stderr, _("%s: created temporary replication slot \"%s\"\n"),
- progname, replication_slot);
- else
- fprintf(stderr, _("%s: created replication slot \"%s\"\n"),
- progname, replication_slot);
- }
+ fprintf(stderr, _("%s: created temporary replication slot \"%s\"\n"),
+ progname, replication_slot);
}
if (format == 'p')
@@ -1773,6 +1766,20 @@ BaseBackup(void)
disconnect_and_exit(1);
}
+ /*
+ * Create (permanent) replication slot, if requested
+ */
+ if (!temp_replication_slot && create_slot)
+ {
+ if (!CreateReplicationSlot(conn, replication_slot, NULL,
+ false, true, true, false))
+ disconnect_and_exit(1);
+
+ if (verbose)
+ fprintf(stderr, _("%s: created replication slot \"%s\"\n"),
+ progname, replication_slot);
+ }
+
/*
* Build contents of recovery.conf if requested
*/
@@ -2366,7 +2373,13 @@ main(int argc, char **argv)
exit(1);
}
- if (replication_slot && includewal != STREAM_WAL)
+ /*
+ * If WAL is not streamed, replication slots are not needed for
+ * pg_basebackup's operation. However, if writing recovery.conf is
+ * requested as well, we allow specifying a replication slot so
+ * recovery.conf can include it for convenience.
+ */
+ if (replication_slot && includewal != STREAM_WAL && !writerecoveryconf)
{
fprintf(stderr,
_("%s: replication slots can only be used with WAL streaming\n"),