0

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 ?

  • Check your logs. – Michael Hampton Nov 17 '20 at 00:12
  • Already checked - in /opt/pgsql/data/log/postgres-xyz.log file the last entry is the shutdown action. No error is there. – Marius Dumitrache Nov 17 '20 at 08:20
  • Why did you move the data directory? There was no need to do that. – Michael Hampton Nov 17 '20 at 08:33
  • This is not helpful :). The answer to your question is that the server has SSD drives and HDD drives. We moved the data dir and wall dir on SSD drives. – Marius Dumitrache Nov 17 '20 at 09:01
  • That's not a good reason to change the data directory path. You should mount your new drives to the default locations. See [here](https://serverfault.com/a/809364/126632). (Which is probably also the solution to this problem.) – Michael Hampton Nov 17 '20 at 09:07
  • The SELinux settings are not the cause of the problem (I've done the settings in the linked article and also disabled the SELinux). And I don't know where to look to see the error. In the /var/log/messages there is nothing more than what is listed in the original post. Nothing else also in postgres log files. – Marius Dumitrache Nov 17 '20 at 11:56

2 Answers2

2

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!

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
  • Well, it is not from that, I have the line uncommented, but not with the wildcard value, I've put the IP of the server. However, to overcome this issue, I've put a delayed cron job that starts the postgres server after 2 minutes after the reboot. – Marius Dumitrache Feb 05 '21 at 22:09
0

I had a similar issue but with RHEL8 (PG did not start at boot time but it started later manually after systemctl start postgresql-13) and I solved it changing the after condition in the systemd service file. First, I read the PG-13 logs (postgresql.log) and noticed this error: "could not bind IPv4 address "xx.xx.xx.xx": Cannot assign requested address. So, I have to fix the file: /usr/lib/systemd/system/postgresql-13.service in the part:

After=network.target

Replaced it with: After=network-online.target

With this change, PG starts automatically at boot time.

You can see this reference that explains the difference between network and network-online, basically, that network-online waits until the network is online and network only that the service has started but it may not have completed.

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/systemd-network-targets-and-services_configuring-and-managing-networking