刚刚将我的系统从 14.04. LTS 升级到 16.04.1 LTS,postgresql 无法在 systemd 上启动:
/etc/init.d/postgresql start
[ ok ] Starting postgresql (via systemctl): postgresql.service
# /etc/init.d/postgresql status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Вт 2016-08-09 13:40:51 MSK; 3min 23s ago
Process: 23142 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 23142 (code=exited, status=0/SUCCESS)Seems that
似乎 systemd 脚本包含错误的数据:
# cat /lib/systemd/system/postgresql.service
# systemd service for managing all PostgreSQL clusters on the system. This
# service is actually a systemd target, but we are using a service since
# targets cannot be reloaded.
[Unit]
Description=PostgreSQL RDBMS
[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on
[Install]
WantedBy=multi-user.target
postgresql 的正确脚本应该是什么?
答案1
Systemd 应该使用 中的脚本/etc/init.d
。相反,systemd 使用某种模板文件。要解决此问题,请按照以下步骤操作:
删除无效的服务脚本:
# rm /lib/systemd/system/postgresql.service
重新加载守护进程脚本:
# systemctl daemon-reload
启用postgresql服务:
# systemctl enable postgresql
之后,您将能够使用任何首选变体启动 postgres:、sudo systemctl start postgresql
或sudo service postgresql start
。sudo /etc/init.d/postgresql start
要检查 postgresql 是否实际运行,请检查服务的状态:sudo systemctl status postgresql
。它应该看起来像:
% sudo systemctl status postgresql
● postgresql.service - LSB: PostgreSQL RDBMS server
Loaded: loaded (/etc/init.d/postgresql; bad; vendor preset: enabled)
Active: active (running) since Пт 2016-08-12 10:13:43 MSK; 1h 37min ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/postgresql.service
├─4086 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf
├─4099 postgres: checkpointer process
├─4100 postgres: writer process
├─4101 postgres: wal writer process
├─4102 postgres: autovacuum launcher process
└─4103 postgres: stats collector process
авг 12 10:13:40 ubuntu-precise systemd[1]: Starting LSB: PostgreSQL RDBMS server...
авг 12 10:13:40 ubuntu-precise postgresql[4009]: * Starting PostgreSQL 9.5 database server
авг 12 10:13:43 ubuntu-precise postgresql[4009]: ...done.
авг 12 10:13:43 ubuntu-precise systemd[1]: Started LSB: PostgreSQL RDBMS server.
答案2
如果您提供正确的版本和集群名称,这应该可以立即使用。
假设您正在运行版本9.5
并且集群被称为main
:
开始:systemctl start [email protected]
停止:systemctl stop [email protected]
地位:systemctl status [email protected]
启用开机自动启动:systemctl enable [email protected]
禁用开机自动启动:systemctl disable [email protected]
foo@postgres:~$ systemctl status [email protected]
● [email protected] - PostgreSQL Cluster 9.5-main
Loaded: loaded (/lib/systemd/system/[email protected]; disabled; vendor preset: enabled)
Active: active (running) since Fri 2017-03-31 17:44:46 CEST; 59s ago
Main PID: 4546 (postgres)
CGroup: /system.slice/system-postgresql.slice/[email protected]
├ ─ 4546 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf
├ ─ 4548 postgres: checkpointer process
├ ─ 4549 postgres: writer process
├ ─ 4550 postgres: wal writer process
├ ─ 4551 postgres: autovacuum launcher process
└ ─ 4552 postgres: stats collector process
Mar 31 17:44:44 postgres postgres[4546]: [1-2] 2017-03-31 17:44:44 CEST [4546] @ HINT: Future log output will go to log destination "syslog".
Mar 31 17:44:44 postgres postgres[4547]: [2-1] 2017-03-31 17:44:44 CEST [4547] @ LOG: database system was shut down at 2017-03-31 17:44:43 CEST
Mar 31 17:44:44 postgres postgres[4547]: [3-1] 2017-03-31 17:44:44 CEST [4547] @ LOG: MultiXact member wraparound protections are now enabled
Mar 31 17:44:44 postgres postgres[4546]: [2-1] 2017-03-31 17:44:44 CEST [4546] @ LOG: database system is ready to accept connections
Mar 31 17:44:44 postgres postgres[4551]: [2-1] 2017-03-31 17:44:44 CEST [4551] @ LOG: autovacuum launcher started
Mar 31 17:44:45 postgres postgres[4553]: [3-1] 2017-03-31 17:44:45 CEST [4553] [unknown]@[unknown] LOG: incomplete startup packet
Mar 31 17:44:46 postgres systemd[1]: Started PostgreSQL Cluster 9.5-main.
Mar 31 17:44:47 postgres systemd[1]: Reloading PostgreSQL Cluster 9.5-main.
Mar 31 17:44:47 postgres postgres[4546]: [3-1] 2017-03-31 17:44:47 CEST [4546] @ LOG: received SIGHUP, reloading configuration files
Mar 31 17:44:47 systemd[1]: Reloaded PostgreSQL Cluster 9.5-main.
答案3
清除 postges9 并在 ubuntu16 上安装 10 后,我遇到了同样的问题。最初,我使用以下内容编辑了 /lib/systemd/system/postgresql.service 文件:
[Unit]
Description=PostgreSQL RDBMS
[Service]
Type=notify
User=postgres
ExecStart=/usr/lib/postgresql/10/bin/postgres -D /analysis2/postgresql/data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0
[Install]
WantedBy=multi-user.target
我可以使用 systemctl restart/stop/start 来控制 postgresql 服务。但是,由于某种原因,上述文件被覆盖(可能是在系统更新后),我无法再运行 systemctl 命令来启动和停止 postgresql 服务器。阅读了一些资料后,我意识到您不应该编辑上述文件。相反,您应该使用 systemctl edit foo 来覆盖默认值。按照以下链接建议的解决方案后,我的系统似乎可以正常使用 postgresql。
答案4
虽然不是最好的解决方案,但无需深入研究就可以解决问题。将其添加到 cron:
@reboot sleep 5; systemctl start postgresql