From 98bc12d5359e73d6c2588a870fd154b9ef1903cb Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Fri, 1 Mar 2019 16:09:53 +0300 Subject: [PATCH] new flag '--temp-slot' allows user to use temporary slot for STREAM backups, if no slot name is specified via '--slot' option - default name 'pg_probackup_slot' is used --- src/backup.c | 7 +++++++ src/help.c | 13 +++++++------ src/pg_probackup.c | 2 ++ src/pg_probackup.h | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/backup.c b/src/backup.c index 36ff52eb..2f143ea4 100644 --- a/src/backup.c +++ b/src/backup.c @@ -2766,6 +2766,12 @@ StreamLog(void *arg) stream_stop_timeout = 0; stream_stop_begin = 0; +#if PG_VERSION_NUM >= 100000 + /* if slot name was not provided for temp slot, use default slot name */ + if (!replication_slot && temp_slot) + replication_slot = "pg_probackup_slot"; +#endif + /* * Start the replication */ @@ -2786,6 +2792,7 @@ StreamLog(void *arg) ctl.walmethod = CreateWalDirectoryMethod(stream_arg->basedir, 0, true); ctl.replication_slot = replication_slot; ctl.stop_socket = PGINVALID_SOCKET; + ctl.temp_slot = temp_slot; #else ctl.basedir = (char *) stream_arg->basedir; #endif diff --git a/src/help.c b/src/help.c index 3be75772..0068ecee 100644 --- a/src/help.c +++ b/src/help.c @@ -97,9 +97,9 @@ help_pg_probackup(void) printf(_(" [--format=format]\n")); printf(_("\n %s backup -B backup-path -b backup-mode --instance=instance_name\n"), PROGRAM_NAME); - printf(_(" [-C] [--stream [-S slot-name]] [--backup-pg-log]\n")); - printf(_(" [-j num-threads] [--archive-timeout=archive-timeout]\n")); - printf(_(" [--progress]\n")); + printf(_(" [-C] [--stream [-S slot-name] [--temp-slot]\n")); + printf(_(" [--backup-pg-log] [-j num-threads]\n")); + printf(_(" [--archive-timeout=archive-timeout] [--progress]\n")); printf(_(" [--log-level-console=log-level-console]\n")); printf(_(" [--log-level-file=log-level-file]\n")); printf(_(" [--log-filename=log-filename]\n")); @@ -186,9 +186,9 @@ static void help_backup(void) { printf(_("%s backup -B backup-path -b backup-mode --instance=instance_name\n"), PROGRAM_NAME); - printf(_(" [-C] [--stream [-S slot-name]] [--backup-pg-log]\n")); - printf(_(" [-j num-threads] [--archive-timeout=archive-timeout]\n")); - printf(_(" [--progress]\n")); + printf(_(" [-C] [--stream [-S slot-name] [--temp-slot]\n")); + printf(_(" [--backup-pg-log] [-j num-threads]\n")); + printf(_(" [--archive-timeout=archive-timeout] [--progress]\n")); printf(_(" [--log-level-console=log-level-console]\n")); printf(_(" [--log-level-file=log-level-file]\n")); printf(_(" [--log-filename=log-filename]\n")); @@ -215,6 +215,7 @@ help_backup(void) printf(_(" -C, --smooth-checkpoint do smooth checkpoint before backup\n")); printf(_(" --stream stream the transaction log and include it in the backup\n")); printf(_(" -S, --slot=SLOTNAME replication slot to use\n")); + printf(_(" --temp-slot use temporary replication slot\n")); printf(_(" --backup-pg-log backup of '%s' directory\n"), PG_LOG_DIR); printf(_(" -j, --threads=NUM number of parallel threads\n")); printf(_(" --archive-timeout=timeout wait timeout for WAL segment archiving (default: 5min)\n")); diff --git a/src/pg_probackup.c b/src/pg_probackup.c index bc596848..a56658cf 100644 --- a/src/pg_probackup.c +++ b/src/pg_probackup.c @@ -62,6 +62,7 @@ bool progress = false; #if PG_VERSION_NUM >= 100000 char *replication_slot = NULL; #endif +bool temp_slot = false; /* backup options */ bool backup_logs = false; @@ -133,6 +134,7 @@ static ConfigOption cmd_options[] = { 'f', 'b', "backup-mode", opt_backup_mode, SOURCE_CMD_STRICT }, { 'b', 'C', "smooth-checkpoint", &smooth_checkpoint, SOURCE_CMD_STRICT }, { 's', 'S', "slot", &replication_slot, SOURCE_CMD_STRICT }, + { 'b', 234, "temp-slot", &temp_slot, SOURCE_CMD_STRICT }, { 'b', 134, "delete-wal", &delete_wal, SOURCE_CMD_STRICT }, { 'b', 135, "delete-expired", &delete_expired, SOURCE_CMD_STRICT }, /* TODO not completed feature. Make it unavailiable from user level diff --git a/src/pg_probackup.h b/src/pg_probackup.h index a10547dc..23db2354 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -359,6 +359,7 @@ extern bool progress; /* In pre-10 'replication_slot' is defined in receivelog.h */ extern char *replication_slot; #endif +extern bool temp_slot; /* backup options */ extern bool smooth_checkpoint;