选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

文档 / 系统目录 / 系统视图

SYSTEM VIEW系统视图

pg_locks

当前持有或等待的锁

系统视图 引入 9.0(基线) 现存至 20 devel 2 次结构变更

类别
系统视图
关系 OID
12073
关系类型
v(视图)
字段数
16
引入版本
9.0(收录基线)
版本状态
当前稳定版
结构变更
2 次

PostgreSQL 18 手册 官方文档

版本轨迹

相对 PostgreSQL 17:描述更新 2 处。

视图pg_locks提供了对数据库服务器中活动进程持有的锁的信息的访问。有关锁定的更多讨论,请参见Chapter 13。

pg_locks包含每个活动的可锁定对象、请求的锁模式和相关进程的一行。 因此,如果多个进程正在持有或等待锁定它,同一可锁定对象可能会出现多次。 但是,当前没有任何锁定的对象将不会出现。

有几种不同类型的可锁定对象: 整个关系(例如,表),关系的单个页面, 关系的单个元组, 事务ID(虚拟和永久ID均包括), 以及一般的数据库对象(由类OID和对象OID标识, 与pg_description或 pg_depend中的方式相同)。 此外,扩展关系的权限被表示为一个单独的可锁定对象,以及更新 pg_database.datfrozenxid 的更新权限。 此外,还可以对具有用户定义含义的数字施加“咨询锁”。

字段

PostgreSQL 18 的 16 个字段,按定义顺序排列。说明默认用本站手册的译文,没有译文的按英文原文显示。

字段 类型 说明
locktype text 可锁定对象的类型: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory 或 applytransaction。 (另请参见Table 27.11。)
database oid pg_database.oid 锁目标存在的数据库的OID,如果目标是一个共享对象则为0,如果目标是一个事务ID则为空
relation oid pg_class.oid 作为锁目标的关系的OID,如果目标不是一个关系或者只是关系的一部分则此列为空
page integer 作为锁目标的页在关系中的页号,如果目标不是一个关系页或元组则此列为空
tuple smallint 作为锁目标的元组在页中的元组号,如果目标不是一个元组则此列为空
virtualxid text 锁定目标事务的虚拟 ID,如果目标不是虚拟事务 ID,则为空;见 Chapter 67
transactionid xid 锁定目标事务的标识,如果目标不是事务 ID,则为空;Chapter 67
classid oid pg_class.oid 包含锁目标的系统目录的OID,如果目标不是一个普通数据库对象则此列为空
objid oid any OID column 锁目标在它的系统目录中的OID,如果目标不是一个普通数据库对象则为空
objsubid smallint 锁的目标列号(classid和objid指表本身),如果目标是某种其他普通数据库对象则此列为0,如果目标不是一个普通数据库对象则此列为空
virtualtransaction text 保持这个锁或者正在等待这个锁的事务的虚拟ID
pid integer 保持这个锁或者正在等待这个锁的服务器进程的PID,如果此锁被一个预备事务所持有则此列为空
mode text 此进程已持有或者希望持有的锁模式的名称(参见Section 13.3.1和Section 13.2.3)
granted boolean 如果锁已授予则为真,如果锁被等待则为假
fastpath boolean 如果锁通过快速路径获得则为真,通过主锁表获得则为假
waitstart timestamp with time zone 服务器进程开始等待该锁的时间;如果锁已被授予则为空。 注意,在开始等待之后,即使granted为false,该值在极短时间内也可能仍为空。

演化历史

相邻两个大版本之间的差异,新的在前。版本号链到该版的字段表。

  1. PostgreSQL 18 ← 17 仅描述更新

    2 处描述更新
    • transactionid ID of the transaction targeted by the lock, or null if the target is not a transaction ID; Chapter 66 ID of the transaction targeted by the lock, or null if the target is not a transaction ID; Chapter 67
    • virtualxid Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see Chapter 66 Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see Chapter 67
  2. PostgreSQL 17 ← 16 仅描述更新

    3 处描述更新
    • locktype Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction. (See also Table 28.11.) Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction. (See also Table 27.11.)
    • transactionid ID of the transaction targeted by the lock, or null if the target is not a transaction ID; Chapter 74 ID of the transaction targeted by the lock, or null if the target is not a transaction ID; Chapter 66
    • virtualxid Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see Chapter 74 Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see Chapter 66
  3. PostgreSQL 16 ← 15 仅描述更新

    3 处描述更新
    • locktype Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, or advisory. (See also Table 28.11.) Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction. (See also Table 28.11.)
    • transactionid ID of the transaction targeted by the lock, or null if the target is not a transaction ID ID of the transaction targeted by the lock, or null if the target is not a transaction ID; Chapter 74
    • virtualxid Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see Chapter 74
  4. PostgreSQL 14 ← 13 结构变更

    waitstart

    1 处描述更新
    • locktype Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, or advisory. (See also Table 27.11.) Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, or advisory. (See also Table 28.11.)
  5. PostgreSQL 13 ← 12 仅描述更新

    1 处描述更新
    • locktype Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, object, userlock, or advisory Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, or advisory. (See also Table 27.11.)
  6. PostgreSQL 10 ← 9.6 仅描述更新

    关系说明更新

  7. PostgreSQL 9.6 ← 9.5 仅描述更新

    关系说明更新

  8. PostgreSQL 9.5 ← 9.4 仅描述更新

    关系说明更新

    1 处描述更新
    • locktype Type of the lockable object: relation, extend, page, tuple, transactionid, virtualxid, object, userlock, or advisory Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, object, userlock, or advisory
  9. PostgreSQL 9.2 ← 9.1 结构变更

    fastpath

    8 处描述更新
    • classid OID of the system catalog containing the object, or null if the object is not a general database object OID of the system catalog containing the lock target, or null if the target is not a general database object
    • database OID of the database in which the object exists, or zero if the object is a shared object, or null if the object is a transaction ID OID of the database in which the lock target exists, or zero if the target is a shared object, or null if the target is a transaction ID
    • objid OID of the object within its system catalog, or null if the object is not a general database object OID of the lock target within its system catalog, or null if the target is not a general database object
    • page Page number within the relation, or null if the object is not a tuple or relation page Page number targeted by the lock within the relation, or null if the target is not a relation page or tuple
    • relation OID of the relation, or null if the object is not a relation or part of a relation OID of the relation targeted by the lock, or null if the target is not a relation or part of a relation
    • transactionid ID of a transaction, or null if the object is not a transaction ID ID of the transaction targeted by the lock, or null if the target is not a transaction ID
    • tuple Tuple number within the page, or null if the object is not a tuple Tuple number targeted by the lock within the page, or null if the target is not a tuple
    • virtualxid Virtual ID of a transaction, or null if the object is not a virtual transaction ID Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID
  10. PostgreSQL 9.1 ← 9.0 仅描述更新

    关系说明更新

    3 处描述更新
    • mode Name of the lock mode held or desired by this process (see Section 13.3.1) Name of the lock mode held or desired by this process (see Section 13.3.1 and Section 13.2.3)
    • objsubid For a table column, this is the column number (the classid and objid refer to the table itself). For all other object types, this column is zero. Null if the object is not a general database object Column number targeted by the lock (the classid and objid refer to the table itself), or zero if the target is some other general database object, or null if the target is not a general database object
    • pid Process ID of the server process holding or awaiting this lock. Null if the lock is held by a prepared transaction. Process ID of the server process holding or awaiting this lock, or null if the lock is held by a prepared transaction

字段矩阵

每个字段在 18 个收录版本里的存在情况;方格指向该版的字段表。「有变」指类型、可空、隐式或数组维数与上一版不同。

存在 有变 已移除 不存在

字段 9.09.19.29.39.49.59.61011121314151617181920
locktype 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
database 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
relation 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
page 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
tuple 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
virtualxid 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
transactionid 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
classid 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
objid 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
objsubid 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
virtualtransaction 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
pid 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
mode 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
granted 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
fastpath 不存在 不存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在
waitstart 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在 存在 存在 存在 存在

同类关系

关系 引入 字段 版本变动 最近变更
SYSTEM VIEW 系统视图 39 个
pg_aios 18 15
正在使用的异步 I/O 句柄 现存
pg_available_extension_versions 9.1 10 192 次
扩展的可用版本 现存
pg_available_extensions 9.1 5 191 次
可用的扩展 现存
pg_backend_memory_contexts 14 10 181 次
后端内存上下文 现存
pg_config 9.6 2
编译时配置参数 现存
pg_cursors 9.0基线 6
打开的游标 现存
pg_dsm_registry_allocations 19 3
DSM 注册表跟踪的共享内存分配 现存
pg_file_settings 9.5 7
配置文件内容摘要 现存
pg_group 9.0基线 3
数据库用户组 现存
pg_hba_file_rules 10 11 161 次
客户端认证配置文件内容的摘要 现存
pg_ident_file_mappings 15 7 161 次
客户端用户名映射配置文件内容摘要 现存
pg_indexes 9.0基线 5
索引 现存
pg_locks 9.0基线 16 142 次
当前持有或等待的锁 现存
pg_matviews 9.3 7
物化视图 现存
pg_policies 9.5 8 101 次
策略 现存
pg_prepared_statements 9.0基线 8 162 次
预备语句 现存
pg_prepared_xacts 9.0基线 5
预备事务 现存
pg_publication_sequences 19 3
发布及其关联序列的信息 现存
pg_publication_tables 10 5 151 次
发布及其关联表的信息 现存
pg_replication_origin_status 9.5 4
有关复制源的信息,包括复制进度 现存
pg_replication_slots 9.4 22 199 次
复制槽信息 现存
pg_roles 9.0基线 13 9.52 次
数据库角色 现存
pg_rules 9.0基线 4
规则 现存
pg_seclabels 9.1 8
安全标签 现存
pg_sequences 10 11
序列 现存
pg_settings 9.0基线 17 9.51 次
参数设置 现存
pg_shadow 9.0基线 9 123 次
数据库用户 现存
pg_shmem_allocations 13 4
共享内存分配 现存
pg_shmem_allocations_numa 18 3
共享内存分配的 NUMA 节点映射 现存
pg_stats 9.0基线 19 193 次
规划器统计信息 现存
pg_stats_ext 12 17 193 次
扩展规划器统计信息 现存
pg_stats_ext_exprs 14 22 192 次
表达式的扩展规划器统计信息 现存
pg_tables 9.0基线 8 9.51 次
现存
pg_timezone_abbrevs 9.0基线 3
时区简写 现存
pg_timezone_names 9.0基线 4
时区名称 现存
pg_user 9.0基线 9 123 次
数据库用户 现存
pg_user_mappings 9.0基线 6
用户映射 现存
pg_views 9.0基线 4
视图 现存
pg_wait_events 17 3
等待事件 现存