热度 1|
昨天发布了一篇文章介绍了红石PG的基本情况和技术特性以及安装部署,今天我们看一下该数据库的进程有什么特别优化之处,我们先看一下开源PG数据库显示的进程如下所示。
[postgres@localhost ~]$ ps -ef | grep postgres
root 1840 1725 0 10:29 pts/0 00:00:00 su - postgres
postgres 1841 1840 0 10:29 pts/0 00:00:00 -bash
postgres 1907 1 6 10:29 ? 00:00:00 /opt/pg/18/bin/postgres
postgres 1908 1907 0 10:29 ? 00:00:00 postgres: checkpointer
postgres 1909 1907 0 10:29 ? 00:00:00 postgres: background writer
postgres 1911 1907 0 10:29 ? 00:00:00 postgres: walwriter
postgres 1912 1907 0 10:29 ? 00:00:00 postgres: autovacuum launcher
postgres 1913 1907 0 10:29 ? 00:00:00 postgres: logical replication launcher
postgres 1914 1841 99 10:29 pts/0 00:00:00 ps -ef
postgres 1915 1841 0 10:29 pts/0 00:00:00 grep --color=auto postgres
上面显示的PG18数据库显示的进程
[postgres@localhost ~]$ ps -ef | grep postgres
postgres 19949 1 0 Sep22 ? 00:00:10 /home/postgres/soft/redrock/bin/postgres -D data
postgres 19950 19949 0 Sep22 ? 00:00:00 postgres: checkpointer
postgres 19951 19949 0 Sep22 ? 00:00:01 postgres: background writer
postgres 19953 19949 0 Sep22 ? 00:00:01 postgres: walwriter
postgres 19954 19949 0 Sep22 ? 00:00:05 postgres: autovacuum launcher
postgres 19955 19949 0 Sep22 ? 00:00:00 postgres: logical replication launcher
postgres 19956 19949 0 Sep22 ? 00:00:00 postgres: undo launcher
root 39843 39828 0 20:58 pts/0 00:00:00 su -l postgres
postgres 39844 39843 1 20:58 pts/0 00:00:00 -bash
postgres 39864 39844 0 20:58 pts/0 00:00:00 ps -ef
postgres 39865 39844 0 20:58 pts/0 00:00:00 grep --color=auto postgres
以上是红石PG显示的数据库进程,从上面的输出的进程来看,几乎和开源PG数据库的进程没有太多区别。最亮眼的是undo launcher,看来红石PG使用了回滚段对历史数据事务进行管理,当然也使用了基于锁的MVCC多版本控制。
另外一个要关注的进程是autovacuum launcher,不过我有个疑问,红石PG已经使用了64位的事务ID,几乎可以不必关心事务年龄问题,红石PG的技术文档也说,这个事务年龄大约和人的寿命相当,约为71岁,该进程是否有必要自动启动。这里我们分析一下,为什么红石PG为什么要启动此进程,以下纯属个人猜测。
1、大家在学习PG数据库时,通常一些技术文章都会花不少时间来介绍事务回卷,我在学习一些圈内大佬的著作时,都对此章节有不少介绍。由于开源PG的事务ID是32位,最大事务ID约为42亿,为了防止事务回卷,需要使用vacuum进行事务ID的冻结,并且冻结有懒惰和急切两种模式。这样会给人一种错觉,以为vacuum只是为了处理事务回卷。实际上vacuum的作用不止如佌,还可以收集整理数据库及表、索引的统计信息,同时还可以进行数据组织,使数据访问更高效。vacuum full还可以进行数据空间的回收,这和vacuum有所不同。
2、虽然红石PG数据库的事务ID是64位,在单机环境中看好像事务ID足够用了,不存在事务回卷问题。但在一些特殊的场景,事务ID的消耗还是十分惊人的,比如高并发的OLTP环境。在分布式数据库环境中,对事务ID的消耗更是惊人。事务回卷是个致命的问题,为了确保万无一失,还是启动autovacuum launcher为好。
合作电话:010-64087828
社区邮箱:greatsql@greatdb.com