You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
postgres/src/include/storage/ipc.h

117 lines
3.1 KiB

/*-------------------------------------------------------------------------
*
* ipc.h
* POSTGRES inter-process communication definitions.
*
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: ipc.h,v 1.50 2001/06/27 23:31:39 tgl Exp $
*
* Some files that would normally need to include only sys/ipc.h must
* instead include this file because on Ultrix, sys/ipc.h is not designed
* to be included multiple times. This file (by virtue of the ifndef IPC_H)
* is.
*-------------------------------------------------------------------------
*/
#ifndef IPC_H
#define IPC_H
#include <sys/types.h>
#ifdef HAVE_SYS_IPC_H
#include <sys/ipc.h>
#endif /* HAVE_SYS_IPC_H */
#ifndef HAVE_UNION_SEMUN
union semun
{
int val;
struct semid_ds *buf;
unsigned short *array;
};
#endif
/* generic IPC definitions */
#define IPCProtection (0600) /* access/modify by user only */
/* semaphore definitions */
typedef uint32 IpcSemaphoreKey; /* semaphore key passed to semget(2) */
typedef int IpcSemaphoreId; /* semaphore ID returned by semget(2) */
#define IPC_NMAXSEM 32 /* maximum number of semaphores per semID */
#define PGSemaMagic 537 /* must be less than SEMVMX */
/* shared memory definitions */
typedef uint32 IpcMemoryKey; /* shared memory key passed to shmget(2) */
typedef int IpcMemoryId; /* shared memory ID returned by shmget(2) */
typedef struct /* standard header for all Postgres shmem */
{
int32 magic; /* magic # to identify Postgres segments */
#define PGShmemMagic 679834892
pid_t creatorPID; /* PID of creating process */
uint32 totalsize; /* total size of segment */
uint32 freeoffset; /* offset to first free space */
} PGShmemHeader;
/* spinlock definitions */
typedef enum _LockId_
{
BUFMGRLOCKID,
OIDGENLOCKID,
XIDGENLOCKID,
CNTLFILELOCKID,
SHMEMLOCKID,
SHMEMINDEXLOCKID,
LOCKMGRLOCKID,
SINVALLOCKID,
PROCSTRUCTLOCKID,
FREESPACELOCKID,
#ifdef STABLE_MEMORY_STORAGE
MMCACHELOCKID,
#endif
MAX_SPINS /* must be last item! */
} _LockId_;
/* ipc.c */
extern bool proc_exit_inprogress;
extern void proc_exit(int code);
extern void shmem_exit(int code);
extern void on_proc_exit(void (*function) (), Datum arg);
extern void on_shmem_exit(void (*function) (), Datum arg);
extern void on_exit_reset(void);
extern void IpcInitKeyAssignment(int port);
extern IpcSemaphoreId IpcSemaphoreCreate(int numSems, int permission,
int semStartValue,
bool removeOnExit);
extern void IpcSemaphoreKill(IpcSemaphoreId semId);
extern void IpcSemaphoreLock(IpcSemaphoreId semId, int sem, bool interruptOK);
extern void IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem);
extern bool IpcSemaphoreTryLock(IpcSemaphoreId semId, int sem);
extern int IpcSemaphoreGetValue(IpcSemaphoreId semId, int sem);
extern PGShmemHeader *IpcMemoryCreate(uint32 size, bool makePrivate,
int permission);
XLOG (and related) changes: * Store two past checkpoint locations, not just one, in pg_control. On startup, we fall back to the older checkpoint if the newer one is unreadable. Also, a physical copy of the newest checkpoint record is kept in pg_control for possible use in disaster recovery (ie, complete loss of pg_xlog). Also add a version number for pg_control itself. Remove archdir from pg_control; it ought to be a GUC parameter, not a special case (not that it's implemented yet anyway). * Suppress successive checkpoint records when nothing has been entered in the WAL log since the last one. This is not so much to avoid I/O as to make it actually useful to keep track of the last two checkpoints. If the things are right next to each other then there's not a lot of redundancy gained... * Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs on alternate bytes. Polynomial borrowed from ECMA DLT1 standard. * Fix XLOG record length handling so that it will work at BLCKSZ = 32k. * Change XID allocation to work more like OID allocation. (This is of dubious necessity, but I think it's a good idea anyway.) * Fix a number of minor bugs, such as off-by-one logic for XLOG file wraparound at the 4 gig mark. * Add documentation and clean up some coding infelicities; move file format declarations out to include files where planned contrib utilities can get at them. * Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also possible to force a checkpoint by sending SIGUSR1 to the postmaster (undocumented feature...) * Defend against kill -9 postmaster by storing shmem block's key and ID in postmaster.pid lockfile, and checking at startup to ensure that no processes are still connected to old shmem block (if it still exists). * Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency stop, for symmetry with postmaster and xlog utilities. Clean up signal handling in bootstrap.c so that xlog utilities launched by postmaster will react to signals better. * Standalone bootstrap now grabs lockfile in target directory, as added insurance against running it in parallel with live postmaster.
25 years ago
extern bool SharedMemoryIsInUse(IpcMemoryKey shmKey, IpcMemoryId shmId);
/* ipci.c */
extern void CreateSharedMemoryAndSemaphores(bool makePrivate,
int maxBackends);
#endif /* IPC_H */