Linux

為什麼 Postgres 服務失敗?

  • September 1, 2020

我正在設置一個用於開發的 ManageIQ 設備。當我將“v2_key”加密密鑰更新為與生產相同時,我的數據庫連接中斷了。最初我收到這些錯誤:

Aug 31 13:26:59 miq-dev.chq.ei sh[3642]: PG::ConnectionBad: FATAL: password authentication failed for user "root"

Aug 31 13:26:59 miq-dev.chq.ei sh[3642]: FATAL: no pg_hba.conf entry for host "::1", user "root", database "vmdb_production", SSL off

我將 pg_hba.conf 更新為:


# TYPE  DATABASE    USER  ADDRESS METHOD
local   all     all             trust
local   all         all           peer map=usermap
local   replication all           peer map=usermap
hostssl all         all   all     md5
host    replication all   all     md5
::1     vmdb_production root            trust        # <--- added last line

現在我得到一組新的錯誤:

● postgresql.service - PostgreSQL database server
  Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since Mon 2020-08-31 18:39:44 EDT; 49s ago
 Process: 3648 ExecStart=/usr/bin/postmaster -D ${PGDATA} (code=exited, status=1/FAILURE)
 Process: 3645 ExecStartPre=/usr/libexec/postgresql-check-db-dir %N (code=exited, status=0/SUCCESS)
Main PID: 3648 (code=exited, status=1/FAILURE)

Aug 31 18:39:44 miq-dev.chq.ei postmaster[3648]: 2020-08-31 18:39:44 EDT::5f4d7c30.e40:@:[3648]:LOG:  listening on IPv4 address "0.0.0.0", port 5432
Aug 31 18:39:44 miq-dev.chq.ei postmaster[3648]: 2020-08-31 18:39:44 EDT::5f4d7c30.e40:@:[3648]:LOG:  listening on IPv6 address "::", port 5432
Aug 31 18:39:44 miq-dev.chq.ei postmaster[3648]: 2020-08-31 18:39:44 EDT::5f4d7c30.e40:@:[3648]:LOG:  listening on Unix socket "/var/run/postgresq...QL.5432"
Aug 31 18:39:44 miq-dev.chq.ei postmaster[3648]: 2020-08-31 18:39:44 EDT::5f4d7c30.e40:@:[3648]:LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Aug 31 18:39:44 miq-dev.chq.ei postmaster[3648]: 2020-08-31 18:39:44 EDT::5f4d7c30.e40:@:[3648]:LOG:  redirecting log output to logging collector process
Aug 31 18:39:44 miq-dev.chq.ei postmaster[3648]: 2020-08-31 18:39:44 EDT::5f4d7c30.e40:@:[3648]:HINT:  Future log output will appear in directory "log".
Aug 31 18:39:44 miq-dev.chq.ei systemd[1]: postgresql.service: main process exited, code=exited, status=1/FAILURE
Aug 31 18:39:44 miq-dev.chq.ei systemd[1]: Failed to start PostgreSQL database server.
Aug 31 18:39:44 miq-dev.chq.ei systemd[1]: Unit postgresql.service entered failed state.
Aug 31 18:39:44 miq-dev.chq.ei systemd[1]: postgresql.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

這告訴我 postgresql 服務沒有執行。

我嘗試了此 SO 文章中的建議:Postgresql12.3 wont start on boot, systemd通過在我的 postgresql.service 文件中添加幾行來啟動,但我仍然得到相同的 ol 錯誤。

有沒有人有什麼建議?謝謝

如手冊中所述,的第一個“列”pg_hba.conf必須是localhosthostssl、或. 您不能將 IP 地址放入第一列,它會進入第四列(如果第一列不是)。hostnossl``hostgssenc``hostnogssenc``local

數據庫需要放入第三列,然後是使用者名,然後是 IP 地址。

所以這一行:

::1     vmdb_production root            trust 

應該:

host   vmdb_production   root  ::1  trust 

這假設您確實有一個Postgres使用者root,這將是非常不尋常的。它甚至可能表明您正在嘗試執行的軟體root是一個非常非常糟糕的主意(尤其trust

但是根本原因,為什麼 Postgres 沒有啟動,是在pg_hba.conf

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