1

I have installed Postgres on an Ubuntu 16.04 server, but I'm working in a corporate environment and am not able to sudo -u postgres (I have sudo rights, but can't impersonate another user).

Is there any other way I can interact with my new Postgres service, or perhaps specify myself as an admin user during setup?

Peter
  • 111
  • 1
  • 7

1 Answers1

0

You may grant yourself the necessary permissions assuming you have the right to edit PostgreSQL configuration under /etc/postgresql.

First, check what version of PostgreSQL is installed and the name of the cluster/instance (see the output of pg_lsclusters). For instance with Ubuntu 16.04 the version would be 9.5 with the default repository because that's what was current in 2016, and the instance would be named main.

In this case, the configuration is under /etc/postgresql/9.5/main (otherwise change the path according to version/cluster). In the configuration, you may declare a mapping from your Unix user name to the postgres superuser database account, for instance:

In /etc/postgresql/9.5/main/pg_ident.conf

# MAPNAME       SYSTEM-USERNAME         PG-USERNAME
mymap           myusername              postgres

In /etc/postgresql/9.5/main/pg_hba.conf, as the first rule (the order does matter):

# local      DATABASE  USER            METHOD  [OPTIONS]
local        all       postgres        peer map=mymap

Then reload (sudo pg_ctlcluster 9.5 main reload), and the Unix myusername account should be able to connect locally as superuser with:

$ psql -U postgres -d postgres

Otherwise check the server logs under /var/log/postgresql

Daniel Vérité
  • 3,045
  • 16
  • 19