PostgreSQL的postmaster的fork动作验证

postmaster.c 中的BackendStartup(Port *port)函数,其中有如下代码:

/* in parent, successful fork */                                
ereport(DEBUG2,                                
        (errmsg_internal("forked new backend, pid=%d socket=%d",                                 (int) pid, port->sock)));  

为了方便调试,改为:

/* in parent, successful fork */                                
ereport(DEBUG2,                                
        (errmsg_internal("forked new backend, pid=%d socket=%d",                                  (int) pid, port->sock)));                                                              
/* added by gaojian begin */                                
fprintf(stderr,"forked new backend ,pid =%d ,socket=%d\n", (int)pid, port->sock ); /* added by gaojian end */

重新编译运行(前台运行):/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start

开启一个客户端:/usr/local/pgsql/bin/psql -h 192.168.66.133
此时在pg_ctl 运行的窗口可以看到: forked new backedn, pid=1166,socket=6

再开一个客户端:/usr/local/pgsql/bin/psql -h 192.168.66.133
此时在pg_ctl 运行的窗口可以看到: forked new backedn, pid=1255,socket=6

此时用 ps -ef|grep postgres,也可以看到确实是 pid为 1166 和 1255的 postgres进程增加了。

posted @ 2012-07-19 13:41  健哥的数据花园  阅读(507)  评论(0编辑  收藏  举报