Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 151 #307

Open
wants to merge 5 commits into
base: release_2_5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <signal.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>

#include "utils/file.h"
#include "utils/configuration.h"
Expand Down Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/pg_probackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down