@@ -80,6 +80,7 @@ static void create_file_list(parray *files,
8080const char * prefix ,
8181bool is_append );
8282static void wait_for_archive (PGconn * conn ,pgBackup * backup ,const char * sql ,bool stop_backup );
83+ static void wait_archive_lsn (XLogRecPtr lsn ,bool last_segno );
8384static void make_pagemap_from_ptrack (parray * files );
8485static void StreamLog (void * arg );
8586
@@ -651,7 +652,12 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
651652ERROR );
652653
653654if (backup != NULL )
655+ {
654656get_lsn (start_stop_connect ,res ,& backup -> start_lsn , false);
657+ if (!stream_wal && !from_replica )
658+ wait_archive_lsn (backup -> start_lsn , true);
659+ }
660+
655661PQclear (res );
656662}
657663
@@ -842,6 +848,42 @@ wait_for_archive(PGconn *conn, pgBackup *backup, const char *sql, bool stop_back
842848elog (LOG ,"%s() .ready deleted in %d try" ,__FUNCTION__ ,try_count );
843849}
844850
851+ static void
852+ wait_archive_lsn (XLogRecPtr lsn ,bool last_segno )
853+ {
854+ TimeLineID tli ;
855+ XLogSegNo targetSegNo ;
856+ char ready_path [MAXPGPATH ];
857+ char file_name [MAXFNAMELEN ];
858+ int try_count ;
859+
860+ tli = get_current_timeline (false);
861+
862+ /* As well as WAL file name */
863+ XLByteToSeg (lsn ,targetSegNo );
864+ if (last_segno )
865+ targetSegNo -- ;
866+ XLogFileName (file_name ,tli ,targetSegNo );
867+
868+ snprintf (ready_path ,lengthof (ready_path ),
869+ "%s/%s" ,arclog_path ,file_name );
870+ elog (LOG ,"%s() wait for lsn:%li %s" ,__FUNCTION__ ,lsn ,ready_path );
871+ /* wait until switched WAL is archived */
872+ try_count = 0 ;
873+ while (!fileExists (ready_path ))
874+ {
875+ sleep (1 );
876+ if (interrupted )
877+ elog (ERROR ,
878+ "interrupted during waiting for WAL archiving" );
879+ try_count ++ ;
880+ if (try_count > TIMEOUT_ARCHIVE )
881+ elog (ERROR ,
882+ "switched WAL could not be archived in %d seconds" ,
883+ TIMEOUT_ARCHIVE );
884+ }
885+ }
886+
845887/*
846888 * Notify end of backup to PostgreSQL server.
847889 */