2013-03-12 60 views
0

我在本地服務器中設置了Rail application。我正在使用Postgresql數據庫。如何解決Rails中的身份驗證錯誤?

但它創造的錯誤:

錯誤消息: FATAL:身份認證失敗 「nobody」 用戶(PG ::錯誤)

Exception類: PhusionPassenger ::不明錯誤

回溯:

File Line Location 
0 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb  1208 in `initialize' 
1 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb  1208 in `new' 
2 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb  1208 in `connect' 
3 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb  326  in `initialize' 
4 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb  28 in `new' 
5 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb  28 in `postgresql_connection' 
6 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 315  in `new_connection' 
7 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 325  in `checkout_new_connection' 
8 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 247  in `block (2 levels) in checkout' 
9 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 242  in `loop' 
10 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 242  in `block in checkout' 
11 /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb  211  in `mon_synchronize' 
12 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 239  in `checkout' 
13 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 102  in `block in connection' 
14 /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb  211  in `mon_synchronize' 
15 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 101  in `connection' 
16 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb 410  in `retrieve_connection' 
17 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb 171  in `retrieve_connection' 
18 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb 145  in `connection' 
19 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/sanitization.rb 130  in `replace_bind_variables' 
20 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/sanitization.rb 117  in `sanitize_sql_array' 
21 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/sanitization.rb 28 in `sanitize_sql_for_conditions' 
22 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/relation/query_methods.rb  324  in `build_where' 
23 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/relation/query_methods.rb  136  in `where' 
24 /usr/local/rvm/gems/[email protected]/gems/activerecord-3.2.11/lib/active_record/querying.rb 9 in `where' 
25 /var/www/PCMI/zil/app/models/order.rb 8 in `' 
26 /var/www/PCMI/zil/app/models/order.rb 1 in `' 
27 /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  251  in `require' 
28 /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  251  in `block in require' 
29 /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  236  in `load_dependency' 
30 /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  251  in `require' 
31 /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  359  in `require_or_load' 
32 /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  313  in `depend_on' 
33 /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/dependencies.rb  225  in `require_dependency' 
34 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/engine.rb  439  in `block (2 levels) in eager_load!' 
35 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/engine.rb  438  in `each' 
36 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/engine.rb  438  in `block in eager_load!' 
37 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/engine.rb  436  in `each' 
38 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/engine.rb  436  in `eager_load!' 
39 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/finisher.rb 53 in `block in ' 
40 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb 30 in `instance_exec' 
41 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb 30 in `run' 
42 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb 55 in `block in run_initializers' 
43 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb 54 in `each' 
44 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb 54 in `run_initializers' 
45 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application.rb 136  in `initialize!' 
46 /usr/local/rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/railtie/configurable.rb 30 in `method_missing' 
47 /var/www/PCMI/zil/config/environment.rb  5 in `' 
48 config.ru 3 in `require' 
49 config.ru 3 in `block in ' 
50 /usr/local/rvm/gems/[email protected]/gems/rack-1.4.5/lib/rack/builder.rb 51 in `instance_eval' 
51 /usr/local/rvm/gems/[email protected]/gems/rack-1.4.5/lib/rack/builder.rb 51 in `initialize' 
52 config.ru 1 in `new' 
53 config.ru 1 in `' 
54 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/rack/application_spawner.rb 225  in `eval' 
55 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/rack/application_spawner.rb 225  in `load_rack_app' 
56 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/rack/application_spawner.rb 157  in `block in initialize_server' 
57 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/utils.rb  563  in `report_app_init_status' 
58 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/rack/application_spawner.rb 154  in `initialize_server' 
59 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb 204  in `start_synchronously' 
60 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb 180  in `start' 
61 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/rack/application_spawner.rb 129  in `start' 
62 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb  253  in `block (2 levels) in spawn_rack_application' 
63 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server_collection.rb 132  in `lookup_or_add' 
64 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb  246  in `block in spawn_rack_application' 
65 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server_collection.rb 82 in `block in synchronize' 
66 < td=""> <> prelude> 10:in `synchronize' 
67 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server_collection.rb 79 in `synchronize' 
68 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb  244  in `spawn_rack_application' 
69 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb  137  in `spawn_application' 
70 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb  275  in `handle_spawn_application' 
71 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb 357  in `server_main_loop' 
72 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb 206  in `start_synchronously' 
73 /usr/local/rvm/gems/[email protected]/gems/passenger-3.0.17/helper-scripts/passenger-spawn-server 

的config/database.yml的

development: 

    adapter: postgresql 
    encoding: utf8 
    database: PCMI 
    pool: 5 
    username: postgres 
    password: postgres 


test: &TEST 

    adapter: postgresql 
    encoding: utf8 
    database: PCMI 
    pool: 5 
    username: postgres 
    password: postgres 

production: 

    adapter: postgresql 
    encoding: utf8 
    database: PCMI 
    pool: 5 
    username: postgres 
    password: postgres 

請幫我如果您需要有關這些錯誤,那麼PLZ告知任何進一步的信息解決這個錯誤..

謝謝。

+0

請發佈您的config/database.yml文件 – plasticide 2013-03-12 12:06:58

+0

我張貼我的config/database.yml文件。 – Zeel 2013-03-12 12:21:46

+0

您正在使用相同的數據庫進行開發和測試。這在開發應用程序時可能會有問題。但我不是你的連接問題的原因。首先登錄到命令行客戶端(psql)並確保您的憑據適用於數據庫。之後,參考[這個答案](http://stackoverflow.com/questions/9491537/rails-postgresql-db-connection-fails)關於如何設置您的客戶端身份驗證文件,以便您可以使用用戶名連接到它/ localhost上的密碼。 – plasticide 2013-03-12 13:29:39

回答

1

PostgreSQL有兩種認證模式。一種是通過Unix套接字認證,這意味着PostgreSQL檢查連接到PostgreSQL的進程的用戶,然後檢查該用戶是否有權訪問數據庫。這種認證模式是您通過pg命令從命令行訪問PostgreSQL時通常使用的模式。

第二個是您已經熟悉的基於密碼的身份驗證。

看起來你沒有爲「postgres」用戶正確設置密碼認證。最重要的是,您的應用程序以「nobody」用戶身份運行,因此PostgreSQL無法通過Unix套接字對您的應用程序進行身份驗證。

解決方法是製作一個PostgreSQL用戶名/密碼認證條目,並將其填充到您的database.yml中。