Skip to content

Commit f3bdedc

Browse files
author
Artur Zakirov
committed
Add backup option --archive-timeout
1 parent 3a7b6d5 commit f3bdedc

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

backup.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
#include "streamutil.h"
2828
#include "receivelog.h"
2929

30-
/* wait 10 sec until WAL archive complete */
31-
#define TIMEOUT_ARCHIVE 10
32-
3330
/* Server version */
3431
static int server_version = 0;
3532

33+
/* Wait timeout for WAL segment archiving */
34+
uint32 archive_timeout = 0;
35+
3636
static bool in_backup = false; /* TODO: more robust logic */
3737
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
3838
static XLogRecPtr stop_backup_lsn = InvalidXLogRecPtr;
@@ -737,7 +737,7 @@ wait_archive_lsn(XLogRecPtr lsn, bool prev_segno)
737737
XLogSegNo targetSegNo;
738738
char wal_path[MAXPGPATH];
739739
char wal_file[MAXFNAMELEN];
740-
int try_count = 0;
740+
uint32 try_count = 0;
741741

742742
tli = get_current_timeline(false);
743743

@@ -748,7 +748,6 @@ wait_archive_lsn(XLogRecPtr lsn, bool prev_segno)
748748
XLogFileName(wal_file, tli, targetSegNo);
749749

750750
join_path_components(wal_path, arclog_path, wal_file);
751-
elog(LOG, "wait for lsn %li in archived WAL segment %s", lsn, wal_path);
752751

753752
/* Wait until switched WAL is archived */
754753
while (!fileExists(wal_path))
@@ -757,10 +756,16 @@ wait_archive_lsn(XLogRecPtr lsn, bool prev_segno)
757756
if (interrupted)
758757
elog(ERROR, "interrupted during waiting for WAL archiving");
759758
try_count++;
760-
if (try_count > TIMEOUT_ARCHIVE)
759+
760+
/* Inform user if WAL segment is absent in first attempt */
761+
if (try_count == 1)
762+
elog(INFO, "wait for lsn %X/%X in archived WAL segment %s",
763+
(uint32) (lsn >> 32), (uint32) lsn, wal_path);
764+
765+
if (archive_timeout > 0 && try_count > archive_timeout)
761766
elog(ERROR,
762767
"switched WAL could not be archived in %d seconds",
763-
TIMEOUT_ARCHIVE);
768+
archive_timeout);
764769
}
765770
}
766771

doc/pg_probackup.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ Backup mode. Supported modes are: FULL (full backup), PAGE (incremental backup,
410410

411411
Makes an autonomous backup that includes all necessary WAL files, by streaming them from database server via replication protocol.
412412

413+
--archive-timeout
414+
415+
Wait timeout for WAL segment archiving. `pg_probackup` waits after `pg_start_backup()` and `pg_stop_backup()` executing when WAL segments with necessary LSN will be archived. For backup from master WAL segment will be archived fast, because master instance switch WAL segment during backup. For backup from standby `pg_probackup` will wait a long time, because standby instance cannot switch WAL segment. By default timeout is infinite.
416+
413417
-S _slot\_name_
414418
--slot=_slot\_name_
415419

pg_probackup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <time.h>
1717
#include <sys/stat.h>
1818

19-
const char *PROGRAM_VERSION = "1.1.1";
19+
const char *PROGRAM_VERSION = "1.1.2";
2020
const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
2121
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
2222

@@ -69,6 +69,7 @@ static pgut_option options[] =
6969
{ 'f', 'b', "backup-mode", opt_backup_mode, SOURCE_CMDLINE },
7070
{ 'b', 'C', "smooth-checkpoint", &smooth_checkpoint, SOURCE_CMDLINE },
7171
{ 's', 'S', "slot", &replication_slot, SOURCE_CMDLINE },
72+
{ 'u', 2, "archive-timeout", &archive_timeout, SOURCE_CMDLINE },
7273
/* options with only long name (keep-xxx) */
7374
/* restore options */
7475
{ 's', 3, "time", &target_time, SOURCE_CMDLINE },
@@ -250,6 +251,7 @@ pgut_help(bool details)
250251
printf(_(" -b, --backup-mode=MODE backup mode (full, page, ptrack)\n"));
251252
printf(_(" -C, --smooth-checkpoint do smooth checkpoint before backup\n"));
252253
printf(_(" --stream stream the transaction log and include it in the backup\n"));
254+
printf(_(" --archive-timeout wait timeout for WAL segment archiving\n"));
253255
printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
254256
printf(_(" --backup-pg-log backup of pg_log directory\n"));
255257
printf(_(" -j, --threads=NUM number of parallel threads\n"));

pg_probackup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ extern bool stream_wal;
225225
extern bool from_replica;
226226
extern bool progress;
227227
extern bool delete_wal;
228+
extern uint32 archive_timeout;
228229

229230
extern uint64 system_identifier;
230231

tests/expected/option_help.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Backup options:
1818
-b, --backup-mode=MODE backup mode (full, page, ptrack)
1919
-C, --smooth-checkpoint do smooth checkpoint before backup
2020
--stream stream the transaction log and include it in the backup
21+
--archive-timeout wait timeout for WAL segment archiving
2122
-S, --slot=SLOTNAME replication slot to use
2223
--backup-pg-log backup of pg_log directory
2324
-j, --threads=NUM number of parallel threads

tests/expected/option_version.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pg_probackup 1.1.1
1+
pg_probackup 1.1.2

0 commit comments

Comments
 (0)