此条目涉及PostgreSQL的一个特性,该特性是PostgreSQL 18的一部分,预计将于2025年底发布。
pg_wal_replay_wait()
是一个用于等待WAL重放到指定LSN的系统函数(过程)。可以可选地指定超时时间(以毫秒为单位)。
pg_wal_replay_wait()
在PostgreSQL 18中添加。
用法
pg_wal_replay_wait (target_lsn
pg_lsn
,timeout
bigint
DEFAULT
0
) →void
请注意,pg_wal_replay_wait()
实现为一个过程,必须通过CALL
命令执行。
更改历史记录
- PostgreSQL 18
- 添加 (提交 3c5db1d6)
pg_wal_replay_wait()
最初是在PostgreSQL 17中添加的 (提交 06c418e1),但随后被回退 (提交 772faafc)。
示例
pg_wal_replay_wait()
的基本用法示例
postgres=# CALL pg_wal_replay_wait('0/4FDFAFF0'); CALL
调用带有超时时间的pg_wal_replay_wait()
,该超时时间已达到
postgres=# CALL pg_wal_replay_wait('0/820A21B2', 1000); ERROR: timed out while waiting for target LSN 0/820A21B2 to be replayed; current replay LSN 0/764D55F0 Time: 1001.330 ms (00:01.001)
pg_wal_replay_wait()
只能在物理备机上执行
postgres=# CALL pg_wal_replay_wait('0/2BBF05B8'); ERROR: recovery is not in progress HINT: Waiting for LSN can only be executed during recovery.
pg_wal_replay_wait()
无法在隔离级别高于READ COMMITTED
的事务中执行
postgres=# BEGIN; BEGIN postgres=*# SET TRANSACTION ISOLATION LEVEL REPEATABLE READ ; SET postgres=*# CALL pg_wal_replay_wait('0/2BBF05B8'); ERROR: pg_wal_replay_wait() must be only called without an active or registered snapshot DETAIL: Make sure pg_wal_replay_wait() isn't called within a transaction with an isolation level higher than READ COMMITTED, another procedure, or a function. postgres=!#
由于它是一个过程而不是一个函数,因此尝试通过SELECT
调用它将不可避免地失败
postgres=# SELECT pg_wal_replay_wait('0/0'); ERROR: pg_wal_replay_wait(unknown) is a procedure LINE 1: SELECT pg_wal_replay_wait('0/0'); ^ HINT: To call a procedure, use CALL.
参考文献
- PostgreSQL 18 文档: 恢复同步过程