@@ -72,7 +72,7 @@ static void pg_switch_xlog(void);
72
72
static bool pg_is_standby (void );
73
73
static void add_pgdata_files (parray * files , const char * root );
74
74
static void create_file_list (parray * files , const char * root , bool is_append );
75
- static void wait_archive_lsn (XLogRecPtr lsn , bool last_segno );
75
+ static void wait_archive_lsn (XLogRecPtr lsn , bool prev_segno );
76
76
static void make_pagemap_from_ptrack (parray * files );
77
77
static void StreamLog (void * arg );
78
78
@@ -230,17 +230,9 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
230
230
* Build page mapping in differential mode. When using this mode, the
231
231
* list of blocks to be taken is known by scanning the WAL segments
232
232
* present in archives up to the point where start backup has begun.
233
- * However, normally this segment is not yet available in the archives,
234
- * leading to failures when building the page map. Hence before doing
235
- * anything and in order to ensure that all the segments needed for the
236
- * scan are here, for a switch of the last segment with pg_switch_xlog.
237
233
*/
238
234
if (current .backup_mode == BACKUP_MODE_DIFF_PAGE )
239
235
{
240
- /* Enforce archiving of last segment and wait for it to be here */
241
- if (!from_replica )
242
- pg_switch_xlog ();
243
-
244
236
/* Now build the page map */
245
237
parray_qsort (backup_files_list , pgFileComparePathDesc );
246
238
elog (LOG , "extractPageMap" );
@@ -252,7 +244,12 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
252
244
(uint32 ) (current .start_lsn >> 32 ),
253
245
(uint32 ) (current .start_lsn ));
254
246
extractPageMap (arclog_path , prev_backup -> start_lsn , current .tli ,
255
- current .start_lsn );
247
+ current .start_lsn ,
248
+ /*
249
+ * For backup from master wait for previous segment.
250
+ * For backup from replica wait for current segment.
251
+ */
252
+ !from_replica );
256
253
}
257
254
else if (current .backup_mode == BACKUP_MODE_DIFF_PTRACK )
258
255
{
@@ -602,7 +599,12 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
602
599
backup -> start_lsn = (XLogRecPtr ) ((uint64 ) xlogid << 32 ) | xrecoff ;
603
600
604
601
if (!stream_wal )
605
- wait_archive_lsn (backup -> start_lsn , true);
602
+ wait_archive_lsn (backup -> start_lsn ,
603
+ /*
604
+ * For backup from master wait for previous segment.
605
+ * For backup from replica wait for current segment.
606
+ */
607
+ !from_replica );
606
608
607
609
PQclear (res );
608
610
}
@@ -729,7 +731,7 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_oid,
729
731
}
730
732
731
733
static void
732
- wait_archive_lsn (XLogRecPtr lsn , bool last_segno )
734
+ wait_archive_lsn (XLogRecPtr lsn , bool prev_segno )
733
735
{
734
736
TimeLineID tli ;
735
737
XLogSegNo targetSegNo ;
@@ -741,7 +743,7 @@ wait_archive_lsn(XLogRecPtr lsn, bool last_segno)
741
743
742
744
/* As well as WAL file name */
743
745
XLByteToSeg (lsn , targetSegNo );
744
- if (last_segno )
746
+ if (prev_segno )
745
747
targetSegNo -- ;
746
748
XLogFileName (wal_file , tli , targetSegNo );
747
749
@@ -844,6 +846,9 @@ pg_stop_backup(pgBackup *backup)
844
846
845
847
PQclear (res );
846
848
849
+ if (!stream_wal )
850
+ wait_archive_lsn (stop_backup_lsn , false);
851
+
847
852
/* Fill in fields if backup exists */
848
853
if (backup != NULL )
849
854
{
@@ -868,9 +873,6 @@ pg_stop_backup(pgBackup *backup)
868
873
869
874
PQclear (res );
870
875
}
871
-
872
- if (!stream_wal )
873
- wait_archive_lsn (stop_backup_lsn , false);
874
876
}
875
877
876
878
/*
0 commit comments