postgresql/src/backend/storage
Tom Lane 7de19fbc0b 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
2019-09-05 13:31:46 -04:00
..
buffer Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
file Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
freespace Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
ipc Use data directory inode number, not port, to select SysV resource keys. 2019-09-05 13:31:46 -04:00
large_object Split tuptoaster.c into three separate files. 2019-09-05 13:15:10 -04:00
lmgr Fix inconsistencies and typos in the tree, take 11 2019-08-19 16:21:39 +09:00
page Make one message just like all its siblings. 2019-05-28 23:44:22 -04:00
smgr Fix inconsistencies and typos in the tree 2019-07-29 12:28:30 +09:00
sync Represent Lists as expansible arrays, not chains of cons-cells. 2019-07-15 13:41:58 -04:00
Makefile Refactor the fsync queue for wider use. 2019-04-04 23:38:38 +13:00