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_PIN
}       WaitClass;

支持的获取等待事件类别和等待事件信息的函数
src/backend/postmaster/pgstat.c

/* ----------
 * pgstat_get_wait_event_type() -
 *
 *      Return a string representing the current wait event type, backend is
 *      waiting on.
 */
const char *
pgstat_get_wait_event_type(uint32 wait_event_info)
{
        uint8           classId;
        const char *event_type;

        /* report process as not waiting. */
        if (wait_event_info == 0)
                return NULL;

        wait_event_info = wait_event_info >> 24;
        classId = wait_event_info & 0XFF;

        switch (classId)
        {
                case WAIT_LWLOCK_NAMED:
                        event_type = "LWLockNamed";
                        break;
                case WAIT_LWLOCK_TRANCHE:
                        event_type = "LWLockTranche";
                        break;
                case WAIT_LOCK:
                        event_type = "Lock";
                        break;
                case WAIT_BUFFER_PIN:
                        event_type = "BufferPin";
                        break;
                default:
                        event_type = "???";
                        break;
        }

        return event_type;
}

/* ----------
 * pgstat_get_wait_event() -
 *
 *      Return a string representing the current wait event, backend is
 *      waiting on.
 */
const char *
pgstat_get_wait_event(uint32 wait_event_info)
{
        uint8           classId;
        uint16          eventId;
        const char *event_name;

        /* report process as not waiting. */
        if (wait_event_info == 0)
                return NULL;

        eventId = wait_event_info & ((1 << 24) - 1);
        wait_event_info = wait_event_info >> 24;
        classId = wait_event_info & 0XFF;

        switch (classId)
        {
                case WAIT_LWLOCK_NAMED:
                case WAIT_LWLOCK_TRANCHE:
                        event_name = GetLWLockIdentifier(classId, eventId);
                        break;
                case WAIT_LOCK:
                        event_name = GetLockNameFromTagType(eventId);
                        break;
                case WAIT_BUFFER_PIN:
                        event_name = "BufferPin";
                        break;
                default:
                        event_name = "unknown wait event";
                        break;
        }

        return event_name;
}

详细的等待信息归类和信息见手册
https://www.postgresql.org/docs/9.6/static/monitoring-stats.html

在pg_stat_activity动态视图中支持的等待事件字段信息如下
wait_event_type

The type of event for which the backend is waiting, if any; otherwise NULL.
Possible values are:

LWLockNamed:
The backend is waiting for a specific named lightweight lock. Each such lock protects a particular data structure in shared memory. wait_event will contain the name of the lightweight lock.

LWLockTranche:
The backend is waiting for one of a group of related lightweight locks. All locks in the group perform a similar function; wait_event will identify the general purpose of locks in that group.

Lock:
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. wait_event will identify the type of lock awaited.

BufferPin:
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.

wait_event

Wait event name if backend is currently waiting, otherwise NULL.
See wait_event for details.

等待事件的归类以及对应的等待信息解释
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    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    Waiting for WAL buffers to be written to disk.
ControlFileLock    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    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 Btree 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    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.

LWLockTranche

clog    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    Waiting to read or write a data page in memory.
buffer_io    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.

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.

BufferPin

BufferPin    Waiting to acquire a pin on a buffer.
时间: 2024-09-15 08:25:06

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 9.6 等待事件的详细分析

背景 PostgreSQL 9.6动态视图pg_stat_activity新增了wait_event_type, wait_event的等待事件展示. 当会话处于等待状态时,wait_event与wait_event_type非空,表示会话正在等待的类型. 根据等待信息,可以了解当前会话的状态. 将来也可以通过插件的形式,掌握数据库在某个时间段内的等待事件统计,更好的诊断数据库的健康状态. 已有的插件如下 https://github.com/postgrespro/pg_wait_sampli

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

db file async I/O submit 等待事件优化

db file async I/O submit 等待事件优化   一.数据发生db file async I/O submit 我们从数据库awr报告中经常会看到很高db file async I/O submit的等待事件: SQL> select event,wait_class,wait_time from v$session_wait where wait_class<>'Idle' EVENT WAIT_CLASS WAIT_TIME --------------------

【MOS】常见问题cursor library cache类型的等待事件

[MOS]常见问题:'cursor:mutex ..'/ 'cursor:pin ..'/ 'library cache:mutex ..'类型的等待事件 (文档 ID 1525791.1) 文档内容 用途 问题和答案   什么是 'cursor: ' 等待事件?   最常见的等待事件是什么?   等待事件最常见的原因是什么?   如何避免这些等待事件?   可以在什么位置找到原因诊断以及关于这些等待事件的更多信息?   有用参考 参考 适用于: Oracle Database - Enterp

【等待事件】等待事件系列(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

Oracle的等待事件

转自http://www.kingsnet.biz/Article/database/oracle/200804/8694_5.html Oracle的等待事件是衡量Oracle运行状况的重要依据及指标.等待事件的概念是在Oracle7.0.1.2中引入的,大致有100个等待事件.在Oracle 8.0中这个数目增加到了大约150个,在Oracle8i中大约有200个事件,在Oracle9i中大约有360个等待事件.主要有两种类别的等待事件,即空闲(idle)等待事件和非空闲(non-idle)

Statspack之十四-&amp;amp;quot;log file sync&amp;amp;quot; 等待事件

原文出处: http://www.eygle.com/statspack/statspack14-LogFileSync.htm 当一个用户提交(commits)或者回滚(rollback),session的redo信息需要写出到redo logfile中.用户进程将通知LGWR执行写出操作,LGWR完成任务以后会通知用户进程.这个等待事件就是指用户进程等待LGWR的写完成通知. 对于回滚操作,该事件记录从用户发出rollback命令到回滚完成的时间. 如果该等待过多,可能说明LGWR的写出效率

Oracle Mutex 等待事件

Oracle Mutex 等待事件之: cursor pin S pin S 等待事件说明,当一个会话(session)试图去更新一个共享的 Mutex Pin,同时已经有其他会话正在更新(updating)同一个 Shared Mutex Pin.注意,Pin S 的Mutex位于子游标上,是动态创建的,无法从等待事件中获得,但是可以在竞争出现的情况下,通过观察 x$mutex_sleep_history 来获得. 文档说明如下: Oracle Mutex 等待事件之: cursor pin