src/bin/pg_ctl/pg_ctl.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 172acfc..5d99eff 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -1513,15 +1513,27 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR *argv) switch (ret) { case WAIT_OBJECT_0: /* shutdown event */ - kill(postmasterPID, SIGINT); + { + /* + * Value status.dwCheckPoint can be incremented by test_postmaster_connection(true) + * so dwCheckPoint might not start from 0. + */ + int maxShutdownCheckPoint; - /* - * 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; + kill(postmasterPID, SIGINT); + + /* + * Increment the checkpoint and try again Abort after 12 + * checkpoints as the postmaster has probably hung + */ + maxShutdownCheckPoint = status.dwCheckPoint + 12; + while (WaitForSingleObject(postmasterProcess, 5000) == WAIT_TIMEOUT && status.dwCheckPoint < maxShutdownCheckPoint) + { + status.dwCheckPoint++; + SetServiceStatus(hStatus, (LPSERVICE_STATUS) &status); + } + break; + } case (WAIT_OBJECT_0 + 1): /* postmaster went down */ break;