Rails Rails 死活连不上 Postgresql

saiga · 2014年03月06日 · 最后由 saiga 回复于 2014年03月07日 · 4392 次阅读

环境:cubieboard,cubian,postgresql9.3.3

SSH 上去可以用 psql,PC 可以用 pgadmin 远程连接。

但是 cb 里面的 rails 会报错:

could not connect to server: Connection timed out
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

postgresql 只改了这俩地方:

postgresql.conf

listen_address = "*"  //CB上这里不设置成*,pg会启动不了

pg_hba.conf

host    all             all             127.0.0.1/32            trust

改为

host    all             all             0.0.0.0/0            md5

rails 的 database.yml

default: &default
  adapter: postgresql
  host: localhost
  port: 5432
  encoding: utf-8
  pool: 5
  username: ***
  password: ***
  timeout: 5000

其中 host 也试过 127.0.0.1 和 10.0.0.5,后者可以在 pgadmin 上登录。

host: localhosthost: 10.0.0.5试试?

其实不建议改任何 postgresql 设置,默认本机 unix socket 侦听是最安全的。

然后 rails 里面这样配,不用 host 和 password 的。。

production:
  adapter: postgresql
  encoding: unicode
  database: sanmate_prd
  port: 5433
  pool: 5
  username: sanmate

#1 楼 @ericguo 奇怪的是,如果 listen_address 注释掉的话(默认注释),pg 会启动不了,日志里显示错误:could not create any TCP/IP sockets。 而 PC 上不会有这个问题

我没用过cubian,我只能说 ubuntu 12.04 的 pg 缺省源安装肯定可以启动的。。

如果你默认安装 pg,啥都不改,然后不能启动,这可能是一个发行版的 bug。。

另外随便查了下文档,如果报 could not create any TCP/IP sockets,可以改/etc/postgresql/9.3/main/postgresql.conf换个端口试试 (比如 port 改为 5433)。

#4 楼 @ericguo 一开始也以为这样,不过端口一直是空闲的。我 PC 用的 mint 自己编译的 9.3 一切正常,cb 无论是 apt 还是 编译都会有这问题 ORZ 现在打算换成 fedora 看看..

#4 楼 @ericguo 重新刷了一次 cubian 就可以了,我怀疑是 linux 网络配置被我玩坏了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号