PG :: ConnectionBad:无法连接到服务器:连接被拒绝

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PG :: ConnectionBad:无法连接到服务器:连接被拒绝相关的知识,希望对你有一定的参考价值。

我尝试运行时出现以下错误

git heroku push master

我不怎么解决这个问题。 我正在使用rails 3.2.19

 fernando@fernando:~/ProyectoTicketMaster/Ticket_Master$ git push  heroku master 

Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       Connecting to database specified by DATABASE_URL
       rake aborted!
       PG::ConnectionBad: could not connect to server: Connection refused
       Is the server running on host "127.0.0.1" and accepting
       TCP/IP connections on port 5432?
       /tmp/build_dd87fdc88ebb265d09b8212e3b0df10b/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `initialize'
       /tmp/build_dd87fdc88ebb265d09b8212e3b0df10b/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `new'
       /tmp/build_dd87fdc88ebb265d09b8212e3b0df10b/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `connect'

这是我的GemFile。 我正在使用pg进行生产,使用sqlite进行开发。 这里附有我的GemFile和我的databse.yml

source 'https://rubygems.org'

gem 'rails', '3.2.19'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
  gem 'sqlite3',     '1.3.9'

end

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end


gem 'hirb'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'


development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000
答案

有几件事可能会导致这个问题。

你有postgres在运行吗? 你有没有把它添加到你的服务器?

你为pg安装了宝石吗?

您的设置应如下所示:

development:
  adapter: postgresql
  host: localhost
  username: user
  database: app-dev

你可以看看这个链接: https//devcenter.heroku.com/articles/heroku-postgresql#connecting-in-ruby ,它可能会帮助:)

注意::这应该是评论,但我没有足够的repoutation评论。

另一答案

在config / application.rb中添加以下行是我的问题的解决方案

 config.assets.initialize_on_precompile = false

以上是关于PG :: ConnectionBad:无法连接到服务器:连接被拒绝的主要内容,如果未能解决你的问题,请参考以下文章

Github 操作工作流 PG::ConnectionBad:无法连接到服务器:运行 bundle exec rake 时没有这样的文件或目录

PG::ConnectionBad: 运行 export DATABASE_URL=postgres://$(whoami) 后无法翻译主机名错误

如何修复:PG::ConnectionBad:fe_sendauth:未提供密码

text PG :: ConnectionBad FATAL:角色“Myname”不存在

PG::ConnectionBad FATAL: 角色“我的名字”不存在

Postgresql 适配器(pg):无法连接到服务器