Postgresql 13 on CentOS8 fail to start at boot time, but can be started manualy

centos8postgresql

I have the following problem with postgres 13 on CentOS8.
It is installed on a separate disk mounted on /opt/pgsql/data (with the pg_wall mounted also on a separate disk – /opt/pgsql/wall) and at boot time fails to start, but if I run systemctl start postgresql-13 is starting fine.

After the reboot, checking the postgres service status I get the following error:

● postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2020-11-16 22:50:55 EET; 32s ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 1203 ExecStart=/usr/pgsql-13/bin/postmaster -D ${PGDATA} (code=exited, status=1/FAILURE)
  Process: 1179 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 1203 (code=exited, status=1/FAILURE)

Nov 16 22:50:55 srvpsql systemd[1]: Starting PostgreSQL 13 database server...
Nov 16 22:50:55 srvpsql postmaster[1203]: 2020-11-16 22:50:55.928 EET [1203] LOG:  redirecting log output to logging collector process
Nov 16 22:50:55 srvpsql postmaster[1203]: 2020-11-16 22:50:55.928 EET [1203] HINT:  Future log output will appear in directory "log".
Nov 16 22:50:55 srvpsql systemd[1]: postgresql-13.service: Main process exited, code=exited, status=1/FAILURE
Nov 16 22:50:55 srvpsql systemd[1]: postgresql-13.service: Killing process 1214 (postmaster) with signal SIGKILL.
Nov 16 22:50:55 srvpsql systemd[1]: postgresql-13.service: Failed with result 'exit-code'.
Nov 16 22:50:55 srvpsql systemd[1]: Failed to start PostgreSQL 13 database server.

The service file in /etc/systemd/system/multi-user.target.wants has the following content:

[Unit]
Description=PostgreSQL 13 database server
Documentation=https://www.postgresql.org/docs/13/static/
After=opt-pgsql-wall.mount
After=syslog.target
After=network.target

[Service]
Type=notify
User=postgres
Group=postgres
Environment=PGDATA=/opt/pgsql/data/
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-13/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

I've added opt-pgsql-wall.mount because I suspect that the postgres process is started before the mounting of the disk is done (it seems that wasn;t the cause of the error).

Also in postgresql.conf file (in /opt/pgsql/data folder) I have the current folder as data directory set.

...
data_directory = '/opt/pgsql/data/' 
...

What am I doing wrong ?

Best Answer

I had exactly the same error! The database was also transferred to another mounted disk, but as it turned out, that was not the problem. In the postgresql.conf file on line 59, change

#listen_addresses = 'localhost' # what IP address (es) to listen on;

to

listen_addresses = '*'

This solved my problem. Now postgresql 13 starts automatically when the server boots!