PostgreSQL 9.6 等待事件的详细分析

背景

PostgreSQL 9.6动态视图pg_stat_activity新增了wait_event_type, wait_event的等待事件展示。

当会话处于等待状态时,wait_event与wait_event_type非空,表示会话正在等待的类型。

根据等待信息,可以了解当前会话的状态。

将来也可以通过插件的形式,掌握数据库在某个时间段内的等待事件统计,更好的诊断数据库的健康状态。

已有的插件如下

https://github.com/postgrespro/pg_wait_sampling

用于对等待事件进行采样。

例子

pg_wait_sampling_history view – history of wait events obtained by sampling into
in-memory ring buffer.

Column name Column type Description
pid int4 Id of process
ts timestamptz Sample timestamp
event_type text Name of wait event type
event text Name of wait event
pg_wait_sampling_profile view – profile of wait events obtained by sampling into
in-memory hash table.

Column name Column type Description
pid int4 Id of process
event_type text Name of wait event type
event text Name of wait event
count text Count of samples
pg_wait_sampling_reset_profile() function resets the profile.

The work of wait event statistics collector worker is controlled by following
GUCs.

Parameter name Data type Description Default value
pg_wait_sampling.history_size int4 Size of history in-memory ring buffer 5000
pg_wait_sampling.history_period int4 Period for history sampling in milliseconds 10
pg_wait_sampling.profile_period int4 Period for profile sampling in milliseconds 10
pg_wait_sampling.profile_pid bool Whether profile should be per pid true
PostgreSQL 9.6 等待事件

详见
https://www.postgresql.org/docs/9.6/static/monitoring-stats.html

pg_stat_activity 视图新增等待事件列,可以观察到会话当前的等待。

1. wait_event_type
表示等待时间的类别,如果backend处于等待状态则有内容,否则为空。

类别如下

1.1 LWLockNamed:

命名的轻量锁,这种锁的目的是用于保护内存中的数据结构,防止并发的问题。     

The backend is waiting for a specific named lightweight lock.    

Each such lock protects a particular data structure in shared memory.    
1.2 LWLockTranche:

分组轻量锁,没有细分名字,只是笼统的分类。     

The backend is waiting for one of a group of related lightweight locks.    

All locks in the group perform a similar function;    
1.3 Lock:

重量级锁,用于保护SQL可见对象,例如表。  也可以用于保护存储,例如扩展表时。     

见 src/include/storage/lock.h       

The backend is waiting for a heavyweight lock.    

Heavyweight locks, also known as lock manager locks or simply locks, primarily protect SQL-visible objects such as tables.    

However, they are also used to ensure mutual exclusion for certain internal operations such as relation extension.    
1.4 BufferPin:

bufferpin用于保护数据库data buffer中的数据,例如保护游标访问的数据。     

The server process is waiting to access to a data buffer during a period when no other process can be examining that buffer.    

Buffer pin waits can be protracted if another process holds an open cursor which last read data from the buffer in question.   
2. wait_event

表示wait_event_type中对应的详细的等待事件。     

如果当前backend处于等待状态,则有值,否则为空   

Wait event name if backend is currently waiting, otherwise NULL.    
2.1 LWLockNamed

ShmemIndexLock     
    Waiting to find or allocate space in shared memory.   

OidGenLock     
    Waiting to allocate or assign an OID.   

XidGenLock     
    通常出现在高并发的请求事务号时   
    Waiting to allocate or assign a transaction id.   

ProcArrayLock      
    通常出现在高并发的请求事务号,并且开启了old_snapshot_threshold时   
    Waiting to get a snapshot or clearing a transaction id at transaction end.   

SInvalReadLock     
    Waiting to retrieve or remove messages from shared invalidation queue.   

SInvalWriteLock    
    Waiting to add a message in shared invalidation queue.   

WALBufMappingLock      
    Waiting to replace a page in WAL buffers.   

WALWriteLock       
    wal刷盘较慢时,可以提高wal writer频率,或者加大BUFFER,或者提高目标盘的IOPS,降低目标盘的RT。     
    Waiting for WAL buffers to be written to disk.   

ControlFileLock    
    如果产生XLOG确实很频繁,并且没有办法降低,可以使用较大的XLOG文件,最大64MB。     
    通常这个很少见。   
    Waiting to read or update the control file or creation of a new WAL file.   

CheckpointLock     
    Waiting to perform checkpoint.   

CLogControlLock    
    Waiting to read or update transaction status.   

SubtransControlLock    
    Waiting to read or update sub-transaction information.   

MultiXactGenLock       
    Waiting to read or update shared multixact state.   

MultiXactOffsetControlLock     
    Waiting to read or update multixact offset mappings.   

MultiXactMemberControlLock     
    Waiting to read or update multixact member mappings.   

RelCacheInitLock       
    Waiting to read or write relation cache initialization file.   

CheckpointerCommLock       
    检查点分三步(write, sync_file_range, fsync),表示fsync请求出现等待,需要提高IO,或者减少fsync时的dirty page。     
    Waiting to manage fsync requests.   

TwoPhaseStateLock      
    Waiting to read or update the state of prepared transactions.   

TablespaceCreateLock       
    Waiting to create or drop the tablespace.   

BtreeVacuumLock    
    频繁出现,说明索引字段被频繁更新。     
    Waiting to read or update vacuum-related information for a B-tree index.   

AddinShmemInitLock     
    Waiting to manage space allocation in shared memory.   

AutovacuumLock     
    Autovacuum worker or launcher waiting to update or read the current state of autovacuum workers.   

AutovacuumScheduleLock     
    说明autovacuum单表比较慢,看看是否可以关闭autovacuum的SLEEP调度。   
    Waiting to ensure that the table it has selected for a vacuum still needs vacuuming.   

SyncScanLock       
    Waiting to get the start location of a scan on a table for synchronized scans.   

RelationMappingLock    
    Waiting to update the relation map file used to store catalog to filenode mapping.   

AsyncCtlLock       
    Waiting to read or update shared notification state.   

AsyncQueueLock     
    Waiting to read or update notification messages.   

SerializableXactHashLock       
    Waiting to retrieve or store information about serializable transactions.  

SerializableFinishedListLock       
    Waiting to access the list of finished serializable transactions.   

SerializablePredicateLockListLock      
    Waiting to perform an operation on a list of locks held by serializable transactions.   

OldSerXidLock      
    Waiting to read or record conflicting serializable transactions.   

SyncRepLock    
    Waiting to read or update information about synchronous replicas.   

BackgroundWorkerLock       
    Waiting to read or update background worker state.   

DynamicSharedMemoryControlLock     
    Waiting to read or update dynamic shared memory state.   

AutoFileLock       
    Waiting to update the postgresql.auto.conf file.   

ReplicationSlotAllocationLock      
    Waiting to allocate or free a replication slot.   

ReplicationSlotControlLock     
    Waiting to read or update replication slot state.   

CommitTsControlLock    
    Waiting to read or update transaction commit timestamps.   

CommitTsLock       
    Waiting to read or update the last value set for the transaction timestamp.   

ReplicationOriginLock      
    Waiting to setup, drop or use replication origin.   

MultiXactTruncationLock    
    Waiting to read or truncate multixact information.   

OldSnapshotTimeMapLock     
    Waiting to read or update old snapshot control information.   
2.2 LWLockTranche

clog       
    通常很少见,可能出现在在非常高并发的极小写事务时,文件IO出现等待,使用cgroup可以很容易复现。     
    Waiting for I/O on a clog (transaction status) buffer.   

commit_timestamp       
    Waiting for I/O on commit timestamp buffer.   

subtrans       
    Waiting for I/O a subtransaction buffer.   

multixact_offset       
    Waiting for I/O on a multixact offset buffer.  

multixact_member       
    Waiting for I/O on a multixact_member buffer.  

async      
    Waiting for I/O on an async (notify) buffer.   

oldserxid      
    Waiting to I/O on an oldserxid buffer.   

wal_insert     
    Waiting to insert WAL into a memory buffer.   

buffer_content     
    指 数据库 shared buffer   
    Waiting to read or write a data page in memory.   

buffer_io      
    指 数据库 shared buffer   
    Waiting for I/O on a data page.   

replication_origin     
    Waiting to read or update the replication progress.   

replication_slot_io    
    Waiting for I/O on a replication slot.   

proc       
    Waiting to read or update the fast-path lock information.   

buffer_mapping     
    Waiting to associate a data block with a buffer in the buffer pool. 

lock_manager       
    Waiting to add or examine locks for backends, or waiting to join or exit a locking group (used by parallel query).   

predicate_lock_manager     
    Waiting to add or examine predicate lock information.   
2.3 Lock

relation       
    Waiting to acquire a lock on a relation.   

extend     
    Waiting to extend a relation.   

page       
    Waiting to acquire a lock on page of a relation.   

tuple      
    Waiting to acquire a lock on a tuple.   

transactionid      
    Waiting for a transaction to finish.   

virtualxid     
    Waiting to acquire a virtual xid lock.   

speculative token      
    Waiting to acquire a speculative insertion lock.   

object     
    Waiting to acquire a lock on a non-relation database object.   

userlock       
    Waiting to acquire a userlock.   

advisory       
    Waiting to acquire an advisory user lock.   
2.4 BufferPin

BufferPin      
    Waiting to acquire a pin on a buffer.   
3. 获取当指定PID当前的等待信息。

pg_stat_get_backend_wait_event_type(integer)       
    Wait event type name if backend is currently waiting, otherwise NULL. See Table 28-4 for details.   

pg_stat_get_backend_wait_event(integer)    
    Wait event name if backend is currently waiting, otherwise NULL. See Table 28-4 for details.

时间: 2024-09-19 16:56:59

PostgreSQL 9.6 等待事件的详细分析的相关文章

PostgreSQL 9.6 等待事件出炉

PostgreSQL 9.6 等待事件 作者 digoal 日期 2016-10-06 标签 PostgreSQL , 9.6 , 等待事件 , wait_event 背景 PostgreSQL 9.6动态视图pg_stat_activity新增了wait_event_type, wait_event的等待事件展示. 当会话处于等待状态时,wait_event与wait_event_type非空,表示会话正在等待的类型. 根据等待信息,可以了解当前会话的状态. 将来也可以通过插件的形式,掌握数据

PostgreSQL 10.0 preview 功能增强 - 新增数十个IO等待事件监控

标签 PostgreSQL , 10.0 , 等待事件 , IO 背景 PostgreSQL 10.0新增了数十个IO等待事件,描述系统调用的等待. Hi All, Attached is the patch, which extend the existing wait event infrastructure to implement the wait events for the disk I/O. Basically pg_stat_activity's wait event infor

Oracle OWI 等待事件历史视图及相关视图

    Oracle提供的等待事件视图使得我们可以获取指定session以及实例级别等待事件的详细信息,这些视图分别是v$session_wait,v$session_event,以及v$system_event.然而这几个视图对于历史等待事件无能为力.对此,Oracle也提供了历史等待事件视图v$session_wait_history,同时视图v$session_wait_class,v$system_wait_class也提供了基于等待类别的性能分析,下面是基于Oracle 10g对此展开

【等待事件】等待事件系列(3+4)--System IO(控制文件)+日志类等待

 [等待事件]等待事件系列(3+4)--System IO(控制文件)+日志类等待   1  BLOG文档结构图     2  前言部分   2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ① 控制文件类等待 ② 日志类等待   2.2  相关参考文章链接 [推荐] 等待事件系列(1)--User I/O类型(下) http://blog.itpub.net/26736162/viewspace-2124435

PostgreSQL 9.6 支持等待事件统计了

PostgreSQL 9.6 统计信息收集进程pgstat,增加了等待事件信息的收集,并且用户可以获得backend的等待事件信息. 目前支持的等待事件分类如下 src/include/pgstat.h /* ---------- * Wait Classes * ---------- */ typedef enum WaitClass { WAIT_UNDEFINED, WAIT_LWLOCK_NAMED, WAIT_LWLOCK_TRANCHE, WAIT_LOCK, WAIT_BUFFER

详细分析Android中onTouch事件传递机制_Android

onTach介绍 ontach是Android系统中整个事件机制的基础.Android中的其他事件,如onClick.onLongClick等都是以onTach为基础的. onTach包括从手指按下到离开手机屏幕的整个过程,在微观形式上,具体表现为action_down.action_move和action_up等过程. onTach两种主要定义形式如下: 1.在自定义控件中,常见的有重写onTouchEvent(MotionEvent ev)方法.如在开发中经常可以看到重写的onTouchEv

RAC性能分析gc buffer busy acquire 等待事件

概述---------------------gc buffer busy是RAC数据库中常见的等待事件,11g开始gc buffer  busy分为gc buffer busy acquire和gc buffer  busy release. gc buffer busy acquire是当session#1尝试请求访问远程实例(remote  instance) buffer,但是在session#1之前已经有相同实例上另外一个session#2请求访问了相同的buffer,并且没有完成,那

详细分析Android中onTouch事件传递机制

onTach介绍 ontach是Android系统中整个事件机制的基础.Android中的其他事件,如onClick.onLongClick等都是以onTach为基础的. onTach包括从手指按下到离开手机屏幕的整个过程,在微观形式上,具体表现为action_down.action_move和action_up等过程. onTach两种主要定义形式如下: 1.在自定义控件中,常见的有重写onTouchEvent(MotionEvent ev)方法.如在开发中经常可以看到重写的onTouchEv

十种流行进程注入技术详细分析

本文讲的是十种流行进程注入技术详细分析, 前言 流程注入是一种恶意软件和无文件间谍攻击中使用的最为广泛的漏洞攻击技术,而且在攻击时还需要在另一个进程的地址空间内运行自定义代码.过程注入除了提高了攻击的隐蔽性之外,也实现了持久性攻击.尽管目前有许多流程注入技术,但在本文中,我只介绍十种在野外看到的能够运用另一个进程运行恶意代码的技术.在介绍的同时,我还会提供这些技术的屏幕截图,以便于逆向工程和恶意软件分析,协助针对这些常见技术进行的检测和防御. 一.经典的DLL注入 这种技术是用于将恶意软件注入另