Get error: when trying to make pgsql use rails, peer authentication of user "postgres" fails

本文翻译自:Getting error: Peer authentication failed for user “postgres”, when trying to get pgsql working with rails

I'm getting the error: I get the error:

FATAL: Peer authentication failed for user "postgres"

when I try to make postgres work with Rails. When I try to use postgres with Rails .

My's here Wallpaper pg_hba.conf, My database.yml, and A dump at The Full of the trace . This is my pg_hba.conf, my database.yml, and complete tracking of the dump .

I changed authentication to md5 in pg_hba and tried different things, but none seem to work. I changed the authentication to md5 in pg_hba and tried different operations, but none seemed to work.

I also tried creating a new user and database as per Rails 3.2, FATAL: Peer authentication failed for user (PG :: Error) I also tried to create a new user and database according to Rails 3.2 , fatal: the user's peer authentication failed (PG :: error)

They do not Show up But pgadmin or the even the when the I ON RUN sudo -u postgres psql -l. But they did not appear on pgadmin, even when I run sudo -u postgres psql -l.

Any idea where I'm going wrong? Any idea where I'm going wrong ?


#1st Floor

Reference: https://stackoom.com/question/1GJNS/ Get error-when trying to make pgsql use rails-peer authentication for user-postgres- failed


#2nd Floor

Still your problem IS at The pg_hba.confFile ( /etc/postgresql/9.1/main/pg_hba.conf*). The question remains your pg_hba.conffile ( /etc/postgresql/9.1/main/pg_hba.conf*).

This line: This line:

local   all             postgres                                peer

Should be: Should be :

local   all             postgres                                md5

The If you CAN not the Find * File the this, running locate pg_hba.confShould Show you the WHERE IS at The File. * If you can not find this file, run locate pg_hba.confshould be the location of the file is displayed.

After altering this file, don't forget to restart your PostgreSQL server. After changing this file, don't forget to restart the PostgreSQL server. You're ON Linux IF, that Would BE sudo service postgresql restart. If you're on Linux, it would be sudo service postgresql restart.

Descriptions of both-are the Brief THESE ACCORDING to Options at The Official Methods PostgreSQL docs ON authentication . These are based on the official PostgreSQL documentation on authentication methods brief description of the two options.

Peer authentication peer authentication

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping). The working principle of the peer authentication method is to obtain the client's operating system user from the kernel Name and use it as the allowed database user name (using the optional user name mapping). This method is only supported on local connections. This method is only supported on local connections .

Password authentication password authentication

The password-based authentication methods are md5 and password. The password-based authentication methods are md5 and password . These methods operate similarly except for the way that the password is sent across the connection, namely MD5-hashed and clear-text respectively. Except for the way to send the password through the connection, the operations of these methods are similar, which are MD5 hash and clear text respectively.

If you are at all concerned about password "sniffing" attacks then md5 is preferred. If you are completely worried about password "sniffing" attacks, then md5 is preferred . Plain password should always be avoided if possible. If possible, common passwords should always be avoided . However, md5 cannot be used with the db_user_namespace feature. However, md5 cannot be used with the db_user_namespace feature . If the connection is protected by SSL encryption then password can be used safely (though SSL certificate authentication might be a better choice if one is depending on using SSL). If the connection is protected by SSL encryption, the password can be used safely (but if it depends on To use SSL, SSL certificate authentication may be a better choice).

Sample location for pg_hba.conf: pg_hba.confSample location:
/etc/postgresql/9.1/main/pg_hba.conf


#3rd floor

I had the same problem. I had the same problem .

The solution from depa is absolutely correct. The solution from depa is absolutely correct .

Just make sure that u have a user configured to use PostgreSQL. Just make sure you have configured the user to use PostgreSQL.

Check the file: Check the file:

$ ls /etc/postgresql/9.1/main/pg_hba.conf -l

The permission of this file should be given to the user you have registered your psql with. The permission of this file should be given to the user of your registered psql.

Further. Further. If you are good till now .. If you are good till now ..

Update as per @ depa's instructions. Update according to @ depa's instructions .

ie immediately

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

and then make changes .


#4th floor

After installing Postgresql I did the below steps. After installing Postgresql, I did the following steps.

  1. at The File Open pg_hba.conffor Ubuntu by Will BE in IT /etc/postgresql/9.x/mainand Change the this Line: Open Ubuntu's file pg_hba.conf, it will /etc/postgresql/9.x/mainchange and this line:
local   all             postgres                                peer

to Itaru

local   all             postgres                                trust
  1. Restart the server to restart the server
 sudo service postgresql restart 
  1. Login into psql and set your password to log psql and password

psql -U postgres psql -U postgres

ALTER USER postgres with password 'your-pass';
  1. Change at The a finally pg_hba.conffrom the last changepg_hba.conf
local   all             postgres                                trust

to Itaru

local   all             postgres                                md5

After restarting the postgresql server, you can access it with your own password after you restart the postgresql server, you can use your own password to access it

Authentication methods details: Authentication methods details:

trust - anyone who can connect to the server is authorized to access the database trust - anyone can connect to the server has access to the database

peer-use client's operating system user name as database user name to access it. peer-use client's operating system user name as database user name to access it .

md5-password-base authentication md5-password- based authentication

Further Reference for the Check here Wallpaper For further reference, please click here


#5th Floor

If you connect over localhost (127.0.0.1) you shouldn't experience that particular issue. If you connect through localhost (127.0.0.1), you should not encounter that particular problem. I wouldn't muck much with the pg_hba.conf but instead I would adjust your connection string: I will not be stingy with pg_hba.conf but I will adjust your connection string:

psql -U someuser -h 127.0.0.1 database

where someuser is your user you're connecting as and database is the database your user has permission to connect to. One of the users is the user you are connecting to, and the database is the database to which your user is entitled to connect.

Here is what I do on Debian to setup postgres: This is how I set up postgres on Debian:

http://www.postgresql.org/download/linux/debian/  (Wheezy 7.x)

as root …

    root@www0:~# echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" >> /etc/apt/sources.list

    root@www0:~# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

    root@www0:~# apt-get update

    root@www0:~# apt-get install postgresql-9.4        

    root@www0:~# su - postgres 

    postgres@www0:~$ createuser --interactive -P someuser
    Enter password for new role:
    Enter it again:
    Shall the new role be a superuser? (y/n) n
    Shall the new role be allowed to create databases? (y/n) y
    Shall the new role be allowed to create more new roles? (y/n) n

    postgres@www0:~$ createdb -O someuser database

    postgres@www0:~$ psql -U someuser -h 127.0.0.1 database

Enjoy! Please enjoy!


#6th floor

The following commands worked for me:

psql -d myDb -U username -W
Published 0 original articles · praised 8 · 30,000+ views

Guess you like

Origin blog.csdn.net/asdfgh0077/article/details/105556373