0

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:

TYPEDATABASEUSERADDRESSMETHOD
localallroot/postgres/home (all was tried already)
IPv4
hostallroot127.0.0.1:5232scram-sha-256
IPv6
hostallroot::1/128scram-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.

Thanks.

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

1 Answer 1

1

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

su - postgres

3
  • It works! Thanks.
    – zanoth
    CommentedMay 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
    CommentedMay 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
    CommentedMay 6, 2022 at 3:03

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.