Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fYmV8-00016D-U3 for pgsql-general@arkaria.postgresql.org; Fri, 29 Jun 2018 06:03:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fYmV4-0001Qk-GL for pgsql-general@arkaria.postgresql.org; Fri, 29 Jun 2018 06:03:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fYmV4-0001Qc-1i for pgsql-general@lists.postgresql.org; Fri, 29 Jun 2018 06:03:18 +0000 Received: from sraihb2.sra.co.jp ([202.32.10.6]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fYmV0-0002We-HT for pgsql-general@postgresql.org; Fri, 29 Jun 2018 06:03:16 +0000 Received: from srascf.sra.co.jp (srascf [133.137.8.80]) by sraihb2.sra.co.jp (Postfix) with ESMTP id 034C42A160B for ; Fri, 29 Jun 2018 15:03:12 +0900 (JST) Received: from srascb.sra.co.jp (unknown [133.137.8.65]) by srascf.sra.co.jp with smtp id 2381_1933_3749ad49_6993_4476_92f1_7b29b9a258d6; Fri, 29 Jun 2018 15:03:12 +0900 Received: from sranhm.sra.co.jp (osspc25 [133.137.174.97]) by srascb.sra.co.jp (Postfix) with ESMTP id D795C2D6942 for ; Fri, 29 Jun 2018 15:03:12 +0900 (JST) Received: from harukat-PC (sraihg-184.sra.co.jp [133.137.9.184]) by sranhm.sra.co.jp (Postfix) with SMTP id 8556AA104F for ; Fri, 29 Jun 2018 15:03:12 +0900 (JST) Date: Fri, 29 Jun 2018 15:03:10 +0900 From: TAKATSUKA Haruka To: pgsql-general@postgresql.org Subject: Windows 10 got stuck with PostgreSQL at starting up. Adding delay lets it avoid. Message-Id: <20180629150310.b01664be02fde699ccc5f683@sraoss.co.jp> Organization: SRA OSS, Inc. X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.23; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Fri__29_Jun_2018_15_03_10_+0900_Hy8Ql8DVk0NJ2uER" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --Multipart=_Fri__29_Jun_2018_15_03_10_+0900_Hy8Ql8DVk0NJ2uER Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit I got a trouble in PostgreSQL 9.3.x on Windows 10. I would like to add new delay code as an official build option. Windows 10 sometime (approximately once in 300 tries) hung up at OS starting up. The logs say it happened while the PostgreSQL service was starting. When OS stopped, some postgres auxiliary process were started and some were not started yet. The Windows dump say some threads of the postgres auxiliary process are waiting OS level locks and the logon processes’thread are also waiting a lock. MS help desk said that PostgreSQL’s OS level deadlock caused OS freeze. I think it is strange story. But, in fact, it not happened in repeated tests when I got rid of PostgreSQL from the initial auto-starting services. I tweaked PostgreSQL 9.3.x (the newest from the repository) to add 0.5 or 3.0 seconds delay after each sub process starts. And then the hung up was gone. This test patch is attached. It is only implemented for Windows. Also, I did not use existing pg_usleep because it contains locking codes (e.g. WaitForSingleObject and Enter/LeaveCriticalSection). Although Windows OS may have some problems, I think we should have a means to avoid it. Can PostgreSQL be accepted such delay codes as build-time options by preprocessor variables? Thanks, Takatsuka Haruka --Multipart=_Fri__29_Jun_2018_15_03_10_+0900_Hy8Ql8DVk0NJ2uER Content-Type: text/plain; name="postmaster.c_0619_win32delay.diff" Content-Disposition: attachment; filename="postmaster.c_0619_win32delay.diff" Content-Transfer-Encoding: 7bit diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index d6fc2ed..ff03ebd 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -398,6 +398,30 @@ extern int optreset; /* might not be declared by system headers */ static DNSServiceRef bonjour_sdref = NULL; #endif +#define USE_AFTER_AUX_FORK_SLEEP 3000 + +#ifdef USE_AFTER_AUX_FORK_SLEEP +#ifndef WIN32 +#define AFTER_AUX_FORK_SLEEP() +#else +#define AFTER_AUX_FORK_SLEEP() do { SleepEx(USE_AFTER_AUX_FORK_SLEEP, FALSE); } while(0) +#endif +#else +#define AFTER_AUX_FORK_SLEEP() +#endif + +#define USE_AFTER_BACKEND_FORK_SLEEP 500 + +#ifdef USE_AFTER_BACKEND_FORK_SLEEP +#ifndef WIN32 +#define AFTER_BACKEND_FORK_SLEEP() +#else +#define AFTER_BACKEND_FORK_SLEEP() do { SleepEx(USE_AFTER_BACKEND_FORK_SLEEP, FALSE); } while(0) +#endif +#else +#define AFTER_BACKEND_FORK_SLEEP() +#endif + /* * postmaster.c - function prototypes */ @@ -1709,6 +1733,7 @@ ServerLoop(void) */ StreamClose(port->sock); ConnFree(port); + AFTER_BACKEND_FORK_SLEEP(); } } } @@ -2801,11 +2826,20 @@ reaper(SIGNAL_ARGS) * situation, some of them may be alive already. */ if (!IsBinaryUpgrade && AutoVacuumingActive() && AutoVacPID == 0) + { AutoVacPID = StartAutoVacLauncher(); + AFTER_AUX_FORK_SLEEP(); + } if (XLogArchivingActive() && PgArchPID == 0) + { PgArchPID = pgarch_start(); + AFTER_AUX_FORK_SLEEP(); + } if (PgStatPID == 0) + { PgStatPID = pgstat_start(); + AFTER_AUX_FORK_SLEEP(); + } /* some workers may be scheduled to start now */ maybe_start_bgworker(); @@ -5259,6 +5293,7 @@ StartChildProcess(AuxProcType type) /* * in parent, successful fork */ + AFTER_AUX_FORK_SLEEP(); return pid; } --Multipart=_Fri__29_Jun_2018_15_03_10_+0900_Hy8Ql8DVk0NJ2uER--