@@ -59,6 +59,7 @@ static void backup_files(void *arg);
59
59
static void do_backup_database (parray * backup_list );
60
60
61
61
static void pg_start_backup (const char * label , bool smooth , pgBackup * backup );
62
+ static void pg_switch_wal (void );
62
63
static void pg_stop_backup (pgBackup * backup );
63
64
64
65
static void add_pgdata_files (parray * files , const char * root );
@@ -214,6 +215,16 @@ do_backup_database(parray *backup_list)
214
215
*/
215
216
if (current .backup_mode == BACKUP_MODE_DIFF_PAGE )
216
217
{
218
+ /*
219
+ * Switch to a new WAL segment. It is necessary to get archived WAL
220
+ * segment, which includes start LSN of current backup.
221
+ *
222
+ * Do not switch for standby node and if backup is stream.
223
+ */
224
+ if (!from_replica && !stream_wal )
225
+ pg_switch_wal ();
226
+ if (!stream_wal )
227
+ wait_archive_lsn (current .start_lsn , false);
217
228
/*
218
229
* Build the page map. Obtain information about changed pages
219
230
* reading WAL segments present in archives up to the point
@@ -581,14 +592,29 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
581
592
/* Calculate LSN */
582
593
backup -> start_lsn = (XLogRecPtr ) ((uint64 ) xlogid << 32 ) | xrecoff ;
583
594
584
- if (!stream_wal )
585
- wait_archive_lsn (backup -> start_lsn ,
586
- /*
587
- * For backup from master wait for previous segment.
588
- * For backup from replica wait for current segment.
589
- */
590
- !from_replica );
595
+ PQclear (res );
596
+ }
597
+
598
+ /*
599
+ * Switch to a new WAL segment. It should be called only for master.
600
+ */
601
+ static void
602
+ pg_switch_wal (void )
603
+ {
604
+ PGresult * res ;
605
+
606
+ /* Remove annoying NOTICE messages generated by backend */
607
+ res = pgut_execute (backup_conn , "SET client_min_messages = warning;" , 0 ,
608
+ NULL );
609
+ PQclear (res );
591
610
611
+ #if PG_VERSION_NUM >= 100000
612
+ res = pgut_execute (backup_conn , "SELECT * FROM pg_switch_wal()" , 0 ,
613
+ NULL );
614
+ #else
615
+ res = pgut_execute (backup_conn , "SELECT * FROM pg_switch_xlog()" , 0 ,
616
+ NULL );
617
+ #endif
592
618
PQclear (res );
593
619
}
594
620
0 commit comments