@@ -880,6 +880,24 @@ func (p *PhysicalInitial) checkRecovery(ctx context.Context, containerID string)
880
880
return output , err
881
881
}
882
882
883
+ /* "Data state at" (DSA) is a timestamp that represents the database's state. This function tries to
884
+ determine its value based on various sources. If it fails, an error is reported. Using the current
885
+ time as a last resort would be misleading, especially in the case when the "sync" container
886
+ is running, and users deal with multiple snapshots.
887
+
888
+ Current steps to determine DSA:
889
+
890
+ Step 1. Using pg_last_xact_replay_timestamp() (either in the "promote" or the "sync" Postgres).
891
+ It may be empty if there are no transactions recently committed on the source.
892
+
893
+ Step 2. Parsing available WALs using pg_waldump. We check WALs in reverse order and try to find
894
+ the latest available Transaction record.
895
+ Again, this may be not working - for example, WALs may be empty if archive_timeout is non-zero
896
+ and the source doesn't have enough activity.
897
+
898
+ Step 3. Use the timestamp of the latest checkpoint. This is extracted from PGDATA using the
899
+ pg_controldata utility. Note that this is not an exact value of the latest activity in the source
900
+ before we took a copy of PGDATA, but we suppose it is not far from it. */
883
901
func (p * PhysicalInitial ) extractDataStateAt (ctx context.Context , containerID , dataDir string , pgVersion float64 ,
884
902
defaultDSA string ) (string , error ) {
885
903
output , err := p .getLastXActReplayTimestamp (ctx , containerID )
0 commit comments