@@ -85,7 +85,7 @@ static int checkpoint_timeout(void);
85
85
86
86
static void add_pgdata_files (parray * files , const char * root );
87
87
static void write_backup_file_list (parray * files , const char * root );
88
- static void wait_wal_lsn (XLogRecPtr lsn );
88
+ static void wait_wal_lsn (XLogRecPtr lsn , bool wait_prev_segment );
89
89
static void wait_replica_wal_lsn (XLogRecPtr lsn , bool is_start_backup );
90
90
static void make_pagemap_from_ptrack (parray * files );
91
91
static void StreamLog (void * arg );
@@ -645,7 +645,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
645
645
* Because WAL streaming will start after pg_start_backup() in stream
646
646
* mode.
647
647
*/
648
- wait_wal_lsn (backup -> start_lsn );
648
+ wait_wal_lsn (backup -> start_lsn , true );
649
649
650
650
/* Wait for start_lsn to be replayed by replica */
651
651
if (from_replica )
@@ -814,9 +814,11 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_oid,
814
814
* archive 'wal' directory with WAL segment file.
815
815
* If current backup started in stream mode wait for 'lsn' to be streamed in
816
816
* 'pg_xlog' directory.
817
+ *
818
+ * If 'wait_prev_segment' wait for previous segment.
817
819
*/
818
820
static void
819
- wait_wal_lsn (XLogRecPtr lsn )
821
+ wait_wal_lsn (XLogRecPtr lsn , bool wait_prev_segment )
820
822
{
821
823
TimeLineID tli ;
822
824
XLogSegNo targetSegNo ;
@@ -830,6 +832,8 @@ wait_wal_lsn(XLogRecPtr lsn)
830
832
831
833
/* Compute the name of the WAL file containig requested LSN */
832
834
XLByteToSeg (lsn , targetSegNo );
835
+ if (wait_prev_segment )
836
+ targetSegNo -- ;
833
837
XLogFileName (wal_segment , tli , targetSegNo );
834
838
835
839
if (stream_wal )
@@ -1196,7 +1200,7 @@ pg_stop_backup(pgBackup *backup)
1196
1200
* Wait for stop_lsn to be archived or streamed.
1197
1201
* We wait for stop_lsn in stream mode just in case.
1198
1202
*/
1199
- wait_wal_lsn (stop_backup_lsn );
1203
+ wait_wal_lsn (stop_backup_lsn , false );
1200
1204
1201
1205
if (stream_wal )
1202
1206
{
0 commit comments