diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 38853e3..265bd3c 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -66,6 +66,9 @@ main(int argc, char *argv[]) * the backend/postmaster crashes with a fatal signal or exception. */ #if defined(WIN32) && defined(HAVE_MINIDUMP_TYPE) + /* In case of general protection fault, don't show GUI popup box */ + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); + pgwin32_install_crashdump_handler(); #endif @@ -266,9 +269,6 @@ startup_hacks(const char *progname) exit(1); } - /* In case of general protection fault, don't show GUI popup box */ - SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); - #if defined(_M_AMD64) && _MSC_VER == 1800 /*---------- diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index f3ddf82..b8b97a1 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -4576,6 +4576,7 @@ internal_forkexec(int argc, char *argv[], Port *port) SECURITY_ATTRIBUTES sa; char paramHandleStr[32]; win32_deadchild_waitinfo *childinfo; + UINT errorMode; /* Make sure caller set up argv properly */ Assert(argc >= 3); @@ -4643,14 +4644,20 @@ retry: /* * Create the subprocess in a suspended state. This will be resumed later, * once we have written out the parameter file. + * + * Start the subprocess with the default error mode, so that a crash before + * main() generates a crash dump. */ + errorMode = SetErrorMode(0); if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) { elog(LOG, "CreateProcess call failed: %m (error code %lu)", GetLastError()); + SetErrorMode(errorMode); return -1; } + SetErrorMode(errorMode); if (!save_backend_variables(param, port, pi.hProcess, pi.dwProcessId)) {