Thread: BUG #15108: Initialization problem postgresql-10-setup initdb

BUG #15108: Initialization problem postgresql-10-setup initdb

From
PG Bug reporting form
Date:
The following bug has been logged on the website:

Bug reference:      15108
Logged by:          Alertas DBA
Email address:      alertas.dba@click-it.es
PostgreSQL version: 10.3
Operating system:   Centos 7.4.1708
Description:

The problem is reported when executing database initialization command,
postgresql-10-setup initdb.
In the official documentation
(https://www.postgresql.org/docs/10/static/app-initdb.html) indicates that
it must be executed with the user postgres, but the command only works if I
execute it as root.

This command does not seem to interpret the parameter step indicated in the
documentation, these are the problem:

(run as root) yum install -y
https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
(run as root) yum install -y postgresql10 postgresql10-server
(run as root) cd /
(run as root) mkdir data
(run as root) chown -R postgres.postgres data
(run as postgres) /usr/pgsql-10/bin/postgresql-10-setup initdb
-bash-4.2$ /usr/pgsql-10/bin/postgresql-10-setup initdb -D /data -A trust -U
postgres
systemctl: invalid option -- 'D'
failed to find PGDATA setting in -D.service

-bash-4.2$ /usr/pgsql-10/bin/postgresql-10-setup initdb -D /data/ -A trust
-U postgres
systemctl: invalid option -- 'D'
failed to find PGDATA setting in -D.service

-bash-4.2$ /usr/pgsql-10/bin/postgresql-10-setup initdb --pgadata=/data/ -A
trust -U postgres
systemctl: unrecognized option '--pgadata=/data/.service'
failed to find PGDATA setting in --pgadata=/data/.service

Should the environment variable PGDATA in
/usr/lib/systemd/system/postgresql-10.service be overwrited after the
database is initialized?


Re: BUG #15108: Initialization problem postgresql-10-setup initdb

From
Sergei Kornilov
Date:
Hello!
Why you tried using /usr/pgsql-10/bin/postgresql-10-setup instead /usr/pgsql-10/bin/initdb ?

regards, Sergei


Re: BUG #15108: Initialization problem postgresql-10-setup initdb

From
Devrim Gündüz
Date:
Hi,

On Tue, 2018-03-13 at 12:12 +0000, PG Bug reporting form wrote:
> The problem is reported when executing database initialization command,
> postgresql-10-setup initdb.
> In the official documentation
> (https://www.postgresql.org/docs/10/static/app-initdb.html) indicates that
> it must be executed with the user postgres, but the command only works if I
> execute it as root.
>
> This command does not

postgresql-10-setup is a wrapper around initdb (which solves many problems),
*not* the initdb binary, and needs to be run as root. You can always run initdb
directly with:

/usr/pgsql-10/bin/initdb

Regards,

--
Devrim Gündüz
EnterpriseDB: https://www.enterprisedb.com
PostgreSQL Consultant, Red Hat Certified Engineer
Twitter: @DevrimGunduz , @DevrimGunduzTR
Attachment

Re: BUG #15108: Initialization problem postgresql-10-setup initdb

From
alertas
Date:
Hi,

I don't understand, in the official documentation appear "initdb must be run as the user that will own the server process, because the server needs to have access to the files and directories that initdb creates. Since the server cannot be run as root, you must not run initdb as root either. (It will in fact refuse to do so.)"

Regards,

El 14/03/18 a las 16:59, Devrim Gündüz escribió:
Hi,

On Tue, 2018-03-13 at 12:12 +0000, PG Bug reporting form wrote:
The problem is reported when executing database initialization command,
postgresql-10-setup initdb.
In the official documentation
(https://www.postgresql.org/docs/10/static/app-initdb.html) indicates that
it must be executed with the user postgres, but the command only works if I
execute it as root.

This command does not
postgresql-10-setup is a wrapper around initdb (which solves many problems), 
*not* the initdb binary, and needs to be run as root. You can always run initdb
directly with:

/usr/pgsql-10/bin/initdb

Regards,


Re: BUG #15108: Initialization problem postgresql-10-setup initdb

From
Devrim Gündüz
Date:
Hi,

On Fri, 2018-03-16 at 08:29 +0100, alertas wrote:

> I don't understand, in the official documentation appear "initdb must be
> run as the user that will own the server process, because the server
> needs to have access to the files and directories that initdb creates.
> *Since the server cannot be run as root, you must not run initdb as root
> either*. (It will in fact refuse to do so.)"

As I wrote in my previous post:

The "initdb" that the documentation mentions is:

/usr/pgsql-10/bin/initdb

which must be run by non-root user.

Then, there is a setup script:

/usr/pgsql-10/bin/postgresql-10-setup

which is a wrapper around initdb (and some other things), and the related lines
are:

 # Initialize the database
    initdbcmd="$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'"
    initdbcmd+=" $PGSETUP_INITDB_OPTIONS"

    $SU -l postgres -c "$initdbcmd" >> "$PGLOG" 2>&1 < /dev/null


So, when user runs

/usr/pgsql-10/bin/postgresql-10-setup initdb

the word "initdb" is a *parameter* to the script, and as written in the
documentation, we run initdb as the postgres user.

-HTH

Regards,
--
Devrim Gündüz
EnterpriseDB: https://www.enterprisedb.com
PostgreSQL Consultant, Red Hat Certified Engineer
Twitter: @DevrimGunduz , @DevrimGunduzTR
Attachment

Re: BUG #15108: Initialization problem postgresql-10-setup initdb

From
Sergei Kornilov
Date:
Hello
Official documentation about initdb binary itself. Not about any wrappers such a postgresql-10-setup.

regards, Sergei