Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cuvpb-00065f-V2 for pgsql-bugs@arkaria.postgresql.org; Mon, 03 Apr 2017 06:51:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cuvpb-00085m-EI for pgsql-bugs@arkaria.postgresql.org; Mon, 03 Apr 2017 06:51:15 +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.84_2) (envelope-from ) id 1cuvpa-00085V-P2 for pgsql-bugs@postgresql.org; Mon, 03 Apr 2017 06:51:15 +0000 Received: from mail-pg0-x22f.google.com ([2607:f8b0:400e:c05::22f]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cuvpY-0007IV-34 for pgsql-bugs@postgresql.org; Mon, 03 Apr 2017 06:51:13 +0000 Received: by mail-pg0-x22f.google.com with SMTP id 21so111214724pgg.1 for ; Sun, 02 Apr 2017 23:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=eGRNXVVitTbE6RlhmqSssQI+w3Q+jxXiJUCx07cHWKE=; b=eohnQGsVqw31CiQ2fqYDwfuySCyi667Iran1P/QiuPaF9yZrTLUWJnqK/dT/rjE1Wv G1DPWoIAuRnbmgxU0+gHlGb5wTK2LLqfDfis8ZngSy4YtcTwfo4Tzmy9aZnIp7n8iAnL wzUoLBhirfTgT8q/5J3snKHJjNZpq7lWZ6lF0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=eGRNXVVitTbE6RlhmqSssQI+w3Q+jxXiJUCx07cHWKE=; b=lTIU5tRp/2cWdAnMMxCB+k/d3IYlS6lR01ts/q+paIr47H94QTooLDOkDo9bk5ML90 cE/NLXprQ31C7/ZDICRRcvrNyFn9t0miD+zN9yKhVEfZo32Y5SV3pBTztKY4+PgK2caN gvGzEQA6S64raGAxa/T8bQwZ7t7MGqNKDDOgOE/+BJi5dsHNmJ9abqBhmnp9Mniu1XC7 ueXuZfHygkplm980mXCk7u0/cjYSYtW6kqgFwiGccr6KDZiSPlx6XZfNh+9y2PcXnMwD ATJCA2GTsnzjlYBkkMcQfPgEgj9XNxPUXf19+Igb1O9W5IP/vld9M2bgTy2YLWNW8SQp KYCA== X-Gm-Message-State: AFeK/H2erGWnUUuGYdLHhUBX6Drjo+vs6l2J4VPiJwxf09V0D8CV3hJDlxfIMkxY+wOfsw== X-Received: by 10.84.254.75 with SMTP id a11mr19896637pln.57.1491202270440; Sun, 02 Apr 2017 23:51:10 -0700 (PDT) Received: from tornado.leadboat.com (c-98-248-47-228.hsd1.ca.comcast.net. [98.248.47.228]) by smtp.gmail.com with ESMTPSA id u23sm16719514pfi.120.2017.04.02.23.51.08 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 02 Apr 2017 23:51:08 -0700 (PDT) Date: Mon, 3 Apr 2017 02:51:06 -0400 From: Noah Misch To: Tomasz Szypowski Cc: Tom Lane , Michael Paquier , PostgreSQL mailing lists Subject: Re: could not fork autovacuum worker process: No error Message-ID: <20170403065106.GA2624300@tornado.leadboat.com> References: <9889.1485358425@sss.pgh.pa.us> <14121.1485360296@sss.pgh.pa.us> <20170401024138.GA2521221@tornado.leadboat.com> <27928.1491148737@sss.pgh.pa.us> <20170402220856.GA2601785@tornado.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AqsLC8rIMeq19msA" Content-Disposition: inline In-Reply-To: <20170402220856.GA2601785@tornado.leadboat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Apr 02, 2017 at 06:08:56PM -0400, Noah Misch wrote: > On Sun, Apr 02, 2017 at 07:51:59PM +0200, Tomasz Szypowski wrote: > > I build PostgreSQL 32 bit on Windows with Microsoft Visual Studio 8. > > That version number is ambiguous. From the command prompt in which you build > PostgreSQL, what is the output of these two commands? > > cl > systeminfo | findstr /B OS > > If you build PostgreSQL on one system and run it on a different system, what > is the output of "systeminfo | findstr /B OS" on the runtime system? Also, could you run a test workload that reproduces the problem against a postgres.exe built with the attached patch? This will dump details of your memory postgres.exe memory map to the log, hopefully giving a clue about the source of the trouble. --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="w32-memory-map-v1.patch" diff --git a/src/backend/Makefile b/src/backend/Makefile index 7a0bbb2..498bdc9 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -80,7 +80,7 @@ libpostgres.a: postgres ; endif # cygwin ifeq ($(PORTNAME), win32) -LIBS += -lsecur32 +LIBS += -lsecur32 -lpsapi postgres: $(OBJS) $(WIN32RES) $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS) -o $@$(X) diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c index 31489fc..1e35278 100644 --- a/src/backend/port/win32_shmem.c +++ b/src/backend/port/win32_shmem.c @@ -17,12 +17,85 @@ #include "storage/ipc.h" #include "storage/pg_shmem.h" +#include + HANDLE UsedShmemSegID = INVALID_HANDLE_VALUE; void *UsedShmemSegAddr = NULL; static Size UsedShmemSegSize = 0; static void pgwin32_SharedMemoryDelete(int status, Datum shmId); +static void +dumpdlls(HANDLE *proc) +{ + HMODULE dll[512]; + DWORD size_used = 1; + int i; + + if (!EnumProcessModules(proc, dll, sizeof(dll), &size_used)) + { + elog(LOG, "EnumProcessModules failed: %lu", GetLastError()); + return; + } + if (size_used == 0) + elog(LOG, "EnumProcessModules: no modules"); + + for (i = 0; i < size_used / sizeof(*dll); i++) + { + char name[MAXPGPATH]; + + if (!GetModuleFileNameEx(proc, dll[i], name, sizeof(name))) + sprintf(name, "GetModuleFileNameEx failed: %lu", GetLastError()); + elog(LOG, "0x%p %s", dll[i], name); + } +} + +static const char * +mi_type(DWORD code) +{ + switch (code) { + case MEM_IMAGE: return "img"; + case MEM_MAPPED: return "map"; + case MEM_PRIVATE: return "prv"; + } + return "???"; +} + +static const char * +mi_state(DWORD code) +{ + switch (code) { + case MEM_COMMIT: return "commit"; + case MEM_FREE: return "free "; + case MEM_RESERVE: return "reserv"; + } + return "???"; +} + +static void +dumpmem(const char *reason, HANDLE *proc) +{ + char *addr = 0; + MEMORY_BASIC_INFORMATION mi; + + elog(LOG, "%s memory map", reason); + do { + if (0 == VirtualQueryEx(proc, addr, &mi, sizeof(mi))) + { + if (GetLastError() == ERROR_INVALID_PARAMETER) + break; + elog(LOG, "VirtualQueryEx failed: %lu", GetLastError()); + return; + } + elog(LOG, "0x%p+0x%p %s (alloc 0x%p) %s", + mi.BaseAddress, (void *) mi.RegionSize, + mi_type(mi.Type), mi.AllocationBase, mi_state(mi.State)); + addr += mi.RegionSize; + } while (addr > 0); + + dumpdlls(proc); +} + /* * Generate shared memory segment name. Expand the data directory, to generate * an identifier unique for this data directory. Then replace all backslashes @@ -276,6 +349,8 @@ PGSharedMemoryReAttach(void) Assert(UsedShmemSegAddr != NULL); Assert(IsUnderPostmaster); + dumpmem("before reattach", GetCurrentProcess()); + /* * Release memory region reservation that was made by the postmaster */ @@ -408,6 +483,7 @@ pgwin32_ReserveSharedMemoryRegion(HANDLE hChild) address = VirtualAllocEx(hChild, UsedShmemSegAddr, UsedShmemSegSize, MEM_RESERVE, PAGE_READWRITE); + dumpmem("after reserve", hChild); if (address == NULL) { /* Don't use FATAL since we're running in the postmaster */ diff --git a/src/makefiles/Makefile.win32 b/src/makefiles/Makefile.win32 index 7abbd01..678371d 100644 --- a/src/makefiles/Makefile.win32 +++ b/src/makefiles/Makefile.win32 @@ -1,5 +1,7 @@ # src/makefiles/Makefile.win32 +override CPPFLAGS+= -DPSAPI_VERSION=1 + ifdef PGXS BE_DLLLIBS= -L$(libdir) -lpostgres override CPPFLAGS+= -I$(includedir_server)/port/win32 diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index 12f73f3..4c39f33 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -172,8 +172,10 @@ sub mkvcbuild 'repl_gram.y', 'syncrep_scanner.l', 'syncrep_gram.y'); $postgres->AddDefine('BUILDING_DLL'); + $postgres->AddDefine('PSAPI_VERSION=1'); $postgres->AddLibrary('secur32.lib'); $postgres->AddLibrary('ws2_32.lib'); + $postgres->AddLibrary('psapi.lib'); $postgres->AddLibrary('wldap32.lib') if ($solution->{options}->{ldap}); $postgres->FullExportDLL('postgres.lib'); --AqsLC8rIMeq19msA Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --AqsLC8rIMeq19msA--