pg_stat_activity
pg_stat_replication
pg_stat_replication_slots
pg_stat_wal_receiver
pg_stat_recovery_prefetch
pg_stat_subscription
pg_stat_subscription_stats
pg_stat_ssl
pg_stat_gssapi
pg_stat_archiver
pg_stat_io
pg_stat_bgwriter
pg_stat_checkpointer
pg_stat_wal
pg_stat_database
pg_stat_database_conflicts
pg_stat_all_tables
pg_stat_all_indexes
pg_statio_all_tables
pg_statio_all_indexes
pg_statio_all_sequences
pg_stat_user_functions
pg_stat_slru
PostgreSQL的累积统计系统支持收集和报告有关服务器活动的信息。 目前,对表和索引的访问以磁盘块和单个行的术语进行计数。每个表中的总行数, 以及每个表的清理和分析操作的信息也被计数。如果启用,对用户定义函数的调用 和每个函数中花费的总时间也会被计数。
PostgreSQL也支持报告关于系统当前正在发生的情况的动态信息, 例如其他服务器进程当前正在执行的确切命令,以及系统中存在哪些其他连接。此功能独立于累积统计系统。
因为统计收集给查询执行增加了一些负荷,系统可以被配置为收集或不收集信息。这由配置参数控制,它们通常在postgresql.conf
中设置(关于设置配置参数的细节请见Chapter 19)。
参数track_activities允许监控当前被任意服务器进程执行的命令。
参数track_counts控制是否收集关于表和索引访问的累积统计信息。
参数track_functions启用对用户定义函数使用的跟踪。
参数 track_io_timing 启用对块读取、写入、扩展和 fsync 时间的监控。
参数 track_wal_io_timing 启用对WAL写入和fsync时间的监控。
通常这些参数被设置在postgresql.conf
中,这样它们会应用于所有服务器进程,但是可以在单个会话中使用SET命令打开或关闭它们(为了阻止普通用户对管理员隐藏他们的活动,只有超级用户被允许使用SET
来改变这些参数)。
累积统计数据存储在共享内存中。每个PostgreSQL进程在本地收集统计数据,
然后在适当的间隔更新共享数据。当服务器,包括物理副本,正常关闭时,统计数据的永久副本存储在
pg_stat
子目录中,以便统计数据可以在服务器重新启动时保留。相反,当从不干净的
关闭开始(例如,立即关闭后,服务器崩溃,从基本备份开始和时间点恢复),所有统计计数器都会被重置。
有几个预定义的视图,列在Table 27.1中, 可用于显示系统的当前状态。还有几个其他视图,列在Table 27.2中,可用于显示累积统计信息。 或者,可以使用底层的累积统计函数构建自定义视图,如在Section 27.2.26中讨论的那样。
当使用累积统计视图和函数来监视收集的数据时,重要的是要意识到信息不会立即更新。每个单独的服务器进程在空闲之前将累积的统计信息刷新到共享内存中,但不会频繁于每PGSTAT_MIN_INTERVAL
毫秒(1秒,除非在构建服务器时更改)一次;因此,仍在进行中的查询或事务不会影响显示的总计,显示的信息滞后于实际活动。然而,由track_activities
收集的当前查询信息始终是最新的。
另一个重要点是,当服务器进程被要求显示任何累积的统计信息时,默认配置下
访问的值会被缓存直到当前事务结束。因此,只要你继续当前事务,统计信息将
显示静态信息。类似地,所有会话当前查询的信息在事务内首次请求时被收集,
并且在整个事务期间显示相同的信息。这是一个特性,而非缺陷,因为它允许你
对统计信息执行多个查询并关联结果,而无需担心数据在背后发生变化。
在交互式分析统计信息或使用开销较大的查询时,访问单个统计信息之间的时
间差可能导致缓存统计数据出现显著偏差。为最小化偏差,可以将
stats_fetch_consistency
设置为 snapshot
,
代价是增加了缓存不必要统计数据的内存使用。相反,如果已知统计信息只被
访问一次,则缓存访问过的统计信息是不必要的,可以通过将
stats_fetch_consistency
设置为 none
来避免。
你可以调用 pg_stat_clear_snapshot()
来丢弃当前事务的
统计快照或缓存值(如果有)。下一次使用统计信息时(在快照模式下)将构建
新快照,或(在缓存模式下)缓存访问过的统计信息。
事务还可以在视图pg_stat_xact_all_tables
、
pg_stat_xact_sys_tables
、
pg_stat_xact_user_tables
和
pg_stat_xact_user_functions
中看到自己的统计信息
(尚未刷新到共享内存统计信息)。这些数字不像上面所述那样起作用;
相反,它们在事务期间持续更新。
动态统计视图中显示的一些信息在Table 27.1中受到安全限制。
普通用户只能查看关于他们自己会话的所有信息(属于他们是成员的角色的会话)。在关于其他会话的行中,许多列将为空。
但是,请注意,所有用户都可以看到会话的存在以及其一般属性,如会话用户和数据库。超级用户和具有内置角色pg_read_all_stats
特权的角色(另请参阅Section 21.5)可以查看所有会话的所有信息。
Table 27.1. 动态统计视图
视图名称 | 描述 |
---|---|
pg_stat_activity
|
每个服务器进程一行,显示与那个进程的当前活动相关的信息,例如状态和当前查询。详见pg_stat_activity 。
|
pg_stat_replication | 每一个 WAL 发送进程一行,显示有关到该发送进程连接的后备服务器的复制的统计信息。
详见pg_stat_replication .
|
pg_stat_wal_receiver | 只有一行,显示来自 WAL 接收器所连接服务器的有关该接收器的统计信息。详见
pg_stat_wal_receiver 。
|
pg_stat_recovery_prefetch | 只有一行,显示了恢复过程中预取的块的统计信息。
详细信息请参见
pg_stat_recovery_prefetch 。
|
pg_stat_subscription | 每个订阅至少一行,显示有关该订阅的工作者的信息。详见
pg_stat_subscription 。
|
pg_stat_ssl | 每个连接(常规的或者复制)一行,显示在这个连接上使用的SSL的信息。详见
pg_stat_ssl 。
|
pg_stat_gssapi | 每个连接(常规和复制)有一行,显示关于GSSAPI验证和加密的信息。详情请参阅
pg_stat_gssapi 。
|
pg_stat_progress_analyze | 每个正在运行ANALYZE 的后台进程(包括自动清理工作进程)对应一行,
显示当前进度。
请参阅Section 27.4.1。
|
pg_stat_progress_create_index | 每个正在运行CREATE INDEX 或REINDEX 的后端对应一行,显示
当前进度。
请参阅Section 27.4.4。
|
pg_stat_progress_vacuum | 每个正在运行VACUUM 的后台进程(包括自动清理工作进程)对应一行,
显示当前进度。
请参阅Section 27.4.5。
|
pg_stat_progress_cluster | 每个正在运行
CLUSTER 或VACUUM FULL 的后台进程对应一行,显示当前进度。
请参阅Section 27.4.2。
|
pg_stat_progress_basebackup | 每个正在流式传输基础备份的WAL发送进程对应一行, 显示当前进度。 请参阅Section 27.4.6。 |
pg_stat_progress_copy | 每个正在运行COPY 的后台进程的一行,显示当前进度。
请参阅Section 27.4.3。
|
Table 27.2. 已收集统计信息的视图
视图名称 | 描述 |
---|---|
pg_stat_archiver | 只有一行,显示有关 WAL 归档进程活动的统计信息。详见
pg_stat_archiver 。
|
pg_stat_bgwriter | 只有一行,显示有关后台写进程的活动的统计信息。详见
pg_stat_bgwriter 。
|
pg_stat_checkpointer | 仅一行,显示有关检查点进程活动的统计信息。详情请参见
pg_stat_checkpointer 。
|
pg_stat_database | 每个数据库一行,显示数据库范围的统计信息。详见
pg_stat_database 。
|
pg_stat_database_conflicts |
每个数据库一行,显示数据库范围的统计信息,
这些信息的内容是关于由于与后备服务器的恢复过程
发生冲突而被取消的查询。详见
pg_stat_database_conflicts 。
|
pg_stat_io |
每个后端类型、上下文和目标对象的组合对应一行,
包含集群范围的I/O统计信息。
详情请参见
pg_stat_io 。
|
pg_stat_replication_slots | 每个复制槽一行,显示关于复制槽的利用率的统计信息。
详请参见 pg_stat_replication_slots 。
|
pg_stat_slru | 每个SLRU一行, 显示操作的统计信息。参见
pg_stat_slru for details.
|
pg_stat_subscription_stats | 每个订阅的一行,显示有关错误的统计信息。
有关详细信息,请参见
pg_stat_subscription_stats 。
|
pg_stat_wal | 仅一行,显示WAL活动的统计信息。
详请参见 pg_stat_wal 。
|
pg_stat_all_tables |
当前数据库中每个表一行,显示有关访问指定表的统计信息。详见
pg_stat_all_tables 。
|
pg_stat_sys_tables | 和pg_stat_all_tables 一样,但只显示系统表。 |
pg_stat_user_tables | 和pg_stat_all_tables 一样,但只显示用户表。 |
pg_stat_xact_all_tables | 和pg_stat_all_tables 相似,但计数动作只在当前事务内发生(还没有被包括在pg_stat_all_tables 和相关视图中)。用于生存和死亡行数量的列以及清理和分析动作在此视图中不出现。 |
pg_stat_xact_sys_tables | 和pg_stat_xact_all_tables 一样,但只显示系统表。 |
pg_stat_xact_user_tables | 和pg_stat_xact_all_tables 一样,但只显示用户表。 |
pg_stat_all_indexes |
当前数据库中的每个索引一行,显示:表OID、索引OID、模式名、表名、索引名、 使用了该索引的索引扫描总数、索引扫描返回的索引记录数、使用该索引的简 单索引扫描抓取的活表(livetable)中数据行数。
当前数据库中的每个索引一行,显示与访问指定索引有关的统计信息。详见
pg_stat_all_indexes 。
|
pg_stat_sys_indexes | 和pg_stat_all_indexes 一样,但只显示系统表上的索引。 |
pg_stat_user_indexes | 和pg_stat_all_indexes 一样,但只显示用户表上的索引。 |
pg_stat_user_functions |
对于所有跟踪功能,函数的OID,模式,名称,数量 通话总时间,和自我的时间。自我时间是 在函数本身所花费的时间量,总时间包括 它调用函数所花费的时间。时间值以毫秒为单位。
每一个被跟踪的函数一行,显示与执行该函数有关的统计信息。详见
pg_stat_user_functions 。
|
pg_stat_xact_user_functions | 和pg_stat_user_functions 相似,但是只统计在当前事务期间的调用(还没有被包括在pg_stat_user_functions 中)。 |
pg_statio_all_tables |
当前数据库中每个表一行(包括TOAST表),显示:表OID、模式名、表名、 从该表中读取的磁盘块总数、缓冲区命中次数、该表上所有索引的磁盘块读取总数、 该表上所有索引的缓冲区命中总数、在该表的辅助TOAST表(如果存在)上的磁盘块读取总数、 在该表的辅助TOAST表(如果存在)上的缓冲区命中总数、TOAST表的索引的磁盘块读 取总数、TOAST表的索引的缓冲区命中总数。
当前数据库中的每个表一行,显示有关在指定表上 I/O 的统计信息。详见
pg_statio_all_tables 。
|
pg_statio_sys_tables | 和pg_statio_all_tables 一样,但只显示系统表。 |
pg_statio_user_tables | 和pg_statio_all_tables 一样,但只显示用户表。 |
pg_statio_all_indexes |
当前数据库中每个索引一行,显示:表OID、索引OID、模式名、 表名、索引名、该索引的磁盘块读取总数、该索引的缓冲区命中总数。
当前数据库中的每个索引一行,显示与指定索引上的 I/O 有关的统计信息。详见
pg_statio_all_indexes 。
|
pg_statio_sys_indexes | 和pg_statio_all_indexes 一样,但只显示系统表上的索引。 |
pg_statio_user_indexes | 和pg_statio_all_indexes 一样,但只显示用户表上的索引。 |
pg_statio_all_sequences |
当前数据库中每个序列对象一行,显示:序列OID、模式名、序列名、序列的磁盘读取总数、序列的缓冲区命中总数。
当前数据库中的每个序列一行,显示与指定序列上的 I/O 有关的统计信息。详见
pg_statio_all_sequences 。
|
pg_statio_sys_sequences | 和pg_statio_all_sequences 一样,但只显示系统序列(目前没有定义系统序列,因此这个视图总是为空)。 |
pg_statio_user_sequences | 和pg_statio_all_sequences 一样,但只显示用户序列。 |
针对每个索引的统计信息对于判断哪个索引正被使用以及它们的效果特别有用。
pg_stat_io
和pg_statio_
视图集对于
确定缓冲区缓存的有效性非常有用。它们可以用来计算缓存命中率。请注意,虽然
PostgreSQL的I/O统计捕获了大多数调用内核以执行
I/O的情况,但它们无法区分需要从磁盘获取的数据和已经驻留在内核页面缓存中的
数据。建议用户将PostgreSQL统计视图与操作系统
工具结合使用,以更全面地了解其数据库的I/O性能。
pg_stat_activity
#
pg_stat_activity
视图每个服务器进程将有一行,显示与该进程当前活动相关的信息。
Table 27.3. pg_stat_activity
视图
列类型 描述 |
---|
这个后端连接到的数据库的OID |
这个后端连接到的数据库的名称 |
这个后端的进程 ID |
如果此进程是并行查询工作者,则为并行组领导者的进程 ID;如果此进程是并行应用
工作者,则为领导应用工作者的进程 ID。 |
登录到这个后端的用户的 OID |
登录到这个后端的用户的 OID |
连接到这个后端的应用的名称 |
连接到这个后端的客户端的 IP 地址。如果这个字段为空,它表示客户端通过服务器机器上的一个 Unix 套接字连接或者这是一个内部进程,如自动清理。 |
已连接的客户端的主机名,由 |
客户端用于与此后端通信的TCP端口号,如果使用Unix套接字,则为 |
这个进程被启动的时间。对客户端后端来说,这就是客户端连接到服务器的时间。 |
这个进程的当前事务被启动的时间,如果没有活动事务则为空。
如果当前查询是它的第一个事务,这一列等于 |
当前活动查询被开始的时间,如果 |
|
后端等待的事件类型,如果有的话;否则NULL。参见Table 27.4。 |
如果后端当前正在等待,则等待事件名称,否则为NULL。参见Table 27.5 到 Table 27.13。 |
这个后端的当前总体状态。可能的值为:
|
此后端的顶级事务标识符(如果有);请参阅 Section 66.1。 |
当前后端的 |
这个后端的最近查询的标识符。
如果 |
这个后端最近查询的文本。如果 |
当前后端的类型。可能的类型有
|
wait_event
和state
列是独立的。如果一个后端处于active
状态,它可能是也可能不是某个事件上的waiting
。如果状态是active
并且wait_event
为非空,它意味着一个查询正在被执行,但是它被阻塞在系统中某处。
Table 27.4. 等待事件类型
等待事件类型 | 描述 |
---|---|
Activity | 服务器进程空闲。此事件类型表示在其主处理循环中等待活动的进程。
wait_event 将识别特定的等待点;参见Table 27.5。
|
BufferPin | 服务器进程正在等待对数据缓冲的独占访问。 如果另一个进程持有一个打开的游标,该游标最后一次从相关缓冲区读取数据,则缓冲区销等待可能是漫长的。 参见Table 27.6。 |
Client | 服务器进程正在等待连接到用户应用程序的套接字上的活动。
因此,服务器预计发生一些独立于其内部进程的事情。wait_event 将识别特定的等待点;参见Table 27.7。
|
Extension | 服务器进程正在等待扩展模块定义的某个条件。参见Table 27.8。 |
InjectionPoint | 服务器进程正在等待注入点达到测试中定义的结果。详见 Section 36.10.13。此类型没有预定义的等待点。 |
IO | 服务器进程正在等待一个I/O操作完成。wait_event 将识别特定的等待点;参见Table 27.9。
|
IPC | 服务器进程正在等待与另一个服务器进程进行交互。wait_event 将识别特定的等待点;参见Table 27.10。
|
Lock | 服务器进程正在等待一个重量级锁。重量级锁,也称为锁管理器锁或简单锁,主要保护表等SQL可见对象。
然而,它们也用于确保某些内部操作的互斥,例如关系扩展。wait_event 将识别等待的锁的类型;参见Table 27.11。
|
LWLock | 服务器进程正在等待一个轻量级锁。大多数这样的锁保护共享内存中的特定数据结构。
wait_event 将包含标识轻量级锁用途的名称。
(有些锁有特定的名称;其他锁是一组锁的一部分,每个锁具有类似的目的。)参见Table 27.12。
|
Timeout | 服务器进程正在等待超时过期。wait_event 将识别特定的等待点;参见Table 27.13。
|
Table 27.5. Wait Events of Type Activity
Activity Wait Event | Description |
---|---|
ArchiverMain | Waiting in main loop of archiver process. |
AutovacuumMain | Waiting in main loop of autovacuum launcher process. |
BgwriterHibernate | Waiting in background writer process, hibernating. |
BgwriterMain | Waiting in main loop of background writer process. |
CheckpointerMain | Waiting in main loop of checkpointer process. |
LogicalApplyMain | Waiting in main loop of logical replication apply process. |
LogicalLauncherMain | Waiting in main loop of logical replication launcher process. |
LogicalParallelApplyMain | Waiting in main loop of logical replication parallel apply process. |
RecoveryWalStream | Waiting in main loop of startup process for WAL to arrive, during streaming recovery. |
ReplicationSlotsyncMain | Waiting in main loop of slot sync worker. |
ReplicationSlotsyncShutdown | Waiting for slot sync worker to shut down. |
SysloggerMain | Waiting in main loop of syslogger process. |
WalReceiverMain | Waiting in main loop of WAL receiver process. |
WalSenderMain | Waiting in main loop of WAL sender process. |
WalSummarizerWal | Waiting in WAL summarizer for more WAL to be generated. |
WalWriterMain | Waiting in main loop of WAL writer process. |
Table 27.6. Wait Events of Type Bufferpin
BufferPin Wait Event | Description |
---|---|
BufferPin | Waiting to acquire an exclusive pin on a buffer. |
Table 27.7. Wait Events of Type Client
Client Wait Event | Description |
---|---|
ClientRead | Waiting to read data from the client. |
ClientWrite | Waiting to write data to the client. |
GssOpenServer | Waiting to read data from the client while establishing a GSSAPI session. |
LibpqwalreceiverConnect | Waiting in WAL receiver to establish connection to remote server. |
LibpqwalreceiverReceive | Waiting in WAL receiver to receive data from remote server. |
SslOpenServer | Waiting for SSL while attempting connection. |
WaitForStandbyConfirmation | Waiting for WAL to be received and flushed by the physical standby. |
WalSenderWaitForWal | Waiting for WAL to be flushed in WAL sender process. |
WalSenderWriteData | Waiting for any activity when processing replies from WAL receiver in WAL sender process. |
Table 27.8. Wait Events of Type Extension
Extension Wait Event | Description |
---|---|
Extension | Waiting in an extension. |
Table 27.9. Wait Events of Type Io
IO Wait Event | Description |
---|---|
BasebackupRead | Waiting for base backup to read from a file. |
BasebackupSync | Waiting for data written by a base backup to reach durable storage. |
BasebackupWrite | Waiting for base backup to write to a file. |
BuffileRead | Waiting for a read from a buffered file. |
BuffileTruncate | Waiting for a buffered file to be truncated. |
BuffileWrite | Waiting for a write to a buffered file. |
ControlFileRead | Waiting for a read from the pg_control file. |
ControlFileSync | Waiting for the pg_control file to reach durable storage. |
ControlFileSyncUpdate | Waiting for an update to the pg_control file to reach durable storage. |
ControlFileWrite | Waiting for a write to the pg_control file. |
ControlFileWriteUpdate | Waiting for a write to update the pg_control file. |
CopyFileRead | Waiting for a read during a file copy operation. |
CopyFileWrite | Waiting for a write during a file copy operation. |
DataFileExtend | Waiting for a relation data file to be extended. |
DataFileFlush | Waiting for a relation data file to reach durable storage. |
DataFileImmediateSync | Waiting for an immediate synchronization of a relation data file to durable storage. |
DataFilePrefetch | Waiting for an asynchronous prefetch from a relation data file. |
DataFileRead | Waiting for a read from a relation data file. |
DataFileSync | Waiting for changes to a relation data file to reach durable storage. |
DataFileTruncate | Waiting for a relation data file to be truncated. |
DataFileWrite | Waiting for a write to a relation data file. |
DsmAllocate | Waiting for a dynamic shared memory segment to be allocated. |
DsmFillZeroWrite | Waiting to fill a dynamic shared memory backing file with zeroes. |
LockFileAddtodatadirRead | Waiting for a read while adding a line to the data directory lock file. |
LockFileAddtodatadirSync | Waiting for data to reach durable storage while adding a line to the data directory lock file. |
LockFileAddtodatadirWrite | Waiting for a write while adding a line to the data directory lock file. |
LockFileCreateRead | Waiting to read while creating the data directory lock file. |
LockFileCreateSync | Waiting for data to reach durable storage while creating the data directory lock file. |
LockFileCreateWrite | Waiting for a write while creating the data directory lock file. |
LockFileRecheckdatadirRead | Waiting for a read during recheck of the data directory lock file. |
LogicalRewriteCheckpointSync | Waiting for logical rewrite mappings to reach durable storage during a checkpoint. |
LogicalRewriteMappingSync | Waiting for mapping data to reach durable storage during a logical rewrite. |
LogicalRewriteMappingWrite | Waiting for a write of mapping data during a logical rewrite. |
LogicalRewriteSync | Waiting for logical rewrite mappings to reach durable storage. |
LogicalRewriteTruncate | Waiting for truncate of mapping data during a logical rewrite. |
LogicalRewriteWrite | Waiting for a write of logical rewrite mappings. |
RelationMapRead | Waiting for a read of the relation map file. |
RelationMapReplace | Waiting for durable replacement of a relation map file. |
RelationMapWrite | Waiting for a write to the relation map file. |
ReorderBufferRead | Waiting for a read during reorder buffer management. |
ReorderBufferWrite | Waiting for a write during reorder buffer management. |
ReorderLogicalMappingRead | Waiting for a read of a logical mapping during reorder buffer management. |
ReplicationSlotRead | Waiting for a read from a replication slot control file. |
ReplicationSlotRestoreSync | Waiting for a replication slot control file to reach durable storage while restoring it to memory. |
ReplicationSlotSync | Waiting for a replication slot control file to reach durable storage. |
ReplicationSlotWrite | Waiting for a write to a replication slot control file. |
SlruFlushSync | Waiting for SLRU data to reach durable storage during a checkpoint or database shutdown. |
SlruRead | Waiting for a read of an SLRU page. |
SlruSync | Waiting for SLRU data to reach durable storage following a page write. |
SlruWrite | Waiting for a write of an SLRU page. |
SnapbuildRead | Waiting for a read of a serialized historical catalog snapshot. |
SnapbuildSync | Waiting for a serialized historical catalog snapshot to reach durable storage. |
SnapbuildWrite | Waiting for a write of a serialized historical catalog snapshot. |
TimelineHistoryFileSync | Waiting for a timeline history file received via streaming replication to reach durable storage. |
TimelineHistoryFileWrite | Waiting for a write of a timeline history file received via streaming replication. |
TimelineHistoryRead | Waiting for a read of a timeline history file. |
TimelineHistorySync | Waiting for a newly created timeline history file to reach durable storage. |
TimelineHistoryWrite | Waiting for a write of a newly created timeline history file. |
TwophaseFileRead | Waiting for a read of a two phase state file. |
TwophaseFileSync | Waiting for a two phase state file to reach durable storage. |
TwophaseFileWrite | Waiting for a write of a two phase state file. |
VersionFileSync | Waiting for the version file to reach durable storage while creating a database. |
VersionFileWrite | Waiting for the version file to be written while creating a database. |
WalsenderTimelineHistoryRead | Waiting for a read from a timeline history file during a walsender timeline command. |
WalBootstrapSync | Waiting for WAL to reach durable storage during bootstrapping. |
WalBootstrapWrite | Waiting for a write of a WAL page during bootstrapping. |
WalCopyRead | Waiting for a read when creating a new WAL segment by copying an existing one. |
WalCopySync | Waiting for a new WAL segment created by copying an existing one to reach durable storage. |
WalCopyWrite | Waiting for a write when creating a new WAL segment by copying an existing one. |
WalInitSync | Waiting for a newly initialized WAL file to reach durable storage. |
WalInitWrite | Waiting for a write while initializing a new WAL file. |
WalRead | Waiting for a read from a WAL file. |
WalSummaryRead | Waiting for a read from a WAL summary file. |
WalSummaryWrite | Waiting for a write to a WAL summary file. |
WalSync | Waiting for a WAL file to reach durable storage. |
WalSyncMethodAssign | Waiting for data to reach durable storage while assigning a new WAL sync method. |
WalWrite | Waiting for a write to a WAL file. |
Table 27.10. Wait Events of Type Ipc
IPC Wait Event | Description |
---|---|
AppendReady | Waiting for subplan nodes of an Append plan node to be ready. |
ArchiveCleanupCommand | Waiting for archive_cleanup_command to complete. |
ArchiveCommand | Waiting for archive_command to complete. |
BackendTermination | Waiting for the termination of another backend. |
BackupWaitWalArchive | Waiting for WAL files required for a backup to be successfully archived. |
BgworkerShutdown | Waiting for background worker to shut down. |
BgworkerStartup | Waiting for background worker to start up. |
BtreePage | Waiting for the page number needed to continue a parallel B-tree scan to become available. |
BufferIo | Waiting for buffer I/O to complete. |
CheckpointDelayComplete | Waiting for a backend that blocks a checkpoint from completing. |
CheckpointDelayStart | Waiting for a backend that blocks a checkpoint from starting. |
CheckpointDone | Waiting for a checkpoint to complete. |
CheckpointStart | Waiting for a checkpoint to start. |
ExecuteGather | Waiting for activity from a child process while executing a Gather plan node. |
HashBatchAllocate | Waiting for an elected Parallel Hash participant to allocate a hash table. |
HashBatchElect | Waiting to elect a Parallel Hash participant to allocate a hash table. |
HashBatchLoad | Waiting for other Parallel Hash participants to finish loading a hash table. |
HashBuildAllocate | Waiting for an elected Parallel Hash participant to allocate the initial hash table. |
HashBuildElect | Waiting to elect a Parallel Hash participant to allocate the initial hash table. |
HashBuildHashInner | Waiting for other Parallel Hash participants to finish hashing the inner relation. |
HashBuildHashOuter | Waiting for other Parallel Hash participants to finish partitioning the outer relation. |
HashGrowBatchesDecide | Waiting to elect a Parallel Hash participant to decide on future batch growth. |
HashGrowBatchesElect | Waiting to elect a Parallel Hash participant to allocate more batches. |
HashGrowBatchesFinish | Waiting for an elected Parallel Hash participant to decide on future batch growth. |
HashGrowBatchesReallocate | Waiting for an elected Parallel Hash participant to allocate more batches. |
HashGrowBatchesRepartition | Waiting for other Parallel Hash participants to finish repartitioning. |
HashGrowBucketsElect | Waiting to elect a Parallel Hash participant to allocate more buckets. |
HashGrowBucketsReallocate | Waiting for an elected Parallel Hash participant to finish allocating more buckets. |
HashGrowBucketsReinsert | Waiting for other Parallel Hash participants to finish inserting tuples into new buckets. |
LogicalApplySendData | Waiting for a logical replication leader apply process to send data to a parallel apply process. |
LogicalParallelApplyStateChange | Waiting for a logical replication parallel apply process to change state. |
LogicalSyncData | Waiting for a logical replication remote server to send data for initial table synchronization. |
LogicalSyncStateChange | Waiting for a logical replication remote server to change state. |
MessageQueueInternal | Waiting for another process to be attached to a shared message queue. |
MessageQueuePutMessage | Waiting to write a protocol message to a shared message queue. |
MessageQueueReceive | Waiting to receive bytes from a shared message queue. |
MessageQueueSend | Waiting to send bytes to a shared message queue. |
MultixactCreation | Waiting for a multixact creation to complete. |
ParallelBitmapScan | Waiting for parallel bitmap scan to become initialized. |
ParallelCreateIndexScan | Waiting for parallel CREATE INDEX workers to finish heap scan. |
ParallelFinish | Waiting for parallel workers to finish computing. |
ProcarrayGroupUpdate | Waiting for the group leader to clear the transaction ID at transaction end. |
ProcSignalBarrier | Waiting for a barrier event to be processed by all backends. |
Promote | Waiting for standby promotion. |
RecoveryConflictSnapshot | Waiting for recovery conflict resolution for a vacuum cleanup. |
RecoveryConflictTablespace | Waiting for recovery conflict resolution for dropping a tablespace. |
RecoveryEndCommand | Waiting for recovery_end_command to complete. |
RecoveryPause | Waiting for recovery to be resumed. |
ReplicationOriginDrop | Waiting for a replication origin to become inactive so it can be dropped. |
ReplicationSlotDrop | Waiting for a replication slot to become inactive so it can be dropped. |
RestoreCommand | Waiting for restore_command to complete. |
SafeSnapshot | Waiting to obtain a valid snapshot for a READ ONLY DEFERRABLE transaction. |
SyncRep | Waiting for confirmation from a remote server during synchronous replication. |
WalReceiverExit | Waiting for the WAL receiver to exit. |
WalReceiverWaitStart | Waiting for startup process to send initial data for streaming replication. |
WalSummaryReady | Waiting for a new WAL summary to be generated. |
XactGroupUpdate | Waiting for the group leader to update transaction status at transaction end. |
Table 27.11. Wait Events of Type Lock
Lock Wait Event | Description |
---|---|
advisory | Waiting to acquire an advisory user lock. |
applytransaction | Waiting to acquire a lock on a remote transaction being applied by a logical replication subscriber. |
extend | Waiting to extend a relation. |
frozenid | Waiting to update pg_database .datfrozenxid and pg_database .datminmxid . |
object | Waiting to acquire a lock on a non-relation database object. |
page | Waiting to acquire a lock on a page of a relation. |
relation | Waiting to acquire a lock on a relation. |
spectoken | Waiting to acquire a speculative insertion lock. |
transactionid | Waiting for a transaction to finish. |
tuple | Waiting to acquire a lock on a tuple. |
userlock | Waiting to acquire a user lock. |
virtualxid | Waiting to acquire a virtual transaction ID lock; see Section 66.1. |
Table 27.12. Wait Events of Type Lwlock
LWLock Wait Event | Description |
---|---|
AddinShmemInit | Waiting to manage an extension's space allocation in shared memory. |
AutoFile | Waiting to update the postgresql.auto.conf file. |
Autovacuum | Waiting to read or update the current state of autovacuum workers. |
AutovacuumSchedule | Waiting to ensure that a table selected for autovacuum still needs vacuuming. |
BackgroundWorker | Waiting to read or update background worker state. |
BtreeVacuum | Waiting to read or update vacuum-related information for a B-tree index. |
BufferContent | Waiting to access a data page in memory. |
BufferMapping | Waiting to associate a data block with a buffer in the buffer pool. |
CheckpointerComm | Waiting to manage fsync requests. |
CommitTs | Waiting to read or update the last value set for a transaction commit timestamp. |
CommitTsBuffer | Waiting for I/O on a commit timestamp SLRU buffer. |
CommitTsSLRU | Waiting to access the commit timestamp SLRU cache. |
ControlFile | Waiting to read or update the pg_control file or create a new WAL file. |
DSMRegistry | Waiting to read or update the dynamic shared memory registry. |
DSMRegistryDSA | Waiting to access dynamic shared memory registry's dynamic shared memory allocator. |
DSMRegistryHash | Waiting to access dynamic shared memory registry's shared hash table. |
DynamicSharedMemoryControl | Waiting to read or update dynamic shared memory allocation information. |
InjectionPoint | Waiting to read or update information related to injection points. |
LockFastPath | Waiting to read or update a process' fast-path lock information. |
LockManager | Waiting to read or update information about “heavyweight” locks. |
LogicalRepLauncherDSA | Waiting to access logical replication launcher's dynamic shared memory allocator. |
LogicalRepLauncherHash | Waiting to access logical replication launcher's shared hash table. |
LogicalRepWorker | Waiting to read or update the state of logical replication workers. |
MultiXactGen | Waiting to read or update shared multixact state. |
MultiXactMemberBuffer | Waiting for I/O on a multixact member SLRU buffer. |
MultiXactMemberSLRU | Waiting to access the multixact member SLRU cache. |
MultiXactOffsetBuffer | Waiting for I/O on a multixact offset SLRU buffer. |
MultiXactOffsetSLRU | Waiting to access the multixact offset SLRU cache. |
MultiXactTruncation | Waiting to read or truncate multixact information. |
NotifyBuffer | Waiting for I/O on a NOTIFY message SLRU buffer. |
NotifyQueue | Waiting to read or update NOTIFY messages. |
NotifyQueueTail | Waiting to update limit on NOTIFY message storage. |
NotifySLRU | Waiting to access the NOTIFY message SLRU cache. |
OidGen | Waiting to allocate a new OID. |
ParallelAppend | Waiting to choose the next subplan during Parallel Append plan execution. |
ParallelHashJoin | Waiting to synchronize workers during Parallel Hash Join plan execution. |
ParallelQueryDSA | Waiting for parallel query dynamic shared memory allocation. |
ParallelVacuumDSA | Waiting for parallel vacuum dynamic shared memory allocation. |
PerSessionDSA | Waiting for parallel query dynamic shared memory allocation. |
PerSessionRecordType | Waiting to access a parallel query's information about composite types. |
PerSessionRecordTypmod | Waiting to access a parallel query's information about type modifiers that identify anonymous record types. |
PerXactPredicateList | Waiting to access the list of predicate locks held by the current serializable transaction during a parallel query. |
PgStatsData | Waiting for shared memory stats data access. |
PgStatsDSA | Waiting for stats dynamic shared memory allocator access. |
PgStatsHash | Waiting for stats shared memory hash table access. |
PredicateLockManager | Waiting to access predicate lock information used by serializable transactions. |
ProcArray | Waiting to access the shared per-process data structures (typically, to get a snapshot or report a session's transaction ID). |
RelationMapping | Waiting to read or update a pg_filenode.map file (used to track the filenode assignments of certain system catalogs). |
RelCacheInit | Waiting to read or update a pg_internal.init relation cache initialization file. |
ReplicationOrigin | Waiting to create, drop or use a replication origin. |
ReplicationOriginState | Waiting to read or update the progress of one replication origin. |
ReplicationSlotAllocation | Waiting to allocate or free a replication slot. |
ReplicationSlotControl | Waiting to read or update replication slot state. |
ReplicationSlotIO | Waiting for I/O on a replication slot. |
SerialBuffer | Waiting for I/O on a serializable transaction conflict SLRU buffer. |
SerialControl | Waiting to read or update shared pg_serial state. |
SerializableFinishedList | Waiting to access the list of finished serializable transactions. |
SerializablePredicateList | Waiting to access the list of predicate locks held by serializable transactions. |
SerializableXactHash | Waiting to read or update information about serializable transactions. |
SerialSLRU | Waiting to access the serializable transaction conflict SLRU cache. |
SharedTidBitmap | Waiting to access a shared TID bitmap during a parallel bitmap index scan. |
SharedTupleStore | Waiting to access a shared tuple store during parallel query. |
ShmemIndex | Waiting to find or allocate space in shared memory. |
SInvalRead | Waiting to retrieve messages from the shared catalog invalidation queue. |
SInvalWrite | Waiting to add a message to the shared catalog invalidation queue. |
SubtransBuffer | Waiting for I/O on a sub-transaction SLRU buffer. |
SubtransSLRU | Waiting to access the sub-transaction SLRU cache. |
SyncRep | Waiting to read or update information about the state of synchronous replication. |
SyncScan | Waiting to select the starting location of a synchronized table scan. |
TablespaceCreate | Waiting to create or drop a tablespace. |
TwoPhaseState | Waiting to read or update the state of prepared transactions. |
WaitEventCustom | Waiting to read or update custom wait events information. |
WALBufMapping | Waiting to replace a page in WAL buffers. |
WALInsert | Waiting to insert WAL data into a memory buffer. |
WALSummarizer | Waiting to read or update WAL summarization state. |
WALWrite | Waiting for WAL buffers to be written to disk. |
WrapLimitsVacuum | Waiting to update limits on transaction id and multixact consumption. |
XactBuffer | Waiting for I/O on a transaction status SLRU buffer. |
XactSLRU | Waiting to access the transaction status SLRU cache. |
XactTruncation | Waiting to execute pg_xact_status or update the oldest transaction ID available to it. |
XidGen | Waiting to allocate a new transaction ID. |
Table 27.13. Wait Events of Type Timeout
Timeout Wait Event | Description |
---|---|
BaseBackupThrottle | Waiting during base backup when throttling activity. |
CheckpointWriteDelay | Waiting between writes while performing a checkpoint. |
PgSleep | Waiting due to a call to pg_sleep or a sibling function. |
RecoveryApplyDelay | Waiting to apply WAL during recovery because of a delay setting. |
RecoveryRetrieveRetryInterval | Waiting during recovery when WAL data is not available from any source (pg_wal , archive or stream). |
RegisterSyncRequest | Waiting while sending synchronization requests to the checkpointer, because the request queue is full. |
SpinDelay | Waiting while acquiring a contended spinlock. |
VacuumDelay | Waiting in a cost-based vacuum delay point. |
VacuumTruncate | Waiting to acquire an exclusive lock to truncate off any empty pages at the end of a table vacuumed. |
WalSummarizerError | Waiting after a WAL summarizer error. |
下面是如何查看等待事件的示例:
SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL; pid | wait_event_type | wait_event ------+-----------------+------------ 2540 | Lock | relation 6644 | LWLock | ProcArray (2 rows)
SELECT a.pid, a.wait_event, w.description FROM pg_stat_activity a JOIN pg_wait_events w ON (a.wait_event_type = w.type AND a.wait_event = w.name) WHERE a.wait_event is NOT NULL and a.state = 'active'; -[ RECORD 1 ]------------------------------------------------------------------ pid | 686674 wait_event | WALInitSync description | Waiting for a newly initialized WAL file to reach durable storage
扩展可以向 Extension
、InjectionPoint
和
LWLock
事件添加到 Table 27.8 和
Table 27.12 中显示的列表。在某些情况下,
由扩展分配的 LWLock
名称可能不会在所有服务器进程中
可用。它可能仅被报告为 “extension
”,
而不是扩展分配的名称。
pg_stat_replication
#
pg_stat_replication
视图将在每个WAL发送方进程中包含一行,显示关于复制到发送方连接的备用服务器的统计信息。
只有直接连接的备用设备被列出;没有关于下游备用服务器的信息。
Table 27.14. pg_stat_replication
视图
列类型 描述 |
---|
一个 WAL 发送进程的进程 ID |
登录到这个 WAL 发送进程的用户的 OID |
登录到这个 WAL 发送进程的用户的名称 |
连接到这个 WAL 发送进程的应用的名称 |
连接到这个 WAL 发送进程的客户端的 IP 地址。 如果这个域为空,它表示该客户端通过服务器机器上的一个Unix 套接字连接。 |
已连接的客户端的主机名,由 |
客户端用来与这个 WAL 发送进程通讯的 TCP 端口号,如果使用 Unix 套接字则为 |
这个进程开始的时间,即客户端是何时连接到这个WAL 发送进程的。 |
由hot_standby_feedback报告的这个后备机的 |
当前的 WAL 发送进程状态。 可能的值是:
|
在这个连接上发送的最后一个预写式日志的位置 |
被这个后备服务器写入到磁盘的最后一个预写式日志的位置 |
被这个后备服务器刷入到磁盘的最后一个预写式日志的位置 |
被重放到这个后备服务器上的数据库中的最后一个预写式日志的位置 |
从本地刷新近期的WAL与接收到此备用服务器已写入WAL的通知(但尚未刷新或应用它)之间的时间经过。
如果将此服务器配置为同步备用服务器,则可以使用此参数来衡量在提交时 |
在本地刷写近期的WAL与接收到后备服务器已经写入并且刷写它(但还没有应用)的通知之间流逝的时间。
如果这台服务器被配置为一个同步后备,这可以用来计量在提交时 |
在本地刷写近期的WAL与接收到后备服务器已经写入它、刷写它并且应用它的通知之间流逝的时间。
如果这台服务器被配置为一个同步后备,这可以用来计量在提交时 |
在基于优先的同步复制中,这台后备服务器被选为同步后备的优先级。在基于规定数量的同步复制中,这个值没有效果。 |
这一台后备服务器的同步状态。 可能的值是:
|
从备用服务器收到的最后一条回复信息的发送时间 |
pg_stat_replication
视图中报告的滞后时间近期的WAL被写入、刷写并且重放以及发送器知道这一切所花的时间的度量。如果远程服务器被配置为一台同步后备,这些时间表示由每一种同步提交级别所带来(或者是可能带来)的提交延迟。对于一台异步后备,replay_lag
列是最近的事务变得对查询可见的延迟时间的近似值。如果后备服务器已经完全追上了发送服务器并且没有WAL活动,在短时间内将继续显示最近测到的滞后时间,再然后就会显示为NULL。
对于物理复制会自动测量滞后时间。逻辑解码插件可能会选择性地发出跟踪消息,如果它们没有这样做,跟踪机制将把滞后显示为NULL。
报告的滞后时间并非按照当前的重放速率该后备还有多久才能追上发送服务器的预测。在新的WAL被生成期间,这样一种系统将显示类似的时间,但是当发送器变为闲置时会显示不同的值。特别是当后备服务器完全追上时,pg_stat_replication
显示的是写入、刷写及重放最近报告的WAL位置所花的时间而不是一些用户可能预期的零。这种做法与为近期的写事务测量同步提交和事务可见性延迟的目的一致。为了降低用户预期一种不同的滞后模型带来的混淆,在一个完全重放完的闲置系统上,lag列会在一段比较短的时间后回复成NULL。监控系统应该选择将这种情况表示为缺失数据、零或者继续显示最近的已知值。
pg_stat_replication_slots
#
pg_stat_replication_slots
视图将包含每个逻辑复制槽的一行,显示关于其使用情况的统计信息。
Table 27.15. pg_stat_replication_slots
View
列类型 描述 |
---|
唯一的,复制槽的集群范围标识符 |
当逻辑解码在解码来自WAL的更改时所使用的内存超过 |
在为该槽位解码来自WAL的更改时,事务溢出到磁盘的次数。 此计数器在每次事务被溢出时递增,并且同一事务可能被溢出多次。 |
在对来自WAL的更改执行解码时,已解码的事务数据溢出到磁盘的数量。
这个和其他溢出计数器可用于测量逻辑解码期间发生的I/O,并且允许调优 |
在逻辑解码在解码来自该槽位的WAL更改的时候,所使用的内存超过 |
在为该槽位解码来自WAL的更改时,将正在进行的事务流到解码输出插件的次数。 此计数器在每次事务流化时递增,并且同一事务可能被流化多次。 |
在为该槽位解码来自WAL的更改时,为将正在进行的事务流到解码输出插件而解码的事务数据的数量。
这个和针对此槽位的其他流计数器可用于调优 |
针对此槽的,发送到解码输出插件的已解码事务数。 这只计算顶级事务,对子事务不会增加。 注意,这包括流化和/或溢出的事务。 |
在对此槽位的WAL进行解码时,为将事务发送到解码输出插件而解码的事务数据量。 注意这包括流和/或溢出的数据。 |
这些统计最后重置的时间 |
pg_stat_wal_receiver
#
pg_stat_wal_receiver
事务只包含一行,它显示了从 WAL 接收器所连接的服务器得到的有关该接收器的统计信息。
Table 27.16. pg_stat_wal_receiver
视图
列类型 描述 |
---|
WAL接收器进程的进程ID |
WAL接收进程的活动状态 |
WAL接收器启动时使用的第一个写前日志位置 |
WAL接收器启动时使用的第一个时间线数字 |
已经接收并写入磁盘的最后一个预写式日志位置,但没有刷入。这不能用于数据完整性检查。 |
已经接收并刷入到磁盘的最后一个预写式日志位置,该字段的初始值是启动WAL接收器时使用的第一个日志位置 |
接收并刷入到磁盘的最后一个预写式日志位置的时间线数字,该字段的初始值为启动WAL接收器时使用的第一个日志位置的时间线数字 |
从源头WAL发送器收到的最后一条信息的发送时间 |
从源头WAL发送器收到的最后一条信息的接收时间 |
向源头WAL发送器报告的最后的预写式日志位置 |
向源头WAL发送方报告的最后一次写前日志位置的时间 |
这个WAL接收器使用的复制槽的名称 |
这个WAL接收器连接到的PostgreSQL实例的主机。
这可以是主机名、IP地址,或者目录路径,如果连接是通过Unix套接字进行的。(路径的情况可以区分,因为它总是以 |
这个WAL接收器连接的PostgreSQL实例的端口号。 |
这个WAL接收器使用的连接字符串,对安全敏感的字段进行了模糊处理。 |
pg_stat_recovery_prefetch
#
pg_stat_recovery_prefetch
视图将只包含一行。
wal_distance
、block_distance
和
io_depth
列显示当前值,其他列显示可以使用
pg_stat_reset_shared
函数重置的累积计数器。
Table 27.17. pg_stat_recovery_prefetch
视图
列类型 描述 |
---|
这些统计数据上次重置的时间 |
因为不在缓冲池中,所以预取的块数 |
因为它们已经在缓冲池中,所以未预取的块数 |
未预取的块数,因为它们将被初始化为零 |
未预取的块数,因为它们尚不存在 |
由于WAL中包含完整页图像而未预取的块数 |
由于最近已经预取过而未预取的块数 |
预取器向前查看多少字节 |
预取器正在查看多少个块之前 |
已启动但尚未完成的预取数量 |
pg_stat_subscription
#Table 27.18. pg_stat_subscription
View
列类型 描述 |
---|
订阅的OID |
订阅的名称 |
订阅工作进程的类型。可能的类型有 |
订阅工作者进程的进程ID |
如果此进程是并行应用工作进程,则为领导应用工作进程的进程ID; 如果此进程是领导应用工作进程或表同步工作进程,则为NULL |
工作线程正在同步的关系的OID;对于主应用工作线程和并行应用工作线程为NULL |
接收到的最后写前日志位置,此字段的初始值为0;对于并行应用工作者为NULL |
从源WAL发送者接收到的最后一条消息的发送时间;对于并行应用工作者为NULL |
从源WAL发送者接收到的最后一条消息的接收时间;对于并行应用工作者为NULL |
报告给源WAL发送器的最新预写日志位置;对于并行应用工作者为NULL |
报告给源WAL发送器的最后写前日志位置的时间;对于并行应用工作者为NULL |
pg_stat_subscription_stats
#
pg_stat_subscription_stats
视图将包含每个订阅的一行。
Table 27.19. pg_stat_subscription_stats
视图
列类型 描述 |
---|
订阅的OID |
订阅的名称 |
应用更改时发生错误的次数 |
在初始表同步期间发生错误的次数 |
这些统计数据最后一次重置的时间 |
pg_stat_ssl
#
pg_stat_ssl
视图将为每一个后端或者 WAL 发送进程包含一行,用来显示这个连接上的 SSL 使用情况。
可以把它与pg_stat_activity
或者pg_stat_replication
通过pid
列连接来得到更多有关该连接的细节。
Table 27.20. pg_stat_ssl
视图
列类型 描述 |
---|
后端或WAL发送器进程ID |
如果在此连接上使用SSL,则为真 |
使用SSL的版本,如果此连接上没有使用SSL则为NULL |
正在使用的SSL密码的名称,如果此连接上没有使用SSL则为NULL |
使用的加密算法中的位数,如果此连接上没有使用SSL则为NULL |
区别名称(DN,Distinguished Name)字段与使用的客户端证书,如果没有提供客户端证书或在此连接上没有使用SSL,则为NULL。
如果DN字段长于 |
客户端证书的序列号,如果没有提供客户端证书或在此连接上没有使用SSL,则为NULL。 证书序列号和证书颁发者的组合唯一标识一个证书(除非颁发者错误地重用序列号)。 |
客户端证书颁发者的区别名称(DN,Distinguished Name),如果没有提供客户端证书或在此连接上没有使用SSL,则为NULL。该字段像 |
pg_stat_gssapi
#
pg_stat_gssapi
视图将包含每一个后端一个行,显示该连接上的GSSAPI使用情况。
它可以加入到pg_stat_activity
或pg_stat_replication
上的pid
列,获取更多关于连接的详细信息。
Table 27.21. pg_stat_gssapi
视图
列类型 描述 |
---|
后端进程ID |
如果此连接使用了GSSAPI身份验证,则为True |
用于验证此连接的主体,如果未使用GSSAPI对此连接进行身份验证,则为NULL。
如果主体长度超过 |
如果在此连接上使用了GSSAPI加密,则为真 |
如果在此连接上委派了 GSSAPI 凭据,则为 True。 |
pg_stat_archiver
#
pg_stat_archiver
视图总是有一行,其中包含关于集群的存档进程的数据。
Table 27.22. pg_stat_archiver
视图
列类型 描述 |
---|
已成功存档的WAL文件数 |
最近成功归档的WAL文件的名称 |
最近成功归档操作的时间 |
记录WAL文件归档失败次数 |
最近一次归档操作失败的WAL文件的名称 |
最近一次归档操作失败的时间 |
这些统计数据最后一次重置的时间 |
通常,WAL文件按照顺序进行归档,从最旧到最新,但这并不是保证,也不适用于特殊情况,比如在推广备用机或崩溃恢复后。因此,不能安全地假设所有早于
last_archived_wal
的文件也已成功归档。
pg_stat_io
#
pg_stat_io
视图将包含每种后端类型、目标I/O对象和I/O上下文
的组合的一行,显示集群范围的I/O统计信息。不合理的组合将被省略。
目前,关系(例如表、索引)的I/O被跟踪。然而,绕过共享缓冲区的关系 I/O(例如将表从一个表空间移动到另一个表空间时)目前尚未被跟踪。
Table 27.23. pg_stat_io
视图
列类型 描述 |
---|
后端的类型(例如,后台工作者,自动清理工作者)。请参阅
|
I/O 操作的目标对象。可能的值包括:
|
I/O 操作的上下文。可能的取值有:
|
读取操作的次数,每次操作的大小由 |
读取操作所花费的时间,以毫秒为单位(如果 track_io_timing已启用,否则为零) |
写操作的数量,每次操作的大小由 |
写操作中花费的时间,以毫秒为单位(如果 track_io_timing已启用,否则为零) |
进程请求内核写入到永久存储的大小为 |
在回写操作中花费的时间,以毫秒为单位(如果 track_io_timing已启用,否则为零)。这包括排队写出请求 所花费的时间,以及可能用于写出脏数据的时间。 |
关系扩展操作的数量,每个操作的大小由 |
在扩展操作中花费的时间(以毫秒为单位)(如果 track_io_timing已启用,否则为零) |
每单位I/O读取、写入或扩展的字节数。
关系数据的读取、写入和扩展是以 |
在共享缓冲区中找到所需块的次数。 |
一个块从共享或本地缓冲区写出以便为其他用途腾出空间的次数。
在 |
在 |
|
在fsync操作中花费的时间,以毫秒为单位(如果 track_io_timing已启用,否则为零) |
上次重置这些统计信息的时间。 |
某些后端类型从不对某些I/O对象和/或某些I/O上下文执行I/O操作。这些行会从视图
中省略。例如,检查点进程不会检查临时表,因此不会有
backend_type
checkpointer
和
object
temp relation
的行。
此外,某些I/O操作永远不会由某些后端类型执行,或者不会在某些I/O对象
和/或某些I/O上下文中执行。这些单元格将为NULL。例如,临时表不会被
fsync
,因此fsyncs
对于
object
temp relation
将为NULL。
同样,后台写入器不执行读取操作,因此reads
在
backend_type
background writer
的行中将为NULL。
pg_stat_io
可以用来为数据库调优提供信息。
例如:
较高的evictions
计数可能表明需要增加共享缓冲区。
客户端后端依赖检查点进程确保数据持久化到永久存储。大量的
fsyncs
由客户端后端
执行可能表明
共享缓冲区或检查点进程配置错误。有关配置检查点进程的更多信息,
请参见Section 28.5。
通常,客户端后端应该能够依赖辅助进程(如检查点进程和后台写入器) 尽可能多地写出脏数据。大量由客户端后端执行的写操作可能表明共享 缓冲区或检查点进程配置错误。有关配置检查点进程的更多信息,请参见 Section 28.5。
只有在启用track_io_timing时,跟踪I/O时间的列才会非零。
用户在结合相应的I/O操作引用这些列时应当小心,以防track_io_timing
并未在自上次统计重置以来的整个时间段内启用。
pg_stat_bgwriter
#
pg_stat_bgwriter
视图将始终只有一行,包含有关集群后台写入器的数据。
Table 27.24. pg_stat_bgwriter
View
列类型 描述 |
---|
后台写入器写入的缓冲区数 |
后台写入器因为写入太多缓冲区而停止清理扫描的次数 |
分配的缓冲区数 |
这些统计数据最后一次重置的时间 |
pg_stat_checkpointer
#
pg_stat_checkpointer
视图将始终只有一行,包含有关集群检查点进程的数据。
Table 27.25. pg_stat_checkpointer
视图
列类型 描述 |
---|
由于超时而计划的检查点数量。请注意,如果服务器自上次检查点以来一直处于空闲状态, 检查点可能会被跳过,此值统计了已完成和跳过的检查点数量 |
已执行的请求检查点数量 |
由于超时或执行失败后尝试,计划的重启点数量 |
请求的重启点数量 |
已执行的重启点数量 |
在处理检查点和重启点期间,写入磁盘文件所花费的总时间, 以毫秒为单位 |
在处理检查点和重启点期间,用于将文件同步到磁盘部分所花费的总时间,单位为毫秒 |
检查点和重启点期间写入的缓冲区数量 |
这些统计数据最后一次重置的时间 |
pg_stat_wal
#
pg_stat_wal
视图一直有一行,包含关于集群的WAL活动的数据。
Table 27.26. pg_stat_wal
View
列类型 描述 |
---|
生成的WAL记录的总数 |
生成的WAL全页映像的总数 |
生成的WAL总数,以字节计 |
因为缓冲区已满,WAL数据被写入磁盘的次数 |
通过 |
通过 |
通过 |
通过 |
这些统计数据最后一次重置的时间 |
pg_stat_database
#
pg_stat_database
视图将包含一行用于集群中的每个数据库,加一行用于共享对象,显示数据库范围的统计信息。
Table 27.27. pg_stat_database
视图
列类型 描述 |
---|
该数据库的OID,属于共享关系的对象为0 |
这个数据库的名称,或者共享对象为 |
当前连接到此数据库的后端数,对于共享对象则为 |
此数据库中已提交的事务数 |
该数据库中已回滚的事务数 |
在该数据库中读取的磁盘块数 |
在缓存中发现磁盘块的次数,因此读取不是必需的(这只包括在PostgreSQL缓存中,而不是在操作系统的文件系统缓存中) |
由顺序扫描获取的活动行数和由索引扫描返回的索引条目数 |
该数据库中由索引扫描检索的活动行数 |
查询在该数据库中插入的行数 |
这个数据库中查询更新的行数 |
这个数据库中被查询删除的行数 |
由于与此数据库中的恢复冲突而取消的查询数。(冲突只发生在备用服务器上;详请参见
|
这个数据库中查询创建的临时文件的数量。所有临时文件都将被计数,而不顾及临时文件为什么被创建(例如,排序或散列),也不考虑log_temp_files设置。 |
这个数据库中的查询写入临时文件的数据总量。所有临时文件都将被计数,而不考虑临时文件为什么被创建,也不考虑log_temp_files设置。 |
在此数据库中检测到的死锁数 |
在此数据库(或共享对象)中检测到的数据页校验码失败数,如果没有启用数据校验码则为NULL。 |
在此数据库(或共享对象)中检测到最后一个数据页校验码失败的时间,如果没有启用数据校验码则为NULL。 |
在这个数据库中通过后端读取数据文件块所花费的时间,以毫秒为单位(如果启用了track_io_timing,否则为零) |
在这个数据库中通过后端写数据文件块所花费的时间,以毫秒为单位(如果启用了track_io_timing,否则为零) |
此数据库中数据库会话所消耗的时间,以毫秒计(注意统计信息仅在会话状态发生变化时更新,因此如果会话空闲很长时间,则不包括此空闲时间) |
此数据库中执行SQL语句所消耗的时间,以毫秒计(这对应于 |
此数据库中事务空闲所消耗的时间,以毫秒计(这对应于 |
此数据库建立的会话总数 |
此数据库因为到客户端的连接丢失而被终止的数据库会话数 |
此数据库因为致命错误而被终止的数据库会话数 |
此数据库因为操作者介入而被终止的数据库会话数 |
这些统计数据最后一次重置的时间 |
pg_stat_database_conflicts
#
pg_stat_database_conflicts
视图为每一个数据库包含一行,用来显示数据库范围内由于与后备服务器上的恢复过程冲突而被取消的查询的统计信息。
这个视图将只包含后备服务器上的信息,因为冲突会不发生在主服务器上。
Table 27.28. pg_stat_database_conflicts
视图
列类型 描述 |
---|
数据库的OID |
数据库的名称 |
这个数据库中由于删除表空间而取消的查询的数量 |
此数据库中由于锁定超时而被取消的查询数 |
此数据库中由于旧快照而取消的查询数 |
此数据库中由于固定缓冲区而被取消的查询数 |
此数据库中由于死锁而被取消的查询数 |
由于旧快照或主服务器上的wal_level 设置过低而被取消的此数据库中逻辑槽的使用次数 |
pg_stat_all_tables
#
pg_stat_all_tables
视图将为当前数据库中的每一个表(包括 TOAST 表)包含一行,该行显示与对该表的访问相关的统计信息。
pg_stat_user_tables
和pg_stat_sys_tables
视图包含相同的信息,但是被过滤得分别只显示用户和系统表。
Table 27.29. pg_stat_all_tables
视图
列类型 描述 |
---|
表的OID |
该表所在的模式的名称 |
这个表的名称 |
在此表上启动的顺序扫描数 |
此表上最后一次顺序扫描的时间,基于最近的事务停止时间 |
连续扫描获取的实时行数 |
对这个表发起的索引扫描数 |
此表上最后一次索引扫描的时间,基于最近的事务停止时间 |
索引扫描获取的实时行数 |
插入的总行数 |
更新的总行数。(这包括在 |
删除的总行数 |
更新的行数HOT 更新。 这些是索引中不需要后续版本的更新。 |
更新的行数,其中后续版本被写入到一个
新的堆页面,留下一个原始版本,
其包含一个
|
活的行的估计数量 |
僵死行的估计数量 |
自上次分析此表以来修改的行的估计数量 |
自上次清空此表以来插入的行的估计数量 |
最后一次手动清理这个表(不包括 |
这个表最后一次被自动清理守护进程清理的时间 |
上一次手动分析这个表 |
自动清理守护进程最后一次分析这个表 |
这个表被手动清理的次数( |
这个表被autovacuum守护进程清理的次数 |
手动分析这个表的次数 |
这个表被autovacuum守护进程分析的次数 |
pg_stat_all_indexes
#
pg_stat_all_indexes
视图将为当前数据库中的每个索引包含一行,该行显示关于对该索引访问的统计信息。pg_stat_user_indexes
和pg_stat_sys_indexes
视图包含相同的信息,但是被过滤得只分别显示用户和系统索引。
Table 27.30. pg_stat_all_indexes
视图
列类型 描述 |
---|
对于此索引的表的OID |
这个索引的OID |
这个索引所在的模式名称 |
这个索引的表的名称 |
这个索引的名称 |
在这个索引上开启的索引扫描的数量 |
此索引上最后一次扫描的时间,基于最近的事务停止时间 |
扫描此索引返回的索引项数 |
使用此索引进行简单索引扫描获取的活动表行数 |
索引可以被简单索引扫描、“位图”索引扫描以及优化器使用。在一次位图扫描中,多个索引的输出可以被通过 AND 或 OR 规则组合,因此当使用一次位图扫描时难以将取得的个体堆行与特定的索引关联起来。因此,一次位图扫描会增加它使用的索引的pg_stat_all_indexes
.idx_tup_read
计数,并且为每个表增加pg_stat_all_tables
.idx_tup_fetch
计数,但是它不影响pg_stat_all_indexes
.idx_tup_fetch
。如果所提供的常量值不在优化器统计信息记录的范围之内,优化器也会访问索引来检查,因为优化器统计信息可能已经“不新鲜”了。
即使不用位图扫描,idx_tup_read
和idx_tup_fetch
计数也可能不同,因为idx_tup_read
统计从该索引取得的索引项而idx_tup_fetch
统计从表取得的活着的行。如果使用该索引取得了任何死亡行或还未提交的行,或者如果通过一次只用索引扫描的方式避免了任何堆获取,后者将较小。
使用某些SQL结构来搜索匹配多个标量值列表或数组中任意值的行
(参见Section 9.25)的查询,在查询执行期间执行多个
“原始”索引扫描(每个标量值最多一个原始扫描)。每个内部原始索引扫描
会增加pg_stat_all_indexes
.idx_scan
,
因此索引扫描的计数可能远远超过索引扫描执行节点执行的总次数。
pg_statio_all_tables
#
pg_statio_all_tables
视图将为当前数据库中的每个表(包括 TOAST 表)包含一行,该行显示指定表上有关 I/O 的统计信息。pg_statio_user_tables
和pg_statio_sys_tables
视图包含相同的信息,但是被过滤得分别只显示用户表和系统表。
Table 27.31. pg_statio_all_tables
视图
列类型 描述 |
---|
表的OID |
该表所在的模式的名称 |
这个表的名称 |
从该表中读取的磁盘块的数量 |
该表中的缓冲区命中数 |
从这个表上所有索引读取的磁盘块数 |
这个表上所有索引中的缓冲区命中数 |
从这个表的TOAST表中读取的磁盘块的数量(如果有的话) |
这个表的TOAST表中的缓冲区命中数(如果有的话) |
从这个表的TOAST表索引中读取的磁盘块的数量(如果有的话) |
这个表的TOAST表索引中的缓冲区命中数(如果有的话) |
pg_statio_all_indexes
#
pg_statio_all_indexes
视图将为当前数据库中的每个索引包含一行,该行显示指定索引上有关 I/O 的统计信息。
pg_statio_user_indexes
和pg_statio_sys_indexes
视图包含相同的信息,但是被过滤得分别只显示用户索引和系统索引。
Table 27.32. pg_statio_all_indexes
视图
列类型 描述 |
---|
对于此索引的表的OID |
这个索引的OID |
这个索引所在的模式名称 |
这个索引的表的名称 |
这个索引的名称 |
从此索引中读取的磁盘块的数量 |
此索引中的缓冲区命中数 |
pg_statio_all_sequences
#
pg_statio_all_sequences
视图将为当前数据库中的每个序列包含一行,该行显示在指定序列上有关 I/O 的统计信息。
Table 27.33. pg_statio_all_sequences
视图
列类型 描述 |
---|
序列的OID |
此序列所在的模式的名称 |
此序列的名称 |
从这个序列中读取的磁盘块的数量 |
在此序列中的缓冲区命中数 |
pg_stat_user_functions
#
pg_stat_user_functions
视图将为每一个被追踪的函数包含一行,该行显示有关该函数执行的统计信息。
track_functions参数控制到底哪些函数被跟踪。
Table 27.34. pg_stat_user_functions
视图
列类型 描述 |
---|
函数的OID |
这个函数所在的模式的名称 |
这个函数的名称 |
这个函数已经被调用的次数 |
在这个函数以及它所调用的其他函数中花费的总时间,以毫秒计 |
在这个函数本身花费的总时间,不包括被它调用的其他函数,以毫秒计 |
pg_stat_slru
#
PostgreSQL 访问某些磁盘上的信息,
通过 SLRU
(简单最近最少使用) 缓存。
pg_stat_slru
视图将包含每个被跟踪的 SLRU 缓存的一行,
显示有关访问缓存页面的统计信息。
对于作为核心服务器一部分的每个SLRU
缓存,存在一个配置参数控制其大小,
参数名后缀为_buffers
。
Table 27.35. pg_stat_slru
视图
列类型 描述 |
---|
SLRU的名称 |
初始化期间被置零的块数 |
已经在SLRU中的磁盘块被发现的次数,因此不需要读取(这只包括SLRU中的命中,而不是操作系统的文件系统缓存) |
为这个SLRU读取的磁盘块数 |
为这个SLRU写入的磁盘块数 |
为这个SLRU检查是否存在的块数 |
此SLRU的脏数据刷新数 |
这个SLRU的截断数 |
这些统计数据最后一次重置的时间 |
其他查看统计信息的方法是直接使用查询,这些查询使用上述标准视图用到的底层统计信息访问函数。
如要了解如函数名等细节,可参考标准视图的定义(例如,在psql中你可以发出\d+ pg_stat_activity
)。
针对每一个数据库统计信息的访问函数把一个数据库 OID 作为参数来标识要报告哪个数据库。而针对每个表和每个索引的函数要求表或索引 OID。
针对每个函数统计信息的函数用一个函数 OID。注意只有在当前数据库中的表、索引和函数才能被这些函数看到。
与累积统计系统相关的其他功能在Table 27.36中列出。
Table 27.36. Additional Statistics Functions
使用pg_stat_reset()
还会重置自动清理使用的计数器,
以确定何时触发清理或分析。重置这些计数器可能导致自动清理不执行必要的工作,
这可能会导致问题,如表膨胀或过时的表统计信息。建议在统计信息重置后进行全库ANALYZE
。
pg_stat_get_activity
,是视图pg_stat_activity
的底层函数,
返回包含每个后端进程所有可用信息的记录集。有时仅获取这部分信息的子集会更方便。
在这种情况下,可以使用另一组每后端统计访问函数;这些函数显示在Table 27.37中。
这些访问函数使用会话的后端ID号,该ID号是一个小整数(>= 0),与任何并发会话的后端ID不同,
尽管会话的ID在退出后可以被回收。后端ID用于识别会话的临时模式(如果有的话)等用途。
函数pg_stat_get_backend_idset
提供了一种方便的方法来列出所有活动后端的ID号,
以便调用这些函数。例如,要显示所有后端的PID和当前查询:
SELECT pg_stat_get_backend_pid(backendid) AS pid, pg_stat_get_backend_activity(backendid) AS query FROM pg_stat_get_backend_idset() AS backendid;
Table 27.37. Per-Backend Statistics Functions
函数 描述 |
---|
返回此后端最近查询的文本。 |
返回后端最近一次查询开始的时间。 |
返回连接到此后端的客户端的IP地址。 |
返回客户端用于通信的TCP端口号。 |
返回此后端连接的数据库的OID。 |
返回当前活动的后端ID号集合。 |
返回此后端进程ID。 |
返回该进程开始的时间。 |
返回关于具有指定ID的后端子事务的信息记录。
返回的字段包括 |
返回登录到此后端的用户的OID。 |
如果后端当前正在等待,则返回等待事件名称,否则为NULL。 参见 Table 27.5 到 Table 27.13。 |
如果后端当前正在等待,返回等待事件类型名称,否则返回NULL。 详请参见Table 27.4。 |
返回后端当前事务开始的时间。 |