解决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