| From: | Jobin Augustine <jobin(dot)augustine(at)percona(dot)com> |
|---|---|
| To: | Xuneng Zhou <xunengzhou(at)gmail(dot)com>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: test: avoid redundant standby catchup in 049_wait_for_lsn |
| Date: | 2026-09-29 11:46:56 |
| Message-ID: | CAEpZXfeLrJUS2+5x6AxB2bF+BCusUvQTBgMxrcifURu9FdfwsQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Xuneng, hackers,
I ran into the same pg_current_wal_insert_lsn() page-boundary problem
discussed in this thread, independently, outside the regression tests,
while evaluating WAIT FOR for read-your-writes on a standby using a custom
coded application to test the usability of this feature.
At this boundary, pg_current_wal_insert_lsn() returns the next insertion
> address, which is after the header gap. The test thus waited for a position
> beyond the existing WAL, requiring another WAL record to make progress. The
> unrelated progression comes from the primary's background writer who
> generated a RUNNING_XACTS record, advancing WAL to 0/0301A050, and then
> notified the waiters.
About 1 in 2000 waits never succeeded and ran to the full TIMEOUT
Since all my sessions were using WAIT FOR LSN, it was a complete stall,
whenever it happens.
A client side workaround similar to the following is a temporary solution
for me for my tests:
CREATE FUNCTION wal_insert_end_lsn(l pg_lsn DEFAULT
pg_current_wal_insert_lsn())
RETURNS pg_lsn LANGUAGE sql STABLE AS $$
SELECT CASE
WHEN (l - '0/0'::pg_lsn) %
pg_size_bytes(current_setting('wal_segment_size'))
< current_setting('wal_block_size')::int -- first page of a
segment
THEN CASE WHEN (l - '0/0'::pg_lsn) %
current_setting('wal_block_size')::int = 40
THEN l - 40 ELSE l END
ELSE CASE WHEN (l - '0/0'::pg_lsn) %
current_setting('wal_block_size')::int = 24
THEN l - 24 ELSE l END
END
$$;
A server-side fix would be better
Could WAIT FOR itself also tolerate such targets? When the target points
exactly past a page header treat it as the page boundary.
Thanks for tracking this down in the test. It saved me from chasing what
looked like a WAIT FOR wakeup bug.
Thanks and Regards,
Jobin.
--
------------------------------
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ashutosh Bapat | 2026-09-29 12:07:24 | Re: [PATCH] Two remaining shmem attachment issues in single-user mode |
| Previous Message | Manu | 2026-09-29 11:45:06 | Re: BUG #19686: Rolling back SET TABLESPACE |