@@ -56,7 +56,7 @@ static void pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn, PGNode
5656
5757static XLogRecPtr wait_wal_lsn (XLogRecPtr lsn , bool is_start_lsn , TimeLineID tli ,
5858 bool in_prev_segment , bool segment_only ,
59- int timeout_elevel , bool in_stream_dir );
59+ int timeout_elevel , bool in_stream_dir , pgBackup * backup );
6060
6161static void check_external_for_tablespaces (parray * external_list ,
6262 PGconn * backup_conn );
@@ -270,7 +270,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
270270 * Because WAL streaming will start after pg_start_backup() in stream
271271 * mode.
272272 */
273- wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , false);
273+ wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , false, & current );
274274 }
275275
276276 /* start stream replication */
@@ -281,6 +281,12 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
281281
282282 start_WAL_streaming (backup_conn , dst_backup_path , & instance_config .conn_opt ,
283283 current .start_lsn , current .tli );
284+
285+ /* Make sure that WAL streaming is working
286+ * PAGE backup in stream mode is waited twice, first for
287+ * segment in WAL archive and then for streamed segment
288+ */
289+ wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , true, & current );
284290 }
285291
286292 /* initialize backup's file list */
@@ -1264,7 +1270,7 @@ pg_is_superuser(PGconn *conn)
12641270static XLogRecPtr
12651271wait_wal_lsn (XLogRecPtr target_lsn , bool is_start_lsn , TimeLineID tli ,
12661272 bool in_prev_segment , bool segment_only ,
1267- int timeout_elevel , bool in_stream_dir )
1273+ int timeout_elevel , bool in_stream_dir , pgBackup * backup )
12681274{
12691275 XLogSegNo targetSegNo ;
12701276 char pg_wal_dir [MAXPGPATH ];
@@ -1296,15 +1302,14 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
12961302 */
12971303 if (in_stream_dir )
12981304 {
1299- pgBackupGetPath2 (& current , pg_wal_dir , lengthof (pg_wal_dir ),
1300- DATABASE_DIR , PG_XLOG_DIR );
1305+ join_path_components (pg_wal_dir , backup -> database_dir , PG_XLOG_DIR );
13011306 join_path_components (wal_segment_path , pg_wal_dir , wal_segment );
13021307 wal_segment_dir = pg_wal_dir ;
13031308 }
13041309 else
13051310 {
13061311 join_path_components (wal_segment_path , arclog_path , wal_segment );
1307- wal_segment_dir = arclog_path ;
1312+ wal_segment_dir = arclog_path ; /* global var */
13081313 }
13091314
13101315 /* TODO: remove this in 3.0 (it is a cludge against some old bug with archive_timeout) */
@@ -1396,7 +1401,7 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
13961401
13971402 sleep (1 );
13981403 if (interrupted )
1399- elog (ERROR , "Interrupted during waiting for WAL archiving" );
1404+ elog (ERROR , "Interrupted during waiting for WAL %s" , in_stream_dir ? "streaming" : " archiving" );
14001405 try_count ++ ;
14011406
14021407 /* Inform user if WAL segment is absent in first attempt */
@@ -1420,9 +1425,10 @@ wait_wal_lsn(XLogRecPtr target_lsn, bool is_start_lsn, TimeLineID tli,
14201425 {
14211426 if (file_exists )
14221427 elog (timeout_elevel , "WAL segment %s was %s, "
1423- "but target LSN %X/%X could not be archived in %d seconds" ,
1428+ "but target LSN %X/%X could not be %s in %d seconds" ,
14241429 wal_segment , wal_delivery_str ,
1425- (uint32 ) (target_lsn >> 32 ), (uint32 ) target_lsn , timeout );
1430+ (uint32 ) (target_lsn >> 32 ), (uint32 ) target_lsn ,
1431+ wal_delivery_str , timeout );
14261432 /* If WAL segment doesn't exist or we wait for previous segment */
14271433 else
14281434 elog (timeout_elevel ,
@@ -1707,7 +1713,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17071713 {
17081714 /* Wait for segment with current stop_lsn, it is ok for it to never arrive */
17091715 wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1710- false, true, WARNING , stream_wal );
1716+ false, true, WARNING , stream_wal , backup );
17111717
17121718 /* Get the first record in segment with current stop_lsn */
17131719 lsn_tmp = get_first_record_lsn (xlog_path , segno , backup -> tli ,
@@ -1735,7 +1741,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17351741 * because previous record can be the contrecord.
17361742 */
17371743 lsn_tmp = wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1738- true, false, ERROR , stream_wal );
1744+ true, false, ERROR , stream_wal , backup );
17391745
17401746 /* sanity */
17411747 if (!XRecOffIsValid (lsn_tmp ) || XLogRecPtrIsInvalid (lsn_tmp ))
@@ -1749,7 +1755,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
17491755 {
17501756 /* Wait for segment with current stop_lsn */
17511757 wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1752- false, true, ERROR , stream_wal );
1758+ false, true, ERROR , stream_wal , backup );
17531759
17541760 /* Get the next closest record in segment with current stop_lsn */
17551761 lsn_tmp = get_next_record_lsn (xlog_path , segno , backup -> tli ,
@@ -1878,7 +1884,7 @@ pg_stop_backup(pgBackup *backup, PGconn *pg_startbackup_conn,
18781884 */
18791885 if (!stop_lsn_exists )
18801886 stop_backup_lsn = wait_wal_lsn (stop_backup_lsn_tmp , false, backup -> tli ,
1881- false, false, ERROR , stream_wal );
1887+ false, false, ERROR , stream_wal , backup );
18821888
18831889 if (stream_wal )
18841890 {
0 commit comments