trace_lock_table
是一个用于输出关于特定表的信息的开发 配置参数。
trace_lock_table
在 PostgreSQL 7.1 中添加。
用法
trace_lock_table
是一个开发者 GUC,仅在编译 PostgreSQL 时在 src/include/pg_config_manual.h 中定义了宏 LOCK_DEBUG
时可用。
如果设置为表的 OID,则有关该表锁使用情况的信息将以 LOG
级别写入 PostgreSQL 日志输出。请参见下面的示例。
默认值
trace_lock_table
的默认值为:0
。
变更历史
- PostgreSQL 7.1
- 添加 (提交 6a68f426)
示例
当 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;
参考
- PostgreSQL 文档: trace_lock_table