pg_locks
是一个列出活动进程持有的锁的系统目录视图。
pg_locks
添加于PostgreSQL 7.3。
按PostgreSQL版本定义
pg_locks (PostgreSQL 17)
View "pg_catalog.pg_locks" Column | Type | Collation | Nullable | Default --------------------+--------------------------+-----------+----------+--------- locktype | text | | | database | oid | | | relation | oid | | | page | integer | | | tuple | smallint | | | virtualxid | text | | | transactionid | xid | | | classid | oid | | | objid | oid | | | objsubid | smallint | | | virtualtransaction | text | | | pid | integer | | | mode | text | | | granted | boolean | | | fastpath | boolean | | | waitstart | timestamp with time zone | | |
文档: pg_locks
pg_locks (PostgreSQL 16)
View "pg_catalog.pg_locks" Column | Type | Collation | Nullable | Default --------------------+--------------------------+-----------+----------+--------- locktype | text | | | database | oid | | | relation | oid | | | page | integer | | | tuple | smallint | | | virtualxid | text | | | transactionid | xid | | | classid | oid | | | objid | oid | | | objsubid | smallint | | | virtualtransaction | text | | | pid | integer | | | mode | text | | | granted | boolean | | | fastpath | boolean | | | waitstart | timestamp with time zone | | |
文档: pg_locks
pg_locks (PostgreSQL 15)
View "pg_catalog.pg_locks" Column | Type | Collation | Nullable | Default --------------------+--------------------------+-----------+----------+--------- locktype | text | | | database | oid | | | relation | oid | | | page | integer | | | tuple | smallint | | | virtualxid | text | | | transactionid | xid | | | classid | oid | | | objid | oid | | | objsubid | smallint | | | virtualtransaction | text | | | pid | integer | | | mode | text | | | granted | boolean | | | fastpath | boolean | | | waitstart | timestamp with time zone | | |
文档: pg_locks
pg_locks (PostgreSQL 14)
View "pg_catalog.pg_locks" Column | Type | Collation | Nullable | Default --------------------+--------------------------+-----------+----------+--------- locktype | text | | | database | oid | | | relation | oid | | | page | integer | | | tuple | smallint | | | virtualxid | text | | | transactionid | xid | | | classid | oid | | | objid | oid | | | objsubid | smallint | | | virtualtransaction | text | | | pid | integer | | | mode | text | | | granted | boolean | | | fastpath | boolean | | | waitstart | timestamp with time zone | | |
文档: pg_locks
pg_locks (PostgreSQL 13)
View "pg_catalog.pg_locks" Column | Type | Collation | Nullable | Default --------------------+----------+-----------+----------+--------- locktype | text | | | database | oid | | | relation | oid | | | page | integer | | | tuple | smallint | | | virtualxid | text | | | transactionid | xid | | | classid | oid | | | objid | oid | | | objsubid | smallint | | | virtualtransaction | text | | | pid | integer | | | mode | text | | | granted | boolean | | | fastpath | boolean | | |
文档: pg_locks
pg_locks (PostgreSQL 12)
View "pg_catalog.pg_locks" Column | Type | Collation | Nullable | Default --------------------+----------+-----------+----------+--------- locktype | text | | | database | oid | | | relation | oid | | | page | integer | | | tuple | smallint | | | virtualxid | text | | | transactionid | xid | | | classid | oid | | | objid | oid | | | objsubid | smallint | | | virtualtransaction | text | | | pid | integer | | | mode | text | | | granted | boolean | | | fastpath | boolean | | |
文档: pg_locks
pg_locks (PostgreSQL 11)
View "pg_catalog.pg_locks" Column | Type | Collation | Nullable | Default --------------------+----------+-----------+----------+--------- locktype | text | | | database | oid | | | relation | oid | | | page | integer | | | tuple | smallint | | | virtualxid | text | | | transactionid | xid | | | classid | oid | | | objid | oid | | | objsubid | smallint | | | virtualtransaction | text | | | pid | integer | | | mode | text | | | granted | boolean | | | fastpath | boolean | | |
文档: pg_locks
pg_locks (PostgreSQL 10)
View "pg_catalog.pg_locks" Column | Type | Collation | Nullable | Default --------------------+----------+-----------+----------+--------- locktype | text | | | database | oid | | | relation | oid | | | page | integer | | | tuple | smallint | | | virtualxid | text | | | transactionid | xid | | | classid | oid | | | objid | oid | | | objsubid | smallint | | | virtualtransaction | text | | | pid | integer | | | mode | text | | | granted | boolean | | | fastpath | boolean | | |
文档: pg_locks
pg_locks (PostgreSQL 9.6)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean | fastpath | boolean |
文档: pg_locks
pg_locks (PostgreSQL 9.5)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean | fastpath | boolean |
文档: pg_locks
pg_locks (PostgreSQL 9.4)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean | fastpath | boolean |
文档: pg_locks
pg_locks (PostgreSQL 9.3)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean | fastpath | boolean |
文档: pg_locks
pg_locks (PostgreSQL 9.2)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean | fastpath | boolean |
文档: pg_locks
pg_locks (PostgreSQL 9.1)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean |
文档: pg_locks
pg_locks (PostgreSQL 9.0)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean |
文档: pg_locks
pg_locks (PostgreSQL 8.4)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean | View definition: SELECT l.locktype, l.database, l.relation, l.page, l.tuple, l.virtualxid, l.transactionid, l.classid, l.objid, l.objsubid, l.virtualtransaction, l.pid, l.mode, l.granted FROM pg_lock_status() l(locktype, database, relation, page, tuple, virtualxid, transactionid, classid, objid, objsubid, virtualtransaction, pid, mode, granted);
文档: pg_locks
pg_locks (PostgreSQL 8.3)
View "pg_catalog.pg_locks" Column | Type | Modifiers --------------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | virtualxid | text | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | virtualtransaction | text | pid | integer | mode | text | granted | boolean | View definition: SELECT l.locktype, l.database, l.relation, l.page, l.tuple, l.virtualxid, l.transactionid, l.classid, l.objid, l.objsubid, l.virtualtransaction, l.pid, l.mode, l.granted FROM pg_lock_status() l(locktype text, database oid, relation oid, page integer, tuple smallint, virtualxid text, transactionid xid, classid oid, objid oid, objsubid smallint, virtualtransaction text, pid integer, mode text, granted boolean);
文档: pg_locks
pg_locks (PostgreSQL 8.2)
View "pg_catalog.pg_locks" Column | Type | Modifiers ---------------+----------+----------- locktype | text | database | oid | relation | oid | page | integer | tuple | smallint | transactionid | xid | classid | oid | objid | oid | objsubid | smallint | transaction | xid | pid | integer | mode | text | granted | boolean | View definition: SELECT l.locktype, l."database", l.relation, l.page, l.tuple, l.transactionid, l.classid, l.objid, l.objsubid, l."transaction", l.pid, l."mode", l."granted" FROM pg_lock_status() l(locktype text, "database" oid, relation oid, page integer, tuple smallint, transactionid xid, classid oid, objid oid, objsubid smallint, "transaction" xid, pid integer, "mode" text, "granted" boolean);
文档: pg_locks
更改历史记录
- PostgreSQL 14
- 添加列
waitstart
(提交 46d6e5f5)
- 添加列
- PostgreSQL 9.2
- 添加列
fastpath
(提交 3cba8999)
- 添加列
- PostgreSQL 8.3
- PostgreSQL 8.1
- PostgreSQL 7.3
- 添加 (提交 82119a69).
示例
来自 pg_locks
的示例行
postgres=# SELECT * FROM pg_locks WHERE relation = 'foo'::regclass; -[ RECORD 1 ]------+-------------------- locktype | relation database | 5 relation | 16425 page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | 6/84 pid | 783970 mode | AccessExclusiveLock granted | t fastpath | f waitstart |
参考
- PostgreSQL文档: pg_locks