Authentication failed for postgresSQL user?

I am trying to run rake db:create db:migrate db:seed

inside ruby ​​on rails project, I am getting errorFATAL: password authentication failed for user "postgres"

Looking at other similar questions, many people have pointed to a correctness error in the pg_hba file, but as far as I can tell, there is no problem with it?

local   all             postgres                                md5    
local   all             all                                     peer
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

      

I also ran into this sudo -u postgres psql -x -c "select * from pg_user where usename='p

and got this:

-[ RECORD 1 ]---------
usename     | postgres
usesysid    | 10
usecreatedb | t
usesuper    | t
usecatupd   | t
userepl     | t
passwd      | ********
valuntil    | 
useconfig   | 

      

More info: System Ubuntu 14.04 is running in a roving field, with postgres v9.3.

update: I have created a new database and a new user, following the instructions given here enter the link here , Added new information to the database.yml file found in the config directory to make sure I am using the DB user, there is no system user.

update-2 : here is the information found in the database.yml file:

development:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: db1
  pool: 5
  username: dev1
  password: dev1
test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  port: 5432
  database: db_test1
  pool: 5
  username: dev1
  password: dev1

      

+3


source to share


1 answer


As there can be quite a few factors, it can be difficult to point out what is wrong with your setup. I guess I'll just try to explain how I'm using vagrant + rails + postgresql, so I hope this helps you. This assumes you have a brand new roaming box with Ubuntu 14.04.

Let's say you have installed the required packages for ruby ​​+ rails. And now you are going to install postgresql.

sudo apt-get install postgresql postgresql-contrib libpq-dev

      

And then you have to login to your postgresql admin user:

sudo su postgres
psql

      



After logging into the psql console, I would normally create a user named vagrant

. I am doing this because postgresql by default uses the current shell user as the database user when logging into the db console. This is more convenient (for me anyway). And then I will also create the database in the console. After that, I grant the user privileges for the database vagrant

.

CREATE USER vagrant WITH PASSWORD 'password';
CREATE DATABASE db1;
GRANT ALL PRIVILEGES ON DATABASE db1 to vagrant;

      

After these steps, I'll just add the appropriate database.yml

config and run rake db:migrate

. I find this workflow to be effective for me and I have never encountered similar problems. I also never touched pg_hba.conf

this setting. Try this and I hope it solves your problems.

Hooray!

0


source







All Articles