Linux – psql: FATAL: no pg_hba.conf entry for host “[local]”, user “root”, database “root”, SSL off

linuxpostgresql

on our Linux server we have PostgreSQL DB

when we type –

psql -l

we get

psql: FATAL:  no pg_hba.conf entry for host "[local]", user "root", database "postgres", SSL off

what we need to set in the /var/lib/pgsql/data/pg_hba.conf in order to fix this?

Best Answer

To list the databases, you can execute your command as postgres user:

$ sudo su postgres -c 'psql -l'

If you are already logged in as root, you can remove sudo from the above command. User postgres is considered as root user for PostgreSQL database engine.

The error shown in your post indicates that there is no access for user root from localhost to access postgres database. So, you can edit pg_hba.conf file to include the desired login details like login name, DB name, and host. The file is well documented.

For your case, you can add the following line to pg_hba.conf file:

local   all       root           peer

You need to reload your postgresql server after saving the changes.