I'm trying to set my server up and came across some troubles related to Unix domain sockets. I don't have so much experience with Unix, despite the stack for web development: Apache, PHP and SQL. I installed Apache and PostgreSQL, but trying to access the psql shell I came across the following error:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "root" does not exist

My pg_hbs.confhas this appearence:

local all root/postgres/home (all was tried already)
host all root scram-sha-256
host all root ::1/128 scram-sha-256

The error references the "local" field in the config file. I just opened up some documentation about Unix sockets, it's very interesting, and I will want to know more about but, despite looking like "I'd be to recreating the wheel", I just want to set the environment for development right now.

Any help will be welcome.


  • Could you add the command you used to access the psql shell? Commented May 5, 2022 at 16:27
  • @BrahimGaabab, focus please... psql
    – zanoth
    Commented May 5, 2022 at 16:35

1 Answer 1


If you are accessing the psql shell as root, you should type this entire command line: (not just psql)

su - postgres

  • It works! Thanks.
    – zanoth
    Commented May 5, 2022 at 16:46
  • And the reason WHY this works is that postgresql has its own database of user accounts which is entirely separate from the unix system accounts. When psql is run, it tries to use the current unix username as the postgres username (unless the -U option is used). root does not have a postgres account. User postgres does. There should be an entry in pg_hba.conf similar to local all all peer (or at least just one for the postgres user: local all postgres peer). The peer method allows local unix users to login via socket to the same pg username in postgres without a password.
    – cas
    Commented May 6, 2022 at 2:59
  • See postgresql.org/docs/current/client-authentication.html for info about client authentication, and chapter 22 for info about roles. The documentation for the postgres CREATE ROLE command is worth reading too (BTW, "CREATE USER" is an alias/synonym for CREATE ROLE).
    – cas
    Commented May 6, 2022 at 3:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .