I am getting this error when i run db:create:
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}
So I figured out that I have to edit pg_hba.conf The problem is... It won't open. It keeps telling me I don't have permission to use this file. So how do I get permission? I'm running ubuntu 12.10 and rails 1.9.3 and postgres 9.1
First note down the location of pg_hba.conf
on your system. If you don't know it but you can connect, connect to Pg with PgAdmin-III or psql
and run:
SHOW hba_file;
to get the location of pg_hba.conf
. It's location is pretty standard; on Ubuntu it'll be in /etc/postgresql/[major.minor]/main/pg_hba.conf
eg /etc/postgresql/9.1/main/pg_hba.conf
. On most other distros it'll be under /var/lib/pgsql/
or /var/lib/postgresql
, either directly or in versioned directory.
To edit this file you must specify the full path or change directory to its location first. Say:
sudo vi /etc/postgresql/9.1/main/pg_hba.conf
If you prefer a friendlier text editor:
sudo nano /etc/postgresql/9.1/main/pg_hba.conf
or replace "nano" with your preferred editor, like gedit
.
Once you save your changes, remember to reload the PostgreSQL service to have them take effect. On Ubuntu you want:
pg_ctlcluster 9.1 main reload
Following Crag's advice worked well.
For his last step, you have to sudo into the database superuser in order to get the PostgreSQL service to reload:
sudo -u postres pg_ctlcluster 9.1 main reload
These steps also work for Debian Sid systems.
To edit pg_hba.conf
, you can try editing as the postgres
user:
switch to the postgres
user
sudo su postgres
run psql
SHOW hba_file;
as a query in psql to get the locationnano *the file location*
(not sudo nano
as that will attempt the editing operation as the root user)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With