Обсуждение: BUG #16204: Fail to setup

Поиск
Список
Период
Сортировка

BUG #16204: Fail to setup

От
PG Bug reporting form
Дата:
The following bug has been logged on the website:

Bug reference:      16204
Logged by:          Takumi Kobayashi
Email address:      chamaharun@outlook.com
PostgreSQL version: 10.11
Operating system:   CentOS7
Description:

I installed postgresql10.11 and ran postgresql-10-setup but it fails.
Maybe character $ for variable of PG_VERSION is missing in
/usr/pgsql-10/bin/postgresql-10-setup below :

150 
151     if [ -f "$PGDATA/PG_VERSION" ]; then
152         return 0
153     fi
154     return 1
155 }
156 
157 initdb(){
158     if [ -f "$PGDATA/PG_VERSION" ]; then
159         echo $"Data directory is not empty!"
160         echo


These are my environment:

[root@tkw-pgcl-sv004 ~]# rpm -qa | grep postgres
postgresql10-10.11-2PGDG.rhel7.x86_64
postgresql10-server-10.11-2PGDG.rhel7.x86_64
postgresql10-libs-10.11-2PGDG.rhel7.x86_64
postgresql10-contrib-10.11-2PGDG.rhel7.x86_64

[root@tkw-pgcl-sv004 ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[root@tkw-pgcl-sv004 ~]# yum list installed | grep postgresql10
postgresql10.x86_64                   10.11-2PGDG.rhel7
@pgdg10   
postgresql10-contrib.x86_64           10.11-2PGDG.rhel7
@pgdg10   
postgresql10-libs.x86_64              10.11-2PGDG.rhel7
@pgdg10   
postgresql10-server.x86_64            10.11-2PGDG.rhel7
@pgdg10   
[root@tkw-pgcl-sv004 ~]# 

And log is here:

[root@tkw-pgcl-sv004 ~]# PGSETUP_INITDB_OPTIONS="--data-checksums -E utf8
--no-locale -D /mnt/postgres/data" bash -x
/usr/pgsql-10/bin/postgresql-10-setup initdb
+ PGVERSION=10
++ echo 10
++ sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'
+ PGMAJORVERSION=10
+ PGENGINE=/usr/pgsql-10/bin
+ PREVMAJORVERSION=9.6
+ PREVPGENGINE=/usr/pgsql-9.6/bin
+ PREVDATADIR=/var/lib/pgsql/9.6/data
+ SERVICE_NAME=
+ '[' x = x ']'
+ SERVICE_NAME=postgresql-10
+ OLD_SERVICE_NAME=
+ '[' x = x ']'
+ OLD_SERVICE_NAME=postgresql-9.6
+ USAGE_STRING='
Usage: /usr/pgsql-10/bin/postgresql-10-setup {initdb|check_upgrade|upgrade}
[SERVICE_NAME]

Script is aimed to help sysadmin with basic database cluster
administration.

The SERVICE_NAME is used for selection of proper unit configuration file;
For
more info and howto/when use this script please look at the docu file
.  The '\''postgresql'\''
string is used when no SERVICE_NAME is explicitly passed.

Available operation mode:
  initdb        Create a new PostgreSQL database cluster.  This is usually
the
                first action you perform after PostgreSQL server
installation.
  check_upgrade Checks whether the old cluster can be upgraded to the new
version
                or not.
  upgrade       Upgrade PostgreSQL database cluster to be usable with new
                server.  Use this if you upgraded your PostgreSQL server
to
                newer major version (currently from 9.6 to 10).

Environment:
  PGSETUP_INITDB_OPTIONS     Options carried by this variable are passed
to
                             subsequent call of `initdb` binary (see man
                             initdb(1)).  This variable is used also
during
                             '\''upgrade'\'' mode because the new cluster is
actually
                             re-initialized from the old one.
  PGSETUP_PGUPGRADE_OPTIONS  Options in this variable are passed next to
the
                             subsequent call of `pg_upgrade`.  For more
info
                             about possible options please look at man
                             pg_upgrade(1).
  PGSETUP_DEBUG              Set to '\''1'\'' if you want to see debugging
output.'
+ case "$1" in
++ systemctl show -p Environment postgresql-10.service
++ sed 's/^Environment=//'
++ tr ' ' '\n'
++ tail -n 1
++ sed -n 's/^PGDATA=//p'
+ PGDATA=/var/lib/pgsql/10/data/
+ '[' x/var/lib/pgsql/10/data/ = x ']'
+ '[' -f /etc/systemd/system/postgresql-10.service ']'
+ '[' -f /usr/lib/systemd/system/postgresql-10.service ']'
+ SERVICE_FILE=/usr/lib/systemd/system/postgresql-10.service
+ PGUPLOG=/var/lib/pgsql/10/pgupgrade.log
+ PGLOG=/var/lib/pgsql/10/initdb.log
+ export PGDATA
+ '[' -x /sbin/runuser ']'
+ SU=runuser
+ script_result=0
+ case "$1" in
+ initdb
+ '[' -f /var/lib/pgsql/10/data//PG_VERSION ']'
+ echo -n 'Initializing database ... '
Initializing database ... + perform_initdb
+ '[' '!' -e /var/lib/pgsql/10/data/ ']'
+ '[' -x /sbin/restorecon ']'
+ /sbin/restorecon /var/lib/pgsql/10/data/
+ '[' '!' -e /var/lib/pgsql/10/initdb.log -a '!' -h
/var/lib/pgsql/10/initdb.log ']'
+ touch /var/lib/pgsql/10/initdb.log
+ chown postgres:postgres /var/lib/pgsql/10/initdb.log
+ chmod go-rwx /var/lib/pgsql/10/initdb.log
+ '[' -x /sbin/restorecon ']'
+ /sbin/restorecon /var/lib/pgsql/10/initdb.log
+ initdbcmd='/usr/pgsql-10/bin/initdb
--pgdata='\''/var/lib/pgsql/10/data/'\'' --auth='\''ident'\'''
+ initdbcmd+=' --data-checksums -E utf8 --no-locale -D /mnt/postgres/data'
+ runuser -l postgres -c '/usr/pgsql-10/bin/initdb
--pgdata='\''/var/lib/pgsql/10/data/'\'' --auth='\''ident'\''
--data-checksums -E utf8 --no-locale -D /mnt/postgres/data'
+ mkdir /var/lib/pgsql/10/data//log
+ chown postgres:postgres /var/lib/pgsql/10/data//log
+ chmod go-rwx /var/lib/pgsql/10/data//log
+ '[' -x /sbin/restorecon ']'
+ /sbin/restorecon /var/lib/pgsql/10/data//log
+ '[' -f /var/lib/pgsql/10/data//PG_VERSION ']'
+ return 1
+ echo 'failed, see /var/lib/pgsql/10/initdb.log'
failed, see /var/lib/pgsql/10/initdb.log
+ script_result=1
+ echo

+ exit 1


Re: BUG #16204: Fail to setup

От
Tom Lane
Дата:
PG Bug reporting form <noreply@postgresql.org> writes:
> I installed postgresql10.11 and ran postgresql-10-setup but it fails.
> Maybe character $ for variable of PG_VERSION is missing in
> /usr/pgsql-10/bin/postgresql-10-setup below :

No, that guess is wrong.  The error message told you to look in
/var/lib/pgsql/10/initdb.log, so what does that file contain?

            regards, tom lane



Re: BUG #16204: Fail to setup

От
小林 巧
Дата:
Dear Tom

Thank you for your reply.

Yeah my guess seem to be wrong but the log says "Success" like this:

[root@tkw-pgcl-sv004 ~]# ls -l  /var/lib/pgsql/10/initdb.log
-rw-------. 1 postgres postgres 831  1月 12 00:52 /var/lib/pgsql/10/initdb.log
[root@tkw-pgcl-sv004 ~]# cat /var/lib/pgsql/10/initdb.log
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".

Data page checksums are enabled.

fixing permissions on existing directory /mnt/postgres/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Asia/Tokyo
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /usr/pgsql-10/bin/pg_ctl -D /mnt/postgres/data -l logfile start

[root@tkw-pgcl-sv004 ~]#

And I have another hypothesis that
"The path used in postgresql-10-setup:L151,L158  is different from data path I set in the environment variable PGSETUP_INITDB_OPTION"

[root@tkw-pgcl-sv004 ~]# ls -l /var/lib/pgsql/10/data//PG_VERSION
ls: cannot access /var/lib/pgsql/10/data//PG_VERSION: No such file or directory

[root@tkw-pgcl-sv004 ~]# ls -l /mnt/postgres/data/PG_VERSION
-rw-------. 1 postgres postgres 3  1月 12 00:52 /mnt/postgres/data/PG_VERSION
[root@tkw-pgcl-sv004 ~]# cat  /mnt/postgres/data/PG_VERSION
10

from: my log below, $PGDATA might not be set from the environment variable:

+ PGDATA=/var/lib/pgsql/10/data/
+ '[' x/var/lib/pgsql/10/data/ = x ']'
+ '[' -f /etc/systemd/system/postgresql-10.service ']'
+ '[' -f /usr/lib/systemd/system/postgresql-10.service ']'
+ SERVICE_FILE=/usr/lib/systemd/system/postgresql-10.service
+ PGUPLOG=/var/lib/pgsql/10/pgupgrade.log
+ PGLOG=/var/lib/pgsql/10/initdb.log


Is this some kind of bug or can I set data path not to default ?


Best regards, Takumi Kobayashi




差出人: Tom Lane <tgl@sss.pgh.pa.us>
送信日時: 2020年1月12日 0:42
宛先: chamaharun@outlook.com <chamaharun@outlook.com>
CC: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
件名: Re: BUG #16204: Fail to setup
 
PG Bug reporting form <noreply@postgresql.org> writes:
> I installed postgresql10.11 and ran postgresql-10-setup but it fails.
> Maybe character $ for variable of PG_VERSION is missing in
> /usr/pgsql-10/bin/postgresql-10-setup below :

No, that guess is wrong.  The error message told you to look in
/var/lib/pgsql/10/initdb.log, so what does that file contain?

                        regards, tom lane

Re: BUG #16204: Fail to setup

От
Tom Lane
Дата:
=?iso-2022-jp?B?GyRCPi5OUxsoQiAbJEI5KhsoQg==?= <chamaharun@outlook.com> writes:
> [root@tkw-pgcl-sv004 ~]# cat /var/lib/pgsql/10/initdb.log
> ...
> fixing permissions on existing directory /mnt/postgres/data ... ok
> ...
> Success. You can now start the database server using:
>     /usr/pgsql-10/bin/pg_ctl -D /mnt/postgres/data -l logfile start

Right.  So, clearly, initdb thinks it was told to initialize
/mnt/postgres/data.  Looking back at your original trace,
we see it being called like this:

+ runuser -l postgres -c '/usr/pgsql-10/bin/initdb
--pgdata='\''/var/lib/pgsql/10/data/'\'' --auth='\''ident'\''
--data-checksums -E utf8 --no-locale -D /mnt/postgres/data'
                                     ^^^^^^^^^^^^^^^^^^^^^

So evidently that won out over the earlier --pgdata switch,
which is unsurprising.  But it definitely looks like this
service script is confused, or else you've put a -D switch
into some option that's not supposed to contain that.

The Postgres project as such doesn't distribute systemd
service scripts, so you'll need to take this up with
whoever created the script you're using.

            regards, tom lane



Re: BUG #16204: Fail to setup

От
小林 巧
Дата:
Thanks.


>The Postgres project as such doesn't distribute systemd
>service scripts, so you'll need to take this up with
>whoever created the script you're using.

Before I install postgresql-10 server, it is no systemd unit file:

[root@tkw-pgcl-sv003 ~]# ls -l /lib/systemd/system/posttgres*
ls: /lib/systemd/system/postgres* にアクセスできません: そのようなファイルやディレクトリはありません

But after install it be created:

[root@tkw-pgcl-sv003 ~]# ls -l /lib/systemd/system/postgres*
-rw-r--r--. 1 root root 1728 11月 30 23:29 /lib/systemd/system/postgresql-10.service

[root@tkw-pgcl-sv003 ~]# cat /lib/systemd/system/postgresql-10.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql-10.service",
# containing
# .include /usr/lib/systemd/system/postgresql-10.service
# ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.

# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 10 database server
Documentation=https://www.postgresql.org/docs/10/static/
After=syslog.target
After=network.target

[Service]
Type=notify

User=postgres
Group=postgres

# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory
Environment=PGDATA=/var/lib/pgsql/10/data/

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

ExecStartPre=/usr/pgsql-10/bin/postgresql-10-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-10/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT


# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0

[Install]
WantedBy=multi-user.target








The systemd unit file seems to derive from the rpm package the official site distributes.
So where should I contact to solve this issue?


I installed postgresql-10 server from the repository from official website:
https://yum.postgresql.org/repopackages.php

And installed commands are:

# yum -y install postgresql10-server postgresql10-contrib
# mkdir /mnt/postgres
# mkdir /mnt/postgres/data
# chown postgres:postgres /mnt/postgres/data


Best regards, Takumi Kobayashi

差出人: Tom Lane <tgl@sss.pgh.pa.us>
送信日時: 2020年1月13日 1:55
宛先: 小林 巧 <chamaharun@outlook.com>
CC: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
件名: Re: BUG #16204: Fail to setup
 
小林 巧 <chamaharun@outlook.com> writes:
> [root@tkw-pgcl-sv004 ~]# cat /var/lib/pgsql/10/initdb.log
> ...
> fixing permissions on existing directory /mnt/postgres/data ... ok
> ...
> Success. You can now start the database server using:
>     /usr/pgsql-10/bin/pg_ctl -D /mnt/postgres/data -l logfile start

Right.  So, clearly, initdb thinks it was told to initialize
/mnt/postgres/data.  Looking back at your original trace,
we see it being called like this:

+ runuser -l postgres -c '/usr/pgsql-10/bin/initdb
--pgdata='\''/var/lib/pgsql/10/data/'\'' --auth='\''ident'\''
--data-checksums -E utf8 --no-locale -D /mnt/postgres/data'
                                     ^^^^^^^^^^^^^^^^^^^^^

So evidently that won out over the earlier --pgdata switch,
which is unsurprising.  But it definitely looks like this
service script is confused, or else you've put a -D switch
into some option that's not supposed to contain that.

The Postgres project as such doesn't distribute systemd
service scripts, so you'll need to take this up with
whoever created the script you're using.

                        regards, tom lane