当我尝试连接到具有 ip 地址的机器上的 postgres 数据库时,在 Rails 控制台上假设 xxx.xxx.xxx.xxx。
宝石安装
gem 'dbi'
sudo apt-get install libpq-dev
gem 'dbd-pg'
我还授予了“postgres”用户的所有权限,并在这台 xxx.xxx.xxx.xxx 机器上重新启动了 postgres 服务器
GRANT ALL PRIVILEGES ON DATABASE test TO postgres WITH GRANT OPTION
sudo /etc/init.d/postgresql restart
我收到以下错误。
1.9.3p448 :001 > dbh = DBI.connect("DBI:Pg:test:xxx.xxx.xxx.xxx", "postgres", "")
DBI::OperationalError: could not connect to server: Connection refused 服务器是否在主机“xxx.xxx.xxx.xxx”上运行并接受端口 5432 上的 TCP/IP 连接?
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/dbd-pg-0.3.9/lib/dbd/pg/database.rb:82:in `rescue in initialize'
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/dbd-pg-0.3.9/lib/dbd/pg/database.rb:41:in `initialize'
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/dbd-pg-0.3.9/lib/dbd/Pg.rb:157:in `new'
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/dbd-pg-0.3.9/lib/dbd/Pg.rb:157:in `connect'
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/dbi-0.4.5/lib/dbi/handles/driver.rb:33:in `connect'
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/dbi-0.4.5/lib/dbi.rb:148:in `connect'
from (irb):1
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /home/ashwini/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
请告诉我哪里出错了。
谢谢...