trace_locks 是一个用于在 PostgreSQL 日志文件中发出有关建议性(用户)锁使用信息的开发 配置参数。
trace_locks 在 PostgreSQL 7.1 中添加。
用法
trace_locks 是一个开发者 GUC,只有在编译 PostgreSQL 时在 src/include/pg_config_manual.h 中定义了宏 LOCK_DEBUG 时才可用。
当 trace_locks 启用时,有关锁使用信息将以 LOG 级别写入 PostgreSQL 日志输出。示例如下。
默认
trace_locks 的默认值为:off。
变更历史
- PostgreSQL 7.1
- 添加于(提交 6a68f426)
示例
启用 trace_locks 时的日志输出示例
[2024-01-02 09:10:38 UTC] psql postgres postgres LOG: 00000: LockAcquire: lock [5,16388] AccessExclusiveLock [2024-01-02 09:10:38 UTC] psql postgres postgres LOCATION: LockAcquireExtended, lock.c:799 [2024-01-02 09:10:38 UTC] psql postgres postgres STATEMENT: CREATE TABLE foo (id INT); [2024-01-02 09:10:38 UTC] psql postgres postgres LOG: 00000: LockAcquire: new: lock(0x7fb387e8cfa8) id(5,16388,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(AccessExclusiveLock) [2024-01-02 09:10:38 UTC] psql postgres postgres LOCATION: LOCK_PRINT, lock.c:337 [2024-01-02 09:10:38 UTC] psql postgres postgres STATEMENT: CREATE TABLE foo (id INT); [2024-01-02 09:10:38 UTC] psql postgres postgres LOG: 00000: LockAcquire: new: proclock(0x7fb38801aec0) lock(0x7fb387e8cfa8) method(1) proc(0x7fb388597af8) hold(0) [2024-01-02 09:10:38 UTC] psql postgres postgres LOCATION: PROCLOCK_PRINT, lock.c:349 [2024-01-02 09:10:38 UTC] psql postgres postgres STATEMENT: CREATE TABLE foo (id INT); [2024-01-02 09:10:38 UTC] psql postgres postgres LOG: 00000: LockCheckConflicts: no conflict: proclock(0x7fb38801aec0) lock(0x7fb387e8cfa8) method(1) proc(0x7fb388597af8) hold(0) [2024-01-02 09:10:38 UTC] psql postgres postgres LOCATION: PROCLOCK_PRINT, lock.c:349 [2024-01-02 09:10:38 UTC] psql postgres postgres STATEMENT: CREATE TABLE foo (id INT); [2024-01-02 09:10:38 UTC] psql postgres postgres LOG: 00000: GrantLock: lock(0x7fb387e8cfa8) id(5,16388,0,0,0,1) grantMask(100) req(0,0,0,0,0,0,0)=1 grant(0,0,0,0,0,0,0)=1 wait(0) type(AccessExclusiveLock) [2024-01-02 09:10:38 UTC] psql postgres postgres LOCATION: LOCK_PRINT, lock.c:337 [2024-01-02 09:10:38 UTC] psql postgres postgres STATEMENT: CREATE TABLE foo (id INT); [2024-01-02 09:10:38 UTC] psql postgres postgres LOG: 00000: LockAcquire: lock [5,16388] AccessExclusiveLock [2024-01-02 09:10:38 UTC] psql postgres postgres LOCATION: LockAcquireExtended, lock.c:799 [2024-01-02 09:10:38 UTC] psql postgres postgres STATEMENT: CREATE TABLE foo (id INT);
参考资料
- PostgreSQL 文档: trace_locks
