@@ -104,7 +104,8 @@ static int checkpoint_timeout(void);
104
104
105
105
//static void backup_list_file(parray *files, const char *root, )
106
106
static void parse_backup_filelist_filenames (parray * files , const char * root );
107
- static void wait_wal_lsn (XLogRecPtr lsn , bool wait_prev_segment );
107
+ static void wait_wal_lsn (XLogRecPtr lsn , bool is_start_lsn ,
108
+ bool wait_prev_segment );
108
109
static void wait_replica_wal_lsn (XLogRecPtr lsn , bool is_start_backup );
109
110
static void make_pagemap_from_ptrack (parray * files );
110
111
static void * StreamLog (void * arg );
@@ -1112,20 +1113,17 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
1112
1113
*/
1113
1114
pg_switch_wal (conn );
1114
1115
1115
- if (!stream_wal )
1116
- {
1117
- /*
1118
- * Do not wait start_lsn for stream backup.
1119
- * Because WAL streaming will start after pg_start_backup() in stream
1120
- * mode.
1121
- */
1116
+ if (current .backup_mode == BACKUP_MODE_DIFF_PAGE )
1122
1117
/* In PAGE mode wait for current segment... */
1123
- if (current .backup_mode == BACKUP_MODE_DIFF_PAGE )
1124
- wait_wal_lsn (backup -> start_lsn , false);
1118
+ wait_wal_lsn (backup -> start_lsn , true, false);
1119
+ /*
1120
+ * Do not wait start_lsn for stream backup.
1121
+ * Because WAL streaming will start after pg_start_backup() in stream
1122
+ * mode.
1123
+ */
1124
+ else if (!stream_wal )
1125
1125
/* ...for others wait for previous segment */
1126
- else
1127
- wait_wal_lsn (backup -> start_lsn , true);
1128
- }
1126
+ wait_wal_lsn (backup -> start_lsn , true, true);
1129
1127
1130
1128
/* Wait for start_lsn to be replayed by replica */
1131
1129
if (backup -> from_replica )
@@ -1443,16 +1441,20 @@ pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_filenode,
1443
1441
* If current backup started in stream mode wait for 'lsn' to be streamed in
1444
1442
* 'pg_wal' directory.
1445
1443
*
1444
+ * If 'is_start_lsn' is true and backup mode is PAGE then we wait for 'lsn' to
1445
+ * be archived in archive 'wal' directory regardless stream mode.
1446
+ *
1446
1447
* If 'wait_prev_segment' wait for previous segment.
1447
1448
*/
1448
1449
static void
1449
- wait_wal_lsn (XLogRecPtr lsn , bool wait_prev_segment )
1450
+ wait_wal_lsn (XLogRecPtr lsn , bool is_start_lsn , bool wait_prev_segment )
1450
1451
{
1451
1452
TimeLineID tli ;
1452
1453
XLogSegNo targetSegNo ;
1453
- char wal_dir [MAXPGPATH ],
1454
- wal_segment_path [MAXPGPATH ];
1455
- char wal_segment [MAXFNAMELEN ];
1454
+ char pg_wal_dir [MAXPGPATH ];
1455
+ char wal_segment_path [MAXPGPATH ],
1456
+ * wal_segment_dir ,
1457
+ wal_segment [MAXFNAMELEN ];
1456
1458
bool file_exists = false;
1457
1459
uint32 try_count = 0 ,
1458
1460
timeout ;
@@ -1469,18 +1471,28 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
1469
1471
targetSegNo -- ;
1470
1472
XLogFileName (wal_segment , tli , targetSegNo );
1471
1473
1472
- if (stream_wal )
1474
+ /*
1475
+ * In pg_start_backup we wait for 'lsn' in 'pg_wal' directory iff it is
1476
+ * stream and non-page backup. Page backup needs archived WAL files, so we
1477
+ * wait for 'lsn' in archive 'wal' directory for page backups.
1478
+ *
1479
+ * In pg_stop_backup it depends only on stream_wal.
1480
+ */
1481
+ if (stream_wal &&
1482
+ (current .backup_mode != BACKUP_MODE_DIFF_PAGE || !is_start_lsn ))
1473
1483
{
1474
- pgBackupGetPath2 (& current , wal_dir , lengthof (wal_dir ),
1484
+ pgBackupGetPath2 (& current , pg_wal_dir , lengthof (pg_wal_dir ),
1475
1485
DATABASE_DIR , PG_XLOG_DIR );
1476
- join_path_components (wal_segment_path , wal_dir , wal_segment );
1486
+ join_path_components (wal_segment_path , pg_wal_dir , wal_segment );
1487
+ wal_segment_dir = pg_wal_dir ;
1477
1488
1478
1489
timeout = (uint32 ) checkpoint_timeout ();
1479
1490
timeout = timeout + timeout * 0.1 ;
1480
1491
}
1481
1492
else
1482
1493
{
1483
1494
join_path_components (wal_segment_path , arclog_path , wal_segment );
1495
+ wal_segment_dir = arclog_path ;
1484
1496
timeout = archive_timeout ;
1485
1497
}
1486
1498
@@ -1523,8 +1535,7 @@ wait_wal_lsn(XLogRecPtr lsn, bool wait_prev_segment)
1523
1535
/*
1524
1536
* A WAL segment found. Check LSN on it.
1525
1537
*/
1526
- if ((stream_wal && wal_contains_lsn (wal_dir , lsn , tli )) ||
1527
- (!stream_wal && wal_contains_lsn (arclog_path , lsn , tli )))
1538
+ if (wal_contains_lsn (wal_segment_dir , lsn , tli ))
1528
1539
/* Target LSN was found */
1529
1540
{
1530
1541
elog (LOG , "Found LSN: %X/%X" , (uint32 ) (lsn >> 32 ), (uint32 ) lsn );
@@ -1912,7 +1923,7 @@ pg_stop_backup(pgBackup *backup)
1912
1923
* Wait for stop_lsn to be archived or streamed.
1913
1924
* We wait for stop_lsn in stream mode just in case.
1914
1925
*/
1915
- wait_wal_lsn (stop_backup_lsn , false);
1926
+ wait_wal_lsn (stop_backup_lsn , false, false );
1916
1927
1917
1928
if (stream_wal )
1918
1929
{
0 commit comments