“PGError:闲置后没有连接到服务器”

时间:2011-01-12 23:50:28

标签: ruby-on-rails apache postgresql

我的应用程序在一夜之间闲置,当我尝试在早上访问它时,我收到500内部服务器错误,日志显示“PGError:没有连接到服务器”。在第一次请求之后,如果我再次刷新页面,一切都很好。

我正在远程服务器上运行带有apache 2,Passenger 3.0.2,Rails 2.3.8和Postgres 8.4的Ubuntu 10.04。

任何想法如何解决这个问题?

这是日志:

Processing ApplicationController#index (for 192.168.1.33 at 2011-01-06 17:28:14) [GET]
  Parameters: {"action"=>"index", "controller"=>"da"}
ActiveRecord::StatementInvalid (PGError: no connection to the server
: SELECT * FROM "users" WHERE ("users"."id" = 1)  LIMIT 1):
  app/controllers/application_controller.rb:47:in `current_user'
  app/controllers/application_controller.rb:51:in `set_current_user'
  app/controllers/application_controller.rb:123:in `render_optional_error_file'
  passenger (3.0.2) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
  passenger (3.0.2) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
  passenger (3.0.2) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
  passenger (3.0.2) lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
  passenger (3.0.2) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
  passenger (3.0.2) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
  passenger (3.0.2) lib/phusion_passenger/utils.rb:479:in `safe_fork'
  passenger (3.0.2) lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
  passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
  passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:180:in `start'
  passenger (3.0.2) lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
  passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
  passenger (3.0.2) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
  passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
  passenger (3.0.2) lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
  passenger (3.0.2) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
  passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
  passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
  passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
  passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
  passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.2) helper-scripts/passenger-spawn-server:99
/!\ FAILSAFE /!\  Thu Jan 06 17:28:14 -0700 2011
  Status: 500 Internal Server Error
  PGError: no connection to the server
: SELECT * FROM "users" WHERE ("users"."id" = 1)  LIMIT 1
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb:221:in `log'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/postgresql_adapter.rb:520:in `execute'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1002:in `select_raw'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/postgresql_adapter.rb:989:in `select'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1578:in `find_every'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1535:in `find_initial'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:616:in `find'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1910:in `find_by_id'
    /home/user/application/releases/20110106230903/app/controllers/application_controller.rb:47:in `current_user'
    /home/user/application/releases/20110106230903/app/controllers/application_controller.rb:51:in `set_current_user'
    /home/user/application/releases/20110106230903/app/controllers/application_controller.rb:123:in `render_optional_error_file'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/rescue.rb:97:in `rescue_action_in_public'
    /home/user/application/releases/20110106230903/vendor/plugins/exception_notification/lib/exception_notification/notifiable.rb:48:in `rescue_action_in_public'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/rescue.rb:154:in `rescue_action_without_handler'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/rescue.rb:74:in `rescue_action'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `send'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/base.rb:532:in `process_without_filters'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/filters.rb:606:in `process'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/rescue.rb:65:in `call_with_exception'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:90:in `dispatch'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:121:in `_call'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:130
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/query_cache.rb:29:in `call'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/query_cache.rb:29:in `call'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/query_cache.rb:9:in `cache'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/query_cache.rb:28:in `call'
    /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/string_coercion.rb:25:in `call'
    /var/lib/gems/1.8/gems/rack-1.1.0/lib/rack/head.rb:9:in `call'
    /var/lib/gems/1.8/gems/rack-1.1.0/lib/rack/methodoverride.rb:24:in `call'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/params_parser.rb:15:in `call'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/session/cookie_store.rb:99:in `call'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/failsafe.rb:26:in `call'
    /var/lib/gems/1.8/gems/rack-1.1.0/lib/rack/lock.rb:11:in `call'
    /var/lib/gems/1.8/gems/rack-1.1.0/lib/rack/lock.rb:11:in `synchronize'
    /var/lib/gems/1.8/gems/rack-1.1.0/lib/rack/lock.rb:11:in `call'
    /var/lib/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:106:in `call'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/utils.rb:479:in `safe_fork'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:180:in `start'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:357:in `__send__'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
    /var/lib/gems/1.8/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
    /var/lib/gems/1.8/gems/passenger-3.0.2/helper-scripts/passenger-spawn-server:99

2 个答案:

答案 0 :(得分:1)

在研究我自己的这个问题的版本时遇到了这个问题。它看起来好像你在spawn库中使用fork方法(可能是Phusion Passenger的一部分?),此时它似乎与Postgres兼容。

我希望这为您和/或下一位访客提供了可能的线索。

答案 1 :(得分:0)

尝试通过将此行添加到database.yml文件来关闭SSL数据库连接:

sslmode: disable