2013-04-17 55 views
1

我將我的開發數據庫從SQLite切換到postgresql。我的應用程序可以在開發和生產(Heroku,postgresql)中工作,但現在我無法在新的postgresql開發數據庫中修改,刪除或創建記錄。用戶只能正確登錄,查看他們的個人資料信息和登出。上創建用戶爲什麼我的應用程序在從SQLite遷移後無法修改開發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從我的製作應用中創建.dump文件,然後將pgrestore用於新的空數據庫。所有看起來不錯,字段和記錄,但仍然無法修改,刪除或創建。只能登錄,並查看用戶配置文件。

  4. 跟隨Railscast #342 Migrating to PostgreSQL使用所有的步驟,包括龍頭寶石,正如在4:40開始描述的那樣。再次,所有看起來不錯,領域和記錄,但行爲與#3相同。

我可以通過pgAdmin GUI或psql mydatabase命令行直接與數據庫進行交互。

的database.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 

我的應用程序日誌顯示了成功的用戶signins,signouts並請求查看配置文件。它還顯示用戶如何通過點擊確認電子郵件中的鏈接成功更改密碼。它還會顯示用戶嘗試更改個人資料,刪除其帳戶或新用戶嘗試註冊時的錯誤。錯誤:

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"=>"[email protected]", "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" = '[email protected]' 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", "[email protected]"], ["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一直非常有幫助。

+0

你的'database.yml'中沒有'host'? ActiveRecord :: Base.connection.execute('select count(*)from users')'必須從Rails控制檯說出什麼? –

+0

我在'database.yml'中有'host:localhost:5432',但Rails Server無法解析並且無法啓動。 Rails控制檯返回'(1.0ms)select count(*)from users =>#'我可以通過'User.find_by_email(「user @ example .com「)' –

回答

1

我可以通過pgAdmin GUI或psql> mydatabase命令行直接與數據庫進行交互。

那麼爲什麼要不停地擺弄數據庫呢?這不是導致你問題的部分。

此:

EBADF:壞的文件描述符

表明連接有問題,或者甚至是與數據庫的連接庫本身的問題。

打開PostgreSQL中的連接日誌記錄。在應用程序中打開日誌記錄。確保在進一步查看之前可以進行連接。

+0

我更新了我的問題,包括postgresql和應用程序日誌記錄。我看到數據庫連接成功,postgresql日誌中沒有錯誤。應用程序日誌顯示錯誤。我看到'壞文件描述符'提到但不知道這意味着什麼,''id = $ 1'這是不正確的,可能是我的問題? –

+0

'$ 1'是一個佔位符,用於實際值,例如57.這很好。 rb_thread_select()中的文件描述符錯誤是當外部庫(libpq)與數據庫進行通信時進行線程鎖定的原因。爲什麼它失敗了,我不能說,儘管你的Ruby安裝有些問題。 –

相關問題