From 0d028b79eca5c90b46ccb310f425cdd67e00135b Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Fri, 1 Nov 2019 18:42:20 +0300 Subject: [PATCH] wal_bytes for ARCHIVE backups was calculated incorrectly --- src/backup.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/backup.c b/src/backup.c index b38719d3..abd10a97 100644 --- a/src/backup.c +++ b/src/backup.c @@ -798,9 +798,19 @@ do_backup(time_t start_time, bool no_validate, /* compute size of wal files of this backup stored in the archive */ if (!current.stream) { - current.wal_bytes = instance_config.xlog_seg_size * - (current.stop_lsn / instance_config.xlog_seg_size - - current.start_lsn / instance_config.xlog_seg_size + 1); + XLogSegNo start_segno; + XLogSegNo stop_segno; + + GetXLogSegNo(current.start_lsn, start_segno, instance_config.xlog_seg_size); + GetXLogSegNo(current.stop_lsn, stop_segno, instance_config.xlog_seg_size); + current.wal_bytes = (stop_segno - start_segno) * instance_config.xlog_seg_size; + + /* + * If start_lsn and stop_lsn are located in the same segment, then + * set wal_bytes to the size of 1 segment. + */ + if (current.wal_bytes <= 0) + current.wal_bytes = instance_config.xlog_seg_size; } /* Backup is done. Update backup status */