从14.04升级到16.04.1后,PostgreSQL服务器无法启动


24

刚刚从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的正确脚本应该是什么?

Answers:


9

如果您提供正确的版本和群集名称,则应该可以立即使用。

假设您正在运行版本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.

可以证明这是工作。我如何设置systemd来自动启动它?
Artur Eshenbrener

1
systemctl enable postgresql@9.5-main是你所需要的全部。
马尔特

1
刚刚将PostgreSQL从9.6升级到10.0,然后再次遇到此问题。尝试过您的解决方案并可以证明:它有效。
Artur Eshenbrener

摘自Kemin的以下答案:您可以使用例如使用systemctl edit postgresql@9.6-main具有systemd指令的覆盖文件来创建替代文件,例如:[Service] Nice = 15 IOSchedulingClass = 2 IOSchedulingPriority = 7
GreenReaper

14

Systemd应该使用中的脚本/etc/init.d。相反,systemd使用某种模板文件。要解决此问题,请按照以下步骤操作:

  1. 删除无效的服务脚本:

    # rm /lib/systemd/system/postgresql.service

  2. 重新加载守护程序脚本:

    # systemctl daemon-reload

  3. 启用postgresql服务:

    # systemctl enable postgresql

在这之后,你将能够与任何优选的变化开始的Postgres: sudo systemctl start postgresqlsudo service postgresql startsudo /etc/init.d/postgresql start。要检查postgresql是否实际运行,请检查service的状态: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.

1
那一定是错的。Systemd 确实有效。它已经很好地启动了9.3集群。它只是无法启动我的9.5群集。这不是无效的服务脚本,而是目标脚本,他们称为服务使其可重装。丑陋的骇客似乎也不是正确的方法,但这确实应该引起systemctl _action_ postgresql@_version_人们的注意
Auspex

我不知道这是否是一个丑陋的破解(可能是),但是后缀存在相同的问题,这个答案似乎可以解决我的问题。
十亿

在systemctl启用postgresql时,出现以下错误:postgresql.service不是本机服务,重定向到systemd-sysv-install执行/ lib / systemd / systemd-sysv-install enable启用postgresql insserv:fopen(.depend.stop):权限拒绝服务:fopen(.depend.stop):权限被拒绝。显然,这不适用于我的设置。
Kemin Zhou

1

清除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一起正常工作。

如何覆盖或配置systemd服务?


-2

不是最好的解决方案,但这可以解决问题,而无需深入研究。将此添加到cron:

@reboot sleep 5; systemctl start postgresql
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.