1

我将一个示例 Rails 应用程序部署到远程服务器上,postgres 托管在同一台服务器上。database.yml 文件是这样的。

production:
  adapter: postgresql
  encoding: unicode
  database: remotepg_production
  pool: 5
  host: localhost
  username: mrmann
  password: secret

一切正常。然后我进入 database.yml 文件并替换host: localhost为另一台服务器上的 postgres 数据库的 IP 地址,host: 178.XXX.XXX如下所示

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 的“出现问题”页面。

两个数据库上的用户名和用户名密码相同。你能建议问题可能是什么吗?谢谢

更新

这些是我要连接到的数据库服务器上 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

假 Rails 应用程序 IP:192.241.XXX.X

假数据库IP:192.34.XX.XXX

4

1 回答 1

1

Do you have access to the database logs? If your connection got as far as attempting to connect to the database, there should be some messages there. My WAG is that you need to add that IP to server's pg_hba.conf file and reload Postgres. To be more clear, the IP to add to the server's pg_hba.conf is the IP that your application is connecting from, and you should also check the value of the database's listen_addresses setting. If the latter is not set to '*' or to the IP of your application, you'll need to change it in the postgresql.conf and restart the db cluster.

[edit, new information provided]

The line in your pg_hba.conf should be

host  all  all 192.241.XXX.X  md5

Reload (not restart) postgres (eg. pg_ctl reload) and then try connecting again. If it fails, find the db log and see what it shows. If there is no message, then it might be a firewall problem. If the latter is suspected, look for any rules relating to port 5432 in the output of iptables -nvL

于 2013-07-25T16:19:11.173 回答