mirror of
https://github.com/postgres/postgres.git
synced 2025-05-18 17:41:14 +03:00
Cause stats processes to detach from shared memory when started, so that
they do not prevent the postmaster from deleting the shmem segment during a post-backend-crash restart cycle. Per recent discussion.
This commit is contained in:
parent
8762e10174
commit
87c93e112b
@ -10,7 +10,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.24 2003/10/27 18:30:07 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.24.2.1 2003/11/07 21:56:01 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -134,7 +134,7 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
|
|||||||
|
|
||||||
/* OK, should be able to attach to the segment */
|
/* OK, should be able to attach to the segment */
|
||||||
#ifdef SHM_SHARE_MMU
|
#ifdef SHM_SHARE_MMU
|
||||||
/* use intimate shared memory on SPARC Solaris */
|
/* use intimate shared memory on Solaris */
|
||||||
memAddress = shmat(shmid, 0, SHM_SHARE_MMU);
|
memAddress = shmat(shmid, 0, SHM_SHARE_MMU);
|
||||||
#else
|
#else
|
||||||
memAddress = shmat(shmid, 0, 0);
|
memAddress = shmat(shmid, 0, 0);
|
||||||
@ -244,7 +244,7 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
|
|||||||
/* Room for a header? */
|
/* Room for a header? */
|
||||||
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
|
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
|
||||||
|
|
||||||
/* Just attach and return the pointer */
|
/* If Exec case, just attach and return the pointer */
|
||||||
if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate)
|
if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate)
|
||||||
{
|
{
|
||||||
if ((hdr = PGSharedMemoryAttach(UsedShmemSegID, &shmid)) == NULL)
|
if ((hdr = PGSharedMemoryAttach(UsedShmemSegID, &shmid)) == NULL)
|
||||||
@ -253,6 +253,9 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
|
|||||||
return hdr;
|
return hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make sure PGSharedMemoryAttach doesn't fail without need */
|
||||||
|
UsedShmemSegAddr = NULL;
|
||||||
|
|
||||||
/* Loop till we find a free IPC key */
|
/* Loop till we find a free IPC key */
|
||||||
NextShmemSegID = port * 1000;
|
NextShmemSegID = port * 1000;
|
||||||
|
|
||||||
@ -326,16 +329,32 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
|
|||||||
hdr->totalsize = size;
|
hdr->totalsize = size;
|
||||||
hdr->freeoffset = MAXALIGN(sizeof(PGShmemHeader));
|
hdr->freeoffset = MAXALIGN(sizeof(PGShmemHeader));
|
||||||
|
|
||||||
|
/* Save info for possible future use */
|
||||||
if (ExecBackend && UsedShmemSegAddr == NULL && !makePrivate)
|
|
||||||
{
|
|
||||||
UsedShmemSegAddr = memAddress;
|
UsedShmemSegAddr = memAddress;
|
||||||
UsedShmemSegID = NextShmemSegID;
|
UsedShmemSegID = NextShmemSegID;
|
||||||
}
|
|
||||||
|
|
||||||
return hdr;
|
return hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PGSharedMemoryDetach
|
||||||
|
*
|
||||||
|
* Detach from the shared memory segment, if still attached. This is not
|
||||||
|
* intended for use by the process that originally created the segment
|
||||||
|
* (it will have an on_shmem_exit callback registered to do that). Rather,
|
||||||
|
* this is for subprocesses that have inherited an attachment and want to
|
||||||
|
* get rid of it.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
PGSharedMemoryDetach(void)
|
||||||
|
{
|
||||||
|
if (UsedShmemSegAddr != NULL)
|
||||||
|
{
|
||||||
|
if (shmdt(UsedShmemSegAddr) < 0)
|
||||||
|
elog(LOG, "shmdt(%p) failed: %m", UsedShmemSegAddr);
|
||||||
|
UsedShmemSegAddr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attach to shared memory and make sure it has a Postgres header
|
* Attach to shared memory and make sure it has a Postgres header
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
|
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.45 2003/09/25 06:58:01 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.45.2.1 2003/11/07 21:56:02 tgl Exp $
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
@ -44,6 +44,7 @@
|
|||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "storage/backendid.h"
|
#include "storage/backendid.h"
|
||||||
#include "storage/ipc.h"
|
#include "storage/ipc.h"
|
||||||
|
#include "storage/pg_shmem.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
#include "utils/hsearch.h"
|
#include "utils/hsearch.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
@ -400,6 +401,9 @@ pgstat_start(void)
|
|||||||
/* Close the postmaster's sockets, except for pgstat link */
|
/* Close the postmaster's sockets, except for pgstat link */
|
||||||
ClosePostmasterPorts(false);
|
ClosePostmasterPorts(false);
|
||||||
|
|
||||||
|
/* Drop our connection to postmaster's shared memory, as well */
|
||||||
|
PGSharedMemoryDetach();
|
||||||
|
|
||||||
pgstat_main();
|
pgstat_main();
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: pg_shmem.h,v 1.7 2003/08/04 02:40:15 momjian Exp $
|
* $Id: pg_shmem.h,v 1.7.4.1 2003/11/07 21:56:02 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -44,5 +44,6 @@ extern void *UsedShmemSegAddr;
|
|||||||
extern PGShmemHeader *PGSharedMemoryCreate(uint32 size, bool makePrivate,
|
extern PGShmemHeader *PGSharedMemoryCreate(uint32 size, bool makePrivate,
|
||||||
int port);
|
int port);
|
||||||
extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);
|
extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);
|
||||||
|
extern void PGSharedMemoryDetach(void);
|
||||||
|
|
||||||
#endif /* PG_SHMEM_H */
|
#endif /* PG_SHMEM_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user