---
title: "PostgreSQL启动过程中的那些事十二：为postmaster进程设置信号句柄"
author: "BeiGang"
date: "2012-05-23T21:38:23Z"
tags: []
categories: ["数据库"]
slug: "postgresql-postmaster"
draft: false
lastmod: "2012-05-23T21:39:13Z"
id: 1539158
url: "https://beigang.iteye.com/blog/1539158"
---

现在离数据库启动过程的高潮只有几步之遥，这几步比较简单，简要描述之。

    这几步包括：

       八：设置虚拟文件描述符

       九：初始化活跃 backend 进程列表

       十：创建 opts 文件

       十一：保存非默认 GUC 参数到文件

       十二：为 postmaster 进程安装信号句柄

       十三：为统计进程启动准备资源

       十四：为 autovuc 进程启动做条件检查

       十五：加载客户端认证配置文件

      

 

再接着调用 pqinitmask 方法和 pqsignal 方法，为 postmaster 进程安装信号句柄

    pqinitmask();

    PG\_SETMASK(&BlockSig);

     pqsignal(SIGHUP, SIGHUP\_handler);  /* reread config file and have  
                                    * children do same \*/  
    pqsignal(SIGINT, pmdie); /* send SIGTERM and shut down \*/  
    pqsignal(SIGQUIT, pmdie);   /* send SIGQUIT and die \*/  
    pqsignal(SIGTERM, pmdie);   /* wait for children and shut down \*/  
    pqsignal(SIGALRM, SIG\_IGN); /* ignored \*/  
    pqsignal(SIGPIPE, SIG\_IGN); /* ignored \*/  
    pqsignal(SIGUSR1, sigusr1\_handler); /* message from child process \*/  
    pqsignal(SIGUSR2, dummy\_handler);  /* unused, reserve for children \*/  
    pqsignal(SIGCHLD, reaper);  /* handle child termination \*/  
    pqsignal(SIGTTIN, SIG\_IGN); /* ignored \*/  
    pqsignal(SIGTTOU, SIG\_IGN); /* ignored \*/  
    /* ignore SIGXFSZ, so that ulimit violations work like disk full \*/  
#ifdef SIGXFSZ  
    pqsignal(SIGXFSZ, SIG\_IGN); /* ignored \*/  
#endif

其中pqsignal(SIGCHLD, reaper);是如果发生SINGCHLD信号，就reaper方法处理。这个后面数据库启动的时候会体现。

![](http://dl.iteye.com/upload/attachment/0068/5589/108ac2ed-0fcc-3429-a6b2-fb60d08c9d61.bmp)

 

初始化信号句柄调用流程图