diff options
author | Robert Haas <rhaas@postgresql.org> | 2014-04-08 11:39:55 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2014-04-08 11:39:55 -0400 |
commit | 11a65eed1637a05b03e174700799b024e104bfb4 (patch) | |
tree | c6634e65fcfc2f3eb7e86f09d18ac9562a46cb24 /src/backend/port/sysv_shmem.c | |
parent | 0886fc6a5c75b294544263ea979b9cf6195407d9 (diff) | |
download | postgresql-11a65eed1637a05b03e174700799b024e104bfb4.tar.gz postgresql-11a65eed1637a05b03e174700799b024e104bfb4.zip |
Get rid of the dynamic shared memory state file.
Instead of storing the ID of the dynamic shared memory control
segment in a file within the data directory, store it in the main
control segment. This avoids a number of nasty corner cases,
most seriously that doing an online backup and then using it on
the same machine (e.g. to fire up a standby) would result in the
standby clobbering all of the master's dynamic shared memory
segments.
Per complaints from Heikki Linnakangas, Fujii Masao, and Tom
Lane.
Diffstat (limited to 'src/backend/port/sysv_shmem.c')
-rw-r--r-- | src/backend/port/sysv_shmem.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index 51c1a2b71f8..5e3850b024d 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -30,6 +30,7 @@ #include "miscadmin.h" #include "portability/mem.h" +#include "storage/dsm.h" #include "storage/ipc.h" #include "storage/pg_shmem.h" #include "utils/guc.h" @@ -421,7 +422,8 @@ CreateAnonymousSegment(Size *size) * zero will be passed. */ PGShmemHeader * -PGSharedMemoryCreate(Size size, bool makePrivate, int port) +PGSharedMemoryCreate(Size size, bool makePrivate, int port, + PGShmemHeader **shim) { IpcMemoryKey NextShmemSegID; void *memAddress; @@ -509,10 +511,13 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) /* * The segment appears to be from a dead Postgres process, or from a - * previous cycle of life in this same process. Zap it, if possible. + * previous cycle of life in this same process. Zap it, if possible, + * and any associated dynamic shared memory segments, as well. * This probably shouldn't fail, but if it does, assume the segment * belongs to someone else after all, and continue quietly. */ + if (hdr->dsm_control != 0) + dsm_cleanup_using_control_segment(hdr->dsm_control); shmdt(memAddress); if (shmctl(shmid, IPC_RMID, NULL) < 0) continue; @@ -539,6 +544,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) hdr = (PGShmemHeader *) memAddress; hdr->creatorPID = getpid(); hdr->magic = PGShmemMagic; + hdr->dsm_control = 0; /* Fill in the data directory ID info, too */ if (stat(DataDir, &statbuf) < 0) @@ -554,6 +560,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) */ hdr->totalsize = size; hdr->freeoffset = MAXALIGN(sizeof(PGShmemHeader)); + *shim = hdr; /* Save info for possible future use */ UsedShmemSegAddr = memAddress; @@ -608,6 +615,7 @@ PGSharedMemoryReAttach(void) if (hdr != origUsedShmemSegAddr) elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)", hdr, origUsedShmemSegAddr); + dsm_set_control_handle(((PGShmemHeader *) hdr)->dsm_control); UsedShmemSegAddr = hdr; /* probably redundant */ } |