pg_replication_slot_advance()
是一个系统函数,用于推进复制槽(物理或逻辑)的当前已确认位置。
pg_replication_slot_advance()
在 PostgreSQL 11 中添加。
用法
pg_replication_slot_advance (slot_name
name
,upto_lsn
pg_lsn
) →
record (slot_nam
ename
,end_lsn
pg_lsn
)
该槽位不能向后移动或移动到当前插入位置之外。
由于槽位先前位置而保留的任何 WAL 将在下一个 检查点 中被移除。
如果无法推进槽位,则会引发错误。
变更历史
- PostgreSQL 11
- 添加 (提交 9c7d06d6)
示例
推进物理复制槽
postgres=# SELECT slot_name, slot_type, active, restart_lsn, confirmed_flush_lsn FROM pg_replication_slots\gx -[ RECORD 1 ]-------+---------- slot_name | node2 slot_type | physical active | f restart_lsn | 0/301C4D8 confirmed_flush_lsn | postgres=# INSERT INTO foo VALUES (1, clock_timestamp()); INSERT 0 1 postgres=# SELECT * FROM pg_replication_slot_advance('node2', pg_current_wal_lsn()); slot_name | end_lsn -----------+----------- node2 | 0/301C5D8 (1 row) postgres=# SELECT slot_name, slot_type, active, restart_lsn, confirmed_flush_lsn FROM pg_replication_slots\gx -[ RECORD 1 ]-------+---------- slot_name | node2 slot_type | physical
active | f restart_lsn | 0/301C5D8 confirmed_flush_lsn |
尝试推进一个未保留 WAL 的槽位,因为该槽位从未使用过或已被失效
postgres=# SELECT * FROM pg_replication_slot_advance('physical_slot_1', '0/3002DE0'); ERROR: replication slot "physical_slot_1" cannot be advanced DETAIL: This slot has never previously reserved WAL, or it has been invalidated.
尝试将复制槽重置到较早的位置
postgres=# SELECT * FROM pg_replication_slot_advance('test_slot_1', '0/301D4E0'); ERROR: cannot advance replication slot to 0/301D4E0, minimum is 0/492C6A8
尝试将复制槽重置到无效的位置
postgres=# SELECT * FROM pg_replication_slot_advance('test_slot_1', '0/0'); ERROR: invalid target WAL LSN
参考文献
- PostgreSQL 文档: 复制管理函数