diff --git a/src/catalog.c b/src/catalog.c index 57da50c8d..780a1f28b 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "utils/file.h" #include "utils/configuration.h" @@ -1493,7 +1494,7 @@ catalog_get_timelines(InstanceConfig *instance) } /* determine which WAL segments must be kept because of wal retention */ - if (instance->wal_depth <= 0) + if (instance->wal_depth <= 0 && instance->wal_window <= 0) return timelineinfos; /* @@ -1559,8 +1560,15 @@ catalog_get_timelines(InstanceConfig *instance) for (i = 0; i < parray_num(timelineinfos); i++) { int count = 0; + time_t days_threshold = current_time; timelineInfo *tlinfo = parray_get(timelineinfos, i); + if (instance_config.wal_window > 0) + { + days_threshold = current_time - + (instance_config.wal_window * 60 * 60 * 24); + } + /* * Iterate backward on backups belonging to this timeline to find * anchor_backup. NOTE Here we rely on the fact that backups list @@ -1597,7 +1605,9 @@ catalog_get_timelines(InstanceConfig *instance) count++; - if (count == instance->wal_depth) + if (count >= instance->wal_depth && + days_threshold >= backup->recovery_time) + { elog(LOG, "On timeline %i WAL is protected from purge at %X/%X", tlinfo->tli, diff --git a/src/configure.c b/src/configure.c index 1aae3df13..41179f9b8 100644 --- a/src/configure.c +++ b/src/configure.c @@ -194,6 +194,11 @@ ConfigOption instance_options[] = &instance_config.wal_depth, SOURCE_CMD, 0, OPTION_RETENTION_GROUP, 0, option_get_value }, + { + 'u', 231, "wal-window", + &instance_config.wal_window, SOURCE_CMD, 0, + OPTION_RETENTION_GROUP, 0, option_get_value + }, /* Compression options */ { 'f', 222, "compress-algorithm", @@ -363,6 +368,7 @@ init_config(InstanceConfig *config, const char *instance_name) config->retention_redundancy = RETENTION_REDUNDANCY_DEFAULT; config->retention_window = RETENTION_WINDOW_DEFAULT; config->wal_depth = 0; + config->wal_window = 0; config->compress_alg = COMPRESS_ALG_DEFAULT; config->compress_level = COMPRESS_LEVEL_DEFAULT; @@ -541,6 +547,11 @@ readInstanceConfigFile(const char *instance_name) &instance->wal_depth, SOURCE_CMD, 0, OPTION_RETENTION_GROUP, 0, option_get_value }, + { + 'u', 231, "wal-window", + &instance->wal_window, SOURCE_CMD, 0, + OPTION_RETENTION_GROUP, 0, option_get_value + }, /* Compression options */ { 's', 222, "compress-algorithm", diff --git a/src/pg_probackup.h b/src/pg_probackup.h index b9f5cff67..09bb5cfbc 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -384,6 +384,7 @@ typedef struct InstanceConfig uint32 retention_redundancy; uint32 retention_window; uint32 wal_depth; + uint32 wal_window; CompressAlg compress_alg; int compress_level;