对Postmaster 对 SIGQUIT 信号处理的理解

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

Postmaster 作为父进程,要对很多子进程进行监控,当遇到各种信号的时候,也要适当地进行传达。

/*                                
 * pmdie -- signal handler for processing various postmaster signals.                                
 */                                
static void                                
pmdie(SIGNAL_ARGS)                                
{                                
    int            save_errno = errno;                
                                
    PG_SETMASK(&BlockSig);                            
                                
    ereport(DEBUG2,                            
            (errmsg_internal("postmaster received signal %d",                    
                             postgres_signal_arg)));    
                                
    switch (postgres_signal_arg)                            
    {                            
        ……                        
        case SIGQUIT:                        
                                
            /*                    
             * Immediate Shutdown:                    
             *                    
             * abort all children with SIGQUIT and exit without attempt to                    
             * properly shut down data base system.                    
             */                    
            ereport(LOG,                    
                    (errmsg("received immediate shutdown request")));            
            SignalChildren(SIGQUIT);                    
            if (StartupPID != 0)                    
                signal_child(StartupPID, SIGQUIT);                
            if (BgWriterPID != 0)                    
                signal_child(BgWriterPID, SIGQUIT);                
            if (CheckpointerPID != 0)                    
                signal_child(CheckpointerPID, SIGQUIT);                
            if (WalWriterPID != 0)                    
                signal_child(WalWriterPID, SIGQUIT);                
            if (WalReceiverPID != 0)                    
                signal_child(WalReceiverPID, SIGQUIT);                
            if (AutoVacPID != 0)                    
                signal_child(AutoVacPID, SIGQUIT);                
            if (PgArchPID != 0)                    
                signal_child(PgArchPID, SIGQUIT);                
            if (PgStatPID != 0)                    
                signal_child(PgStatPID, SIGQUIT);                
            ExitPostmaster(0);                    
            break;                    
    }                            
                                
    PG_SETMASK(&UnBlockSig);                            
                                
    errno = save_errno;                            
}                                

实验验证:

启动:

[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data
LOG:  database system was shut down at 2012-10-31 15:19:46 CST
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections

发信号:

[postgres@localhost bin]$ ./pg_ctl -D /usr/local/pgsql/data stop -m immediate
waiting for server to shut down.... done
server stopped
[postgres@localhost bin]$ 

后台出现的信息是:

LOG:  received immediate shutdown request
bg_quickdie happend.
WARNING:  terminating connection because of crash of another server process
DETAIL:  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.

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

结束

posted @ 2012-10-31 16:15  健哥的数据花园  阅读(556)  评论(0编辑  收藏  举报