问题描述
刚刚从 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 的正确脚本应该是什么?
最佳回答
Systemd 应该使用来自 /etc/init.d
的脚本。相反,systemd 使用某种模板文件。要解决此问题,请按照以下步骤操作:
-
删除无效的服务脚本:\n
# rm /lib/systemd/system/postgresql.service
-
重新加载守护程序脚本:\n
# systemctl daemon-reload
-
启用 postgresql 服务:\n
# 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.
次佳回答
如果您提供正确的版本和集群名称,这应该可以开箱即用。
假设您正在运行版本 9.5
并且集群称为 main
:
开始: systemctl start postgresql@9.5-main
停止:systemctl stop postgresql@9.5-main
状态:systemctl status postgresql@9.5-main
启动时启用自动启动:systemctl enable postgresql@9.5-main
启动时禁用自动启动:systemctl disable postgresql@9.5-main
foo@postgres:~$ systemctl status postgresql@9.5-main
● postgresql@9.5-main.service - PostgreSQL Cluster 9.5-main
Loaded: loaded (/lib/systemd/system/postgresql@.service; 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/postgresql@9.5-main.service
├ ─ 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.