trace_lock_table

一个用于发出表锁使用信息的开发 GUC

trace_lock_table 是一个开发 配置参数,用于发出关于特定表的信息。

trace_lock_tablePostgreSQL 7.1 中添加。

用法

trace_lock_table 是一个开发者 GUC,只有当 PostgreSQL 编译时在 src/include/pg_config_manual.h 中定义了宏 LOCK_DEBUG 时才可用。

如果将其设置为表的 OID,则关于该表的使用信息将以 LOG 级别写入 PostgreSQL 日志输出。示例如下。

默认

trace_lock_table 的默认值为:0

变更历史

示例

trace_lock_table 对某个特定表启用时的日志输出示例,假设有以下情况

postgres=# SELECT oid FROM pg_class WHERE relname = 'foo';
  oid  
-------
 16395
(1 row)

postgres=# SET trace_lock_table TO 16395;
SET

postgres=# BEGIN;
BEGIN

postgres=*# LOCK TABLE foo IN EXCLUSIVE MODE;
LOCK TABLE

postgres=*# LOCK TABLE bar IN EXCLUSIVE MODE;
LOCK TABLE
postgres=*# 

日志文件包含表 foo 的条目,但不包含 bar 的条目

[2024-01-02 09:52:29 UTC] psql postgres postgres LOG:  00000: LockAcquire: lock [5,16395] ExclusiveLock
[2024-01-02 09:52:29 UTC] psql postgres postgres LOCATION:  LockAcquireExtended, lock.c:799
[2024-01-02 09:52:29 UTC] psql postgres postgres STATEMENT:  LOCK TABLE foo IN EXCLUSIVE MODE;
[2024-01-02 09:52:29 UTC] psql postgres postgres LOG:  00000: LockAcquire: new: lock(0x7fb387e97d28) id(5,16395,0,0,0,1) grantMask(0) req(0,0,0,0,0,0,0)=0 grant(0,0,0,0,0,0,0)=0 wait(0) type(ExclusiveLock)
[2024-01-02 09:52:29 UTC] psql postgres postgres LOCATION:  LOCK_PRINT, lock.c:337
[2024-01-02 09:52:29 UTC] psql postgres postgres STATEMENT:  LOCK TABLE foo IN EXCLUSIVE MODE;
[2024-01-02 09:52:29 UTC] psql postgres postgres LOG:  00000: LockAcquire: new: proclock(0x7fb3880253c0) lock(0x7fb387e97d28) method(1) proc(0x7fb3885965c8) hold(0)
[2024-01-02 09:52:29 UTC] psql postgres postgres LOCATION:  PROCLOCK_PRINT, lock.c:349
[2024-01-02 09:52:29 UTC] psql postgres postgres STATEMENT:  LOCK TABLE foo IN EXCLUSIVE MODE;
[2024-01-02 09:52:29 UTC] psql postgres postgres LOG:  00000: LockCheckConflicts: no conflict: proclock(0x7fb3880253c0) lock(0x7fb387e97d28) method(1) proc(0x7fb3885965c8) hold(0)
[2024-01-02 09:52:29 UTC] psql postgres postgres LOCATION:  PROCLOCK_PRINT, lock.c:349
[2024-01-02 09:52:29 UTC] psql postgres postgres STATEMENT:  LOCK TABLE foo IN EXCLUSIVE MODE;
[2024-01-02 09:52:29 UTC] psql postgres postgres LOG:  00000: GrantLock: lock(0x7fb387e97d28) id(5,16395,0,0,0,1) grantMask(80) req(0,0,0,0,0,0,1)=1 grant(0,0,0,0,0,0,1)=1 wait(0) type(ExclusiveLock)
[2024-01-02 09:52:29 UTC] psql postgres postgres LOCATION:  LOCK_PRINT, lock.c:337
[2024-01-02 09:52:29 UTC] psql postgres postgres STATEMENT:  LOCK TABLE foo IN EXCLUSIVE MODE;

分类

开发/测试, GUC 配置项, 锁定

另请参阅

trace_locks, trace_lwlocks, trace_userlocks

反馈

在此处提交关于“trace_lock_table”的任何评论、建议或更正 此处