PostgreSQL 10.0 preview 功能增强 - 老板特性, LONG SQL过程可视 pg_stat_progress_vacuum

标签

PostgreSQL , 10.0 , pg_stat_progress_vacuum


背景

在PostgreSQL中执行SQL时,如果SQL执行时间比较长,总想知道它执行到哪里了,还剩余多少任务,剩余多少时间。

目前PostgreSQL增加了对VACUUM的可视监控(目前涵盖了autovacuum与手工的vacuum命令,但是不涵盖VACUUM FULL),将来还会加入更多的progress动态视图,方便用户了解LONG SQL或者任务的执行情况。

动态视图解释如下

可以了解每个vacuum worker工作进程在工作过程中,扫描了多少HEAP PAGE, 回收了多少PAGE,index的vacuum关卡次数(每个关卡的大小取决于maintenance_work_mem可以存储的heap tuple数量)。

Table 28.21. pg_stat_progress_vacuum View

Column Type Description
pid integer Process ID of backend.
datid oid OID of the database to which this backend is connected.
datname name Name of the database to which this backend is connected.
relid oid OID of the table being vacuumed.
phase text Current processing phase of vacuum. See Table 28.22.
heap_blks_total bigint Total number of heap blocks in the table. This number is reported as of the beginning of the scan; blocks added later will not be (and need not be) visited by this VACUUM.
heap_blks_scanned bigint Number of heap blocks scanned. Because the visibility map is used to optimize scans, some blocks will be skipped without inspection; skipped blocks are included in this total, so that this number will eventually become equal to heap_blks_total when the vacuum is complete. This counter only advances when the phase is scanning heap.
heap_blks_vacuumed bigint Number of heap blocks vacuumed. Unless the table has no indexes, this counter only advances when the phase is vacuuming heap. Blocks that contain no dead tuples are skipped, so the counter may sometimes skip forward in large increments.
index_vacuum_count bigint Number of completed index vacuum cycles.
max_dead_tuples bigint Number of dead tuples that we can store before needing to perform an index vacuum cycle, based on maintenance_work_mem.
num_dead_tuples bigint Number of dead tuples collected since the last index vacuum cycle.

过程术语解释

Table 28.22. VACUUM phases

Phase Description
initializing VACUUM is preparing to begin scanning the heap. This phase is expected to be very brief.
scanning heap VACUUM is currently scanning the heap. It will prune and defragment each page if required, and possibly perform freezing activity. The heap_blks_scanned column can be used to monitor the progress of the scan.
vacuuming indexes VACUUM is currently vacuuming the indexes. If a table has any indexes, this will happen at least once per vacuum, after the heap has been completely scanned. It may happen multiple times per vacuum if maintenance_work_mem is insufficient to store the number of dead tuples found.
vacuuming heap VACUUM is currently vacuuming the heap. Vacuuming the heap is distinct from scanning the heap, and occurs after each instance of vacuuming indexes. If heap_blks_scanned is less than heap_blks_total, the system will return to scanning the heap after this phase is completed; otherwise, it will begin cleaning up indexes after this phase is completed.
cleaning up indexes VACUUM is currently cleaning up indexes. This occurs after the heap has been completely scanned and all vacuuming of the indexes and the heap has been completed.
truncating heap VACUUM is currently truncating the heap so as to return empty pages at the end of the relation to the operating system. This occurs after cleaning up indexes.
performing final cleanup VACUUM is performing final cleanup. During this phase, VACUUM will vacuum the free space map, update statistics in pg_class, and report statistics to the statistics collector. When this phase is completed, VACUUM will end.

这个patch的讨论,详见邮件组,本文末尾URL。

PostgreSQL社区的作风非常严谨,一个patch可能在邮件组中讨论几个月甚至几年,根据大家的意见反复的修正,patch合并到master已经非常成熟,所以PostgreSQL的稳定性也是远近闻名的。

参考

https://www.postgresql.org/docs/devel/static/progress-reporting.html#vacuum-progress-reporting

时间: 2024-10-21 20:25:01

PostgreSQL 10.0 preview 功能增强 - 老板特性, LONG SQL过程可视 pg_stat_progress_vacuum的相关文章

PostgreSQL 10.0 preview 功能增强 - 后台运行(pg_background)

标签 PostgreSQL , 10.0 , 后台运行 , pg_background_launch , pg_background_result , pg_background_detach , pg_background 背景 当用户在管理数据库时,如果要在交互式界面跑一些QUERY,但是不知道QUERY要运行多久,担心网络问题或者其他问题导致终端断开,QUERY执行情况不明的话.就需要后台运行这个功能了. 后台运行在LINUX中也很常见,比如 nohup ls -la / >/tmp/re

PostgreSQL 10.0 preview 功能增强 - 增加access method CHECK接口amcheck

标签 PostgreSQL , 10.0 , amcheck , 逻辑一致性检测 , 物理存储检测 背景 一些高端存储.包括ZFS文件系统,在使用了RAID后,有块检测和异常块的修复功能. 对于数据库来说,数据的可靠性是非常重要的指标,例如: 1. 写进入是什么,读出来就应该是什么. 2. 当操作系统的collate发生变化时,索引的顺序可能与实际的collate顺序不匹配.造成不稳定现象. 3. 数据块partial write,可能导致数据损坏. 4. 内存页异常,使用到某些异常页时,可能带

PostgreSQL 10.0 preview 功能增强 - 逻辑订阅端 控制参数解说

标签 PostgreSQL , 10.0 , 逻辑订阅 背景 PostgreSQL 逻辑订阅相关文章请参考 <PostgreSQL 10.0 preview 变化 - 逻辑复制pg_hba.conf变化,不再使用replication条目> <PostgreSQL 10.0 preview 功能增强 - 备库支持逻辑订阅,订阅支持主备漂移了> <PostgreSQL 10.0 preview 功能增强 - 逻辑复制支持并行COPY初始化数据> <PostgreSQ

PostgreSQL 10.0 preview 功能增强 - OLAP增强 向量聚集索引(列存储扩展)

标签 PostgreSQL , 10.0 , Vertical Clustered Index (columnar store extension) , 列存储 , 向量聚集索引 背景 未来数据库OLTP+OLAP逐渐模糊化,需求逐渐融合是一个大的趋势,如果你的数据库只支持OLTP的场景,未来可能会成为业务的绊脚石. 在这方面PostgreSQL每年发布的新版本,都给用户很大的惊喜,OLTP已经具备非常强大的竞争力(性能.功能.稳定性.成熟度.案例.跨行业应用等),而OLAP方面,新增的feat

PostgreSQL 10.0 preview 功能增强 - 逻辑复制支持并行COPY初始化数据

标签 PostgreSQL , 10.0 , 逻辑复制 , 初始数据COPY 背景 PostgreSQL 已支持逻辑复制,同时对逻辑复制增加了一个初始同步的增强功能,支持通过wal receiver协议跑COPY命令(已封装在逻辑复制的内核代码中),支持多表并行. 也就是说,你可以使用PostgreSQL的逻辑复制,快速的(流式.并行)将一个实例迁移到另一个实例. Logical replication support for initial data copy Add functionalit

PostgreSQL 10.0 preview 功能增强 - 回滚范围可精细控制(事务、语句级)

标签 PostgreSQL , 10.0 , 事务回滚 , 语句回滚 , 服务端特性 背景 数据库的原子操作单位是事务,那么在一个事务中的SQL,正常情况下,应该是这样的:要么全部提交,要么全部回滚. 为了保证持久性,数据库还有一个概念,事务日志,每当事务提交时,都需要确保REDO持久化(REDO的写IO会比较多,IO延迟直接关系到tps吞吐量,特别是小事务). 因此,有些业务,为了提高整体的吞吐(比如数据插入的吞吐),通常会使用分批提交的方式,比如一个事务中封装1000条INSERT语句. 但

PostgreSQL 10.0 preview 功能增强 - 触发器函数内置中间表

标签 PostgreSQL , 10.0 , 触发器 , 中间表 , OLD , NEW 背景 在触发器中,如果要提取触发该事件的记录,使用OLD和NEW关键字. OLD.* , NEW.* 提取 对于for statement after触发器,触发的记录数可能是很多的,PostgreSQL 10.0增加了一个功能,中间表. 在触发器函数中,可以使用这个中间表,中间表的数据就是触发器涉及的数据,中级镖的功能支持after触发器(因为after后才有全部的记录呀). 语法 [ REFERENCI

PostgreSQL 10.0 preview 功能增强 - 动态视图pg_stat_activity新增数据库管理进程信息

标签 PostgreSQL , 10.0 , pg_stat_activity , 管理进程 , 后台进程 , 工作进程 , 并行计算进程 背景 PostgreSQL为进程模型,启动时.启动后会fork一些管理进程,以及用户连接时会产生用户的服侍进程. 例如 1. postmaster,负责监听 2. startup进程,负责recovery 3. logger, 负责写日志 4. shared buffer writer,负责通过LRU算法刷脏页,持久化数据文件 5. wal buffer w

PostgreSQL 10.0 preview 功能增强 - libpq支持多主机连接(failover,LB)让数据库HA和应用配合更紧密

标签 PostgreSQL , 10.0 , libpq , jdbc , failover , loadbalance , multi host , target_session_attrs 背景 数据库一主多备,这个词在互联网应该不陌生.但是主备切换和应用程序如何配合才能天衣无缝呢?你可能会有这样的疑问. 1. 什么类型的QUERY发给主库,什么类型的QUERY发给备库? 2. 主库和备库发生了角色切换之后,客户端连接如何配合? 业界有一些做法可以回答这两个问题. 1. 通常使用集群软件,使