Return-Path: owner-postman
Received: from localhost (localhost [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id NAA23484 for postgres-dist; Mon, 28 Mar 1994 13:43:18 -0800
Resent-From: POSTGRES mailing list <postman@postgres.Berkeley.EDU>
Resent-Message-Id: <199403282143.NAA23484@nobozo.CS.Berkeley.EDU>
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: owner-postman
Received: from faerie.CS.Berkeley.EDU (faerie.CS.Berkeley.EDU [128.32.149.14]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with ESMTP id NAA23475 for <postgres@postgres.Berkeley.EDU>; Mon, 28 Mar 1994 13:43:17 -0800
Received: from localhost (localhost [127.0.0.1]) by faerie.CS.Berkeley.EDU (8.6.4/8.1B) with SMTP id NAA27909; Mon, 28 Mar 1994 13:43:15 -0800
Message-Id: <199403282143.NAA27909@faerie.CS.Berkeley.EDU>
X-Authentication-Warning: faerie.CS.Berkeley.EDU: Host localhost didn't use HELO protocol
From: aoki@postgres.Berkeley.EDU (Paul M. Aoki)
To: postgres@postgres.Berkeley.EDU
Subject: Re: postgres & root 
Reply-To: aoki@postgres.Berkeley.EDU (Paul M. Aoki)
In-reply-to: Your message of Mon, 28 Mar 1994 10:26:21 -0800 
	     <199403281826.KAA23468@newberry.uoregon.edu> 
Date: Mon, 28 Mar 94 13:43:14 -0800
X-Sender: aoki@postgres.Berkeley.EDU
Resent-To: postgres-dist@postgres.Berkeley.EDU
X-Mts: smtp
Resent-Date: Mon, 28 Mar 94 13:43:18 -0800
Resent-XMts: smtp

a system administrator writes:
> I'm the guilty party Ken Dueker at U of Oregon implied to you for running 
> postmaster under root - Postmaster fails to get shared memory allocated when
> running as postgres.  error message is IpcMemoryAttach:  shmat failed: permis
sion
> denied.

i don't know offhand, but the following can cause a problem with
the same symptoms:

> faerie:postgres (142)> whoami
> postgres
> faerie:postgres (143)> ipcs
> 
> IPC status from /dev/kmem as of Mon Mar 28 21:22:04 1994
> Message Queues:
> T     ID     KEY        MODE       OWNER    GROUP
> *** No message queues are currently defined ***
> 
> Shared Memory
> T     ID     KEY        MODE       OWNER    GROUP
> m      0          0 D-rw-------     root   system
> m      1          0 D-rw-------     root   system
> m      2          0 D-rw-------     root   system
> m    803  123585129 --rw-------     aoki postgres
> m    804  123585135 --rw-------     aoki postgres
> 
> Semaphores
> T     ID     KEY        MODE       OWNER    GROUP
> s    280  123585139 --ra-------     aoki postgres
> s    281  123585140 --ra-------     aoki postgres
> s    282  123585141 --ra-------     aoki postgres

[segments owned by aoki are left over from a dead postmaster]

> faerie:postgres (144)> postmaster
> IpcMemoryAttach: shmat() failed: Permission denied
> faerie:postgres (145)> 

that is, say someone once tried to start a postmaster on a given 
port as user <foo>, which crashed without releasing its shared 
memory segments.  if you then try to start a postmaster as user 
<bar> on the *same port*, the postmaster will try to create a 
new segment with the same key (the key is derived from the port
number).  shmget(2) says, "great, there's already a segment with 
that key, here's the shmid for it," but when the postmaster tries 
to *attach* with shmat(2), shmat says, "bogus! this segment doesn't
belong to you -- hasta luego."  (it actually says EACCES but that's
my translation into kowfornian.)

you don't get the usual "two postmasters on one port" message:

> FATAL: StreamServerPort: bind() failed: errno=13
>	Is another postmaster already running on that port?
>	If not, wait a few seconds and retry.
> postmaster: cannot create stream port

because the other postmaster is dead and not occupying the port.

(it is also possible but less likely that some other random process 
just happens to have a segment with the same shared memory key.  in 
either case, however, ipcs reveals all.)

if this is the problem, it ought to go away if you blow away the 
dead shmem segments (using ipcrm) or reboot the machine.

(to prevent a different set of problems, make sure the binaries 
aren't setuid.)
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  aoki@postgres.Berkeley.EDU
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki
