pg_replication_slots 是一个 系统目录 视图,列出了所有复制槽。
pg_replication_slots 在 PostgreSQL 9.4 中添加。
用法
pg_replication_slots 底层函数直接读取复制槽的磁盘结构,这意味着此视图的内容在任何事务状态下始终可见,并且可能在事务中发生变化。因此,在将其与其他关系(例如 pg_stat_activity)结合使用时应格外小心,因为那些关系的内容可能对当前事务不可见。
按 PostgreSQL 版本定义
pg_replication_slots (PostgreSQL 19)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+--------------------------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
wal_status | text | | |
safe_wal_size | bigint | | |
two_phase | boolean | | |
two_phase_at | pg_lsn | | |
inactive_since | timestamp with time zone | | |
conflicting | boolean | | |
invalidation_reason | text | | |
failover | boolean | | |
synced | boolean | | |
pg_replication_slots (PostgreSQL 18)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+--------------------------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
wal_status | text | | |
safe_wal_size | bigint | | |
two_phase | boolean | | |
two_phase_at | pg_lsn | | |
inactive_since | timestamp with time zone | | |
conflicting | boolean | | |
invalidation_reason | text | | |
failover | boolean | | |
synced | boolean | | |
pg_replication_slots (PostgreSQL 17)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+--------------------------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
wal_status | text | | |
safe_wal_size | bigint | | |
two_phase | boolean | | |
inactive_since | timestamp with time zone | | |
conflicting | boolean | | |
invalidation_reason | text | | |
failover | boolean | | |
synced | boolean | | |
pg_replication_slots (PostgreSQL 16)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+---------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
wal_status | text | | |
safe_wal_size | bigint | | |
two_phase | boolean | | |
conflicting | boolean | | |
pg_replication_slots (PostgreSQL 15)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+---------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
wal_status | text | | |
safe_wal_size | bigint | | |
two_phase | boolean | | |
pg_replication_slots (PostgreSQL 14)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+---------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
wal_status | text | | |
safe_wal_size | bigint | | |
two_phase | boolean | | |
pg_replication_slots (PostgreSQL 13)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+---------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
wal_status | text | | |
safe_wal_size | bigint | | |
pg_replication_slots (PostgreSQL 12)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+---------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
pg_replication_slots (PostgreSQL 11)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+---------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
pg_replication_slots (PostgreSQL 10)
View "pg_catalog.pg_replication_slots"
Column | Type | Collation | Nullable | Default
---------------------+---------+-----------+----------+---------
slot_name | name | | |
plugin | name | | |
slot_type | text | | |
datoid | oid | | |
database | name | | |
temporary | boolean | | |
active | boolean | | |
active_pid | integer | | |
xmin | xid | | |
catalog_xmin | xid | | |
restart_lsn | pg_lsn | | |
confirmed_flush_lsn | pg_lsn | | |
pg_replication_slots (PostgreSQL 9.6)
View "pg_catalog.pg_replication_slots"
Column | Type | Modifiers
---------------------+---------+-----------
slot_name | name |
plugin | name |
slot_type | text |
datoid | oid |
database | name |
active | boolean |
active_pid | integer |
xmin | xid |
catalog_xmin | xid |
restart_lsn | pg_lsn |
confirmed_flush_lsn | pg_lsn |
pg_replication_slots (PostgreSQL 9.5)
View "pg_catalog.pg_replication_slots"
Column | Type | Modifiers
--------------+---------+-----------
slot_name | name |
plugin | name |
slot_type | text |
datoid | oid |
database | name |
active | boolean |
active_pid | integer |
xmin | xid |
catalog_xmin | xid |
restart_lsn | pg_lsn |
pg_replication_slots (PostgreSQL 9.4)
View "pg_catalog.pg_replication_slots"
Column | Type | Modifiers
--------------+---------+-----------
slot_name | name |
plugin | name |
slot_type | text |
datoid | oid |
database | name |
active | boolean |
xmin | xid |
catalog_xmin | xid |
restart_lsn | pg_lsn |
变更历史
- PostgreSQL 18
- 添加了
two_phase_at列 (提交 4868c96b)
- 添加了
- PostgreSQL 17
- PostgreSQL 16
- 添加了
conflicting列 (提交 be87200e)
- 添加了
- PostgreSQL 14
- 添加了
two_phase列 (提交 19890a06)
- 添加了
- PostgreSQL 13
- PostgreSQL 10
- 添加了
temporary列 (提交 a924c327)
- 添加了
- PostgreSQL 9.6
- 添加了
confirmed_flush_lsn列 (提交 3f811c2d)
- 添加了
- PostgreSQL 9.5
- 添加了
active_pid列 (提交 d811c037)
- 添加了
- PostgreSQL 9.4
- 添加 (提交 858ec118)
示例
当使用单个物理复制槽时 pg_replication_slots 的示例内容 (截至 PostgreSQL 13)
postgres=# SELECT * FROM pg_replication_slots\gx -[ RECORD 1 ]-------+-------------- slot_name | node2 plugin | slot_type | physical datoid | database | temporary | f active | t active_pid | 1597000 xmin | catalog_xmin | restart_lsn | 0/3002470 confirmed_flush_lsn | wal_status | reserved safe_wal_size |
参考资料
- PostgreSQL 文档: pg_replication_slots
