我将一个示例Rails应用程序部署到远程服务器上,并在同一服务器上托管了postgres。 database.yml文件是这样的。
production:
adapter: postgresql
encoding: unicode
database: remotepg_production
pool: 5
host: localhost
username: mrmann
password: secret
一切都很好。然后我进入了database.yml文件并将host: localhost
替换为另一台服务器host: 178.XXX.XXX
上的postgres数据库的ip地址
production:
adapter: postgresql
encoding: unicode
database: remotepg_production
pool: 5
host: 178.XXX.XXX.XXX #ip address of server with other postgres database
username: mrmann
password: secret
当我使用Rails应用程序在服务器上重新启动postgres时,示例应用程序现在给了我Rails的“出错了”页面。
用户名和密码在两个dbs上都是相同的。你能说出问题所在吗?感谢
更新
这些是服务器上pg_hba.conf中的设置,其中包含我要连接的数据库。
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
Fake Rails app IP:192.241.XXX.X
虚假数据库IP:192.34.XX.XXX
答案 0 :(得分:1)
您是否可以访问数据库日志?如果您的连接尝试连接到数据库,那么应该有一些消息。我的WAG是你需要将该IP添加到服务器的pg_hba.conf文件并重新加载Postgres。
为了更清楚,添加到服务器的pg_hba.conf的IP是应用程序连接的IP,您还应该检查数据库的listen_addresses
设置的值。如果后者未设置为'*'或应用程序的IP,则需要在postgresql.conf中更改它并重新启动数据库集群。
[编辑,提供新信息]
pg_hba.conf中的行应该是
host all all 192.241.XXX.X md5
重新加载(不重启)postgres(例如pg_ctl reload
),然后再次尝试连接。如果失败,请找到db日志并查看它显示的内容。如果没有消息,则可能是防火墙问题。如果怀疑后者,请在iptables -nvL