Postgresql12.3在启动时无法启动,systemd

问题描述 投票:2回答:1

我从源码上安装了Postgres 12.3,步骤如下(根据我的经验) 这个):

./configure --with-openssl --with-systemd
make
sudo make install

如果我从pg_ctl开始... 邮局 用户都能正常工作。pg_ctl -D $PGDATA -l /path/to/logfile

然后我试着创建一个systemd服务,就像描述的那样 此处.步骤。

  1. 创建文件 /etc/systemd/system/postgresql.service 与内容。
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)

[Service]
Type=notify
User=postgres
ExecStart=/usr/local/pgsql/bin/postgres -D /path/to/pgdata
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target
  1. sudo systemctl enable postgresql.service
  2. 然后我重启了我的机器.重启后Postgres无法访问. 一些日志。sudo systemctl status postgresql.service
postgresql.service - PostgreSQL database server
   Loaded: loaded (/etc/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2020-06-05 03:23:32 MSK; 37s ago
     Docs: man:postgres(1)
  Process: 724 ExecStart=/usr/local/pgsql/bin/postgres -D /path/to/pgdata (code=exited, status=1/FAILURE)
 Main PID: 724 (code=exited, status=1/FAILURE)

Jun 05 03:23:31 ctsvc systemd[1]: Starting PostgreSQL database server...
Jun 05 03:23:32 ctsvc systemd[1]: postgresql.service: Main process exited, code=exited, status=1/FAILURE
Jun 05 03:23:32 ctsvc systemd[1]: Failed to start PostgreSQL database server.
Jun 05 03:23:32 ctsvc systemd[1]: postgresql.service: Unit entered failed state.
Jun 05 03:23:32 ctsvc systemd[1]: postgresql.service: Failed with result 'exit-code'.

journalctl -xe | grep postgres

-- Subject: Unit postgresql.service has begun start-up
-- Unit postgresql.service has begun starting up.
Jun 05 03:23:32 ctsvc postgres[724]: 2020-06-05 03:23:32.209 MSK [724] LOG:  starting PostgreSQL 12.3 on armv7l-unknown-linux-gnueabihf, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 32-bit
Jun 05 03:23:32 ctsvc postgres[724]: 2020-06-05 03:23:32.211 MSK [724] LOG:  could not bind IPv4 address "172.17.17.42": Cannot assign requested address
Jun 05 03:23:32 ctsvc postgres[724]: 2020-06-05 03:23:32.211 MSK [724] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
Jun 05 03:23:32 ctsvc postgres[724]: 2020-06-05 03:23:32.211 MSK [724] WARNING:  could not create listen socket for "172.17.17.42"
Jun 05 03:23:32 ctsvc postgres[724]: 2020-06-05 03:23:32.211 MSK [724] FATAL:  could not create any TCP/IP sockets
Jun 05 03:23:32 ctsvc postgres[724]: 2020-06-05 03:23:32.212 MSK [724] LOG:  database system is shut down
Jun 05 03:23:32 ctsvc systemd[1]: postgresql.service: Main process exited, code=exited, status=1/FAILURE
-- Subject: Unit postgresql.service has failed
-- Unit postgresql.service has failed.
Jun 05 03:23:32 ctsvc systemd[1]: postgresql.service: Unit entered failed state.
Jun 05 03:23:32 ctsvc systemd[1]: postgresql.service: Failed with result 'exit-code'.
Jun 05 03:24:09 ctsvc sudo[1602]:   user1 : TTY=pts/0 ; PWD=/home/user1 ; USER=root ; COMMAND=/bin/systemctl status postgresql.service

netstat -tnl | grep "5432" - 然后我可以手动运行这个服务。sudo systemctl status postgresql.service

● postgresql.service - PostgreSQL database server
   Loaded: loaded (/etc/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-06-05 03:30:57 MSK; 8s ago
     Docs: man:postgres(1)
 Main PID: 1681 (postgres)
    Tasks: 8 (limit: 4915)
   CGroup: /system.slice/postgresql.service
           ├─1681 /usr/local/pgsql/bin/postgres -D /path/to/pgdata
           ├─1683 postgres: checkpointer   
           ├─1684 postgres: background writer   
           ├─1685 postgres: walwriter   
           ├─1686 postgres: autovacuum launcher   
           ├─1687 postgres: stats collector   
           ├─1688 postgres: logical replication launcher   
           └─1693 postgres: postgres postgres 172.17.17.40(53600) idle

Jun 05 03:30:56 ctsvc systemd[1]: Starting PostgreSQL database server...
Jun 05 03:30:57 ctsvc postgres[1681]: 2020-06-05 03:30:57.006 MSK [1681] LOG:  starting PostgreSQL 12.3 on armv7l-unknown-linux-gnueabihf, compiled b
Jun 05 03:30:57 ctsvc postgres[1681]: 2020-06-05 03:30:57.007 MSK [1681] LOG:  listening on IPv4 address "172.17.17.42", port 5432
Jun 05 03:30:57 ctsvc postgres[1681]: 2020-06-05 03:30:57.032 MSK [1681] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Jun 05 03:30:57 ctsvc postgres[1681]: 2020-06-05 03:30:57.424 MSK [1682] LOG:  database system was shut down at 2020-06-05 02:59:03 MSK
Jun 05 03:30:57 ctsvc postgres[1681]: 2020-06-05 03:30:57.725 MSK [1681] LOG:  database system is ready to accept connections
Jun 05 03:30:57 ctsvc systemd[1]: Started PostgreSQL database server.
netstat -tnl | grep '5432'
tcp        0      0 172.17.17.42:5432       0.0.0.0:*               LISTEN

在我的 postgresql.conf 我有以下几点。

# - Connection Settings -
listen_addresses = '172.17.17.42'
port = 5432
max_connections = 100

如果能帮到你的话 Postgres在Cubietruck上和Armbian一起运行。

uname -a
Linux ctsvc 4.19.62-sunxi #5.92 SMP Wed Jul 31 22:07:23 CEST 2019 armv7l GNU/Linux

在我的系统中,已经没有任何进程在启动时试图绑定这个端口。据我所知,服务本身和Postgresql一切正常。然而,在启动时发生了一些奇怪的事情,但我不明白如何找出这种行为的原因。

linux postgresql systemd
1个回答
0
投票

最后,我的文件 /etc/systemd/system/postgresql.service 看起来是这样的。

[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
Wants=network-online.target
After=network.target network-online.target

[Service]
Type=notify
User=postgres
ExecStart=/usr/local/pgsql/bin/postgres -D /path/to/pgdata
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target

谢谢 Laurenz Albe 评论我在下面添加了 单位 节。

Wants=network-online.target
After=network.target network-online.target

在PG启动前确保网络完全正常运行。此后PG重启后正常运行。

© www.soinside.com 2019 - 2024. All rights reserved.