Postgresql

遠端 Postgres 連接

  • January 27, 2014

我已經按照我在網上找到的關於如何執行此操作的所有內容進行了操作,據我所知,一切都是正確的——但它不起作用。

我有一台執行 Postgres 9.1 的 Linux 12.04 伺服器。我可以通過 SSH 連接到伺服器並從那裡完美地使用 Postgres,通過本地連接進行連接。

當我嘗試設置 Postgres 進行遠端訪問時,我無法讓它工作。我做了以下更改:(所有列出的文件都在 /etc/postgresql/9.1/main 中)

  1. 在 /environment 中,我添加了PGOPTIONS='-i'
  2. 在 /pg_hba.conf 中,我添加了host all all 0.0.0.0/0 md5
  3. 在 /postgresql.conf 中,我改變了listen_addresses='*'
  4. 我檢查了防火牆,它是預設配置,但打開了 postgres 埠以防萬一
  5. Netstat -a 顯示tcp 0 0 localhost:5432 *:* LISTEN
  6. 我已確保我的 postgres 使用者密碼和名稱正確,並且可以在本地與該使用者連接
  7. 我嘗試重新啟動 ( services postgresql restart) 並啟動/停止。

然而,我仍然無法遠端連接。我收到以下錯誤:

$ psql -h [server address] -U [username] -d [database name] psql: could
not connect to server: Connection refused   Is the server running on
host "[server address]" ([ip address]) and accepting    TCP/IP
connections on port 5432?

有任何想法嗎?

您確定在此之後重新啟動了 postgresql 嗎?配置是正確的,但它仍然只綁定到 localhost。

引用自:https://serverfault.com/questions/570037