@@ -837,9 +837,22 @@ wait_wal_lsn(XLogRecPtr lsn)
837
837
timeout = archive_timeout ;
838
838
}
839
839
840
- /* Wait untilswitched WAL is archived */
841
- while (! fileExists ( wal_segment_full_path ) )
840
+ /* Wait untiltarget LSN is archived */
841
+ while (true )
842
842
{
843
+ bool file_exists = fileExists (wal_segment_full_path );
844
+
845
+ if (file_exists )
846
+ {
847
+ /*
848
+ * WAL segment was archived. Check LSN on it.
849
+ */
850
+ if ((stream_wal && wal_contains_lsn (wal_dir ,lsn ,tli ))||
851
+ (!stream_wal && wal_contains_lsn (arclog_path ,lsn ,tli )))
852
+ /* Target LSN was found */
853
+ return ;
854
+ }
855
+
843
856
sleep (1 );
844
857
if (interrupted )
845
858
elog (ERROR ,"interrupted during waiting for WAL archiving" );
@@ -851,18 +864,17 @@ wait_wal_lsn(XLogRecPtr lsn)
851
864
(uint32 ) (lsn >>32 ), (uint32 )lsn ,wal_segment_full_path );
852
865
853
866
if (timeout > 0 && try_count > timeout )
854
- elog (ERROR ,
855
- "switched WAL segment %s could not be archived in %d seconds" ,
856
- wal_segment ,timeout );
867
+ {
868
+ if (file_exists )
869
+ elog (ERROR ,"WAL segment %s was archived, "
870
+ "but target LSN %X/%X could not be archived in %d seconds" ,
871
+ wal_segment , (uint32 ) (lsn >>32 ), (uint32 )lsn ,timeout );
872
+ else
873
+ elog (ERROR ,
874
+ "switched WAL segment %s could not be archived in %d seconds" ,
875
+ wal_segment ,timeout );
876
+ }
857
877
}
858
-
859
- /*
860
- * WAL segment was archived. Check LSN on it.
861
- */
862
- if ((stream_wal && !wal_contains_lsn (wal_dir ,lsn ,tli ))||
863
- (!stream_wal && !wal_contains_lsn (arclog_path ,lsn ,tli )))
864
- elog (ERROR ,"WAL segment %s doesn't contain target LSN %X/%X" ,
865
- wal_segment , (uint32 ) (lsn >>32 ), (uint32 )lsn );
866
878
}
867
879
868
880
/*
@@ -984,8 +996,11 @@ pg_stop_backup(pgBackup *backup)
984
996
PQclear (res );
985
997
986
998
if (stream_wal )
999
+ {
987
1000
/* Wait for the completion of stream */
1001
+ elog (LOG ,"Wait end of WAL streaming" );
988
1002
pthread_join (stream_thread ,NULL );
1003
+ }
989
1004
wait_wal_lsn (stop_backup_lsn );
990
1005
991
1006
/* Fill in fields if that is the correct end of backup. */