Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fe90fb4

Browse files
committed
The attached patch improves pg_ctl's win32 service code to eliminate
some possible causes of the stale postmaster.pid problem that some users have reported. - The service did not properly report that it accepts SERVICE_CONTROL_SHUTDOWN events, thus it's possible the SCM simply killed the postmaster on shutdown. - 'WaitHints' are now given to the SCM to prevent it timing out if pg_ctl doesn't respond to a control event quickly enough. - During shutdown, the service checkpoint counter is incremented every five seconds for up to a minute to prevent the SCM timing out and assuming the service is not responding. Dave Page
1 parent f7587ae commit fe90fb4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.27 2004/08/28 22:04:01 momjian Exp $
7+
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.28 2004/08/28 23:26:37 momjian Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -938,12 +938,18 @@ static void WINAPI pgwin32_ServiceHandler(DWORD request)
938938
{
939939
case SERVICE_CONTROL_STOP:
940940
case SERVICE_CONTROL_SHUTDOWN:
941+
/*
942+
* We only need a short wait hint here as it just needs to wait for
943+
* the next checkpoint. They occur every 5 seconds during shutdown
944+
*/
945+
status.dwWaitHint = 10000;
941946
pgwin32_SetServiceStatus(SERVICE_STOP_PENDING);
942947
SetEvent(shutdownEvent);
943948
return;
944949

945950
case SERVICE_CONTROL_PAUSE:
946951
/* Win32 config reloading */
952+
status.dwWaitHint = 5000;
947953
kill(postmasterPID,SIGHUP);
948954
return;
949955

@@ -964,9 +970,9 @@ static void WINAPI pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
964970
/* Initialize variables */
965971
status.dwWin32ExitCode = S_OK;
966972
status.dwCheckPoint = 0;
967-
status.dwWaitHint = 0;
973+
status.dwWaitHint = 60000;
968974
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
969-
status.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_PAUSE_CONTINUE;
975+
status.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN|SERVICE_ACCEPT_PAUSE_CONTINUE;
970976
status.dwServiceSpecificExitCode = 0;
971977
status.dwCurrentState = SERVICE_START_PENDING;
972978

@@ -1000,7 +1006,15 @@ static void WINAPI pgwin32_ServiceMain(DWORD argc, LPTSTR *argv)
10001006
{
10011007
case WAIT_OBJECT_0: /* shutdown event */
10021008
kill(postmasterPID,SIGINT);
1003-
WaitForSingleObject(postmasterProcess,INFINITE);
1009+
1010+
/*
1011+
* Increment the checkpoint and try again
1012+
* Abort after 12 checkpoints as the postmaster has probably hung
1013+
*/
1014+
while (WaitForSingleObject(postmasterProcess,5000) == WAIT_TIMEOUT && status.dwCheckPoint < 12)
1015+
{
1016+
status.dwCheckPoint++;
1017+
}
10041018
break;
10051019

10061020
case (WAIT_OBJECT_0+1): /* postmaster went down */

0 commit comments

Comments
 (0)