Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TaSL8-00008P-CI for pgsql-bugs@postgresql.org; Mon, 19 Nov 2012 14:28:46 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TaSL4-0001ji-Ub for pgsql-bugs@postgresql.org; Mon, 19 Nov 2012 14:28:45 +0000 Received: from 172.24.2.119 (EHLO szxeml207-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id ASU56975; Mon, 19 Nov 2012 22:28:39 +0800 (CST) Received: from SZXEML421-HUB.china.huawei.com (10.82.67.160) by szxeml207-edg.china.huawei.com (172.24.2.56) with Microsoft SMTP Server (TLS) id 14.1.323.3; Mon, 19 Nov 2012 22:28:38 +0800 Received: from blrprnc07ns (10.18.96.96) by szxeml421-hub.china.huawei.com (10.82.67.160) with Microsoft SMTP Server id 14.1.323.3; Mon, 19 Nov 2012 22:28:35 +0800 From: Hari Babu To: Subject: BUG #7643: Issuing a shutdown request while server startup leads to server hang Date: Mon, 19 Nov 2012 19:58:31 +0530 Message-ID: <007501cdc662$27066e80$75134b80$@kommi@huawei.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0076_01CDC690.40BEAA80" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac3GYd8OYJOq4YFySaauEy+qd+tFhAAAAfiQ Content-Language: en-us X-Originating-IP: [10.18.96.96] X-CFilter-Loop: Reflected X-Pg-Spam-Score: -1.3 (-) X-Archive-Number: 201211/144 X-Sequence-Number: 34702 ------=_NextPart_000_0076_01CDC690.40BEAA80 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit For defect 7643 which is described in the following mail, http://archives.postgresql.org/message-id/E1TWWd4-0008AD-9E@wrigleys.postgre sql.org The problem identified as the postmaster handling SIGUSR1 after SIGINT signal leads to the problem as bgwriter process is not signaled to terminate by the postmaster as it was not exist during the processing of SIGINT signal and after that during the processing of SIGUSR1 signal the process got created. As the postmaster is waiting for the bgwriter process to terminate in the further shutdown follow leads the postmaster process to wait until the Bgwriter process stops, which enters into a deadlock. The issue is occurring only incase of SIGINT signal and it was handled for SIGTERM signal as during the processing of SIGTERM signal the pmState is modified which blocks the further start of bgwriter. The following patch handles the SIGINT signal also the same way as the SIGTERM signal for the pmState. *** a/src/backend/postmaster/postmaster.c --- b/src/backend/postmaster/postmaster.c *************** *** 2258,2270 **** pmdie(SIGNAL_ARGS) signal_child(BgWriterPID, SIGTERM); if (WalReceiverPID != 0) signal_child(WalReceiverPID, SIGTERM); ! if (pmState == PM_RECOVERY) { - /* - * Only startup, bgwriter, and checkpointer should be active - * in this state; we just signaled the first two, and we don't - * want to kill checkpointer yet. - */ pmState = PM_WAIT_BACKENDS; } else if (pmState == PM_RUN || --- 2258,2277 ---- signal_child(BgWriterPID, SIGTERM); if (WalReceiverPID != 0) signal_child(WalReceiverPID, SIGTERM); ! ! /* ! * In the case of pmState as PM_STARTUP, to avoid further startup ! * of bgwriter and checkpointer incase of standby or in archieve ! * recovery mode because we are already in the process of handling ! * fast shutdown. ! * ! * In the case of pmState as PM_RECOVERY, only startup, bgwriter ! * and checkpointer should be active in this state; we just ! * signaled the first two, and we don't want to kill checkpointer ! * yet. ! */ ! if (pmState == PM_RECOVERY || pmState == PM_STARTUP) { pmState = PM_WAIT_BACKENDS; } else if (pmState == PM_RUN || Regards, Hari babu. ------=_NextPart_000_0076_01CDC690.40BEAA80 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

For defect 7643 which is = described in the following mail,
http://archives.postgresql.org/message-id/E1TWWd4-000= 8AD-9E@wrigleys.postgresql.org
 
The problem identified = as the postmaster handling SIGUSR1 after SIGINT signal leads to the = problem as
bgwriter process is not signaled to terminate by the = postmaster as it was not exist during the processing  of
SIGINT = signal and after that during the processing of SIGUSR1 signal the = process got created.
 
As the postmaster is waiting for the = bgwriter process to terminate in the further shutdown follow leads the = postmaster process to wait until the
Bgwriter process stops, which = enters into a deadlock.
 
The issue is occurring only = incase of SIGINT signal and it was handled for SIGTERM signal as during = the processing of
SIGTERM signal the pmState is modified which = blocks the further start of bgwriter.
 
The following patch = handles the SIGINT signal also the same way as the SIGTERM signal for = the pmState.
 
*** = a/src/backend/postmaster/postmaster.c
--- = b/src/backend/postmaster/postmaster.c
*************= **
*** = 2258,2270 **** pmdie(SIGNAL_ARGS)
  =                     =             signal_child(BgWriterPID, = SIGTERM);
  =                     =     if (WalReceiverPID !=3D 0)
  =                     =             signal_child(WalReceiverPID, = SIGTERM);
!   =                     =   if (pmState =3D=3D PM_RECOVERY)
  =                     =     {
-   =                     =           /*
-   =                     =            * Only startup, bgwriter, and = checkpointer should be active
-   =                     =            * in this state; we just = signaled the first two, and we don't
-   =                     =            * want to kill checkpointer = yet.
-   =                     =            */
  =                     =             pmState =3D = PM_WAIT_BACKENDS;
  =                     =     }
  =                     =     else if (pmState =3D=3D PM_RUN ||
--- = 2258,2277 ----
  =                     =             signal_child(BgWriterPID, = SIGTERM);
  =                     =     if (WalReceiverPID !=3D 0)
  =                     =             signal_child(WalReceiverPID, = SIGTERM);
! =
!   =                     =   /*
!   =                     =    * In the case of pmState as PM_STARTUP, to avoid further = startup
!   =                     =    * of bgwriter and checkpointer incase of standby or in = archieve
!   =                     =    * recovery mode because we are already in the process of = handling
!   =                     =    * fast shutdown.
!   =                     =    *
!   =                     =    * In the case of pmState as PM_RECOVERY, only startup, = bgwriter
!   =                     =    * and checkpointer should be active in this state; we = just
!   =                     =    * signaled the first two, and we don't want to kill = checkpointer
!   =                     =    * yet.
!   =                     =    */
!   =                     =   if (pmState =3D=3D PM_RECOVERY || pmState =3D=3D = PM_STARTUP)
  =                     =     {
  =                     =             pmState =3D = PM_WAIT_BACKENDS;
  =                     =     }
  =                     =     else if (pmState =3D=3D PM_RUN ||

Regards,
Hari babu. =

------=_NextPart_000_0076_01CDC690.40BEAA80--