PostgreSQL – How to Map a Linux User to Login

linuxpostgresqlpsql

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.

Best Answer

Finally, it comes to end.

The problem is I need to replace the below line.

local   all             postgres                                peer

 to 

local   all             postgres                                peer  map=root

Thats it, no more changes.

Got this from:

This link