當前位置: 首頁>>技術教程>>正文


將 14.04 升級到 16.04.1 後 Postgresql 服務器無法啟動

, ,

問題描述

剛剛從 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 使用某種模板文件。要解決此問題,請按照以下步驟操作:

  1. 刪除無效的服務腳本:\n # rm /lib/systemd/system/postgresql.service

  2. 重新加載守護程序腳本:\n # systemctl daemon-reload

  3. 啟用 postgresql 服務:\n # systemctl enable postgresql

之後,您將能夠使用任何首選變體啟動 postgres: sudo systemctl start postgresqlsudo service postgresql startsudo /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.

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/13143.html,未經允許,請勿轉載。