2012-12-01 92 views
3

當我運行分貝我得到這個錯誤:創建:無法訪問Postgres的文件pg_hba.conf中

FATAL: Peer authentication failed for user "wandrr" 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout' 
/home/jack/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection' 
/home/jack/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection' 
....Edit out 40 more of these warnings... 
/home/jack/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval' 
/home/jack/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>' 
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"wandrr_test", "pool"=>5, "username"=>"wandrr", "password"=>nil} 

所以我想通了,我需要編輯pg_hba.conf的問題是...它將無法打開。它一直告訴我我沒有權限使用此文件。那麼我如何獲得許可?我正在運行ubuntu 12.10和rails 1.9.3和postgres 9.1

+0

您是否嘗試使用sudo編輯它:'sudo vi pg_hba.conf'? –

+1

你......沒什麼出現。我以爲它被認爲是充滿了文字? – Jakxna360

+0

礦井也是空的。這可能是別的。你能從命令行登錄嗎? –

回答

8

首先記下您系統上pg_hba.conf的位置。如果你不知道,但你可以連接,連接到與PG的pgAdmin-III或者psql並運行:

SHOW hba_file; 

得到的pg_hba.conf位置。它的位置很標準,在Ubuntu上它將在/etc/postgresql/[major.minor]/main/pg_hba.conf例如/etc/postgresql/9.1/main/pg_hba.conf。在大多數其他發行版中,它將在/var/lib/pgsql//var/lib/postgresql之下,直接或在版本化的目錄中。

要編輯此文件,您必須先指定完整路徑或將目錄更改爲其位置。你說:

sudo vi /etc/postgresql/9.1/main/pg_hba.conf 

如果你喜歡一個更友好的文本編輯器:

sudo nano /etc/postgresql/9.1/main/pg_hba.conf 

或與您喜歡的編輯器代替 「納米」,像gedit

保存更改後,請記住重新加載PostgreSQL服務以使其生效。在Ubuntu上你需要:

pg_ctlcluster 9.1 main reload 
+0

當我做'sudo gedit pg_hba.conf'我的目錄除了pg_hba.conf之外還添加了一個pg_hba.conf〜。編輯pg_hba.conf文件的最佳方法是什麼? –

+1

使用不保存備份文件的編輯器。 –

1

以下Crag的建議運行良好。

對於他的最後一步,你必須須藤到數據庫超級用戶才能得到PostgreSQL服務重新加載:

sudo -u postres pg_ctlcluster 9.1 main reload 

這些步驟也適用於Debian希德系統工作。