天天看点

PostgreSQL 各个后台进程关系的理解

启动PostgreSQL 进程后,可以看到:

[root@localhost ~]# ps -ef | grep post 

root 2991 2925 0 10:42 pts/1 00:00:00 su - postgres

postgres 2992 2991 0 10:42 pts/1 00:00:00 -bash

postgres 3029 2992 0 10:42 pts/1 00:00:00 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data

postgres 3031 3029 0 10:42 ? 00:00:00 postgres: checkpointer process 

postgres 3032 3029 0 10:42 ? 00:00:00 postgres: writer process 

postgres 3033 3029 0 10:42 ? 00:00:00 postgres: wal writer process 

postgres 3034 3029 0 10:42 ? 00:00:00 postgres: autovacuum launcher process 

postgres 3035 3029 0 10:42 ? 00:00:00 postgres: stats collector process 

root 3061 3039 0 10:43 pts/2 00:00:00 grep post

[root@localhost ~]#

不难发现,

checkpointer process,

writer process,

wal writer process

autovacuum launcher process

stats collector process 

都是 postgres 进程的子进程。

那么是如何做到的呢?各个子进程名称不同,而且还被同一个父进程来生成,用来完成不同的工作。

有点 龙生九子各不同的感觉。

看代码(Postmaster.c):

PostgreSQL 各个后台进程关系的理解
PostgreSQL 各个后台进程关系的理解

可以看到 ,Postmaster.c 的 主循环中,安排了如下部分:

http://postgresql.1045698.n5.nabble.com/where-EXEC-BACKEND-td2008305.html 

> hi, 

> 

> actually i try to execute postgres step by step (on paper) 

> i don't retreive where EXEC_BACKEND is initialized 

> can any one help me? 

> it is very important for me 

Nowhere.  If you want it, you have to define it manually in 

pg_config_manual.h. 

EXEC_BACKEND is a source code hack that allows the Unix build (which 

normally uses only fork() without exec()) to follow the same startup 

code as the Windows version (which uses CreateProcess(), equivalent to 

both fork() and exec()), allowing for better debuggability for those of 

us that do not use Windows. 

If you want to follow postmaster initialization on a POSIX platform, 

it's easier if you just assume that EXEC_BACKEND is not defined. 

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/10/24/2736805.html,如需转载请自行联系原作者

继续阅读