From: Amit Kapila <amit.kapila16@gmail.com>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Haribabu Kommi <kommi.haribabu@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Dmitry Vasilyev <d.vasilyev@postgrespro.ru>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] Re: [HACKERS] Re: [HACKERS] Re: [HACKERS] Windows service is not starting so there’s message in log: FATAL: "could not create shared memory segment “Global/PostgreSQL.851401618”: Permission denied”
Date: Wed, 25 May 2016 12:41:18 +0530
Message-ID: <CAA4eK1JyNdMeF-dgrpHozDecpDfsRZUtpCi+1AbtuEkfG3YooQ@mail.gmail.com> (raw)
In-Reply-To: <CAB7nPqSYExhuwXM6JFQLtiNC93sJx8RQNt6doz8QJqgPDcXGWA@mail.gmail.com>
References: <1444920387.3661.7.camel@postgrespro.ru>
<1444921511.3661.13.camel@postgrespro.ru>
<CAA4eK1+pjtDouF-Lc9y0UgFDmWHnaf4KwiM1Y3Anq0wZ1gwsAA@mail.gmail.com>
<CA+TgmoZiYV=fFnWQZbfjZ250=YYxAWn_XETGVdUpwFnKxd7B9A@mail.gmail.com>
<CAA4eK1K-c0P7_RVRUFrkgQyy-X4JC1rDyHpZiUQeJJJPpAy_jw@mail.gmail.com>
<31461.1445090619@sss.pgh.pa.us>
<CAJrrPGfkMyYmr+7fki+nKsWGZ0LOXMgPJSixSFo=uL6MFF=OGQ@mail.gmail.com>
<CAA4eK1JTS3bOUX8KHGJrhGs5i54FdbU0Ez4PMqDqj5r_KvwKOQ@mail.gmail.com>
<CAJrrPGcC27MYAmeHq=o8zo52c+-X7NbrzF26d1CZBS-JQkHaYQ@mail.gmail.com>
<CAA4eK1J7mSohkNb2q0yUn8aFdfaR66jH3HnWi6pT4XaXRrdxjQ@mail.gmail.com>
<CAJrrPGcT8URvcyeWzZcHgB6PVyus-r785thn6vUGZ9SyA3Kq8A@mail.gmail.com>
<CAA4eK1LSqMRWnjnakWejfKg8_Bt7DZvBTHUsYbP1MerXxX7YYw@mail.gmail.com>
<CAJrrPGfnFB+wmc3FMo6f9fC+p5+mevw5nQdkMSqfTB-1Ey=wmA@mail.gmail.com>
<CAA4eK1K+c3Scr4WPcnt6=UQX6ZttJkHOe5+UQ3mMtjAnq2xGdQ@mail.gmail.com>
<CAJrrPGcEyYbffNh6VEpXaykVsGthvZ7Qhn4d6TmxsHda5MPDtQ@mail.gmail.com>
<CAA4eK1Jgm3MxO1=RAGJWE1cARQxFwUe48pFgFZ_GEGwMiCWM2A@mail.gmail.com>
<CA+TgmoYnjfBU5qTATm_RpQUpmbBr_husxs1BgMOjdaC0NnhhWg@mail.gmail.com>
<CAA4eK1J8sEcdsGLSQn4TWvyV_c=9-Shpq_c7cA2BP8s0NMS_Kg@mail.gmail.com>
<CAB7nPqRKdNu2WF0rZ8k9OvfWcKDpaY7BsxiVuJT1yY4B9kNYiQ@mail.gmail.com>
<CAA4eK1La8-KdvpOan3nAYDhijyk_=wjSRT3fTq=Qzk1fyEf8WA@mail.gmail.com>
<CAB7nPqSYExhuwXM6JFQLtiNC93sJx8RQNt6doz8QJqgPDcXGWA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On Tue, May 17, 2016 at 2:31 AM, Michael Paquier <michael.paquier@gmail.com>
wrote:
>
> On Tue, May 17, 2016 at 4:16 AM, Amit Kapila <amit.kapila16@gmail.com>
wrote:
> > On Mon, May 16, 2016 at 9:45 AM, Michael Paquier <
michael.paquier@gmail.com>
> > wrote:
> >>
> >> On Sun, May 15, 2016 at 3:34 PM, Amit Kapila <amit.kapila16@gmail.com>
> >> wrote:
> >> > Sounds sensible, but if we want to that route, shall we have some
> >> > mechanism
> >> > such that if retrying it for 10 times (10 is somewhat arbitrary, but
we
> >> > retry 10 times in PGSharedMemoryCreate, so may be there is some
> >> > consistency)
> >> > doesn't give us unique name and we are getting EACCES error, then
just
> >> > throw
> >> > the error instead of more retries. This is to ensure that if the
API is
> >> > returning EACCES due to reason other than duplicate handle, then we
> >> > won't
> >> > retry indefinitely.
> >>
> >> The logic in win32_shmem.c relies on the fact that a segment will be
> >> recycled, and the retry is here because it may take time at OS level.
> >> On top of that it relies on the segment names being unique across
> >> systems. So it seems to me that it is not worth the complication to
> >> duplicate that logic in the dsm implementation.
> >
> > If we don't do retry for fixed number of times, then how will we handle
the
> > case if EACCES is due to the reason other than duplicate handle?
>
> EACCES is a bit too low-level... I had in mind to check GetLastError
> with only ERROR_ACCESS_DENIED, and retry only in this case, which is
> the case where one postmaster is trying to access the segment of
> another.
>
Okay, attached patch just does that and I have verified that it allows to
start multiple services in windows. In off list discussion with Robert, he
suggested not to complicate the patch by retrying for fixed number of times
as there is no proof that ERROR_ACCESS_DENIED can occur due to any other
reason in this code path. This patch is based on Kyotaro san's patch
posted upthread with just minor changes in comments and indentation.
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:dsm_win_segment_access_v1.patch (application/octet-stream, 1.7K) downloaddiff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.cindex 173b982..6e0f0a7 100644--- a/src/backend/storage/ipc/dsm_impl.c+++ b/src/backend/storage/ipc/dsm_impl.c@@ -671,6 +671,7 @@ dsm_impl_windows(dsm_op op, dsm_handle handle, Size request_size,
{
DWORD size_high;
DWORD size_low;
+ DWORD errcode;
/* Shifts >= the width of the type are undefined. */
#ifdef _WIN64
@@ -686,27 +687,31 @@ dsm_impl_windows(dsm_op op, dsm_handle handle, Size request_size,
size_high, /* Upper 32 bits of size */
size_low, /* Lower 32 bits of size */
name);
++ errcode = GetLastError();+ if (errcode == ERROR_ALREADY_EXISTS || errcode == ERROR_ACCESS_DENIED)+ {+ /*+ * On Windows, when the segment already exists, a handle for the+ * existing segment is returned. We must close it before+ * returning. However, if the existing segment is created by a+ * service, then it returns ERROR_ACCESS_DENIED. We don't do+ * _dosmaperr here, so errno won't be modified.+ */+ if (hmap)+ CloseHandle(hmap);+ return false;+ }+
if (!hmap)
{
- _dosmaperr(GetLastError());+ _dosmaperr(errcode);
ereport(elevel,
(errcode_for_dynamic_shared_memory(),
errmsg("could not create shared memory segment \"%s\": %m",
name)));
return false;
}
- _dosmaperr(GetLastError());- if (errno == EEXIST)- {- /*- * On Windows, when the segment already exists, a handle for the- * existing segment is returned. We must close it before- * returning. We don't do _dosmaperr here, so errno won't be- * modified.- */- CloseHandle(hmap);- return false;- }
}
else
{
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: amit.kapila16@gmail.com, michael.paquier@gmail.com, robertmhaas@gmail.com, kommi.haribabu@gmail.com, tgl@sss.pgh.pa.us, d.vasilyev@postgrespro.ru
Subject: Re: [HACKERS] Re: [HACKERS] Re: [HACKERS] Re: [HACKERS] Windows service is not starting so there’s message in log: FATAL: "could not create shared memory segment “Global/PostgreSQL.851401618”: Permission denied”
In-Reply-To: <CAA4eK1JyNdMeF-dgrpHozDecpDfsRZUtpCi+1AbtuEkfG3YooQ@mail.gmail.com>
References: <1444920387.3661.7.camel@postgrespro.ru> <CAA4eK1J7mSohkNb2q0yUn8aFdfaR66jH3HnWi6pT4XaXRrdxjQ@mail.gmail.com> <CAJrrPGcT8URvcyeWzZcHgB6PVyus-r785thn6vUGZ9SyA3Kq8A@mail.gmail.com> <CAA4eK1LSqMRWnjnakWejfKg8_Bt7DZvBTHUsYbP1MerXxX7YYw@mail.gmail.com> <CAJrrPGfnFB+wmc3FMo6f9fC+p5+mevw5nQdkMSqfTB-1Ey=wmA@mail.gmail.com> <CAA4eK1K+c3Scr4WPcnt6=UQX6ZttJkHOe5+UQ3mMtjAnq2xGdQ@mail.gmail.com> <CAJrrPGcEyYbffNh6VEpXaykVsGthvZ7Qhn4d6TmxsHda5MPDtQ@mail.gmail.com> <CAA4eK1Jgm3MxO1=RAGJWE1cARQxFwUe48pFgFZ_GEGwMiCWM2A@mail.gmail.com> <CA+TgmoYnjfBU5qTATm_RpQUpmbBr_husxs1BgMOjdaC0NnhhWg@mail.gmail.com> <CAA4eK1J8sEcdsGLSQn4TWvyV_c=9-Shpq_c7cA2BP8s0NMS_Kg@mail.gmail.com> <CAB7nPqRKdNu2WF0rZ8k9OvfWcKDpaY7BsxiVuJT1yY4B9kNYiQ@mail.gmail.com> <CAA4eK1La8-KdvpOan3nAYDhijyk_=wjSRT3fTq=Qzk1fyEf8WA@mail.gmail.com> <CAB7nPqSYExhuwXM6JFQLtiNC93sJx8RQNt6doz8QJqgPDcXGWA@mail.gmail.com> <CAA4eK1JyNdMeF-dgrpHozDecpDfsRZUtpCi+1AbtuEkfG3YooQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox