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

1 minute read

背景

PostgreSQL为进程模型,启动时、启动后会fork一些管理进程,以及用户连接时会产生用户的服侍进程。

例如

1. postmaster,负责监听

2. startup进程,负责recovery

3. logger, 负责写日志

4. shared buffer writer,负责通过LRU算法刷脏页,持久化数据文件

5. wal buffer writer,负责将WAL写入WAL日志文件

6. checkpointer,负责检查点任务

7. stats process,负责收集统计信息,更新计数器计数(query 消耗资源统计、表插入记录数、更新记录数、删除记录数、deadtuple 等等)。

8. autovacuum launcher,负责监控表的年龄,垃圾比例,触动阈值时唤醒vacuum worker进行垃圾回收,更新表的统计信息(用于执行计划成本计算的统计信息,pg_stats)。

9. autovacuum worker,自动垃圾回收的工作进程。

10. 并行计算worker process,当执行并行计算任务时的工作进程。

11. wal sender,作为上游节点时,流复制消息发送进程。

12. wal receiver,作为下游节点是,流复制消息接收进程。

13. 其他worker process,其他插件开发的工作进程。

14. user backend process,用户进程。

以前的版本,数据库的管理进程都不会被展示出来,10.0扩展了pg_stat_activity视图的功能,增加了一个进程类型字段,所有进程的信息都会被展示。

方便管理员观察数据库的运行状态。

+    <row>  
+     <entry><structfield>backend_type</structfield></entry>  
+     <entry><type>text</type></entry>  
+     <entry>Type of current backend. Possible types are   
+      <literal>autovacuum launcher</>, <literal>autovacuum worker</>,  
+      <literal>background worker</>, <literal>background writer</>,  
+      <literal>client backend</>, <literal>checkpointer</>,  
+      <literal>startup</>, <literal>walreceiver</>,  
+      <literal>walsender</> and <literal>walwriter</>.  
+     </entry>  
+    </row>  

patch信息如下

Show more processes in pg_stat_activity.  
  
Previously, auxiliary processes and background workers not connected  
to a database (such as the logical replication launcher) weren't  
shown.  Include them, so that we can see the associated wait state  
information.  Add a new column to identify the processes type, so that  
people can filter them out easily using SQL if they wish.  
  
Before this patch was written, there was discussion about whether we  
should expose this information in a separate view, so as to avoid  
contaminating pg_stat_activity with things people might not want to  
see.  But putting everything in pg_stat_activity was a more popular  
choice, so that's what the patch does.  
  
Kuntal Ghosh, reviewed by Amit Langote and Michael Paquier.  Some  
revisions and bug fixes by me.  
  
Discussion: http://postgr.es/m/CA+TgmoYES5nhkEGw9nZXU8_FhA8XEm8NTm3-SO+3ML1B81Hkww@mail.gmail.com         

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

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

参考

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=fc70a4b0df38bda6a13941f1581f25fbb643c7f3

Flag Counter

digoal’s 大量PostgreSQL文章入口