ruby-on-rails - PG::ConnectionBad,无法连接到服务器

标签 ruby-on-rails database connection

我在使用 Rails 应用程序时遇到问题,而其他人正在处理的很少。我刚刚克隆了 repo,并执行 rails db:migrate 或尝试访问页面(当服务器正在运行时)导致此错误:

Started GET "/" for 127.0.0.1 at 2017-06-18 11:58:41 +0100

PG::ConnectionBad (could not connect to server: Cannot assign requested address (0x00002741/10049)
    Is the server running on host "0.0.0.0" and accepting
    TCP/IP connections on port 6543?
):

pg-0.19.0-x64 (mingw32) lib/pg.rb:45:in 'initialize'
pg-0.19.0-x64 (mingw32) lib/pg.rb:45:in 'new'
pg-0.19.0-x64 (mingw32) lib/pg.rb:45:in 'connect'
activerecord (5.1.1) lib/active_record/connection_adapters/postgresql_adapter.rb:701:in 'connect'
activerecord (5.1.1) lib/active_record/connection_adapters/postgresql_adapter.rb:220:in 'initialize'
activerecord (5.1.1) lib/active_record/connection_adapters/postgresql_adapter.rb:38:in 'new'
activerecord (5.1.1) lib/active_record/connection_adapters/postgresql_adapter.rb:38:in 'postgresql_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:759:in 'new_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:803:in 'checkout_new_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:782:in 'try_to_checkout_new_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:743:in 'acquire_connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:500:in 'checkout'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in 'connection'
activerecord (5.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in 'retrieve_connection'
activerecord (5.1.1) lib/active_record/connection_handling.rb:116:in 'retrieve_connection'
activerecord (5.1.1) lib/active_record/connection_handling.rb:88:in 'connection'
activerecord (5.1.1) lib/active_record/migration.rb:562:in 'connection'
activerecord (5.1.1) lib/active_record/migration.rb:553:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/callbacks.rb:26:in 'block in call'
activesupport (5.1.1) lib/active_support/callbacks.rb:97:in 'run_callbacks'
actionpack (5.1.1) lib/action_dispatch/middleware/callbacks.rb:24:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/executor.rb:12:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:59:in 'call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in 'call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in 'block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in 'catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in 'call'
railties (5.1.1) lib/rails/rack/logger.rb:36:in 'call_app'
railties (5.1.1) lib/rails/rack/logger.rb:24:in 'block in call'
activesupport (5.1.1) lib/active_support/tagged_logging.rb:69:in 'block in tagged'
activesupport (5.1.1) lib/active_support/tagged_logging.rb:26:in 'tagged'
activesupport (5.1.1) lib/active_support/tagged_logging.rb:69:in 'tagged'
railties (5.1.1) lib/rails/rack/logger.rb:24:in 'call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/remote_ip.rb:79:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/request_id.rb:25:in 'call'
rack (2.0.3) lib/rack/method_override.rb:22:in 'call'
rack (2.0.3) lib/rack/runtime.rb:22:in 'call'
activesupport (5.1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/executor.rb:12:in 'call'
actionpack (5.1.1) lib/action_dispatch/middleware/static.rb:125:in 'call'
rack (2.0.3) lib/rack/sendfile.rb:111:in 'call'
railties (5.1.1) lib/rails/engine.rb:522:in 'call'
puma (3.9.1) lib/puma/configuration.rb:224:in 'call'
puma (3.9.1) lib/puma/server.rb:602:in 'handle_request'
puma (3.9.1) lib/puma/server.rb:435:in 'process_client'
puma (3.9.1) lib/puma/server.rb:299:in 'block in run'
puma (3.9.1) lib/puma/thread_pool.rb:120:in 'call'
puma (3.9.1) lib/puma/thread_pool.rb:120:in 'block in spawn_thread'

我读过类似的问题,都说要重新启动 postgres,但是在 Windows 上有点乱,所以我重新启动了我的笔记本电脑,但没有解决任何问题。我还尝试重新克隆 repo 协议(protocol)。

请注意,其他 Rails 项目确实有效,这让我认为它与 database.yml 有关,但我真的不知道从那里可以做什么。 干杯

最佳答案

然后确保你的 postgresql 服务正在运行 确保您已经创建了您的应用程序所需的数据库,您可以执行 rake db:create

另请参阅您的 database.yml。默认配置是这样的

development:
<<: *default
database: yourappname_development

您还可以添加连接到您的 postgres 所需的信息,例如,

port: 
username: 
password: 
hostname: 

您可以从另一个正在运行的 Rails 应用程序中获取示例

关于ruby-on-rails - PG::ConnectionBad,无法连接到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44614424/

相关文章:

javascript - 使用 RSpec 和 JS 选择元素

mysql - rails : Proper way for MySQL query to search multiple attributes

ruby-on-rails - rails 3 : Storing Session in Active Record (not cookie)

javascript - 与客户端的持久连接

ruby-on-rails - 在 ruby​​ on rails 应用程序中使用 application.html.erb 以外的布局?

database - ms Access 转储到 sql 插入

php - 在Mysql中过滤数据

.net - Silverlight 作为前端。后端技术有哪些可能的选择?

java - 如何使 HSQL 驱动程序工作?

java - JmsTemplate 无法发送响应,因为 javax.jms.IllegalStateException : Session is closed