简体   繁体   English

DBI :: OperationalError:无法连接到服务器:连接被拒绝

[英]DBI::OperationalError: could not connect to server: Connection refused

On rails console when I tried to connect to postgres database which on machine having ip address suppose xxx.xxx.xxx.xxx. 在Rails控制台上,当我尝试连接到具有IP地址的机器上的postgres数据库假定为xxx.xxx.xxx.xxx时。

Gem installed 宝石安装

gem 'dbi'  
sudo apt-get install libpq-dev
gem 'dbd-pg'

I also granted all permission to 'postgres' user and restarted postgres server on this xxx.xxx.xxx.xxx machine 我还向“ postgres”用户授予了所有权限,并在此xxx.xxx.xxx.xxx机器上重新启动了postgres服务器

GRANT ALL PRIVILEGES ON DATABASE test TO postgres WITH GRANT OPTION
sudo /etc/init.d/postgresql restart

I am getting following error. 我收到以下错误。

1.9.3p448 :001 > dbh = DBI.connect("DBI:Pg:test:xxx.xxx.xxx.xxx", "postgres", "") 1.9.3p448:001> dbh = DBI.connect(“ DBI:Pg:test:xxx.xxx.xxx.xxx”,“ postgres”,“”)

DBI::OperationalError: could not connect to server: Connection refused Is the server running on host "xxx.xxx.xxx.xxx" and accepting TCP/IP connections on port 5432? DBI :: OperationalError:无法连接到服务器:连接被拒绝服务器是否在主机“ 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>'

Please tell me where am going wrong. 请告诉我哪里出了问题。

Thank you... 谢谢...

Connect with psql and run: psql连接并运行:

SHOW port;

Betcha the port given isn't 5432 . Betcha提供的端口不是5432 You're probably also on a mac; 您可能也在Mac上; it's common for mac users to have some binaries linked to the libpq supplied by the operating system (an old PostgreSQL) and some to the libpq of a PostgreSQL they installed themselves. 这是常见的Mac用户有一个链接到一些二进制文件libpq由操作系统提供(旧PostgreSQL的)和一些对libpq他们自己安装一个PostgreSQL的。 These can have different default socket directories and different TCP port defaults. 这些可以具有不同的默认套接字目录和不同的TCP端口默认值。

You should also: 您还应该:

SHOW listen_addresses ;

and make sure it is * . 并确保它是* If it instead says localhost then your PostgreSQL isn't listening on external IPs, only the local loopback. 如果改为显示localhost则您的PostgreSQL不监听外部IP,仅监听本地环回。 In that case, you should change that in the config file. 在这种情况下,您应该在配置文件中进行更改。 See the introductory PostgreSQL documentation. 请参阅入门PostgreSQL文档。

If you've confirmed that PostgreSQL is listening on the IP and port of interest, you should make sure you don't have a firewall blocking connections from outside machines. 如果已确认PostgreSQL正在侦听目标IP和端口,则应确保没有防火墙阻止来自外部计算机的连接。 That would usually result in a timeout, not a connection refused error, though. 但这通常会导致超时,而不是连接被拒绝的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Heroku Rails 4无法连接到服务器:连接被拒绝 - Heroku Rails 4 could not connect to server: connection refused PG::ConnectionBad - 无法连接到服务器:连接被拒绝 - PG::ConnectionBad - could not connect to server: Connection refused Heroku上的“ PG :: ConnectionBad-无法连接到服务器:连接被拒绝” - “PG::ConnectionBad - could not connect to server: Connection refused” Sinatra server on Heroku Heroku Rails部署失败,并显示错误“无法连接到服务器:连接被拒绝” - Heroku Rails deploy fails with error “could not connect to server: Connection refused” Heroku:PG :: ConnectionBad:无法连接到服务器:连接被拒绝 - Heroku: PG::ConnectionBad: could not connect to server: Connection refused heroku迁移,无法连接到服务器:连接被拒绝 - heroku migration, getting could not connect to server: Connection refused rake 中止:PG::ConnectionBad:无法连接到服务器:连接被拒绝 - rake aborted! PG::ConnectionBad: could not connect to server: Connection refused PG 错误无法连接到服务器:连接被拒绝服务器是否在端口 5432 上运行? - PG Error could not connect to server: Connection refused Is the server running on port 5432? 耙子中止,无法连接做postgresql:连接被拒绝 - Rake aborted, Could not connect do postgresql: connection refused 无法建立连接,因为目标计算机主动拒绝它。 - 连接(2) - No connection could be made because the target machine actively refused it. - connect(2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM