Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a Mac running OS X Lion (10.7.5), with PostgreSQL 9.2.4 installed. I've initialized a database cluster and started a server, all as the postgres user. When I try to access certain directories related to my PostgreSQL installation, or execute certain binaries, I need to switch to the postgres user first. For instance:

# Ideally I'd want this to work:
my_name$ psql
psql: FATAL:  role "my_name" does not exist

# I'd settle for this working, but it doesn't
my_name$ sudo psql
psql: FATAL:  role "root" does not exist

# I don't understand why this doesn't work but the next things does
my_name$ sudo su postgres psql
/opt/local/lib/postgresql92/bin/psql: /opt/local/lib/postgresql92/bin/psql: cannot execute binary file

# This works
my_name$ sudo su postgres
sh$ psql
psql (9.2.4)
Type "help" for help.

Another example:

my_name$ cd /opt/local/var/db/postgresql92/defaultdb
-bash: cd: /opt/local/var/db/postgresql92/defaultdb/: Permission denied

my_name$ sudo su postgres cd /opt/local/var/db/postgresql92/defaultdb
my_name$ pwd

my_name$ sudo su postgres
sh$ cd /opt/local/var/db/postgresql92/defaultdb
sh$ pwd
  1. Why does sudo su postgres <cmd> not work, but when I separate the steps of switching the user and then invoking the command, it does work?
  2. Is there another way around this so that I don't have to switch users every time?
  3. More generally, is there a way to give a user all the permissions of another user in addition to the ones it already has? E.g. can I add all of the postgres user's permissions to the my_name user's permissions?
share|improve this question

You must have a user created in your postgresql database and allow it from localhost in your pg_hba.conf file - plenty of examples in the file on the various options.

Then you can do:

psql -H localhost -U myuser

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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