shared memory size.
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.35 2004/09/28 20:46:27 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.36 2004/09/29 15:15:54 tgl Exp $
  *
  *
  * NOTES:
        size = MAXALIGN(sizeof(FSMHeader));
 
        /* hash table, including the FSMRelation objects */
-       size += hash_estimate_size(MaxFSMRelations, sizeof(FSMRelation));
+       size += hash_estimate_size(MaxFSMRelations + 1, sizeof(FSMRelation));
 
        /* page-storage arena */
        nchunks = (MaxFSMPages - 1) / CHUNKPAGES + 1;
 
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.71 2004/08/29 05:06:48 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.72 2004/09/29 15:15:55 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
                size = hash_estimate_size(SHMEM_INDEX_SIZE, sizeof(ShmemIndexEnt));
                size += BufferShmemSize();
                size += LockShmemSize(maxBackends);
+               size += ProcGlobalShmemSize(maxBackends);
                size += XLOGShmemSize();
                size += CLOGShmemSize();
                size += SUBTRANSShmemSize();
 
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.141 2004/09/28 20:46:32 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.142 2004/09/29 15:15:55 tgl Exp $
  *
  * NOTES
  *       Outside modules can create a lock table and acquire/release
 }
 
 
+/*
+ * Estimate shared-memory space used for lock tables
+ */
 int
 LockShmemSize(int maxBackends)
 {
        int                     size = 0;
        long            max_table_size = NLOCKENTS(maxBackends);
 
-       size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */
-       size += maxBackends * MAXALIGN(sizeof(PGPROC));         /* each MyProc */
-       size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LockMethodData));            /* each lock method */
+       /* lock method headers */
+       size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LockMethodData));
 
        /* lockHash table */
        size += hash_estimate_size(max_table_size, sizeof(LOCK));
        size += hash_estimate_size(max_table_size, sizeof(PROCLOCK));
 
        /*
+        * Note we count only one pair of hash tables, since the userlocks
+        * table actually overlays the main one.
+        *
         * Since the lockHash entry count above is only an estimate, add 10%
         * safety margin.
         */
 
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.153 2004/08/29 05:06:48 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.154 2004/09/29 15:15:55 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 static bool CheckStatementTimeout(void);
 
 
+/*
+ * Report shared-memory space needed by InitProcGlobal.
+ */
+int
+ProcGlobalShmemSize(int maxBackends)
+{
+       int                     size = 0;
+
+       size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */
+       size += MAXALIGN(NUM_DUMMY_PROCS * sizeof(PGPROC));     /* DummyProcs */
+       size += MAXALIGN(maxBackends * sizeof(PGPROC));         /* MyProcs */
+       size += MAXALIGN(sizeof(slock_t)); /* ProcStructLock */
+
+       return size;
+}
+
 /*
  * Report number of semaphores needed by InitProcGlobal.
  */
         * processes, too.      These do not get linked into the freeProcs list.
         */
        DummyProcs = (PGPROC *)
-               ShmemInitStruct("DummyProcs", sizeof(PGPROC) * NUM_DUMMY_PROCS,
+               ShmemInitStruct("DummyProcs", NUM_DUMMY_PROCS * sizeof(PGPROC),
                                                &foundDummy);
 
        if (foundProcGlobal || foundDummy)
                /*
                 * We're the first - initialize.
                 */
+               PGPROC     *procs;
                int                     i;
 
                ProcGlobal->freeProcs = INVALID_OFFSET;
                 * Pre-create the PGPROC structures and create a semaphore for
                 * each.
                 */
+               procs = (PGPROC *) ShmemAlloc(maxBackends * sizeof(PGPROC));
+               if (!procs)
+                       ereport(FATAL,
+                                       (errcode(ERRCODE_OUT_OF_MEMORY),
+                                        errmsg("out of shared memory")));
+               MemSet(procs, 0, maxBackends * sizeof(PGPROC));
                for (i = 0; i < maxBackends; i++)
                {
-                       PGPROC     *proc;
-
-                       proc = (PGPROC *) ShmemAlloc(sizeof(PGPROC));
-                       if (!proc)
-                               ereport(FATAL,
-                                               (errcode(ERRCODE_OUT_OF_MEMORY),
-                                                errmsg("out of shared memory")));
-                       MemSet(proc, 0, sizeof(PGPROC));
-                       PGSemaphoreCreate(&proc->sem);
-                       proc->links.next = ProcGlobal->freeProcs;
-                       ProcGlobal->freeProcs = MAKE_OFFSET(proc);
+                       PGSemaphoreCreate(&(procs[i].sem));
+                       procs[i].links.next = ProcGlobal->freeProcs;
+                       ProcGlobal->freeProcs = MAKE_OFFSET(&procs[i]);
                }
 
-               MemSet(DummyProcs, 0, sizeof(PGPROC) * NUM_DUMMY_PROCS);
+               MemSet(DummyProcs, 0, NUM_DUMMY_PROCS * sizeof(PGPROC));
                for (i = 0; i < NUM_DUMMY_PROCS; i++)
                {
                        DummyProcs[i].pid = 0;          /* marks dummy proc as not in use */
 
  * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.75 2004/08/29 05:06:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.76 2004/09/29 15:15:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
  * Function Prototypes
  */
 extern int     ProcGlobalSemas(int maxBackends);
+extern int     ProcGlobalShmemSize(int maxBackends);
 extern void InitProcGlobal(int maxBackends);
 extern void InitProcess(void);
 extern void InitDummyProcess(int proctype);