From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use data directory inode number, not port, to select SysV resour
Date: Thu, 05 Sep 2019 17:32:04 +0000
Message-ID: <E1i5vc4-0004Lg-4U@gemulon.postgresql.org> (raw)
Use data directory inode number, not port, to select SysV resource keys.
This approach provides a much tighter binding between a data directory
and the associated SysV shared memory block (and SysV or named-POSIX
semaphores, if we're using those). Key collisions are still possible,
but only between data directories stored on different filesystems,
so the situation should be negligible in practice. More importantly,
restarting the postmaster with a different port number no longer
risks failing to identify a relevant shared memory block, even when
postmaster.pid has been removed. A standalone backend is likewise
much more certain to detect conflicting leftover backends.
(In the longer term, we might now think about deprecating the port as
a cluster-wide value, so that one postmaster could support sockets
with varying port numbers. But that's for another day.)
The hazards fixed here apply only on Unix systems; our Windows code
paths already use identifiers derived from the data directory path
name rather than the port.
src/test/recovery/t/017_shm.pl, which intends to test key-collision
cases, has been substantially rewritten since it can no longer use
two postmasters with identical port numbers to trigger the case.
Instead, use Perl's IPC::SharedMem module to create a conflicting
shmem segment directly. The test script will be skipped if that
module is not available. (This means that some older buildfarm
members won't run it, but I don't think that that results in any
meaningful coverage loss.)
Patch by me; thanks to Noah Misch and Peter Eisentraut for discussion
and review.
Discussion: https://postgr.es/m/16908.1557521200@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7de19fbc0b1a9172d0907017302b32846b2887b9
Modified Files
--------------
src/backend/port/posix_sema.c | 23 ++++--
src/backend/port/sysv_sema.c | 23 ++++--
src/backend/port/sysv_shmem.c | 38 +++++----
src/backend/port/win32_sema.c | 2 +-
src/backend/port/win32_shmem.c | 2 +-
src/backend/postmaster/postmaster.c | 25 +++---
src/backend/storage/ipc/ipci.c | 6 +-
src/backend/utils/init/postinit.c | 8 +-
src/include/storage/ipc.h | 2 +-
src/include/storage/pg_sema.h | 2 +-
src/include/storage/pg_shmem.h | 2 +-
src/test/recovery/t/017_shm.pl | 150 +++++++++++++++++++-----------------
12 files changed, 159 insertions(+), 124 deletions(-)
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-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Use data directory inode number, not port, to select SysV resour
In-Reply-To: <E1i5vc4-0004Lg-4U@gemulon.postgresql.org>
References: <E1i5vc4-0004Lg-4U@gemulon.postgresql.org>
* 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