diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-07-14 20:00:23 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-07-14 20:00:23 +0000 |
commit | de98a7e23a193a9c9a6505540ad03c5b4a57f345 (patch) | |
tree | ef7cc573f950bc10272d52c53f83aa19730f8328 /src | |
parent | 8460000069a14c44fef3177815c1bf2ad21c2fc9 (diff) |
The default values for shared_buffers and max_connections are now 1000
and 100 respectively, if the platform will allow it. initdb selects
values that are not too large to allow the postmaster to start, and
places these values in the installed postgresql.conf file. This allows
us to continue to start up out-of-the-box on platforms with small SHMMAX,
while having somewhat-realistic default settings on platforms with
reasonable SHMMAX. Per recent pghackers discussion.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/port/sysv_shmem.c | 86 | ||||
-rw-r--r-- | src/backend/utils/init/postinit.c | 8 | ||||
-rw-r--r-- | src/backend/utils/misc/postgresql.conf.sample | 4 | ||||
-rw-r--r-- | src/bin/initdb/initdb.sh | 51 |
4 files changed, 73 insertions, 76 deletions
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index ffe5bfa268a..8d6a1814ecb 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -10,7 +10,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.10 2003/05/08 19:17:07 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.11 2003/07/14 20:00:22 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -45,10 +45,8 @@ void *UsedShmemSegAddr = NULL; static void *InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size); static void IpcMemoryDetach(int status, Datum shmaddr); static void IpcMemoryDelete(int status, Datum shmId); -static void *PrivateMemoryCreate(uint32 size); -static void PrivateMemoryDelete(int status, Datum memaddr); static PGShmemHeader *PGSharedMemoryAttach(IpcMemoryKey key, - IpcMemoryId *shmid, void *addr); + IpcMemoryId *shmid); /* @@ -243,41 +241,6 @@ PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2) } -/* ---------------------------------------------------------------- - * private memory support - * - * Rather than allocating shmem segments with IPC_PRIVATE key, we - * just malloc() the requested amount of space. This code emulates - * the needed shmem functions. - * ---------------------------------------------------------------- - */ - -static void * -PrivateMemoryCreate(uint32 size) -{ - void *memAddress; - - memAddress = malloc(size); - if (!memAddress) - { - fprintf(stderr, "PrivateMemoryCreate: malloc(%u) failed\n", size); - proc_exit(1); - } - MemSet(memAddress, 0, size); /* keep Purify quiet */ - - /* Register on-exit routine to release storage */ - on_shmem_exit(PrivateMemoryDelete, PointerGetDatum(memAddress)); - - return memAddress; -} - -static void -PrivateMemoryDelete(int status, Datum memaddr) -{ - free(DatumGetPointer(memaddr)); -} - - /* * PGSharedMemoryCreate * @@ -289,6 +252,9 @@ PrivateMemoryDelete(int status, Datum memaddr) * collision with non-Postgres shmem segments. The idea here is to detect and * re-use keys that may have been assigned by a crashed postmaster or backend. * + * makePrivate means to always create a new segment, rather than attach to + * or recycle any existing segment. + * * The port number is passed for possible use as a key (for SysV, we use * it to generate the starting shmem key). In a standalone backend, * zero will be passed. @@ -307,8 +273,7 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port) /* Just attach and return the pointer */ if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate) { - if ((hdr = (PGShmemHeader *) memAddress = PGSharedMemoryAttach( - UsedShmemSegID, &shmid, UsedShmemSegAddr)) == NULL) + if ((hdr = PGSharedMemoryAttach(UsedShmemSegID, &shmid)) == NULL) { fprintf(stderr, "Unable to attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %s\n", (int) UsedShmemSegID, UsedShmemSegAddr, strerror(errno)); @@ -317,34 +282,29 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port) return hdr; } - /* Create shared memory */ - - NextShmemSegID = port * 1000 + 1; + /* Loop till we find a free IPC key */ + NextShmemSegID = port * 1000; - for (;;NextShmemSegID++) + for (NextShmemSegID++;; NextShmemSegID++) { - /* Special case if creating a private segment --- just malloc() it */ - if (makePrivate) - { - memAddress = PrivateMemoryCreate(size); - break; - } - /* Try to create new segment */ memAddress = InternalIpcMemoryCreate(NextShmemSegID, size); if (memAddress) break; /* successful create and attach */ /* Check shared memory and possibly remove and recreate */ - - if ((hdr = (PGShmemHeader *) memAddress = PGSharedMemoryAttach( - NextShmemSegID, &shmid, UsedShmemSegAddr)) == NULL) + + if (makePrivate) /* a standalone backend shouldn't do this */ + continue; + + if ((memAddress = PGSharedMemoryAttach(NextShmemSegID, &shmid)) == NULL) continue; /* can't attach, not one of mine */ /* * If I am not the creator and it belongs to an extant process, * continue. */ + hdr = (PGShmemHeader *) memAddress; if (hdr->creatorPID != getpid()) { if (kill(hdr->creatorPID, 0) == 0 || errno != ESRCH) @@ -407,22 +367,25 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port) /* - * Attach to shared memory and make sure it has a Postgres header + * Attach to shared memory and make sure it has a Postgres header + * + * Returns attach address if OK, else NULL */ static PGShmemHeader * -PGSharedMemoryAttach(IpcMemoryKey key, IpcMemoryId *shmid, void *addr) +PGSharedMemoryAttach(IpcMemoryKey key, IpcMemoryId *shmid) { PGShmemHeader *hdr; if ((*shmid = shmget(key, sizeof(PGShmemHeader), 0)) < 0) return NULL; - hdr = (PGShmemHeader *) shmat(*shmid, UsedShmemSegAddr, + hdr = (PGShmemHeader *) shmat(*shmid, + UsedShmemSegAddr, #if defined(solaris) && defined(__sparc__) - /* use intimate shared memory on SPARC Solaris */ - SHM_SHARE_MMU + /* use intimate shared memory on Solaris */ + SHM_SHARE_MMU #else - 0 + 0 #endif ); @@ -434,5 +397,6 @@ PGSharedMemoryAttach(IpcMemoryKey key, IpcMemoryId *shmid, void *addr) shmdt(hdr); return NULL; /* segment belongs to a non-Postgres app */ } + return hdr; } diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 48194071e59..3cd3f579294 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.122 2003/06/27 14:45:30 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.123 2003/07/14 20:00:22 tgl Exp $ * * *------------------------------------------------------------------------- @@ -176,12 +176,8 @@ InitCommunication(void) { /* * We're running a postgres bootstrap process or a standalone backend. - * Create private "shmem" and semaphores. Force MaxBackends to 1 so - * that we don't allocate more resources than necessary. + * Create private "shmem" and semaphores. */ - SetConfigOption("max_connections", "1", - PGC_POSTMASTER, PGC_S_OVERRIDE); - CreateSharedMemoryAndSemaphores(true, MaxBackends, 0); } } diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 73332106927..2dd980cc18e 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -210,6 +210,10 @@ #client_encoding = sql_ascii # actually, defaults to database encoding # These settings are initialized by initdb -- they may be changed +#lc_messages = 'C' # locale for system error message strings +#lc_monetary = 'C' # locale for monetary formatting +#lc_numeric = 'C' # locale for number formatting +#lc_time = 'C' # locale for time formatting # Other Defaults diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index 08fe399bfc5..0c22560ffef 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -27,7 +27,7 @@ # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.193 2003/07/04 16:41:21 tgl Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.194 2003/07/14 20:00:23 tgl Exp $ # #------------------------------------------------------------------------- @@ -579,20 +579,53 @@ echo "ok" ########################################################################## # +# DETERMINE PLATFORM-SPECIFIC CONFIG SETTINGS +# +# Use reasonable values if kernel will let us, else scale back + +cp /dev/null "$PGDATA"/postgresql.conf || exit_nicely + +$ECHO_N "selecting default shared_buffers... "$ECHO_C + +for nbuffers in 1000 900 800 700 600 500 400 300 200 100 50 +do + TEST_OPT="$PGSQL_OPT -c shared_buffers=$nbuffers -c max_connections=5" + if "$PGPATH"/postgres $TEST_OPT template1 </dev/null >/dev/null 2>&1 + then + break + fi +done + +echo "$nbuffers" + +$ECHO_N "selecting default max_connections... "$ECHO_C + +for nconns in 100 50 40 30 20 10 +do + TEST_OPT="$PGSQL_OPT -c shared_buffers=$nbuffers -c max_connections=$nconns" + if "$PGPATH"/postgres $TEST_OPT template1 </dev/null >/dev/null 2>&1 + then + break + fi +done + +echo "$nconns" + +########################################################################## +# # CREATE CONFIG FILES $ECHO_N "creating configuration files... "$ECHO_C cp "$PG_HBA_SAMPLE" "$PGDATA"/pg_hba.conf || exit_nicely cp "$PG_IDENT_SAMPLE" "$PGDATA"/pg_ident.conf || exit_nicely -( - trigger="# These settings are initialized by initdb -- they may be changed" - sed -n "1,/$trigger/p" "$POSTGRESQL_CONF_SAMPLE" - for cat in MESSAGES MONETARY NUMERIC TIME; do - echo "LC_$cat = '`pg_getlocale $cat`'" - done - sed -n "1,/$trigger/!p" "$POSTGRESQL_CONF_SAMPLE" -) > "$PGDATA"/postgresql.conf || exit_nicely +sed -e "s/^#shared_buffers = 64/shared_buffers = $nbuffers/" \ + -e "s/^#max_connections = 32/max_connections = $nconns/" \ + -e "s/^#lc_messages = 'C'/lc_messages = '`pg_getlocale MESSAGES`'/" \ + -e "s/^#lc_monetary = 'C'/lc_monetary = '`pg_getlocale MONETARY`'/" \ + -e "s/^#lc_numeric = 'C'/lc_numeric = '`pg_getlocale NUMERIC`'/" \ + -e "s/^#lc_time = 'C'/lc_time = '`pg_getlocale TIME`'/" \ + "$POSTGRESQL_CONF_SAMPLE" > "$PGDATA"/postgresql.conf || exit_nicely chmod 0600 "$PGDATA"/pg_hba.conf "$PGDATA"/pg_ident.conf \ "$PGDATA"/postgresql.conf |