diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml
index 36d16a5..4748d08 100644
--- a/doc/src/sgml/protocol.sgml
+++ b/doc/src/sgml/protocol.sgml
@@ -1837,7 +1837,7 @@ The commands accepted in walsender mode are:
- BASE_BACKUP [LABEL'label'] [PROGRESS] [FAST] [WAL] [NOWAIT] [MAX_RATErate]
+ BASE_BACKUP [LABEL'label'] [PROGRESS] [FAST] [WAL] [NOWAIT] [REPLICATION_SLOT] [MAX_RATErate]
Instructs the server to start streaming a base backup.
@@ -1909,6 +1909,18 @@ The commands accepted in walsender mode are:
+ REPLICATION_SLOT
+
+
+ By default, the backup will not include the replication slot
+ information in pg_replslot> and is created as an
+ empty repository. Specifying REPLICATION_SLOT
+ permits to includes replication slot information in the backup.
+
+
+
+
+ MAX_RATErate>
diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml
index 6ce0c8c..be77f7b 100644
--- a/doc/src/sgml/ref/pg_basebackup.sgml
+++ b/doc/src/sgml/ref/pg_basebackup.sgml
@@ -210,6 +210,17 @@ PostgreSQL documentation
+
+
+
+ Include replication slot information in the base backup. This is added
+ in pg_replslot by default empty if this option is
+ not specified.
+
+
+
+
+
@@ -254,7 +265,7 @@ PostgreSQL documentation
- Specifies the location for the transaction log directory.
+ Specifies the location for the transaction log directory.
xlogdir must be an absolute path.
The transaction log directory can only be specified when
the backup is in plain mode.
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index f611f59..4a86117 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -45,6 +45,7 @@ typedef struct
bool fastcheckpoint;
bool nowait;
bool includewal;
+ bool replication_slot;
uint32 maxrate;
} basebackup_options;
@@ -71,6 +72,9 @@ static bool backup_started_in_recovery = false;
/* Relative path of temporary statistics directory */
static char *statrelpath = NULL;
+/* Include replication slot data in base backup? */
+static bool include_replication_slots = false;
+
/*
* Size of each block sent into the tar stream for larger files.
*/
@@ -131,6 +135,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
datadirpathlen = strlen(DataDir);
backup_started_in_recovery = RecoveryInProgress();
+ include_replication_slots = opt->replication_slot;
startptr = do_pg_start_backup(opt->label, opt->fastcheckpoint, &starttli,
&labelfile);
@@ -548,6 +553,7 @@ parse_basebackup_options(List *options, basebackup_options *opt)
bool o_nowait = false;
bool o_wal = false;
bool o_maxrate = false;
+ bool o_replication_slot = false;
MemSet(opt, 0, sizeof(*opt));
foreach(lopt, options)
@@ -618,6 +624,15 @@ parse_basebackup_options(List *options, basebackup_options *opt)
opt->maxrate = (uint32) maxrate;
o_maxrate = true;
}
+ else if (strcmp(defel->defname, "replication_slot") == 0)
+ {
+ if (o_replication_slot)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("duplicate option \"%s\"", defel->defname)));
+ opt->replication_slot = true;
+ o_replication_slot = true;
+ }
else
elog(ERROR, "option \"%s\" not recognized",
defel->defname);
@@ -984,10 +999,11 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
}
/*
- * Skip pg_replslot, not useful to copy. But include it as an empty
- * directory anyway, so we get permissions right.
+ * Skip pg_replslot and create it as an empty repository if not
+ * requested in the base backup so we get the permissions right.
*/
- if (strcmp(de->d_name, "pg_replslot") == 0)
+ if (!include_replication_slots &&
+ strcmp(pathbuf, "./pg_replslot") == 0)
{
if (!sizeonly)
_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
diff --git a/src/backend/replication/repl_gram.y b/src/backend/replication/repl_gram.y
index 154aaac..6400a0f 100644
--- a/src/backend/replication/repl_gram.y
+++ b/src/backend/replication/repl_gram.y
@@ -70,6 +70,7 @@ Node *replication_parse_result;
%token K_FAST
%token K_NOWAIT
%token K_MAX_RATE
+%token K_REPLICATION_SLOT
%token K_WAL
%token K_TIMELINE
%token K_PHYSICAL
@@ -119,7 +120,8 @@ identify_system:
;
/*
- * BASE_BACKUP [LABEL '