@@ -93,6 +93,8 @@ static pg_time_t last_progress_report = 0;
93
93
static int32 maxrate = 0 ; /* no limit by default */
94
94
static char * replication_slot = NULL ;
95
95
static bool temp_replication_slot = true;
96
+ static bool create_slot = false;
97
+ static bool no_slot = false;
96
98
97
99
static bool success = false;
98
100
static bool made_new_pgdata = false;
@@ -346,6 +348,7 @@ usage(void)
346
348
printf (_ ("\nGeneral options:\n" ));
347
349
printf (_ (" -c, --checkpoint=fast|spread\n"
348
350
" set fast or spread checkpointing\n" ));
351
+ printf (_ (" -C, --create-slot create replication slot\n" ));
349
352
printf (_ (" -l, --label=LABEL set backup label\n" ));
350
353
printf (_ (" -n, --no-clean do not clean up after errors\n" ));
351
354
printf (_ (" -N, --no-sync do not wait for changes to be written safely to disk\n" ));
@@ -466,7 +469,6 @@ typedef struct
466
469
char xlog [MAXPGPATH ]; /* directory or tarfile depending on mode */
467
470
char * sysidentifier ;
468
471
int timeline ;
469
- bool temp_slot ;
470
472
} logstreamer_param ;
471
473
472
474
static int
@@ -492,9 +494,6 @@ LogStreamerMain(logstreamer_param *param)
492
494
stream .mark_done = true;
493
495
stream .partial_suffix = NULL ;
494
496
stream .replication_slot = replication_slot ;
495
- stream .temp_slot = param -> temp_slot ;
496
- if (stream .temp_slot && !stream .replication_slot )
497
- stream .replication_slot = psprintf ("pg_basebackup_%d" , (int ) PQbackendPID (param -> bgconn ));
498
497
499
498
if (format == 'p' )
500
499
stream .walmethod = CreateWalDirectoryMethod (param -> xlog , 0 , do_sync );
@@ -583,9 +582,29 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
583
582
584
583
/* Temporary replication slots are only supported in 10 and newer */
585
584
if (PQserverVersion (conn ) < MINIMUM_VERSION_FOR_TEMP_SLOTS )
586
- param -> temp_slot = false;
587
- else
588
- param -> temp_slot = temp_replication_slot ;
585
+ temp_replication_slot = false;
586
+
587
+ /*
588
+ * Create replication slot if requested
589
+ */
590
+ if (temp_replication_slot && !replication_slot )
591
+ replication_slot = psprintf ("pg_basebackup_%d" , (int ) PQbackendPID (param -> bgconn ));
592
+ if (temp_replication_slot || create_slot )
593
+ {
594
+ if (!CreateReplicationSlot (param -> bgconn , replication_slot , NULL ,
595
+ temp_replication_slot , true, true, false))
596
+ disconnect_and_exit (1 );
597
+
598
+ if (verbose )
599
+ {
600
+ if (temp_replication_slot )
601
+ fprintf (stderr , _ ("%s: created temporary replication slot \"%s\"\n" ),
602
+ progname , replication_slot );
603
+ else
604
+ fprintf (stderr , _ ("%s: created replication slot \"%s\"\n" ),
605
+ progname , replication_slot );
606
+ }
607
+ }
589
608
590
609
if (format == 'p' )
591
610
{
@@ -2079,6 +2098,7 @@ main(int argc, char **argv)
2079
2098
{"pgdata" , required_argument , NULL , 'D' },
2080
2099
{"format" , required_argument , NULL , 'F' },
2081
2100
{"checkpoint" , required_argument , NULL , 'c' },
2101
+ {"create-slot" , no_argument , NULL , 'C' },
2082
2102
{"max-rate" , required_argument , NULL , 'r' },
2083
2103
{"write-recovery-conf" , no_argument , NULL , 'R' },
2084
2104
{"slot" , required_argument , NULL , 'S' },
@@ -2105,7 +2125,6 @@ main(int argc, char **argv)
2105
2125
int c ;
2106
2126
2107
2127
int option_index ;
2108
- bool no_slot = false;
2109
2128
2110
2129
progname = get_progname (argv [0 ]);
2111
2130
set_pglocale_pgservice (argv [0 ], PG_TEXTDOMAIN ("pg_basebackup" ));
@@ -2127,11 +2146,14 @@ main(int argc, char **argv)
2127
2146
2128
2147
atexit (cleanup_directories_atexit );
2129
2148
2130
- while ((c = getopt_long (argc , argv , "D :F:r:RT: X:l:nNzZ:d:c:h:p:U:s:S :wWvP" ,
2149
+ while ((c = getopt_long (argc , argv , "CD :F:r:RS:T: X:l:nNzZ:d:c:h:p:U:s:wWvP" ,
2131
2150
long_options , & option_index )) != -1 )
2132
2151
{
2133
2152
switch (c )
2134
2153
{
2154
+ case 'C' :
2155
+ create_slot = true;
2156
+ break ;
2135
2157
case 'D' :
2136
2158
basedir = pg_strdup (optarg );
2137
2159
break ;
@@ -2348,6 +2370,29 @@ main(int argc, char **argv)
2348
2370
temp_replication_slot = false;
2349
2371
}
2350
2372
2373
+ if (create_slot )
2374
+ {
2375
+ if (!replication_slot )
2376
+ {
2377
+ fprintf (stderr ,
2378
+ _ ("%s: --create-slot needs a slot to be specified using --slot\n" ),
2379
+ progname );
2380
+ fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ),
2381
+ progname );
2382
+ exit (1 );
2383
+ }
2384
+
2385
+ if (no_slot )
2386
+ {
2387
+ fprintf (stderr ,
2388
+ _ ("%s: --create-slot and --no-slot are incompatible options\n" ),
2389
+ progname );
2390
+ fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ),
2391
+ progname );
2392
+ exit (1 );
2393
+ }
2394
+ }
2395
+
2351
2396
if (xlog_dir )
2352
2397
{
2353
2398
if (format != 'p' )
0 commit comments