When sending SIGHUP to bgwriter - Mailing list pgsql-general

From 高健
Subject When sending SIGHUP to bgwriter
Date
Msg-id CAL454F1NWmSegHdO+vujT-4R_P2ODbCz-nZwND-3KYmmTBFd3w@mail.gmail.com
Whole thread Raw
List pgsql-general
Hi:

I am now reading the bgwriter.c’s source code, and found :

pqsignal(SIGHUP, BgSigHupHandler); /* set flag to read config file */

So I tried to use Kill –s SIGHUP to confirm it.

I found that if I directly send SIGHUP to bgwriter, it has no response.
If I send SIGHUP to its parent—postgres, I will found the postresql.conf really re-read.

[root@localhost ~]# ps -ef|grep post
postgres  4628  4535  0 13:30 pts/1    00:00:00 ./postgres -D /usr/local/pgsql/data
postgres  4630  4628  0 13:30 ?        00:00:00 postgres: checkpointer process     
postgres  4631  4628  0 13:30 ?        00:00:00 postgres: writer process          
postgres  4632  4628  0 13:30 ?        00:00:00 postgres: wal writer process       
postgres  4633  4628  0 13:30 ?        00:00:00 postgres: autovacuum launcher process   
postgres  4634  4628  0 13:30 ?        00:00:00 postgres: stats collector process   
postgres  4689  4592  0 13:31 pts/2    00:00:00 ./psql
postgres  4690  4628  0 13:31 ?        00:00:00 postgres: postgres postgres [local] idle
root      4694  4638  0 13:31 pts/3    00:00:00 grep post
When using
# kill -s SIGHUP 4631
I found in psql, "show bgwriter_delay" is same to original value(200ms).

When using
# kill -s SIGHUP 4628
I found in psql, "show bgwriter_delay" showed the newly saved value of postgresql.conf(300ms)

At the same time , postgres in background print the follwing output:
LOG:  received SIGHUP, reloading configuration files
LOG:  parameter "bgwriter_delay" changed to "300ms"

What confused me is that postgres as parent, can transfer the SIGHUP, and call the BgSigHupHandler, but why directly send SIGHUP to bgwriter does not work?
Is there some place which hold code like "execl" and make bgwriter does not response to SIGHUP directly?

I have test simple parent and child like following, both parent and child will response to signal.

//////////////////////////////////////////
[root@localhost test]# cat testfork.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
int test=0;
void sighandler(int sig);
int main()
{
      signal(SIGHUP,sighandler);
      pid_t pid;
   
      pid=fork();
      if (pid < 0)
      {
           printf("Fork failured!\n");
      }else if (pid == 0)
      {
           printf("This is child thread!\n");
           test=100;
           for (;;)
           {
             sleep(1);
           }
      }else
      {
           printf("Child process %d created!\n", pid);
           for (;;)
           {
              sleep(1);
           }
      }
      return 0;
}
void sighandler(int sig)
{
   fprintf(stderr,"my test is:%d\n",test);
}
[root@localhost test]#./testfork.o
                          [root@localhost ~]# ps -ef|grep testfork
                           root      6157  5297  0 17:35 pts/6    00:00:00 ./testfork.o
                           root      6158  6157  0 17:35 pts/6    00:00:00 ./testfork.o
                           root      6160  5479  0 17:35 pts/7    00:00:00 grep testfork
                         [root@localhost ~]# kill -s SIGHUP 6158
[root@localhost ~]#my test is:100

                         [root@localhost ~]# kill -s SIGHUP 6157
[root@localhost ~]#my test is 0
//////////////////////////////////////////

pgsql-general by date:

Previous
From: John R Pierce
Date:
Subject: Re: Too much clients connected to the PostgreSQL Database
Next
From: Rodrigo Pereira da Silva
Date:
Subject: Re: Too much clients connected to the PostgreSQL Database