@@ -837,9 +837,22 @@ wait_wal_lsn(XLogRecPtr lsn)
837837timeout = archive_timeout ;
838838}
839839
840- /* Wait untilswitched WAL is archived */
841- while (! fileExists ( wal_segment_full_path ) )
840+ /* Wait untiltarget LSN is archived */
841+ while (true )
842842{
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+
843856sleep (1 );
844857if (interrupted )
845858elog (ERROR ,"interrupted during waiting for WAL archiving" );
@@ -851,18 +864,17 @@ wait_wal_lsn(XLogRecPtr lsn)
851864 (uint32 ) (lsn >>32 ), (uint32 )lsn ,wal_segment_full_path );
852865
853866if (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+ }
857877}
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 );
866878}
867879
868880/*
@@ -984,8 +996,11 @@ pg_stop_backup(pgBackup *backup)
984996PQclear (res );
985997
986998if (stream_wal )
999+ {
9871000/* Wait for the completion of stream */
1001+ elog (LOG ,"Wait end of WAL streaming" );
9881002pthread_join (stream_thread ,NULL );
1003+ }
9891004wait_wal_lsn (stop_backup_lsn );
9901005
9911006/* Fill in fields if that is the correct end of backup. */