Dump/read non-default GUC values for use by exec'ed backends, for Win32.
authorBruce Momjian
Fri, 2 May 2003 21:52:42 +0000 (21:52 +0000)
committerBruce Momjian
Fri, 2 May 2003 21:52:42 +0000 (21:52 +0000)
src/backend/access/transam/clog.c
src/backend/bootstrap/bootstrap.c
src/backend/postmaster/postmaster.c
src/backend/storage/ipc/ipci.c
src/backend/tcop/postgres.c
src/include/miscadmin.h
src/include/storage/ipc.h

index 74a6dc98b2383fbd102fe77789bee615620621aa..42e12b6282c36656b04cefbb76088e7ecfec4477 100644 (file)
@@ -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.12 2003/04/14 17:31:33 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.13 2003/05/02 21:52:42 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);
index f120192bc88a8509fcb06f6bcd53f3a012e5cfa2..9c971ff931450880eff6b7e09f564c6e904c65e4 100644 (file)
@@ -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.148 2003/03/06 00:04:27 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.149 2003/05/02 21:52:42 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)
index e9a7d86f3d8176b0d364b043392b52f8fba9a3fb..0e52aff2c500ae5a99f78f1ef651345d39db41ba 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.315 2003/04/26 02:57:14 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.316 2003/05/02 21:52:42 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
  */
@@ -1403,7 +1410,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))
index 68d922ff86f933c1daf4b96fda75a59122874df1..094f3c145a269e8e0e4b8373ecba56e40fe762ae 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.49 2002/09/02 02:47:03 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.50 2003/05/02 21:52:42 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();
+}
+
index 6c2e456ccc17d0c94a2d2a8766665975a1da5593..2bd147cc57a6d5a5163c140b3154c0ac188236f1 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.327 2003/05/02 20:54:35 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.328 2003/05/02 21:52:42 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.327 $ $Date: 2003/05/02 20:54:35 $\n");
+       puts("$Revision: 1.328 $ $Date: 2003/05/02 21:52:42 $\n");
    }
 
    /*
index d4bd255cb0bc9b8d7c30bf2f452b2264e07f9701..4b6a6621f00c10e1a8d38599f8ff8ab7ec833e82 100644 (file)
@@ -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.118 2003/04/06 22:45:23 petere Exp $
+ * $Id: miscadmin.h,v 1.119 2003/05/02 21:52:42 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);
index d12ec20cfd6edbd3e6bed8cb134b8e282f7a0dc8..0798ea4bb3d3ed671484a915176fdb8479060f47 100644 (file)
@@ -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.57 2002/09/04 20:31:45 momjian Exp $
+ * $Id: ipc.h,v 1.58 2003/05/02 21:52:42 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 */