@@ -61,6 +61,11 @@ typedef struct TablespaceList
6161 */
6262#define MINIMUM_VERSION_FOR_PG_WAL 100000
6363
64+ /*
65+ * Temporary replication slots are supported from version 10.
66+ */
67+ #define MINIMUM_VERSION_FOR_TEMP_SLOTS 100000
68+
6469/*
6570 * Different ways to include WAL
6671 */
@@ -88,6 +93,8 @@ static bool do_sync = true;
8893static int standby_message_timeout = 10 * 1000 ; /* 10 sec = default */
8994static pg_time_t last_progress_report = 0 ;
9095static int32 maxrate = 0 ; /* no limit by default */
96+ static char * replication_slot = NULL ;
97+ static bool temp_replication_slot = true;
9198
9299static bool success = false;
93100static bool made_new_pgdata = false;
@@ -332,6 +339,7 @@ usage(void)
332339 printf (_ (" -R, --write-recovery-conf\n"
333340 " write recovery.conf after backup\n" ));
334341 printf (_ (" -S, --slot=SLOTNAME replication slot to use\n" ));
342+ printf (_ (" --no-slot prevent creation of temporary replication slot\n" ));
335343 printf (_ (" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
336344 " relocate tablespace in OLDDIR to NEWDIR\n" ));
337345 printf (_ (" -X, --xlog-method=none|fetch|stream\n"
@@ -460,6 +468,7 @@ typedef struct
460468 char xlog [MAXPGPATH ]; /* directory or tarfile depending on mode */
461469 char * sysidentifier ;
462470 int timeline ;
471+ bool temp_slot ;
463472} logstreamer_param ;
464473
465474static int
@@ -479,6 +488,10 @@ LogStreamerMain(logstreamer_param *param)
479488 stream .do_sync = do_sync ;
480489 stream .mark_done = true;
481490 stream .partial_suffix = NULL ;
491+ stream .replication_slot = replication_slot ;
492+ stream .temp_slot = param -> temp_slot ;
493+ if (stream .temp_slot && !stream .replication_slot )
494+ stream .replication_slot = psprintf ("pg_basebackup_%d" , (int ) getpid ());
482495
483496 if (format == 'p' )
484497 stream .walmethod = CreateWalDirectoryMethod (param -> xlog , do_sync );
@@ -565,6 +578,11 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
565578 PQserverVersion (conn ) < MINIMUM_VERSION_FOR_PG_WAL ?
566579 "pg_xlog" : "pg_wal" );
567580
581+ /* Temporary replication slots are only supported in 10 and newer */
582+ if (PQserverVersion (conn ) < MINIMUM_VERSION_FOR_TEMP_SLOTS )
583+ param -> temp_slot = false;
584+ else
585+ param -> temp_slot = temp_replication_slot ;
568586
569587 if (format == 'p' )
570588 {
@@ -2063,11 +2081,13 @@ main(int argc, char **argv)
20632081 {"verbose" , no_argument , NULL , 'v' },
20642082 {"progress" , no_argument , NULL , 'P' },
20652083 {"xlogdir" , required_argument , NULL , 1 },
2084+ {"no-slot" , no_argument , NULL , 2 },
20662085 {NULL , 0 , NULL , 0 }
20672086 };
20682087 int c ;
20692088
20702089 int option_index ;
2090+ bool no_slot = false;
20712091
20722092 progname = get_progname (argv [0 ]);
20732093 set_pglocale_pgservice (argv [0 ], PG_TEXTDOMAIN ("pg_basebackup" ));
@@ -2117,7 +2137,16 @@ main(int argc, char **argv)
21172137 writerecoveryconf = true;
21182138 break ;
21192139 case 'S' :
2140+
2141+ /*
2142+ * When specifying replication slot name, use a permanent
2143+ * slot.
2144+ */
21202145 replication_slot = pg_strdup (optarg );
2146+ temp_replication_slot = false;
2147+ break ;
2148+ case 2 :
2149+ no_slot = true;
21212150 break ;
21222151 case 'T' :
21232152 tablespace_list_append (optarg );
@@ -2277,7 +2306,7 @@ main(int argc, char **argv)
22772306 exit (1 );
22782307 }
22792308
2280- if (replication_slot && includewal != STREAM_WAL )
2309+ if (( replication_slot || no_slot ) && includewal != STREAM_WAL )
22812310 {
22822311 fprintf (stderr ,
22832312 _ ("%s: replication slots can only be used with WAL streaming\n" ),
@@ -2287,6 +2316,20 @@ main(int argc, char **argv)
22872316 exit (1 );
22882317 }
22892318
2319+ if (no_slot )
2320+ {
2321+ if (replication_slot )
2322+ {
2323+ fprintf (stderr ,
2324+ _ ("%s: --no-slot cannot be used with slot name\n" ),
2325+ progname );
2326+ fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ),
2327+ progname );
2328+ exit (1 );
2329+ }
2330+ temp_replication_slot = false;
2331+ }
2332+
22902333 if (strcmp (xlog_dir , "" ) != 0 )
22912334 {
22922335 if (format != 'p' )
0 commit comments