@@ -80,6 +80,7 @@ static void create_file_list(parray *files,
80
80
const char * prefix ,
81
81
bool is_append );
82
82
static 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 );
83
84
static void make_pagemap_from_ptrack (parray * files );
84
85
static void StreamLog (void * arg );
85
86
@@ -651,7 +652,12 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
651
652
ERROR );
652
653
653
654
if (backup != NULL )
655
+ {
654
656
get_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
+
655
661
PQclear (res );
656
662
}
657
663
@@ -842,6 +848,42 @@ wait_for_archive(PGconn *conn, pgBackup *backup, const char *sql, bool stop_back
842
848
elog (LOG , "%s() .ready deleted in %d try" , __FUNCTION__ , try_count );
843
849
}
844
850
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
+
845
887
/*
846
888
* Notify end of backup to PostgreSQL server.
847
889
*/
0 commit comments