user1778824
user1778824

Reputation: 369

Accessing postgres without being root users

I have created a postgres database in postgres named "databaseName". Now I can access this data2database through

 su - postgres

and then typing my password

Then I enter into the database through: psql databaseName

I have created users of this database through:

   createuser -P userName1

Now I dont want the users of the database to access the database as root user. Now when the users try to login into postgres as

 su - postgres -u userName1 
        or through
 psql databaseName -u userName1

I get error...can someone guide me as to how the users can get access to postgres and database without being root user?

Upvotes: 2

Views: 7579

Answers (1)

Craig Ringer
Craig Ringer

Reputation: 324771

Configure pg_hba.conf to accept peer connections over unix sockets or ident connections over host (tcp) connections. If you prefer you can use md5 to use password authentication instead.

By default psql will connect with the same username as your local OS username; this can be overridden by the -U flag, eg:

psql -U myusername thedatabase

Note that it's -U not -u (it's upper case).

This is all covered in detail in the PostgreSQL documentation; see:

BTW, if you want to run commands as the postgres user, rather than su'ing you can just write:

sudo -u postgres psql

Upvotes: 7

Related Questions