pg_wal_replay_wait()

等待WAL重放的过程
此条目涉及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命令执行。

更改历史记录

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.

分类

复制系统函数WAL

另请参阅

pg_wal_replay_pause()pg_last_wal_replay_lsn()

反馈

提交任何关于"pg_wal_replay_wait()"的评论、建议或更正 此处