mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Fix race condition in 028_pitr_timelines.pl test, add note to docs.
The 028_pitr_timelines.pl test would sometimes hang, waiting for a WAL segment that was just filled up to be archived. It was because the test used 'pg_stat_archiver.last_archived_wal' to check if a file was archived, but the order that WAL files are archived when a standby is promoted is not fully deterministic, and 'last_archived_wal' tracks the last segment that was archived, not the highest-numbered WAL segment. Because of that, if the archiver archived segment 3, and then 2, 'last_archived_wal' say 2, and the test query would think that 3 has not been archived yet. Normally, WAL files are marked ready for archival in order, and the archiver process will process them in order, so that issue doesn't arise. We have used the same query on 'last_archived_wal' in a few other tests with no problem. But when a standby is promoted, things are a bit chaotic. After promotion, the server will try to archive all the WAL segments from the old timeline that are in pg_wal, as well as the history file and any new WAL segments on the new timeline. The end-of-recovery checkpoint will create the .ready files for all the WAL files on the old timeline, but at the same time, the new timeline is opened up for business. A file from the new timeline can therefore be archived before the files from the old timeline have been marked as ready for archival. It turns out that we don't really need to wait for the archival in this particular test, because the standby server is about to be stopped, and stopping a server will wait for the end-of-recovery checkpoint and all WAL archivals to finish, anyway. So we can just remove it from the test. Add a note to the docs on 'pg_stat_archiver' view that files can be archived out of order. Reviewed-by: Tom Lane Discussion: https://www.postgresql.org/message-id/3186114.1644960507@sss.pgh.pa.us
This commit is contained in:
@ -3422,7 +3422,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
|
||||
<structfield>last_archived_wal</structfield> <type>text</type>
|
||||
</para>
|
||||
<para>
|
||||
Name of the last WAL file successfully archived
|
||||
Name of the WAL file most recently successfully archived
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
@ -3431,7 +3431,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
|
||||
<structfield>last_archived_time</structfield> <type>timestamp with time zone</type>
|
||||
</para>
|
||||
<para>
|
||||
Time of the last successful archive operation
|
||||
Time of the most recent successful archive operation
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
@ -3449,7 +3449,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
|
||||
<structfield>last_failed_wal</structfield> <type>text</type>
|
||||
</para>
|
||||
<para>
|
||||
Name of the WAL file of the last failed archival operation
|
||||
Name of the WAL file of the most recent failed archival operation
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
@ -3458,7 +3458,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
|
||||
<structfield>last_failed_time</structfield> <type>timestamp with time zone</type>
|
||||
</para>
|
||||
<para>
|
||||
Time of the last failed archival operation
|
||||
Time of the most recent failed archival operation
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
@ -3474,6 +3474,15 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
|
||||
</tgroup>
|
||||
</table>
|
||||
|
||||
<para>
|
||||
Normally, WAL files are archived in order, oldest to newest, but that is
|
||||
not guaranteed, and does not hold under special circumstances like when
|
||||
promoting a standby or after crash recovery. Therefore it is not safe to
|
||||
assume that all files older than
|
||||
<structfield>last_archived_wal</structfield> have also been successfully
|
||||
archived.
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
<sect2 id="monitoring-pg-stat-bgwriter-view">
|
||||
|
Reference in New Issue
Block a user