ruby-on-rails – Rails – Postgres – 无法连接到服务器:连接被拒绝(PG :: ConnectionBad)

ruby-on-rails – Rails – Postgres – 无法连接到服务器:连接被拒绝(PG :: ConnectionBad),第1张

概述昨天我安装了Postgres和pgAdminIII,都运行正常,但重装后它停止工作.在rails服务器之后我收到错误消息: => Booting Thin=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000=> Call with -d to detach=> Ctrl-C to shutdown 昨天我安装了Postgres和pgadminIII,都运行正常,但重装后它停止工作.在rails服务器之后我收到错误消息:

=> Booting Thin=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000=> Call with -d to detach=> Ctrl-C to shutdown serverExiting/home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize': Could not connect to server: Connection refused (PG::ConnectionBad)        Is the server running on host "localhost" (127.0.0.1) and accepting        TCP/IP connections on port 5432?        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `new'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `connect'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:324:in `initialize'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'        from /home/home/.rvm/rubIEs/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'        from /home/home/.rvm/rubIEs/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrIEve_connection'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrIEve_connection'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/railtIE.rb:88:in `block in <class:RailtIE>'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/initializable.rb:30:in `run'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/initializable.rb:54:in `each'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/application.rb:136:in `initialize!'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/railtIE/configurable.rb:30:in `method_missing'        from /home/home/Projects/mostdance/config/environment.rb:5:in `<top (required)>'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.13/lib/active_support/dependencIEs.rb:251:in `require'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.13/lib/active_support/dependencIEs.rb:251:in `block in require'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.13/lib/active_support/dependencIEs.rb:236:in `load_dependency'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.13/lib/active_support/dependencIEs.rb:251:in `require'        from /home/home/Projects/mostdance/config.ru:3:in `block in <main>'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'        from /home/home/Projects/mostdance/config.ru:in `new'        from /home/home/Projects/mostdance/config.ru:in `<main>'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/commands/server.rb:46:in `app'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/commands/server.rb:70:in `start'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/commands.rb:50:in `tap'        from /home/home/.rvm/gems/ruby-1.9.3-p448/gems/railtIEs-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'        from script/rails:6:in `require'        from script/rails:6:in `<main>'

这是我的database.yml文件:

development:  host: localhost  adapter: postgresql  enCoding: unicode  database: mydb  pool: 5  timeout: 5000  username: postgres  password: password  min_messages: WARNINGtest:  host: localhost  adapter: sqlite3  database: db/test.sqlite3  pool: 5  timeout: 5000production:  adapter: postgresql  enCoding: unicode  database: mydb  pool: 5  timeout: 5000  username: postgres  password: password  host: 127.0.0.1  port: 5432  min_messages: WARNING

我也尝试运行服务器Postgres:

su postgres /etc/init.d/postgresql startPassword:  * Starting Postgresql 9.1 database server                                                                                                                                                       * Use of uninitialized value $info{"pgdata"} in -d at /usr/bin/pg_ctlcluster line 331.Use of uninitialized value $info{"pgdata"} in concatenation (.) or string at /usr/bin/pg_ctlcluster line 332.Error:  is not accessible or does not exist

另外我不知道为什么,但现在rails服务器发出此错误:

=> Booting Thin=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000=> Call with -d to detach=> Ctrl-C to shutdown serverExiting/home/home/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize': FATAL:  Peer authentication Failed for user "postgres" (PG::ConnectionBad)

请帮我!如果您需要更多信息 – 写入评论,我会更新我的问题

解决方法 当我过去遇到这个问题时,通常会有一些事情可以让它运行起来,其中大多数看似简单,但我很健忘 –

有时我切换到postgres后实际上没有创建数据库

bundle exec rake db:create

然后把我所有的桌子放在那里 –

bundle exec rake db:migrate

其他时候我需要仔细检查并确保安装PG gem

gem install pg
总结

以上是内存溢出为你收集整理的ruby-on-rails – Rails – Postgres – 无法连接到服务器:连接被拒绝(PG :: ConnectionBad)全部内容,希望文章能够帮你解决ruby-on-rails – Rails – Postgres – 无法连接到服务器:连接被拒绝(PG :: ConnectionBad)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1294434.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存