PostgreSQL 9.6 支持等待事件统计了

本文涉及的产品
云数据库 RDS SQL Server,基础系列 2核4GB
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
云原生数据库 PolarDB 分布式版,标准版 2核8GB
简介: PostgreSQL 9.6 统计信息收集进程pgstat,增加了等待事件信息的收集,并且用户可以获得backend的等待事件信息。 目前支持的等待事件分类如下src/include/pgstat.h /* ---------- * Wait Classes * --------

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.
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
SQL 弹性计算 关系型数据库
HTAP数据库 PostgreSQL 场景与性能测试之 3.1 - (OLAP) 大表JOIN统计查询-10亿 join 1亿 agg
标签 PostgreSQL , HTAP , OLTP , OLAP , 场景与性能测试 背景 PostgreSQL是一个历史悠久的数据库,历史可以追溯到1973年,最早由2014计算机图灵奖得主,关系数据库的鼻祖Michael_Stonebraker 操刀设计,PostgreSQL具备与Oracle类似的功能、性能、架构以及稳定性。 PostgreSQL社区的贡献者众多
2072 0
|
5月前
|
SQL 关系型数据库 PostgreSQL
PostgreSQL 如何通过身份证号码进行年龄段的统计?
【8月更文挑战第20天】PostgreSQL 如何通过身份证号码进行年龄段的统计?
599 2
|
SQL 关系型数据库 Java
PostgreSQL统计信息的几个重要视图
PostgreSQL统计信息的几个重要视图
304 1
|
缓存 监控 关系型数据库
[译]PostgreSQL16-新特性-新增IO统计视图:pg_stat_io
[译]PostgreSQL16-新特性-新增IO统计视图:pg_stat_io
252 0
|
SQL 监控 Oracle
PostgreSQL pgcenter - 采样、统计、性能诊断、profile、cli小工具
标签 PostgreSQL , pgcenter , pg_top , awr , perf insight , 等待事件 , perf , profile , 采样 , 统计信息 背景 PostgreSQL 性能诊断的方法很多: 例如: 1、函数的性能诊断,PROFILE。 《PostgreSQL 函数调试、诊断、优化 & auto_explain & plpro
2092 0
|
SQL 弹性计算 关系型数据库
PostgreSQL 12 preview - CTE 增强,支持用户语法层控制 materialized 优化
标签 PostgreSQL , CTE , materialized , not materialized , push down 背景 PostgreSQL with 语法,能跑非常复杂的SQL逻辑,包括递归,多语句物化计算等。 在12以前的版本中,WITH中的每一个CTE(common table express),都是直接进行物化的,也就是说外层的条件不会推到CTE(物化节点)里
1040 0
|
存储 SQL Oracle
AnalyticDB PostgreSQL 7.0 支持存储过程(CREATE PROCEDURE)特性
AnalyticDB PostgreSQL 7.0 新增了存储过程功能的支持,让用户在使用ADB PG时能够更方便高效地开发业务,并能够更好地兼容Oracle等传统数仓的业务。
517 1
AnalyticDB PostgreSQL 7.0 支持存储过程(CREATE PROCEDURE)特性
|
关系型数据库 PostgreSQL
PostgreSQL 性能优化: 等待事件
等待事件是 PostgreSQL 的重要优化工具。当您能查明会话为什么在等待资源以及会话在做什么时,您就能更好地减少瓶颈。您可以使用本节中的信息来查找可能的原因和纠正措施。
289 0
|
SQL 缓存 监控
PostgreSQL 监控1统计进程和统计信息的解读|学习笔记(二)
快速学习PostgreSQL 监控1统计进程和统计信息的解读
446 0
PostgreSQL 监控1统计进程和统计信息的解读|学习笔记(二)
|
SQL 监控 IDE
PostgreSQL监控1统计进程和统计信息的解读|学习笔记(一)
快速学习PostgreSQL监控1统计进程和统计信息的解读
631 0
PostgreSQL监控1统计进程和统计信息的解读|学习笔记(一)

相关产品

  • 云原生数据库 PolarDB
  • 云数据库 RDS PostgreSQL 版