Skip to content

Commit 5f0c024

Browse files
committed
[Issue #150] Pinned backups should be ignored for the purpose of WAL retention fulfillment
1 parent 4000349 commit 5f0c024

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

src/catalog.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,14 +988,22 @@ catalog_get_timelines(InstanceConfig *instance)
988988
{
989989
pgBackup *backup = parray_get(tlinfo->backups, j);
990990

991+
/* sanity */
992+
if (XLogRecPtrIsInvalid(backup->start_lsn) ||
993+
backup->tli <= 0)
994+
continue;
995+
991996
/* skip invalid backups */
992997
if (backup->status != BACKUP_STATUS_OK &&
993998
backup->status != BACKUP_STATUS_DONE)
994999
continue;
9951000

996-
/* sanity */
997-
if (XLogRecPtrIsInvalid(backup->start_lsn) ||
998-
backup->tli <= 0)
1001+
/*
1002+
* Pinned backups should be ignored for the
1003+
* purpose of retention fulfillment, so skip them.
1004+
*/
1005+
if (backup->expire_time > 0 &&
1006+
backup->expire_time > current_time)
9991007
continue;
10001008

10011009
count++;

src/delete.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ static void
209209
do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purge_list)
210210
{
211211
int i;
212-
time_t current_time;
213212

214213
parray *redundancy_full_backup_list = NULL;
215214

@@ -221,9 +220,6 @@ do_retention_internal(parray *backup_list, parray *to_keep_list, parray *to_purg
221220
/* For fancy reporting */
222221
uint32 actual_window = 0;
223222

224-
/* Get current time */
225-
current_time = time(NULL);
226-
227223
/* Calculate n_full_backups and days_threshold */
228224
if (instance_config.retention_redundancy > 0)
229225
{

src/pg_probackup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static char *target_action = NULL;
9292
static pgRecoveryTarget *recovery_target_options = NULL;
9393
static pgRestoreParams *restore_params = NULL;
9494

95+
time_t current_time = 0;
9596
bool restore_as_replica = false;
9697
bool no_validate = false;
9798

@@ -267,6 +268,9 @@ main(int argc, char *argv[])
267268
PROGRAM_NAME = get_progname(argv[0]);
268269
PROGRAM_FULL_PATH = palloc0(MAXPGPATH);
269270

271+
/* Get current time */
272+
current_time = time(NULL);
273+
270274
//set_pglocale_pgservice(argv[0], "pgscripts");
271275

272276
#if PG_VERSION_NUM >= 110000

src/pg_probackup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ typedef struct InstanceConfig
282282

283283
extern ConfigOption instance_options[];
284284
extern InstanceConfig instance_config;
285+
extern time_t current_time;
285286

286287
typedef struct PGNodeInfo
287288
{

src/restore.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,8 @@ pg12_recovery_config(pgBackup *backup, bool add_include)
11011101

11021102
if (add_include)
11031103
{
1104-
time_t current_time;
11051104
char current_time_str[100];
11061105

1107-
current_time = time(NULL);
11081106
time2iso(current_time_str, lengthof(current_time_str), current_time);
11091107

11101108
snprintf(postgres_auto_path, lengthof(postgres_auto_path),

src/show.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ show_instance_plain(const char *instance_name, parray *backup_list, bool show_na
468468
uint32 widths[SHOW_FIELDS_COUNT];
469469
uint32 widths_sum = 0;
470470
ShowBackendRow *rows;
471-
time_t current_time = time(NULL);
472471
TimeLineID parent_tli = 0;
473472

474473
for (i = 0; i < SHOW_FIELDS_COUNT; i++)

0 commit comments

Comments
 (0)