@@ -239,6 +239,7 @@ usage(void)
239239" (in kB/s, or use suffix \"k\" or \"M\")\n" ));
240240printf (_ (" -R, --write-recovery-conf\n"
241241" write recovery.conf after backup\n" ));
242+ printf (_ (" -S, --slot=SLOTNAME replication slot to use\n" ));
242243printf (_ (" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"
243244" relocate tablespace in OLDDIR to NEWDIR\n" ));
244245printf (_ (" -x, --xlog include required WAL files in backup (fetch mode)\n" ));
@@ -1526,6 +1527,13 @@ GenerateRecoveryConf(PGconn *conn)
15261527appendPQExpBuffer (recoveryconfcontents ,"primary_conninfo = '%s'\n" ,escaped );
15271528free (escaped );
15281529
1530+ if (replication_slot )
1531+ {
1532+ escaped = escape_quotes (replication_slot );
1533+ appendPQExpBuffer (recoveryconfcontents ,"primary_slot_name = '%s'\n" ,replication_slot );
1534+ free (escaped );
1535+ }
1536+
15291537if (PQExpBufferBroken (recoveryconfcontents )||
15301538PQExpBufferDataBroken (conninfo_buf ))
15311539{
@@ -1924,6 +1932,7 @@ main(int argc, char **argv)
19241932{"checkpoint" ,required_argument ,NULL ,'c' },
19251933{"max-rate" ,required_argument ,NULL ,'r' },
19261934{"write-recovery-conf" ,no_argument ,NULL ,'R' },
1935+ {"slot" ,required_argument ,NULL ,'S' },
19271936{"tablespace-mapping" ,required_argument ,NULL ,'T' },
19281937{"xlog" ,no_argument ,NULL ,'x' },
19291938{"xlog-method" ,required_argument ,NULL ,'X' },
@@ -1964,7 +1973,7 @@ main(int argc, char **argv)
19641973}
19651974}
19661975
1967- while ((c = getopt_long (argc ,argv ,"D:F:r:RT:xX:l:zZ:d:c:h:p:U:s:wWvP" ,
1976+ while ((c = getopt_long (argc ,argv ,"D:F:r:RT:xX:l:zZ:d:c:h:p:U:s:S: wWvP" ,
19681977long_options ,& option_index ))!= -1 )
19691978{
19701979switch (c )
@@ -1991,6 +2000,9 @@ main(int argc, char **argv)
19912000case 'R' :
19922001writerecoveryconf = true;
19932002break ;
2003+ case 'S' :
2004+ replication_slot = pg_strdup (optarg );
2005+ break ;
19942006case 'T' :
19952007tablespace_list_append (optarg );
19962008break ;
@@ -2155,6 +2167,16 @@ main(int argc, char **argv)
21552167exit (1 );
21562168}
21572169
2170+ if (replication_slot && !streamwal )
2171+ {
2172+ fprintf (stderr ,
2173+ _ ("%s: replication slots can only be used with WAL streaming\n" ),
2174+ progname );
2175+ fprintf (stderr ,_ ("Try \"%s --help\" for more information.\n" ),
2176+ progname );
2177+ exit (1 );
2178+ }
2179+
21582180if (strcmp (xlog_dir ,"" )!= 0 )
21592181{
21602182if (format != 'p' )