Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
/Users/my_name

my_name$ sudo su postgres
sh$ cd /opt/local/var/db/postgresql92/defaultdb
sh$ pwd
/opt/local/var/db/postgresql92/defaultdb
  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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.