Switch to postgres user on Mac

flossfan picture flossfan · May 25, 2012 · Viewed 11k times · Source

I would like to su to the postgres user on Mac, so that I can run postgres.

What am I doing wrong here?

delirium:~ anna$ sudo su postgres
delirium:~ anna$

Nothing happens. If I try to run postgres, I then get something like this:

delirium:~ anna$ sudo pg_ctl -D /usr/local/var/postgres -l      
/usr/local/var/postgres/server.log startpg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

If I try this in order to su, I also get an error:

delirium:~ anna$ sudo su - postgres
su: no directory
delirium:~ anna$

What can I do instead? I'm fairly sure that the postgres user exists.

Answer

Iain picture Iain · May 25, 2012

That looks consistent with the postgres user not having a login shell. Try sudo -u postgres bash