Postgresql

CentOS 7 上 PostgreSQL 服務啟動失敗

  • April 9, 2019

使用以下方式安裝 PostgreSQL:

sudo yum install postgresql-server postgresql-contrib

PostgreSQL 版本:9.2.18

啟動服務時:

sudo service postgresql start

得到錯誤:

Redirecting to /bin/systemctl start  postgresql.service
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.

journalctl -xe細節:

-- Unit postgresql.service has failed.
--
-- The result is failed.
7月 19 04:17:04 node2 systemd[1]: Unit postgresql.service entered failed state.
7月 19 04:17:04 node2 systemd[1]: postgresql.service failed.
7月 19 04:17:04 node2 polkitd[19772]: Unregistered Authentication Agent for unix-process:27133:53830492 (system bus name :1.405, object path /org/freedesktop/PolicyKit1/AuthenticationA
7月 19 04:19:33 node2 polkitd[19772]: Registered Authentication Agent for unix-process:27165:53845472 (system bus name :1.406 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object pat
7月 19 04:19:33 node2 systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has begun starting up.
7月 19 04:19:34 node2 pg_ctl[27187]: pg_ctl: could not start server
7月 19 04:19:34 node2 pg_ctl[27187]: Examine the log output.
7月 19 04:19:34 node2 systemd[1]: postgresql.service: control process exited, code=exited status=1
7月 19 04:19:34 node2 systemd[1]: Failed to start PostgreSQL database server.
-- Subject: Unit postgresql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has failed.
--
-- The result is failed.
7月 19 04:19:34 node2 systemd[1]: Unit postgresql.service entered failed state.
7月 19 04:19:34 node2 systemd[1]: postgresql.service failed.
7月 19 04:19:34 node2 polkitd[19772]: Unregistered Authentication Agent for unix-process:27165:53845472 (system bus name :1.406, object path /org/freedesktop/PolicyKit1/AuthenticationA
lines 2850-2910/2910 (END)

執行systemctl status PostgreSQL.service,得到以下資訊:

● postgresql.service - PostgreSQL database server
  Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since Wed 2017-07-19 04:30:26 EDT; 42min ago
 Process: 27285 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=1/FAILURE)
 Process: 27280 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 26640 (code=exited, status=0/SUCCESS)

在能夠連接到 PostgreSQL 數據庫之前,您有 3 個步驟:

  • 安裝 PostgreSQL
  • 創建數據集群 ($PGDATA)
  • 啟動伺服器

您已經安裝了 PostgreSQL,現在需要創建集群。該initdb工具是您所需要的。

您將在此處找到文件。

這可能會令人困惑,因為當您使用基於 debian 的發行版時,aptperl 包裝器會為您完成所有步驟。

在我的情況下,它shared_buffers太大了導致失敗狀態,我將它減少到 128MB 並重新啟動然後工作正常,我的情況是我在作業系統崩潰到新作業系統後複製了數據目錄。

引用自:https://dba.stackexchange.com/questions/180209