aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/access/transam/clog.c68
-rw-r--r--src/backend/bootstrap/bootstrap.c7
-rw-r--r--src/backend/postmaster/postmaster.c15
-rw-r--r--src/backend/storage/ipc/ipci.c15
-rw-r--r--src/backend/tcop/postgres.c8
-rw-r--r--src/include/miscadmin.h3
-rw-r--r--src/include/storage/ipc.h3
7 files changed, 90 insertions, 29 deletions
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index 8b055aa9603..3eb25f604eb 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.14 2003/05/02 21:59:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.15 2003/05/03 03:52:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -157,7 +157,7 @@ static ClogCtlData *ClogCtl = NULL;
* The value is automatically inherited by backends via fork, and
* doesn't need to be in shared memory.
*/
-static LWLockId ClogBufferLocks[NUM_CLOG_BUFFERS]; /* Per-buffer I/O locks */
+static LWLockId *ClogBufferLocks; /* Per-buffer I/O locks */
/*
* ClogDir is set during CLOGShmemInit and does not change thereafter.
@@ -271,41 +271,67 @@ TransactionIdGetStatus(TransactionId xid)
/*
* Initialization of shared memory for CLOG
*/
-
int
CLOGShmemSize(void)
{
- return MAXALIGN(sizeof(ClogCtlData) + CLOG_BLCKSZ * NUM_CLOG_BUFFERS);
+ return MAXALIGN(sizeof(ClogCtlData) + CLOG_BLCKSZ * NUM_CLOG_BUFFERS)
+#ifdef EXEC_BACKEND
+ + MAXALIGN(NUM_CLOG_BUFFERS * sizeof(LWLockId))
+#endif
+ ;
}
+
void
CLOGShmemInit(void)
{
bool found;
- char *bufptr;
int slotno;
+ /* Handle ClogCtl */
+
/* this must agree with space requested by CLOGShmemSize() */
- ClogCtl = (ClogCtlData *)
- ShmemInitStruct("CLOG Ctl",
- MAXALIGN(sizeof(ClogCtlData) +
- CLOG_BLCKSZ * NUM_CLOG_BUFFERS),
- &found);
- Assert(!found);
+ ClogCtl = (ClogCtlData *) ShmemInitStruct("CLOG Ctl",
+ MAXALIGN(sizeof(ClogCtlData) +
+ CLOG_BLCKSZ * NUM_CLOG_BUFFERS), &found);
- memset(ClogCtl, 0, sizeof(ClogCtlData));
+ if (!IsUnderPostmaster)
+ /* Initialize ClogCtl shared memory area */
+ {
+ char *bufptr;
- bufptr = ((char *) ClogCtl) + sizeof(ClogCtlData);
+ Assert(!found);
- for (slotno = 0; slotno < NUM_CLOG_BUFFERS; slotno++)
- {
- ClogCtl->page_buffer[slotno] = bufptr;
- ClogCtl->page_status[slotno] = CLOG_PAGE_EMPTY;
- ClogBufferLocks[slotno] = LWLockAssign();
- bufptr += CLOG_BLCKSZ;
- }
+ memset(ClogCtl, 0, sizeof(ClogCtlData));
+
+ bufptr = (char *)ClogCtl + sizeof(ClogCtlData);
+
+ for (slotno = 0; slotno < NUM_CLOG_BUFFERS; slotno++)
+ {
+ ClogCtl->page_buffer[slotno] = bufptr;
+ ClogCtl->page_status[slotno] = CLOG_PAGE_EMPTY;
+ bufptr += CLOG_BLCKSZ;
+ }
- /* ClogCtl->latest_page_number will be set later */
+ /* ClogCtl->latest_page_number will be set later */
+ }
+ else
+ Assert(found);
+
+ /* Handle ClogBufferLocks */
+
+#ifdef EXEC_BACKEND
+ ClogBufferLocks = (LWLockId *) ShmemInitStruct("CLOG Buffer Locks",
+ NUM_CLOG_BUFFERS * sizeof(LWLockId), &found);
+ Assert((!found && !IsUnderPostmaster) || (found && IsUnderPostmaster));
+#else
+ ClogBufferLocks = malloc(NUM_CLOG_BUFFERS * sizeof(LWLockId));
+ Assert(ClogBufferLocks);
+#endif
+
+ if (!IsUnderPostmaster)
+ for (slotno = 0; slotno < NUM_CLOG_BUFFERS; slotno++)
+ ClogBufferLocks[slotno] = LWLockAssign();
/* Init CLOG directory path */
snprintf(ClogDir, MAXPGPATH, "%s/pg_clog", DataDir);
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 8040dd5bb84..d7db3cd375c 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.150 2003/05/02 21:59:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.151 2003/05/03 03:52:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -301,6 +301,11 @@ BootstrapMain(int argc, char *argv[])
Assert(dbName);
+ if (IsUnderPostmaster && ExecBackend && MyProc /* ordinary backend */)
+ {
+ AttachSharedMemoryAndSemaphores();
+ }
+
if (!IsUnderPostmaster)
{
if (!potential_DataDir)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 7e6c02e76a2..767af51e917 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.319 2003/05/02 22:02:47 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.320 2003/05/03 03:52:07 momjian Exp $
*
* NOTES
*
@@ -172,6 +172,13 @@ static int ServerSock_INET = INVALID_SOCK; /* stream socket server */
static int ServerSock_UNIX = INVALID_SOCK; /* stream socket server */
#endif
+/* Used to reduce macros tests */
+#ifdef EXEC_BACKEND
+const bool ExecBackend = true;
+#else
+const bool ExecBackend = false;
+#endif
+
/*
* Set by the -o option
*/
@@ -1407,7 +1414,11 @@ processCancelRequest(Port *port, void *pkt)
elog(DEBUG1, "processCancelRequest: CheckPointPID in cancel request for process %d", backendPID);
return;
}
-
+ else if (ExecBackend)
+ {
+ AttachSharedMemoryAndSemaphores();
+ }
+
/* See if we have a matching backend */
for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index ae27a3ce401..c19fee1d28c 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.51 2003/05/02 21:59:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.52 2003/05/03 03:52:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -134,3 +134,16 @@ CreateSharedMemoryAndSemaphores(bool makePrivate,
*/
PMSignalInit();
}
+
+
+/*
+ * AttachSharedMemoryAndSemaphores
+ * Attaches to the existing shared resources when exec()'d off
+ * by the postmaster.
+ */
+void
+AttachSharedMemoryAndSemaphores(void)
+{
+ CLOGShmemInit();
+}
+
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index e201bc77e59..76d958b4999 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.329 2003/05/02 21:59:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.330 2003/05/03 03:52:07 momjian Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -1453,6 +1453,7 @@ PostgresMain(int argc, char *argv[], const char *username)
break;
}
+
/*
* -d is not the same as setting
* log_min_messages because it enables other
@@ -1577,6 +1578,9 @@ PostgresMain(int argc, char *argv[], const char *username)
* restart... */
}
BaseInit();
+#ifdef EXECBACKEND
+ AttachSharedMemoryAndSemaphores();
+#endif
}
else
{
@@ -1672,7 +1676,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.329 $ $Date: 2003/05/02 21:59:31 $\n");
+ puts("$Revision: 1.330 $ $Date: 2003/05/03 03:52:07 $\n");
}
/*
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index ce2fad6d4a4..18781c5dc52 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: miscadmin.h,v 1.120 2003/05/02 21:59:31 momjian Exp $
+ * $Id: miscadmin.h,v 1.121 2003/05/03 03:52:07 momjian Exp $
*
* NOTES
* some of the information in this file should be moved to
@@ -106,6 +106,7 @@ extern void ProcessInterrupts(void);
*/
extern bool IsUnderPostmaster;
extern bool ClientAuthInProgress;
+extern const bool ExecBackend;
extern int PostmasterMain(int argc, char *argv[]);
extern void ClosePostmasterPorts(bool pgstat_too);
diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h
index a01dc2cb223..24a7acdf2e3 100644
--- a/src/include/storage/ipc.h
+++ b/src/include/storage/ipc.h
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: ipc.h,v 1.59 2003/05/02 21:59:31 momjian Exp $
+ * $Id: ipc.h,v 1.60 2003/05/03 03:52:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -32,5 +32,6 @@ extern void on_exit_reset(void);
extern void CreateSharedMemoryAndSemaphores(bool makePrivate,
int maxBackends,
int port);
+extern void AttachSharedMemoryAndSemaphores(void);
#endif /* IPC_H */