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

每次运行rails 4.0服务器时,我都会得到这个输出

于2013-11-06 23:56:36-0500开始获取127.0.0.1版本的“/”
PG::ConnectionBad-无法连接到服务器:连接被拒绝
服务器是否在主机“localhost”(::1)上运行并接受
端口5432上的TCP/IP连接?
无法连接到服务器:连接被拒绝
服务器是否在主机“localhost”(127.0.0.1)上运行并接受
端口5432上的TCP/IP连接?
无法连接到服务器:连接被拒绝
服务器是否在主机“localhost”(fe80::1)上运行并接受
端口5432上的TCP/IP连接?
:
activerecord(4.0.0)lib/active\u record/connection\u adapters/postgresql\u adapter.rb:825:in'connect'
activerecord(4.0.0)lib/active\u record/connection\u adapters/postgresql\u adapter.rb:542:in'initialize'
activerecord(4.0.0)lib/active\u record/connection\u adapters/postgresql\u adapter.rb:41:in`postgresql\u connection'
activerecord(4.0.0)lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:440:in'new\u connection'
activerecord(4.0.0)lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:450:in'checkout\u new\u connection'
activerecord(4.0.0)lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:421:in'acquire\u connection'
activerecord(4.0.0)lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:356:in`block in checkout'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/Ruby/2.0.0/monitor.rb:211:in'mon_synchronize'
activerecord(4.0.0)lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:355:in'checkout'
activerecord(4.0.0)lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in`block in connection'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/Ruby/2.0.0/monitor.rb:211:in'mon_synchronize'
activerecord(4.0.0)lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:264:in'connection'
activerecord(4.0.0)lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:546:in'retrieve\u connection'
activerecord(4.0.0)lib/active\u record/connection\u handling.rb:79:in'retrieve\u connection'
activerecord(4.0.0)lib/active\u record/connection\u handling.rb:53:in'connection'
activerecord(4.0.0)lib/active\u record/migration.rb:792:in'current\u version'
activerecord(4.0.0)lib/active\u record/migration.rb:800:in'needs\u migration'
activerecord(4.0.0)lib/active\u record/migration.rb:379:in'check\u pending!'
activerecord(4.0.0)lib/active_record/migration.rb:366:in'call'
actionpack(4.0.0)lib/action_dispatch/middleware/callbacks.rb:29:in'block in call'
activesupport(4.0.0)lib/active\u support/callbacks.rb:373:in``运行调用调用调用调用'
activesupport(4.0.0)lib/active\u support/callbacks.rb:80:in'run\u callbacks'
actionpack(4.0.0)lib/action_dispatch/middleware/callbacks.rb:27:in'call'
actionpack(4.0.0)lib/action_dispatch/middleware/reloader.rb:64:in'call'
actionpack(4.0.0)lib/action_dispatch/middleware/remote_ip.rb:76:in'call'
better_errors(0.9.0)lib/better_errors/middleware.rb:84:in'protected_app_call'
better_errors(0.9.0)lib/better_errors/middleware.rb:79:in'better_errors_call'
better_errors(0.9.0)lib/better_errors/middleware.rb:56:in'call'
actionpack(4.0.0)lib/action\u dispatch/middleware/debug\u exceptions.rb:17:in'call'
actionpack(4.0.0)lib/action\u dispatch/middleware/show\u exceptions.rb:30:in'call'
railties(4.0.0)lib/rails/rack/logger.rb:38:in'call_app'
railties(4.0.0)lib/rails/rack/logger.rb:21:in'block in call'
activesupport(4.0.0)lib/active\u support/taged\u logging.rb:67:in'block in taged'
activesupport(4.0.0)lib/active\u support/taged\u logging.rb:25:in'taged'
activesupport(4.0.0)lib/active\u support/taged\u logging.rb:67:in'taged'
railties(4.0.0)lib/rails/rack/logger.rb:21:in'call'
quiet_assets(1.0.2)lib/quiet_assets.rb:18:in'call_with_quiet_assets'
actionpack(4.0.0)lib/action\u dispatch/middleware/request\u id.rb:21:in'call'
rack(1.5.2)lib/rack/methodoverride.rb:21:in'call'
rack(1.5.2)lib/rack/runtime.rb:17:in'call'
activesupport(4.0.0)lib/active_support/cache/strategy/local_cache.rb:83:in'call'
机架(1.5.2)lib/rack/lock.rb:17:in'call'
actionpack(4.0.0)lib/action\u dispatch/middleware/static.rb:64:in'call'
railties(4.0.0)lib/rails/engine.rb:511:in'call'
railties(4.0.0)lib/rails/application.rb:97:in'call'
机架(1.5.2)lib/rack/content_length.rb:14:in'call'
精简(1.5.1)lib/thin/connection.rb:81:in'block in pre_进程'
精简(1.5.1)lib/thin/connection.rb:79:in'pre_进程'
精简(1.5.1)lib/thin/connection.rb:54:in'process'
精简(1.5.1)lib/thin/connection.rb:39:in'receive_data'
eventmachine(1.0.3)lib/eventmachine.rb:187:in'run'
精简(1.5.1)lib/thin/backends/base.rb:63:in'start'
thin(1.5.1)lib/thin/server.rb:159:in'start'
机架(1.5.2)lib/rack/handler/thin.rb:16:in'run'
机架(1.5.2)lib/rack/server.rb:264:in'start'
railties(4.0.0)lib/rails/commands/server.rb:84:in'start'
railties(4.0.0)lib/rails/commands.rb:78:in`block in<顶部(必需)>'
railties(4.0.0)lib/rails/commands.rb:73:in`<顶部(必需)>'
箱子/轨道:4:in`<主>'

我运行的是Mavericks OS X 10.9,所以我不知道这是否是问题所在。我已经尽了我所能,但似乎没有任何效果。我已经多次卸载并安装了postgres和pg gem

这是我的database.yml文件

开发:
适配器:postgresql
编码:unicode
数据库:metals-U开发目录
游泳池:5
用户名:
密码:
模板:template0
主机:本地主机
港口:5432
测试:&测验
适配器:postgresql
编码:unicode
数据库:metals-U测试
游泳池:5
用户名:
密码:
模板:template0
主机:本地主机
港口:5432
登台:
适配器:postgresql
编码:unicode
数据库:metals-U生产目录
游泳池:5
用户名:
密码:
模板:template0
主机:本地主机
制作:
适配器:postgresql
编码:unicode
数据库:metals-U生产目录
游泳池:5
用户名:
密码:
模板:template0
主机:本地主机
黄瓜:
&lt<:*测验

它可以像一个过时的PID文件一样简单。它可能会无声地失败,因为您的计算机没有完全完成关闭过程,这意味着postgres没有删除PID(进程id)文件

postgres使用PID文件来确保一次只运行一个服务器实例。因此,当它再次启动时,它会失败,因为已经有一个PID文件告诉postgres服务器的另一个实例已启动(即使它没有运行,也没有关闭并删除PID)

  1. 要修复此问题,请删除/重命名PID文件。查找postgres数据目录。在使用自制软件的macOS上,它位于/usr/local/var/postgres/中,
    或者/usr/local/var/log/其他系统可能是/usr/var/postgres/
  2. 要确保这是问题所在,请查看日志文件(server.log)。在最后几行中,您将看到:

致命:锁定文件"邮政署署长;已存在
提示:是否有另一个邮局主管(PID 347)正在数据目录中运行/usr/local/var/postgres“是什么

  1. 如果是这样,rm postmaster.pid

  2. 重新启动服务器。在使用launchctl(使用自制)的mac上,以下命令将重新启动服务器

    brew服务重新启动postgresql

或在较早版本的Brew上

launchctl unload homebrew.mxcl.postgresql.plist
launchctl load-w homebrew.mxcl.postgresql.plist

发表评论