postgresql PG::Error 服务器意外关闭连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12796313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:24:07  来源:igfitidea点击:

PG::Error server closed the connection unexpectedly

ruby-on-railsrubypostgresql

提问by Jashwant

I am new to Ruby on rails. I've created two basic demo apps by tutorial learning by examples

我是 Ruby on rails 的新手。我通过教程创建了两个基本的演示应用程序learning by examples

and suddenly it stops working for my new sample app.

突然它停止为我的新示例应用程序工作。

I have generated a controller Pagesand two actions homeand contactand nothing fancy.

我已经产生了控制器Pages和两个动作home,并contact和没有什么花哨。

Now, I am not able to open any pages, except the default index.html rails page at localhost:3000. The page at localhost:3000/pages/homeand localhost:3000/pages/contactreturns this error.

现在,我无法打开任何页面,除了默认的 index.html rails 页面localhost:3000。页面localhost:3000/pages/homelocalhost:3000/pages/contact返回此错误。

PG::Error

server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.

PG::错误

服务器意外关闭连接 这可能意味着服务器在处理请求之前或处理请求时异常终止。

and sometimes (usually when I restart postgresql),

有时(通常当我重新启动 postgresql 时),

PG::Error

server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. could not send startup packet: Broken pipe

PG::错误

服务器意外关闭连接 这可能意味着服务器在处理请求之前或处理请求时异常终止。 无法发送启动包:管道损坏

This is my stack trace

这是我的堆栈跟踪

activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in initialize' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in new' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in connect' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:329:in initialize' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:28:in new' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:28:in postgresql_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in new_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in checkout_new_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in block (2 levels) in checkout' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in loop' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in block in checkout' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in checkout' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in block in connection' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in retrieve_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in retrieve_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in connection' activerecord (3.2.8) lib/active_record/query_cache.rb:67:inrescue in call' activerecord (3.2.8) lib/active_record/query_cache.rb:61:in call' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in call' actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in block in call' activesupport (3.2.8) lib/active_support/callbacks.rb:405:in run_3261957284442330683_call_599627944998934036__callbacks' activesupport (3.2.8) lib/active_support/callbacks.rb:405:in __run_callback' activesupport (3.2.8) lib/active_support/callbacks.rb:385:in_run_call_callbacks' activesupport (3.2.8) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:incall' actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in call' actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in call' actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in call' actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:incall' railties (3.2.8) lib/rails/rack/logger.rb:26:in call_app' railties (3.2.8) lib/rails/rack/logger.rb:16:incall' actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in call' rack (1.4.1) lib/rack/methodoverride.rb:21:incall' rack (1.4.1) lib/rack/runtime.rb:17:in call' activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:incall' rack (1.4.1) lib/rack/lock.rb:15:in call' actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:incall' railties (3.2.8) lib/rails/engine.rb:479:in call' railties (3.2.8) lib/rails/application.rb:223:incall' rack (1.4.1) lib/rack/content_length.rb:14:in call' railties (3.2.8) lib/rails/rack/log_tailer.rb:17:incall' rack (1.4.1) lib/rack/handler/webrick.rb:59:in service' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in service' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in run' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in block in start_thread'

activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in initialize' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in new'activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in connect' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:329:in 初始化'activerecord (3.2.8) lib/ active_record/connection_adapters/postgresql_adapter.rb:28:in new' activerecord (3.2.8) lib/active_record/connection_adapters/postgresql_adapter.rb:28:in postgresql_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in new_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in checkout_new_connection' activerecord (3.2.8) lib/active_adtracters/connection connection_pool.rb:241:in block (2 levels) in checkout' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in loop' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in block in checkout' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb: 233:输入 checkout' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in 阻止连接'/home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in connection' activerecord (3.2.8) lib/active_record/connection_adapters /abstract/connection_pool.rb:404:inretrieve_connection'activerecord retrieve_connection' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:144:connection' activerecord (3.2.8) lib/active_record/query_cache.rb:67:in在调用中的 救援中'activerecord (3.2.8) lib/active_record/query_cache.rb :61:in call' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in call' actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in block in call' activesupport (3.2.8) lib/active_support/callbacks.rb:405:in run_3261957284442330683_ call_5996279444998934036__callbacks' activecall lib/action_dispatch/middleware/callbacks.rb:28:in run_3261957284442330683_ call_599627944998934036__callbacks' activecall lib/action_dispatch/middleware/callbacks.rb:28:in run_3261957284442330627944998934036__callbacks' activecall lib/action_dispatch/middleware/callbacks.rb: __run_callback' activesupport (3.2.8) lib/active_support/callbacks.rb:385:in3.261957284444998934036 (3.2.8) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:incall' actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in call' actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in call' actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in call' actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:incall' railties (3.2.8) lib/rails/rack/logger.rb:26:in call_app' railties (3.2.8) lib/rails/rack/logger.rb:16:incall' actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in call' rack (1.4.1) lib/rack/methodoverride.rb:21:incall' rack (1.4.1) lib/rack/runtime.rb: 17:in call' activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:incall'rack (1.4.1) lib/rack/lock.rb:15:in call' actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:incall' railties (3.2.8) lib/rails/engine.rb:479:in call'rack call' railties (3.2.8) lib/rails/application.rb:223:in(1.4.1) lib /rack/content_length.rb:14:in call'rack call' railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in(1.4.1) lib/rack/handler/webrick.rb:59:in service' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in service' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194 /lib/ruby/1.9.1/webrick/httpserver.rb:94:in run' /home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in block in start_thread'

I am not using database for now. I tried to do rake db:migratebut it returns the same error.

我现在不使用数据库。我尝试这样做,rake db:migrate但它返回相同的错误。

I am on Ubuntu 12.04 (as some bugs on google were related to ubuntu)

我使用的是 Ubuntu 12.04(因为 google 上的一些错误与 ubuntu 相关)

I have found similar questions on SO, but they are experiencing at some advance stage and thus involves some advance solutions.

我在 SO 上发现了类似的问题,但他们正在经历某个高级阶段,因此涉及一些高级解决方案。

采纳答案by Jashwant

Although, I am not using the database but specifying the port in configuration in database.ymlsolves the problem. By default, the rails new <app_name> --database=postgresqlcommand does not put a portthere.

虽然,我没有使用数据库,但在配置中指定端口database.yml解决了问题。默认情况下,该rails new <app_name> --database=postgresql命令不会在port那里放置。

Here's my config.

这是我的配置。

development:
  adapter: postgresql
  encoding: unicode
  database: sample_app_development
  pool: 5  
  port: 5433
  username: myusername
  password: mypassword
  reconnect: true