Re: Postgres service stops when I kill client backend on Windows

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Ali Akbar <the(dot)apaan(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Dmitry Vasilyev <d(dot)vasilyev(at)postgrespro(dot)ru>, Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Postgres service stops when I kill client backend on Windows
Date: 2015-10-14 03:58:50
Message-ID: CAA4eK1K4_Y1uSCF2Ngcc-izkEGYzmbKC6VdSJNd0mhFcHRocwg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 13, 2015 at 8:57 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
> > On Tue, Oct 13, 2015 at 5:35 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >> After poking around a bit more, I propose the attached patch. I've
> >> checked that this is happy with an EXEC_BACKEND Unix build, but I'm not
> >> able to test it on Windows ... would somebody do that?
>
> > Looking at the patch, clearly +1 for the additional routine in both
> > win32_shmem.c and sysv_shmem.c to clean up the shmem state at backend
> > level. I have played as well with the patch on Windows and it behaves
> > as expected: without the patch a process killed with taskkill /f stops
> > straight the server even if restart_on_crash is on. With the patch the
> > server restarts correctly.
>
> OK, pushed with some additional comment-smithing.
>
> I noticed while looking at this that for subprocesses that aren't supposed
> to be attached to shared memory, we do pgwin32_ReserveSharedMemoryRegion()
> anyway in internal_forkexec(), and then that's never undone anywhere,
> so that that segment of the subprocess's memory space remains reserved.
> I'm not sure if this is worth changing, but if it is, we could do so now
> by calling VirtualFree() in PGSharedMemoryNoReAttach().
>

I think it is worth doing, as it can save the memory for processes which
don't attach to shared memory. Another thing is that we do allocate
handles (by using duplicate handle) in save_backend_variables() which
I am not sure are required for all the processes, anyway this doesn't
seem worth the trouble.

> BTW, I am suspicious that the DSM stuff may have related issues --- do
> we use inheritable mapping handles for DSM segments on Windows?
>

Not by default, there is an API dsm_pin_segment() which Duplicates the
handle for Postmaster process to retain the shared memory segment
till Postmaster shutdown. In general, I don't see such issues for DSM,
but please point me if you see anything problematic.

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2015-10-14 04:34:42 Re: Support for N synchronous standby servers - take 2
Previous Message Kouhei Kaigai 2015-10-14 03:07:31 Re: Foreign join pushdown vs EvalPlanQual