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:

TYPE DATABASE USER ADDRESS METHOD
local all root/postgres/home (all was tried already)
IPv4
host all root 127.0.0.1:5232 scram-sha-256
IPv6
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.

Thanks.

2
  • Could you add the command you used to access the psql shell? May 5 at 16:27
  • @BrahimGaabab, focus please... psql May 5 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. May 5 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
    May 6 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
    May 6 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.