Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit853c640

Browse files
committed
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 WALsegment that was just filled up to be archived. It was because thetest used 'pg_stat_archiver.last_archived_wal' to check if a file wasarchived, but the order that WAL files are archived when a standby ispromoted is not fully deterministic, and 'last_archived_wal' tracksthe last segment that was archived, not the highest-numbered WALsegment. Because of that, if the archiver archived segment 3, and then2, 'last_archived_wal' say 2, and the test query would think that 3has not been archived yet.Normally, WAL files are marked ready for archival in order, and thearchiver process will process them in order, so that issue doesn'tarise. We have used the same query on 'last_archived_wal' in a fewother tests with no problem. But when a standby is promoted, thingsare a bit chaotic. After promotion, the server will try to archive allthe WAL segments from the old timeline that are in pg_wal, as well asthe history file and any new WAL segments on the new timeline. Theend-of-recovery checkpoint will create the .ready files for all theWAL files on the old timeline, but at the same time, the new timelineis opened up for business. A file from the new timeline can thereforebe archived before the files from the old timeline have been marked asready for archival.It turns out that we don't really need to wait for the archival inthis particular test, because the standby server is about to bestopped, and stopping a server will wait for the end-of-recoverycheckpoint and all WAL archivals to finish, anyway. So we can justremove it from the test.Add a note to the docs on 'pg_stat_archiver' view that files can bearchived out of order.Reviewed-by: Tom LaneDiscussion:https://www.postgresql.org/message-id/3186114.1644960507@sss.pgh.pa.us
1 parent988ffc3 commit853c640

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,7 +3422,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
34223422
<structfield>last_archived_wal</structfield> <type>text</type>
34233423
</para>
34243424
<para>
3425-
Name of thelastWAL file successfully archived
3425+
Name of the WAL file most recently successfully archived
34263426
</para></entry>
34273427
</row>
34283428

@@ -3431,7 +3431,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
34313431
<structfield>last_archived_time</structfield> <type>timestamp with time zone</type>
34323432
</para>
34333433
<para>
3434-
Time of thelast successful archive operation
3434+
Time of themost recent successful archive operation
34353435
</para></entry>
34363436
</row>
34373437

@@ -3449,7 +3449,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
34493449
<structfield>last_failed_wal</structfield> <type>text</type>
34503450
</para>
34513451
<para>
3452-
Name of the WAL file of thelast failed archival operation
3452+
Name of the WAL file of themost recent failed archival operation
34533453
</para></entry>
34543454
</row>
34553455

@@ -3458,7 +3458,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
34583458
<structfield>last_failed_time</structfield> <type>timestamp with time zone</type>
34593459
</para>
34603460
<para>
3461-
Time of thelast failed archival operation
3461+
Time of themost recent failed archival operation
34623462
</para></entry>
34633463
</row>
34643464

@@ -3474,6 +3474,15 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
34743474
</tgroup>
34753475
</table>
34763476

3477+
<para>
3478+
Normally, WAL files are archived in order, oldest to newest, but that is
3479+
not guaranteed, and does not hold under special circumstances like when
3480+
promoting a standby or after crash recovery. Therefore it is not safe to
3481+
assume that all files older than
3482+
<structfield>last_archived_wal</structfield> have also been successfully
3483+
archived.
3484+
</para>
3485+
34773486
</sect2>
34783487

34793488
<sect2 id="monitoring-pg-stat-bgwriter-view">

‎src/test/recovery/t/028_pitr_timelines.pl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
# Initialize and start primary node with WAL archiving
3737
my$node_primary = PostgreSQL::Test::Cluster->new('primary');
3838
$node_primary->init(has_archiving=> 1,allows_streaming=> 1);
39-
$node_primary->append_conf('postgresql.conf','log_min_messages=debug1');
4039
$node_primary->start;
4140

4241
# Take a backup.
@@ -70,7 +69,6 @@
7069
has_archiving=> 1,
7170
has_restoring=> 0);
7271
$node_standby->append_conf('postgresql.conf','archive_mode = always');
73-
$node_standby->append_conf('postgresql.conf','log_min_messages=debug1');
7472
$node_standby->start;
7573
$node_primary->wait_for_catchup($node_standby);
7674

@@ -93,15 +91,8 @@
9391
# Make WAL segment eligible for archival
9492
$node_standby->safe_psql('postgres','SELECT pg_switch_wal()');
9593

96-
# Wait until the WAL segment has been archived.
97-
my$archive_wait_query =
98-
"SELECT '$walfile_to_be_archived' <= last_archived_wal FROM pg_stat_archiver;";
99-
$node_standby->poll_query_until('postgres',$archive_wait_query)
100-
ordie"Timed out while waiting for WAL segment to be archived";
101-
my$last_archived_wal_file =$walfile_to_be_archived;
102-
103-
# Ok, the standby has now archived the WAL on timeline 2. We don't
104-
# need the standby anymore.
94+
# We don't need the standby anymore, request shutdown. The server will
95+
# finish archiving all the WAL on timeline 2 before it exits.
10596
$node_standby->stop;
10697

10798
# Contents of the WAL archive at this point:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp