@@ -61,6 +61,11 @@ typedef struct TablespaceList
61
61
*/
62
62
#define MINIMUM_VERSION_FOR_PG_WAL 100000
63
63
64
+ /*
65
+ * Temporary replication slots are supported from version 10.
66
+ */
67
+ #define MINIMUM_VERSION_FOR_TEMP_SLOTS 100000
68
+
64
69
/*
65
70
* Different ways to include WAL
66
71
*/
@@ -88,6 +93,8 @@ static bool do_sync = true;
88
93
static int standby_message_timeout = 10 * 1000 ;/* 10 sec = default */
89
94
static pg_time_t last_progress_report = 0 ;
90
95
static int32 maxrate = 0 ;/* no limit by default */
96
+ static char * replication_slot = NULL ;
97
+ static bool temp_replication_slot = true;
91
98
92
99
static bool success = false;
93
100
static bool made_new_pgdata = false;
@@ -332,6 +339,7 @@ usage(void)
332
339
printf (_ (" -R, --write-recovery-conf\n"
333
340
" write recovery.conf after backup\n" ));
334
341
printf (_ (" -S, --slot=SLOTNAME replication slot to use\n" ));
342
+ printf (_ (" --no-slot prevent creation of temporary replication slot\n" ));
335
343
printf (_ (" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
336
344
" relocate tablespace in OLDDIR to NEWDIR\n" ));
337
345
printf (_ (" -X, --xlog-method=none|fetch|stream\n"
@@ -460,6 +468,7 @@ typedef struct
460
468
char xlog [MAXPGPATH ];/* directory or tarfile depending on mode */
461
469
char * sysidentifier ;
462
470
int timeline ;
471
+ bool temp_slot ;
463
472
}logstreamer_param ;
464
473
465
474
static int
@@ -479,6 +488,10 @@ LogStreamerMain(logstreamer_param *param)
479
488
stream .do_sync = do_sync ;
480
489
stream .mark_done = true;
481
490
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 ());
482
495
483
496
if (format == 'p' )
484
497
stream .walmethod = CreateWalDirectoryMethod (param -> xlog ,do_sync );
@@ -565,6 +578,11 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
565
578
PQserverVersion (conn )< MINIMUM_VERSION_FOR_PG_WAL ?
566
579
"pg_xlog" :"pg_wal" );
567
580
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 ;
568
586
569
587
if (format == 'p' )
570
588
{
@@ -2063,11 +2081,13 @@ main(int argc, char **argv)
2063
2081
{"verbose" ,no_argument ,NULL ,'v' },
2064
2082
{"progress" ,no_argument ,NULL ,'P' },
2065
2083
{"xlogdir" ,required_argument ,NULL ,1 },
2084
+ {"no-slot" ,no_argument ,NULL ,2 },
2066
2085
{NULL ,0 ,NULL ,0 }
2067
2086
};
2068
2087
int c ;
2069
2088
2070
2089
int option_index ;
2090
+ bool no_slot = false;
2071
2091
2072
2092
progname = get_progname (argv [0 ]);
2073
2093
set_pglocale_pgservice (argv [0 ],PG_TEXTDOMAIN ("pg_basebackup" ));
@@ -2117,7 +2137,16 @@ main(int argc, char **argv)
2117
2137
writerecoveryconf = true;
2118
2138
break ;
2119
2139
case 'S' :
2140
+
2141
+ /*
2142
+ * When specifying replication slot name, use a permanent
2143
+ * slot.
2144
+ */
2120
2145
replication_slot = pg_strdup (optarg );
2146
+ temp_replication_slot = false;
2147
+ break ;
2148
+ case 2 :
2149
+ no_slot = true;
2121
2150
break ;
2122
2151
case 'T' :
2123
2152
tablespace_list_append (optarg );
@@ -2277,7 +2306,7 @@ main(int argc, char **argv)
2277
2306
exit (1 );
2278
2307
}
2279
2308
2280
- if (replication_slot && includewal != STREAM_WAL )
2309
+ if (( replication_slot || no_slot ) && includewal != STREAM_WAL )
2281
2310
{
2282
2311
fprintf (stderr ,
2283
2312
_ ("%s: replication slots can only be used with WAL streaming\n" ),
@@ -2287,6 +2316,20 @@ main(int argc, char **argv)
2287
2316
exit (1 );
2288
2317
}
2289
2318
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
+
2290
2333
if (strcmp (xlog_dir ,"" )!= 0 )
2291
2334
{
2292
2335
if (format != 'p' )