Re: pgsql: Implement pg_wal_replay_wait() stored procedure
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Alexander Korotkov <aekorotkov@gmail.com>,
Pavel Borisov <pashkin.elfe@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>,
Michael Paquier <michael@paquier.xyz>, pgsql-committers@lists.postgresql.org
Date: 2024-10-25T06:06:10Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Revert pg_wal_replay_wait() stored procedure
- 3a7ae6b3d91e 18.0 landed
-
Add 'no_error' argument to pg_wal_replay_wait()
- e546989a269d 18.0 landed
-
Refactor WaitForLSNReplay() to return the result of waiting
- 73da6b8d1b3e 18.0 landed
-
Make WaitForLSNReplay() issue FATAL on postmaster death
- 6cfebfe88b9a 18.0 landed
-
Move LSN waiting declarations and definitions to better place
- 5035172e4ab5 18.0 landed
-
Update oid for pg_wal_replay_wait() procedure
- e658038772f5 18.0 landed
-
Move pg_wal_replay_wait() to xlogfuncs.c
- 014f9f34d252 18.0 landed
-
Implement pg_wal_replay_wait() stored procedure
- 3c5db1d6b016 18.0 cited
If you call this procedure on a stand-alone server, you get:
postgres=# call pg_wal_replay_wait('1234/0');
ERROR: recovery is not in progress
DETAIL: Recovery ended before replaying target LSN 1234/0; last replay
LSN 0/0.
The DETAIL seems a bit misleading. Recovery never ended, because it
never started in the first place. Last replay LSN is indeed 0/0, but
that's not helpful.
If a standby server has been promoted and you pass an LSN that's earlier
than the last replay LSN, it returns successfully. That makes sense I
guess; if you connect to a standby and wait for it to replay a commit
that you made in the primary, and the standby gets promoted, that seems
correct. But it's a little inconsistent: If the standby crashes
immediately after promotion, and you call pg_wal_replay_wait() after
recovery, it returns success. However, if you shut down the promoted
server and restart it, then last replay LSN is 0/0, and the call will
fail because no recovery happened.
What is the use case for the 'no_error' argument? Why would you ever
want to pass no_error=true ? The separate pg_wal_replay_wait_status()
function feels weird to me. Also it surely shouldn't be marked IMMUTABLE
nor parallel safe.
This would benefit from more documentation, explaining how you would use
this in practice. I believe the use case is that you want "read your
writes" consistency between a primary and a standby. You commit a
transaction in the primary, and you then want to run read-only queries
in a standby, and you want to make sure that you see your own commit,
but you're ok with slightly delayed results otherwise. It would be good
to add a chapter somewhere in the docs to show how to do that in
practice with these functions.
--
Heikki Linnakangas
Neon (https://neon.tech)