1

我将我的开发数据库从 SQLite 切换到了 postgresql。我的应用程序在开发和生产(Heroku、postgresql)中都可以工作,但现在我无法在新的 postgresql 开发数据库中修改、删除或创建记录。用户只能正确登录、查看他们的个人资料信息和注销。

创建用户时出错:

ActiveRecord::StatementInvalid in Devise::RegistrationsController#create

Errno::EBADF: Bad file descriptor - rb_thread_select(): INSERT INTO "users" ("field1", "field2", "field3", ...etc continues through..., "Field28") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28) RETURNING "id"

删除用户错误:

ActiveRecord::StatementInvalid in Devise::RegistrationsController#destroy

Errno::EBADF: Bad file descriptor - rb_thread_select(): DELETE FROM "users" WHERE "users"."id" = $1

这一切都在生产中正确运行。

我在 Windows 7 上使用 Cygwin 并使用 pgAdmin Windows 包安装 postgresql。

我使用以下方法创建了 4 次不同的新数据库,所有这些方法都产生了与上述相同的结果。

  1. 在 pgAdmin 中创建了一个空数据库并使用rake db:migrate正确创建了字段,但应用程序无法创建记录。

  2. 在 pgAdmin 中创建了一个空数据库,然后使用db:schema:load与 #1 相同的结果。

  3. 在 pgAdmin 中创建了一个空数据库。用于从我的生产应用程序pgbackups创建一个文件,然后用于新的空数据库。一切看起来都不错,字段和记录,但仍然无法修改、删除或创建。只能登录,并查看用户个人资料。.dumppgrestore

  4. 按照Railscast #342 迁移到 PostgreSQL使用所有步骤,包括 Taps Gem,完全按照 4:40 开始的描述。同样,所有字段和记录看起来都不错,但行为与 #3 相同。

我可以通过 pgAdmin GUI 或psql mydatabase命令行直接与数据库交互。

数据库.yml

development:
  adapter: postgresql
  encoding: unicode
  database: devdatabase
  pool: 5
  username: postgres
  password: 'password'

test:
  adapter: postgresql
  encoding: unicode
  database: testdatabase
  pool: 5
  username: postgress
  password: 'password'

我的 postgresql 日志显示成功连接到数据库:

2013-04-18 15:12:09 EDT LOG:  database system was shut down at 2013-04-18 15:03:00 EDT
2013-04-18 15:12:09 EDT LOG:  database system is ready to accept connections
2013-04-18 15:12:09 EDT LOG:  autovacuum launcher started
2013-04-18 15:12:10 EDT LOG:  connection received: host=::1 port=58635
2013-04-18 15:13:14 EDT LOG:  connection received: host=::1 port=58637
2013-04-18 15:13:14 EDT LOG:  connection authorized: user=postgres database=brdevelopment
2013-04-18 15:13:25 EDT LOG:  connection received: host=::1 port=58653
2013-04-18 15:13:25 EDT LOG:  connection authorized: user=postgres database=brdevelopment
2013-04-18 15:18:32 EDT LOG:  received fast shutdown request
2013-04-18 15:18:32 EDT LOG:  aborting any active transactions
2013-04-18 15:18:32 EDT LOG:  autovacuum launcher shutting down
2013-04-18 15:18:32 EDT LOG:  shutting down
2013-04-18 15:18:32 EDT LOG:  database system is shut down

我的应用程序日志显示成功的用户登录、注销和查看配置文件的请求。它还显示了用户如何通过单击确认电子邮件中的链接成功更改密码。当用户尝试更改其个人资料、删除其帐户或新用户尝试注册时,它还会显示错误。错误:

  Rendered /home/Pavilion/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
  Rendered /home/Pavilion/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.0ms)
  Rendered /home/Pavilion/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (42.0ms)
Connecting to database specified by database.yml
Connecting to database specified by database.yml

...

Started DELETE "/users" for 127.0.0.1 at 2013-04-18 15:14:20 -0400
Processing by Devise::RegistrationsController#destroy as HTML
  Parameters: {"authenticity_token"=>"xxxxx="}
  [1m[35mUser Load (0.0ms)[0m  SELECT "users".* FROM "users" WHERE "users"."id" = 57 LIMIT 1
  [1m[36m (0.0ms)[0m  [1mBEGIN[0m
  [1m[35mSQL (1.0ms)[0m  DELETE FROM "users" WHERE "users"."id" = $1  [["id", 57]]
Errno::EBADF: Bad file descriptor - rb_thread_select(): DELETE FROM "users" WHERE "users"."id" = $1
  [1m[36m (0.0ms)[0m  [1mROLLBACK[0m
Completed 500 Internal Server Error in 5ms

ActiveRecord::StatementInvalid (Errno::EBADF: Bad file descriptor - rb_thread_select(): DELETE FROM "users" WHERE "users"."id" = $1):
  activerecord (3.2.11) lib/active_record/connection_adapters/postgresql_adapter.rb:1165:in `block'
  activerecord (3.2.11) lib/active_record/connection_adapters/postgresql_adapter.rb:1165:in `exec_cache'
  activerecord (3.2.11) lib/active_record/connection_adapters/postgresql_adapter.rb:674:in `block in exec_delete'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
  activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
  activerecord (3.2.11) lib/active_record/connection_adapters/postgresql_adapter.rb:672:in `exec_delete'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:101:in `delete'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `delete'
  activerecord (3.2.11) lib/active_record/relation.rb:413:in `delete_all'
  activerecord (3.2.11) lib/active_record/persistence.rb:141:in `destroy'
  activerecord (3.2.11) lib/active_record/locking/optimistic.rb:103:in `destroy'
  activerecord (3.2.11) lib/active_record/callbacks.rb:254:in `block in destroy'
  activesupport (3.2.11) lib/active_support/callbacks.rb:403:in `_run__747758159__destroy__128269692__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_destroy_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  activerecord (3.2.11) lib/active_record/callbacks.rb:254:in `destroy'
  activerecord (3.2.11) lib/active_record/transactions.rb:254:in `block in destroy'
  activerecord (3.2.11) lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
  activerecord (3.2.11) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (3.2.11) lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
  activerecord (3.2.11) lib/active_record/transactions.rb:254:in `destroy'
  devise (2.2.3) app/controllers/devise/registrations_controller.rb:59:in `destroy'
  actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.2.11) lib/active_support/callbacks.rb:436:in `_run__389569436__process_action__28646103__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
  actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.11) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `call'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in `call'
  actionpack (3.2.11) lib/action_dispatch/routing/mapper.rb:42:in `call'
  journey (1.0.4) lib/journey/router.rb:68:in `block in call'
  journey (1.0.4) lib/journey/router.rb:56:in `each'
  journey (1.0.4) lib/journey/router.rb:56:in `call'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
  omniauth (1.1.3) lib/omniauth/strategy.rb:177:in `call!'
  omniauth (1.1.3) lib/omniauth/strategy.rb:157:in `call'
  meta_request (0.2.3) lib/meta_request/middlewares/app_request_handler.rb:11:in `call'
  rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.2.3) lib/meta_request/middlewares/headers.rb:16:in `call'
  meta_request (0.2.3) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.1) lib/warden/manager.rb:34:in `catch'
  warden (1.2.1) lib/warden/manager.rb:34:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.5) lib/rack/etag.rb:23:in `call'
  rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
  rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__111743413__call__128269692__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.11) lib/rails/engine.rb:479:in `call'
  railties (3.2.11) lib/rails/application.rb:223:in `call'
  rack (1.4.5) lib/rack/content_length.rb:14:in `call'
  railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
  /home/Pavilion/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /home/Pavilion/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /home/Pavilion/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

...

Started POST "/users" for 127.0.0.1 at 2013-04-18 15:15:23 -0400
Processing by Devise::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"xxxxx=", "user"=>{"email"=>"me@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
  [1m[36m (1.0ms)[0m  [1mBEGIN[0m
  [1m[35mUser Exists (0.0ms)[0m  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'me@example.com' LIMIT 1
  [1m[36mUser Load (0.0ms)[0m  [1mSELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'xxxxx' LIMIT 1[0m
  [1m[35mSQL (1.0ms)[0m  INSERT INTO "users" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "description", "email", "encrypted_password", "first_name", "headline", "image", "industry", "last_name", "last_sign_in_at", "last_sign_in_ip", "location", "name", "nickname", "provider", "public_profile", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "uid", "unconfirmed_email", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28) RETURNING "id"  [["confirmation_sent_at", Thu, 18 Apr 2013 19:15:23 UTC +00:00], ["confirmation_token", "xxxxx"], ["confirmed_at", nil], ["created_at", Thu, 18 Apr 2013 19:15:23 UTC +00:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["description", nil], ["email", "me@example.com"], ["encrypted_password", "xxxxx"], ["first_name", nil], ["headline", nil], ["image", nil], ["industry", nil], ["last_name", nil], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["location", nil], ["name", nil], ["nickname", nil], ["provider", nil], ["public_profile", nil], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["sign_in_count", 0], ["uid", nil], ["unconfirmed_email", nil], ["updated_at", Thu, 18 Apr 2013 19:15:23 UTC +00:00]]
Errno::EBADF: Bad file descriptor - rb_thread_select(): INSERT INTO "users" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "description", "email", "encrypted_password", "first_name", "headline", "image", "industry", "last_name", "last_sign_in_at", "last_sign_in_ip", "location", "name", "nickname", "provider", "public_profile", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "uid", "unconfirmed_email", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28) RETURNING "id"
  [1m[36m (1.0ms)[0m  [1mROLLBACK[0m
Completed 500 Internal Server Error in 469ms

ActiveRecord::StatementInvalid (Errno::EBADF: Bad file descriptor - rb_thread_select(): INSERT INTO "users" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "description", "email", "encrypted_password", "first_name", "headline", "image", "industry", "last_name", "last_sign_in_at", "last_sign_in_ip", "location", "name", "nickname", "provider", "public_profile", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "uid", "unconfirmed_email", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28) RETURNING "id"):


...

Started DELETE "/users" for 127.0.0.1 at 2013-04-18 15:17:25 -0400
Processing by Devise::RegistrationsController#destroy as HTML
  Parameters: {"authenticity_token"=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="}
  [1m[35mUser Load (1.0ms)[0m  SELECT "users".* FROM "users" WHERE "users"."id" = 57 LIMIT 1
  [1m[36m (3.0ms)[0m  [1mBEGIN[0m
  [1m[35mSQL (0.0ms)[0m  DELETE FROM "users" WHERE "users"."id" = $1  [["id", 57]]
Errno::EBADF: Bad file descriptor - rb_thread_select(): DELETE FROM "users" WHERE "users"."id" = $1
  [1m[36m (1.0ms)[0m  [1mROLLBACK[0m
Completed 500 Internal Server Error in 7ms

ActiveRecord::StatementInvalid (Errno::EBADF: Bad file descriptor - rb_thread_select(): DELETE FROM "users" WHERE "users"."id" = $1):

为什么我不能从我新创建的开发数据库中获得全部功能,而一切都在生产中正常工作?我从我的研究中了解到,在开发和生产中拥有相同的数据库非常重要。

我是新手,正在学习 ruby​​、rails、数据库和 postgresql。stackoverflow 非常有帮助。

4

1 回答 1

1

我可以通过 pgAdmin GUI 或 psql > mydatabase 命令行直接与数据库交互。

那么为什么要继续摆弄数据库呢?那不是导致您出现问题的部分。

这个:

EBADF:错误的文件描述符

表明连接有问题,甚至可能是数据库连接库本身的问题。

在 PostgreSQL 中打开连接日志记录。在您的应用程序中打开登录。在进一步查看之前,请确保您可以连接。

于 2013-04-17T22:00:01.613 回答