3

I want to map Linux's root user to Postgres user, like if I enter psql in root user it should go the PostgreSQL cli without asking any authentication.

I tried to add an entry in pg_ident.conf and make the necessary changes in pg_hba.conf, but it didn't work.

psql: FATAL:  role "root" does not exist

Postgresql Version 9.6

pg_ident.conf
# MAPNAME       SYSTEM-USERNAME PG-USERNAME
root                 root            postgres

pg_hba.conf
# TYPE  DATABASE USER   ADDRESS         METHOD
local   all     all                     peer map=root 
host    all     all     127.0.0.1/32    ident map=root 

Any suggestions to achieve this?

I need to map multiple Linux users. The above one is for who all are using root user.

0

3 Answers 3

1

A couple notes on this

  • this only works on "peer" connections - i.e., non-network connections over a unix socket.
    • Importantly, specifying -h localhost makes it a network connection.
  • In my experience, you still have to use the client side -U argument to specify what user you want on your command line.
    • e.g. psql -U postgres
1

Finally, it comes to end.

The problem is I need to replace the below line:

local   all             postgres                                peer

with the following line:

local   all             postgres                                peer  map=root

That's it, no more changes.

Got this from:

This link

0

You need to reload the configuration, with pg_ctl reload or kill -HUP to the postmaster process. (You did not mention it in your question so I suppose you forgot about it.)

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.