Postgresql 锁查看

之前版本 PostgreSQL 的 pg_stat_activity 视图的 waiting 字段判断会话是否等待锁资源(通俗地讲, waiting 值为true表示申请不到锁资源处于等待状态),但是并不会给出具体的锁的信息,9.6 版本之后 pg_stat_activity 视图的 waiting 字段被 wait_event_type 和 wait_event 字段取代,这两个字段分别代表等待事件的类型、等待事件名称;

 

SELECT pid, wait_event_type, wait_event FROM pg_stat_activity;

 

Wait Event TypeWait Event NameDescription
LWLockNamedShmemIndexLockWaiting to find or allocate space in shared memory.
OidGenLockWaiting to allocate or assign an OID.
XidGenLockWaiting to allocate or assign a transaction id.
ProcArrayLockWaiting to get a snapshot or clearing a transaction id at transaction end.
SInvalReadLockWaiting to retrieve or remove messages from shared invalidation queue.
SInvalWriteLockWaiting to add a message in shared invalidation queue.
WALBufMappingLockWaiting to replace a page in WAL buffers.
WALWriteLockWaiting for WAL buffers to be written to disk.
ControlFileLockWaiting to read or update the control file or creation of a new WAL file.
CheckpointLockWaiting to perform checkpoint.
CLogControlLockWaiting to read or update transaction status.
SubtransControlLockWaiting to read or update sub-transaction information.
MultiXactGenLockWaiting to read or update shared multixact state.
MultiXactOffsetControlLockWaiting to read or update multixact offset mappings.
MultiXactMemberControlLockWaiting to read or update multixact member mappings.
RelCacheInitLockWaiting to read or write relation cache initialization file.
CheckpointerCommLockWaiting to manage fsync requests.
TwoPhaseStateLockWaiting to read or update the state of prepared transactions.
TablespaceCreateLockWaiting to create or drop the tablespace.
BtreeVacuumLockWaiting to read or update vacuum-related information for a Btree index.
AddinShmemInitLockWaiting to manage space allocation in shared memory.
AutovacuumLockAutovacuum worker or launcher waiting to update or read the current state of autovacuum workers.
AutovacuumScheduleLockWaiting to ensure that the table it has selected for a vacuum still needs vacuuming.
SyncScanLockWaiting to get the start location of a scan on a table for synchronized scans.
RelationMappingLockWaiting to update the relation map file used to store catalog to filenode mapping.
AsyncCtlLockWaiting to read or update shared notification state.
AsyncQueueLockWaiting to read or update notification messages.
SerializableXactHashLockWaiting to retrieve or store information about serializable transactions.
SerializableFinishedListLockWaiting to access the list of finished serializable transactions.
SerializablePredicateLockListLockWaiting to perform an operation on a list of locks held by serializable transactions.
OldSerXidLockWaiting to read or record conflicting serializable transactions.
SyncRepLockWaiting to read or update information about synchronous replicas.
BackgroundWorkerLockWaiting to read or update background worker state.
DynamicSharedMemoryControlLockWaiting to read or update dynamic shared memory state.
AutoFileLockWaiting to update the postgresql.auto.conf file.
ReplicationSlotAllocationLockWaiting to allocate or free a replication slot.
ReplicationSlotControlLockWaiting to read or update replication slot state.
CommitTsControlLockWaiting to read or update transaction commit timestamps.
CommitTsLockWaiting to read or update the last value set for the transaction timestamp.
ReplicationOriginLockWaiting to setup, drop or use replication origin.
MultiXactTruncationLockWaiting to read or truncate multixact information.
LWLockTrancheclogWaiting for I/O on a clog (transaction status) buffer.
commit_timestampWaiting for I/O on commit timestamp buffer.
subtransWaiting for I/O a subtransaction buffer.
multixact_offsetWaiting for I/O on a multixact offset buffer.
multixact_memberWaiting for I/O on a multixact_member buffer.
asyncWaiting for I/O on an async (notify) buffer.
oldserxidWaiting to I/O on an oldserxid buffer.
wal_insertWaiting to insert WAL into a memory buffer.
buffer_contentWaiting to read or write a data page in memory.
buffer_ioWaiting for I/O on a data page.
replication_originWaiting to read or update the replication progress.
replication_slot_ioWaiting for I/O on a replication slot.
procWaiting to read or update the fast-path lock information.
buffer_mappingWaiting to associate a data block with a buffer in the buffer pool.
lock_managerWaiting to add or examine locks for backends, or waiting to join or exit a locking group (used by parallel query).
predicate_lock_managerWaiting to add or examine predicate lock information.
LockrelationWaiting to acquire a lock on a relation.
extendWaiting to extend a relation.
pageWaiting to acquire a lock on page of a relation.
tupleWaiting to acquire a lock on a tuple.
transactionidWaiting for a transaction to finish.
virtualxidWaiting to acquire a virtual xid lock.
speculative tokenWaiting to acquire a speculative insertion lock.
objectWaiting to acquire a lock on a non-relation database object.
userlockWaiting to acquire a userlock.
advisoryWaiting to acquire an advisory user lock.
BufferPinBufferPinWaiting to acquire a pin on a buffer.
 
备注:通过以上表格, wait_event_type 主要分类四类:
  • LWLockNamed:表示backend后台进程等待某种特定的轻量级锁;
  • LWLockTranche:表示backend后台进程等待一组相关轻量级锁;
  • Lock:表示backend后台进程等待重量级的锁,通常是指 relation、tuple、page、transactionid 等子类型锁;
  • BufferPin:表示server process 后台进程等待 buffer pin,手册上解释为 Waiting to acquire a pin on a buffer,比较难理解,以后想想如何模拟此场景。

 

转载于:https://www.cnblogs.com/zhangeamon/p/9197321.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值