啟動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):
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiZpdmLlR2bjlHcvN2LcNXZnFWbp9CXt92YuM3ZvxmYuNmLu9Wbt92Yvw1LcpDc0RHaiojIsJye.gif)
可以看到 ,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,如需轉載請自行聯系原作者