Index: pg_ctl.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_ctl/pg_ctl.c,v retrieving revision 1.24 diff -u -r1.24 pg_ctl.c --- pg_ctl.c 29 Jul 2004 16:11:11 -0000 1.24 +++ pg_ctl.c 24 Aug 2004 14:41:40 -0000 @@ -918,12 +918,18 @@ { case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: + /* + * We only need a short wait hint here as it just needs to wait for + * the next checkpoint. They occur every 5 seconds during shutdown + */ + status.dwWaitHint = 10000; pgwin32_SetServiceStatus(SERVICE_STOP_PENDING); SetEvent(shutdownEvent); return; case SERVICE_CONTROL_PAUSE: /* Win32 config reloading */ + status.dwWaitHint = 5000; kill(postmasterPID,SIGHUP); return; @@ -944,9 +950,9 @@ /* Initialize variables */ status.dwWin32ExitCode = S_OK; status.dwCheckPoint = 0; - status.dwWaitHint = 0; + status.dwWaitHint = 60000; status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; - status.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_PAUSE_CONTINUE; + status.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN|SERVICE_ACCEPT_PAUSE_CONTINUE; status.dwServiceSpecificExitCode = 0; status.dwCurrentState = SERVICE_START_PENDING; @@ -980,7 +986,15 @@ { case WAIT_OBJECT_0: /* shutdown event */ kill(postmasterPID,SIGINT); - WaitForSingleObject(postmasterProcess,INFINITE); + + /* + * Increment the checkpoint and try again + * Abort after 12 checkpoints as the postmaster has probably hung + */ + while (WaitForSingleObject(postmasterProcess,5000) == WAIT_TIMEOUT && status.dwCheckPoint < 12) + { + status.dwCheckPoint++; + } break; case (WAIT_OBJECT_0+1): /* postmaster went down */