Rails Can't Login to Postgresql - Pg::Error - Password - Correct Info

Rails can't login to postgresql - PG::Error - password - Correct info

Database.yml:

connection: &connection
adapter: postgresql
encoding: unicode
pool: 5
username: username
password: tehpass

development:
<<: *connection
database: dbname_development

test:
<<: *connection
database: dbname_test

production:
<<: *connection
database: dbname_production

If this is not working for you then, there might be something wrong during installation.

Visit this blog, hope this might help you out.


EDIT


ERROR CASE:

e_sendauth: no password supplied 

fe_sendauth: no password supplied

This happens under a stock Ubuntu install, and is due to the permissions in pg_hba.conf being too restrictive by default. To allow rails to connect, simply change the bottom of pg_hba.conf to look like this.

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust

Let me know if this helps or not?

Getting error: Peer authentication failed for user postgres , when trying to get pgsql working with rails

The problem is still your pg_hba.conf file*.

This line:

local   all             postgres                                peer

Should be:

local   all             postgres                                md5

After altering this file, don't forget to restart your PostgreSQL server. If you're on Linux, that would be sudo systemctl restart postgresql (on older systems: sudo service postgresql restart).



Locating hba.conf

Note that the location of this file isn't very consistent.

You can use locate pg_hba.conf or ask PostgreSQL SHOW hba_file; to discover the file location.

Usual locations are /etc/postgresql/[version]/main/pg_hba.conf and /var/lib/pgsql/data/pg_hba.conf.


These are brief descriptions of the peer vs md5 options according to the official PostgreSQL docs on authentication methods.

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). This method is
only supported on local connections.

Password authentication

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.

If you are at all concerned about password "sniffing" attacks then md5
is preferred. Plain password should always be avoided if possible.
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).

FATAL: password authentication failed for user postgres (postgresql 11 with pgAdmin 4)

The default authentication mode for PostgreSQL is set to ident.

You can access your pgpass.conf via pgAdmin -> Files -> open pgpass.conf

Sample Image

That will give you the path of pgpass.conf at the bottom of the window (official documentation).

After knowing the location, you can open this file and edit it to your liking.

If that doesn't work, you can:

  • Find your pg_hba.conf, usually located under C:\Program Files\PostgreSQL\9.1\data\pg_hba.conf

  • If necessary, set the permissions on it so that you can modify it. Your user account might not be able to do so until you use the security tab in the properties dialog to give yourself that right by using an admin override.

  • Alternately, find notepad or notepad++ in your start menu, right click, choose "Run as administrator", then use File->Open to open pg_hba.conf that way.

  • Edit it to set the "host" line for user "postgres" on host "127.0.0.1/32" to "trust". You can add the line if it isn't there; just insert host all postgres 127.0.0.1/32 trust before any other lines. (You can ignore comments, lines beginning with #).

  • Restart the PostgreSQL service from the Services control panel (start->run->services.msc)

  • Connect using psql or pgAdmin4 or whatever you prefer

  • Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

  • Remove the line you added to pg_hba.conf or change it back

  • Restart PostgreSQL again to bring the changes to effect.

Here is an example of the pg_hba.conf file (METHOD is already set to trust):

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host all all 127.0.0.1/32 trust

# IPv6 local connections:
host all all ::1/128 trust

NOTE: Remember to change the METHOD back to md5 or other auth-methods listed here after changing your password (as stated above).

PG::ConnectionBad: FATAL: password authentication failed for user postgres on the production server

I am having LINODE server and was facing this issue.

I noticed that when I run rails c in current directory after login to the server using ssh, it loads the development environment and that's why it is giving me authentication error.

We have to run bundle exec rails console production so it loads the production environment and it's working

Rails: FATAL: Password Authentication Failed For User

  1. make you user superuser: ALTER USER user_name WITH SUPERUSER;

  2. edit the file pg_hba.conf : set method from md5 in trust

TYPE DATABASE USER ADDRESS METHOD

IPv4 local connections:
host all all 127.0.0.1/32 trust

IPv6 local connections:
host all all ::1/128 trust

...............................................................................

Postgres password authentication fails

As shown in the latest edit, the password is valid until 1970, which means it's currently invalid.
This explains the error message which is the same as if the password was incorrect.

Reset the validity with:

ALTER USER postgres VALID UNTIL 'infinity';

In a recent question, another user had the same problem with user accounts and PG-9.2:

PostgreSQL - Password authentication fail after adding group roles

So apparently there is a way to unintentionally set a bogus password validity to the Unix epoch (1st Jan, 1970, the minimum possible value for the abstime type). Possibly, there's a bug in PG itself or in some client tool that would create this situation.

EDIT: it turns out to be a pgadmin bug. See https://dba.stackexchange.com/questions/36137/

Password authentication failing for Postgresql

The issue turned out to be an issue with the port. The Postgresql Activerecord adapter defaults to port 5432, while the port in my configuration was port 5433. My database.yml now looks like this:

development:
adapter: postgresql
database: core_apps_dev
username: core
password: n7zD5FG5
host: localhost
port: 5433

pg Admin 4 - password for postgres user when trying to connect to PostgreSQL 13 server

I ran into the same problem recently. The solution below works for me. I'm using Windows btw, so you should try equivalent commands in your OS.

  1. Change METHOD of all rows in your pg_hba.conf file from scram-sha-256 to trust
  2. Add bin folder of Postgres installation to path, if you haven't
  3. Open command prompt and enter psql -U postgres. You won't be asked for password here.
  4. Enter \password postgres
  5. Choose and confirm your password
  6. Revert pg_hba.conf to original state

Now you should be able to enter password for postgres in pgAdmin.

Postgres & Rails – FATAL: password authentication failed for user

The default login for rails is the current username logged in and a blank password.



Related Topics



Leave a reply



Submit