博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
向bgwriter 发送 SIGQUIT 的实验
阅读量:6168 次
发布时间:2019-06-21

本文共 5228 字,大约阅读时间需要 17 分钟。

bgwriter.c 的代码中有如下部分:

pqsignal(SIGQUIT, bg_quickdie);        /* hard crash time */

[作者:技术者高健@博客园  mail:  ]

还有:

/* * bg_quickdie() occurs when signalled SIGQUIT by the postmaster. * * Some backend has bought the farm, * so we need to stop what we're doing and exit. */static voidbg_quickdie(SIGNAL_ARGS){    PG_SETMASK(&BlockSig);    /*     * We DO NOT want to run proc_exit() callbacks -- we're here because     * shared memory may be corrupted, so we don't want to try to clean up our     * transaction.  Just nail the windows shut and get out of town.  Now that     * there's an atexit callback to prevent third-party code from breaking     * things by calling exit() directly, we have to reset the callbacks     * explicitly to make this work as intended.     */    on_exit_reset();    /*     * Note we do exit(2) not exit(0).    This is to force the postmaster into a     * system reset cycle if some idiot DBA sends a manual SIGQUIT to a random     * backend.  This is necessary precisely because we don't clean up our     * shared memory state.  (The "dead man switch" mechanism in pmsignal.c     * should ensure the postmaster sees this as a crash, too, but no harm in     * being doubly sure.)     */    exit(2);}

我是这样实验的:

首先个给 bgwriter.c 的 pg_quickdie,加入一小段代码,变成:

/* * bg_quickdie() occurs when signalled SIGQUIT by the postmaster. * * Some backend has bought the farm, * so we need to stop what we're doing and exit. */static voidbg_quickdie(SIGNAL_ARGS){
fprintf(stderr,"bg_quickdie happend.\n"); PG_SETMASK(&BlockSig); /* * We DO NOT want to run proc_exit() callbacks -- we're here because * shared memory may be corrupted, so we don't want to try to clean up our * transaction. Just nail the windows shut and get out of town. Now that * there's an atexit callback to prevent third-party code from breaking * things by calling exit() directly, we have to reset the callbacks * explicitly to make this work as intended. */ on_exit_reset(); /* * Note we do exit(2) not exit(0). This is to force the postmaster into a * system reset cycle if some idiot DBA sends a manual SIGQUIT to a random * backend. This is necessary precisely because we don't clean up our * shared memory state. (The "dead man switch" mechanism in pmsignal.c * should ensure the postmaster sees this as a crash, too, but no harm in * being doubly sure.) */ exit(2);}

然后,我启动 postgreSQL ,并查看进程状态:

[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/dataLOG:  database system was shut down at 2012-10-31 10:25:11 CSTLOG:  autovacuum launcher startedLOG:  database system is ready to accept connections
[root@localhost postgresql-9.2.0]# ps -ef|grep postroot      2928  2897  0 10:34 pts/1    00:00:00 su - postgrespostgres  2929  2928  0 10:34 pts/1    00:00:00 -bashpostgres  2967  2929  0 10:34 pts/1    00:00:00 ./postgres -D /usr/local/pgsql/datapostgres  2969  2967  0 10:34 ?        00:00:00 postgres: checkpointer process     postgres  2970  2967  0 10:34 ?        00:00:00 postgres: writer process           postgres  2971  2967  0 10:34 ?        00:00:00 postgres: wal writer process       postgres  2972  2967  0 10:34 ?        00:00:00 postgres: autovacuum launcher process   postgres  2973  2967  0 10:34 ?        00:00:00 postgres: stats collector process   root      3000  2977  0 10:35 pts/2    00:00:00 grep post[root@localhost postgresql-9.2.0]#

然后,向 bgwriter 发送 SIGQUIT 信号:

[root@localhost postgresql-9.2.0]# kill -s SIGQUIT 2970

这个时候,我们会从pts/1 中看到什么?

bg_quickdie happend.LOG:  background writer process (PID 2970) exited with exit code 2LOG:  terminating any other active server processesWARNING:  terminating connection because of crash of another server processDETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.HINT:  In a moment you should be able to reconnect to the database and repeat your command.LOG:  all server processes terminated; reinitializingLOG:  database system was interrupted; last known up at 2012-10-31 10:34:47 CSTLOG:  database system was not properly shut down; automatic recovery in progressLOG:  record with zero length at 0/192D458LOG:  redo is not requiredLOG:  autovacuum launcher startedLOG:  database system is ready to accept connections

也就是说,bgwriter 捕获了SIGQUIT 的信号,而Postmaster/postgres 重新启动了各个子进程!

再看 ps 来验证一下:

[root@localhost postgresql-9.2.0]# ps -ef|grep postroot      2928  2897  0 10:34 pts/1    00:00:00 su - postgrespostgres  2929  2928  0 10:34 pts/1    00:00:00 -bashpostgres  2967  2929  0 10:34 pts/1    00:00:00 ./postgres -D /usr/local/pgsql/datapostgres  3002  2967  0 10:35 ?        00:00:00 postgres: checkpointer process     postgres  3003  2967  0 10:35 ?        00:00:00 postgres: writer process           postgres  3004  2967  0 10:35 ?        00:00:00 postgres: wal writer process       postgres  3005  2967  0 10:35 ?        00:00:00 postgres: autovacuum launcher process   postgres  3006  2967  0 10:35 ?        00:00:00 postgres: stats collector process   root      3010  2977  0 10:36 pts/2    00:00:00 grep post[root@localhost postgresql-9.2.0]#

转载地址:http://banba.baihongyu.com/

你可能感兴趣的文章
\r,\n,\t
查看>>
【转】Dijkstra算法(单源最短路径)
查看>>
一起谈.NET技术,走向ASP.NET架构设计——第三章:分层设计,初涉架构(后篇)...
查看>>
思考记--跳出以往的自己
查看>>
ORACLE数据库链接
查看>>
[转载].关注电子工程师的身体健康与职业规划
查看>>
C#条件判断-根据条件判断要走的路-if结构
查看>>
有线路由器下面接无线路由器(笔记本无线上网),如何设置?
查看>>
[转]W3C 验证 there is no attribute target for this element
查看>>
erlang的一些系统限制修改
查看>>
equals
查看>>
浅析列表页请求优化(history API)
查看>>
java设计模式-代理模式
查看>>
nginx的upstream目前支持5种方式的分配(转)
查看>>
HTTP 错误 500.21 - Internal Server Error 解决方案
查看>>
MySQL InnoDB引擎B+树索引简单整理说明
查看>>
(转)一键自动发布ipa(更新svn,拷贝资源,压缩资源,加密图片资源,加密数据文件,加密lua脚本,编译代码,ipa签名,上传ftp)...
查看>>
Swift:超炫的View Controller切换动画
查看>>
拔草ing...
查看>>
云计算读书笔记(三)
查看>>