postgres登錄失敗Connection refused與SSL off失敗


連接失敗問題

使用postgres數據庫連接工具測試,遇到兩次失敗

第一個登錄失敗問題

Connection to 192.168.XX.XX:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
  Connection refused: connect
  Connection refused: connect

這語句翻譯下,用戶名密碼是正確的,但是tcp/ip的連接失敗了。這個解決方法其實就是去建立tcp/ip連接過程。
原因是宿主機並沒有監聽其他的主機接口,因此沒有建立連接。
解決方法

修改/var/lib/pgsql/9.6/data/postgresql.conf  
新增listen_addresses = '*'  #what IP address(es) to listen on
#默認
listen_addresses = 'localhost'

第二個登錄失敗問題

The server doesn't grant access to the database: the server reports 
FATAL: no pg_hba.conf entry for host "192.168.X.X", user "postgres", database "postgres"
#FATA:no pg_hba.conf entry for host "192.168.113.1",user "postgres",database "postgres",SSL off

這個問題也說這個主機沒有權限訪問數據庫,也告訴配置文件在哪:pg_hba.conf。
pg_hba.conf為PostgreSQL的訪問策略配置文件,默認位於/var/lib/pgsql/9.6/data/pg_hba.conf目錄(postgres 9.6)。
該配置文件有5個參數,分別為:TYPE(主機類型)、DATABASE(數據庫名)、USER(用戶名)、ADDRESS(IP地址和掩碼)、METHOD(加密方法)。
關於這個配置文件可以參考PostgreSQL的pg_hba.conf文件講解
解決方式增加選項支持所所有的主機ip訪問
增加

host    all             all             0.0.0.0/0               md5


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM