diff options
Diffstat (limited to 'src/backend/postmaster/postmaster.c')
-rw-r--r-- | src/backend/postmaster/postmaster.c | 97 |
1 files changed, 10 insertions, 87 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 3b2eb95d4fc..9fa4ebb3689 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.193 2000/11/27 04:03:20 inoue Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.194 2000/11/28 23:27:55 tgl Exp $ * * NOTES * @@ -118,26 +118,6 @@ char * UnixSocketDir; char * Virtual_host; /* - * This is a sequence number that indicates how many times we've had to - * throw away the shared memory and start over because we doubted its - * integrity. It starts off at zero and is incremented every time we - * start over. We use this to ensure that we use a new IPC shared memory - * key for the new shared memory segment in case the old segment isn't - * entirely gone yet. - * - * The sequence actually cycles back to 0 after 9, so pathologically there - * could be an IPC failure if 10 sets of backends are all stuck and won't - * release IPC resources. - */ -static short shmem_seq = 0; - -/* - * This is the base IPC shared memory key. Other keys are generated by - * adding to this. - */ -static IpcMemoryKey ipc_key; - -/* * MaxBackends is the actual limit on the number of backends we will * start. The default is established by configure, but it can be * readjusted from 1..MAXBACKENDS with the postmaster -N switch. Note @@ -1292,39 +1272,6 @@ ConnFree(Port *conn) free(conn); } -/* - * get_host_port -- return a pseudo port number (16 bits) - * derived from the primary IP address of Virtual_host. - */ -static unsigned short -get_host_port(void) -{ - static unsigned short hostPort = 0; - - if (hostPort == 0) - { - SockAddr saddr; - struct hostent *hp; - - hp = gethostbyname(Virtual_host); - if ((hp == NULL) || (hp->h_addrtype != AF_INET)) - { - char msg[1024]; - snprintf(msg, sizeof(msg), - "FATAL: get_host_port: gethostbyname(%s) failed\n", - Virtual_host); - fputs(msg, stderr); - pqdebug("%s", msg); - exit(1); - } - memmove((char *) &(saddr.in.sin_addr), - (char *) hp->h_addr, - hp->h_length); - hostPort = ntohl(saddr.in.sin_addr.s_addr) & 0xFFFF; - } - - return hostPort; -} /* * reset_shared -- reset shared memory and semaphores @@ -1333,40 +1280,16 @@ static void reset_shared(unsigned short port) { /* - * A typical ipc_key is 5432001, which is port 5432, sequence - * number 0, and 01 as the index in IPCKeyGetBufferMemoryKey(). - * The 32-bit INT_MAX is 2147483 6 47. - * - * The default algorithm for calculating the IPC keys assumes that all - * instances of postmaster on a given host are listening on different - * ports. In order to work (prevent shared memory collisions) if you - * run multiple PostgreSQL instances on the same port and different IP - * addresses on a host, we change the algorithm if you give postmaster - * the -h option, or set PGHOST, to a value other than the internal - * default. - * - * If Virtual_host is set, then we generate the IPC keys using the - * last two octets of the IP address instead of the port number. - * This algorithm assumes that no one will run multiple PostgreSQL - * instances on one host using two IP addresses that have the same two - * last octets in different class C networks. If anyone does, it - * would be rare. - * - * So, if you use -h or PGHOST, don't try to run two instances of - * PostgreSQL on the same IP address but different ports. If you - * don't use them, then you must use different ports (via -p or - * PGPORT). And, of course, don't try to use both approaches on one - * host. + * Reset assignment of shared mem and semaphore IPC keys. + * Doing this means that in normal cases we'll assign the same keys + * on each "cycle of life", and thereby avoid leaving dead IPC objects + * floating around if the postmaster crashes and is restarted. */ - - if (Virtual_host[0] != '\0') - port = get_host_port(); - - ipc_key = port * 1000 + shmem_seq * 100; - CreateSharedMemoryAndSemaphores(ipc_key, MaxBackends); - shmem_seq += 1; - if (shmem_seq >= 10) - shmem_seq -= 10; + IpcInitKeyAssignment(port); + /* + * Create or re-create shared memory and semaphores. + */ + CreateSharedMemoryAndSemaphores(false, MaxBackends); } |