解決Postgres無法連接的問題


錯誤信息如下:

could not connect to server: Connection refused
Is the server running on host host.domain.com and accepting
TCP/IP connections on port 5432?

第一步:設置pg_hba.conf

$ su - postgres
$ vi /var/lib/pgsql/data/pg_hba.conf

host all all 192.168.1.0 255.255.255.0 trust

第二步:設置postgresql.conf

$ su - postgres
$ vi /var/lib/pgsql/data/postgresql.conf

tcpip_socket = true
listen_addresses = '*'
port = 5432

第三步:重啟PostgreSQL 

/etc/rc.d/init.d/postgresql restart

第四步:打開端口

#iptables中追加
$ -A INPUT -p tcp --dport 5432 -j ACCEPT

#重啟iptables
$ /etc/rc.d/init.d/iptables restart

第六步:測試連接

$ psql -h 192.168.1.11 -U username -d database

 


免責聲明!

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



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