Ident authentication failed for user "postgres" I am using PostgreSQL12 on Cent0S8, and I am able to connect to PostgreSQL using the command:
sudo -u postgres psql
However, when I attempt to connect using:
psql -U postgres -h localhost
I recieve the following error:
psql: error: count not connect to server: FATAL: Ident authentication failed for user &quot;postgres&quot;
Every option is set to trust within my pg_hba.conf file, and I successfully restarted the server after making these changes.
Does anyone know of what I would need to change to be able to login using the psql -U postgres -h localhost command?
If you are editing wrong hba file this should fix

Switch to postgres user on OS
run psql
should be connected to PostgreSQL
run show hba_file;
should be seeing to correct hba_file directory and edit that file.
reload postgresql


lloyd@localhost:~$ sudo su - postgres
postgres@localhost:~$ psql
psql (13.1 (Ubuntu 13.1-1.pgdg18.04+1), server 12.5 (Ubuntu
12.5-1.pgdg18.04+1)) Type &quot;help&quot; for help.
postgres=# show hba_file ;

hba_file
/etc/postgresql/12/main/pg_hba.conf (1 row)
postgres=# select pg_reload_conf();

Last query should return true if it's not, there is an error in hba file so PostgreSQL won't refresh hba file. So you should look for error in file. Also you can look at logs. After reloading PostgreSQL, it shows you error with line.