Re: How do the Linux distributions create the Linux user/group "postgres"?

From: Joe Conway <mail(at)joeconway(dot)com>
To: Ron <ronljohnsonjr(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: How do the Linux distributions create the Linux user/group "postgres"?
Date: 2023-01-09 15:57:35
Message-ID: c908736c-3126-2650-296c-35bfb2079761@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/9/23 09:11, Ron wrote:
> On 1/9/23 07:15, Joe Conway wrote:
>> On 1/9/23 07:41, Matthias Apitz wrote:
>>> Please note: I'm talking about the user and group "postgres" in the
>>> Linux OS and not in the PostgreSQL server.
>>>
>>> We're compiling PostgreSQL from source (actually 14.1) and distribute that
>>> to our customers. They're asked to setup user and group "postgres"
>>> before creating the cluster. As nowadays there are a lot of setup such
>>> things in bigger installations, like LDAP or AD, etc. I'd like to know
>>> how other installations for Linux deal with this?
>>
>> See for example the PGDG RPM spec file:
>>
>> https://git.postgresql.org/gitweb/?p=pgrpms.git;a=blob;f=rpm/redhat/main/non-common/postgresql-15/main/postgresql-15.spec;h=60cd42147a7563ba76c401643d0a7c79b59d2520;hb=HEAD
>>
>>
>> 8<-------------------
>> %pre server
>> groupadd -g 26 -o -r postgres >/dev/null 2>&1 || :
>> useradd -M -g postgres -o -r -d /var/lib/pgsql -s /bin/bash \
>>     -c "PostgreSQL Server" -u 26 postgres >/dev/null 2>&1 || :
>> 8<-------------------
>
> What if (for example in an already-installed package) uid and gid 26 already
> exist?

The "|| :" at the end of those lines is essentially "or true" -- i.e. if
the first command fails *due to preexisting uid/gid, the line still
evaluates as successful. Whether that is a good thing or not is in the
eye of the beholder I guess.

I have thought about, and played with a bit, the idea of making the
uid/gid in the community spec file a variable so that it could be passed
in at rpmbuild time. But that quickly bloomed into a host of related
issues -- e.g. the default "/var/lib/pgsql" for the home dir, the
default "postgres" for the user/group names, and/or what to do if the
username does not exist but the directory does, etc -- I ran out of
energy to chase it all down.

--
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martin Ritchie 2023-01-10 04:51:19 pg_multixact_member file limits
Previous Message Ron 2023-01-09 14:11:35 Re: How do the Linux distributions create the Linux user/group "postgres"?