Re: Error: Could not change user id - Mailing list pgsql-admin

From Russell Davie
Subject Re: Error: Could not change user id
Date
Msg-id 20060529142515.2da47049@localhost.localdomain
Whole thread Raw
In response to Re: Error: Could not change user id  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Error: Could not change user id
List pgsql-admin
On Sun, 28 May 2006 20:59:33 -0400
Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Russell Davie <rjrd@exemail.com.au> writes:
> > Manually starting postgresql by the user postgres:
> > postgres@XXXX:/etc/init.d$ ./postgresql-7.4 start
> > chmod: changing permissions of `/var/run/postgresql': Operation not permitted
> >  * Starting PostgreSQL 7.4 database server:main
> > Error: Could not change user id                  [fail]
>
> There is no such error message anywhere in the PG 7.4 source code.
> I suppose it's coming out of whatever init script you're using;
> have you tried reading the init script for enlightenment?
>

Interesting! I never thought it could be the window manager.
This is still occurring using Metacity and it still happened in Enlightnement and WindowMaker and also at CLI without
anywindow-manager at all! 

> (FWIW, init scripts are almost always designed to be executed as
> root, not as random unprivileged users like postgres.  sudo might
> help.)
>
>             regards, tom lane

postgresql doesn't like been stared as root:
f
XX@XXXX:/etc/init.d$ sudo ./postgresql-7.4 start
Password:
 * Starting PostgreSQL 7.4 database server:main
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.
The PostgreSQL server failed to start. Please check the log output:                         [fail]

On doing a search on the disk using the terms: "Could not change user id"
located this in in line 467 of /usr/share/postgresql-common/PgCommon.pm

It seems this is checking the group and user of the process which suggests not getting settings correct.

Maybe this could help in showing where to correct this issue?

[CODE]
# Change effective and real user and group id. If the user id is member of the
# "shadow" group, then "shadow" will be in the set of effective groups. Exits
# with an error message if user/group ID cannot be changed.
# Arguments: <user id> <group id>
sub change_ugid {
    my ($uid, $gid) = @_;
    my $groups = $gid;
    $groups .= " $groups"; # first additional group

    # check whether owner is in the shadow group, and keep shadow privileges in
    # this case; this is a poor workaround for the lack of initgroups().
    my @shadowmembers = split /\s+/, ((getgrnam 'shadow')[3]);
    for my $m (@shadowmembers) {
        my $mid = getpwnam $m;
        if ($mid == $uid) {
            $groups .= ' ' . (getgrnam 'shadow');
            last;
        }
    }

    $( = $) = $groups;
    $< = $> = $uid;
    error 'Could not change user id' if $< != $uid;
    error 'Could not change group id' if $( != $gid;
}
[/CODE]


regards

Russell

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: Error: Could not change user id
Next
From: Tim Allen
Date:
Subject: Re: Error: Could not change user id