Skip to content

Commit 759aefc

Browse files
committed
[Issue #103] select oldest backup with valid start_lsn and tli to determine oldest lsn for WAL purge
1 parent 961293c commit 759aefc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/delete.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ do_retention_wal(void)
622622
XLogRecPtr oldest_lsn = InvalidXLogRecPtr;
623623
TimeLineID oldest_tli = 0;
624624
bool backup_list_is_empty = false;
625+
int i;
625626

626627
/* Get list of backups. */
627628
backup_list = catalog_get_backup_list(INVALID_BACKUP_ID);
@@ -630,14 +631,17 @@ do_retention_wal(void)
630631
backup_list_is_empty = true;
631632

632633
/* Save LSN and Timeline to remove unnecessary WAL segments */
633-
if (!backup_list_is_empty)
634+
for (i = (int) parray_num(backup_list) - 1; i >= 0; i--)
634635
{
635-
pgBackup *backup = NULL;
636-
/* Get LSN and TLI of oldest alive backup */
637-
backup = (pgBackup *) parray_get(backup_list, parray_num(backup_list) -1);
636+
pgBackup *backup = (pgBackup *) parray_get(backup_list, parray_num(backup_list) -1);
638637

639-
oldest_tli = backup->tli;
640-
oldest_lsn = backup->start_lsn;
638+
/* Get LSN and TLI of the oldest backup with valid start_lsn and tli */
639+
if (backup->tli > 0 && !XLogRecPtrIsInvalid(backup->start_lsn))
640+
{
641+
oldest_tli = backup->tli;
642+
oldest_lsn = backup->start_lsn;
643+
break;
644+
}
641645
}
642646

643647
/* Be paranoid */

0 commit comments

Comments
 (0)