22

i have a problem with my postgreSQL setup on my new Mac OSX Lion machine.

I can't seem to connect to the service

$ createuser -a -d _postgres
Password: 
createuser: could not connect to database postgres: FATAL:  password authentication failed for user 

I have no chance to find the correct password. Any idea what could that be. I have the default setup with a localhost server. The same happens when I try to connect via pgAdmin.

$ su postgres
Password:
su: Sorry

I have no chance to find out what's wrong?

4
  • 1
    Is FATAL: password authentication failed for user the reason?
    – xdazz
    Commented Oct 14, 2011 at 9:01
  • no, id don't think so. I typed my userpass a 100 times. It's always the same message. And I don't think in this case I should enter the userpass, but rather the database password!
    – matt
    Commented Oct 14, 2011 at 9:30
  • 1
    It's just silly to suggest that this isn't on topic. Commented Oct 20, 2015 at 3:31
  • I posted the equivalent of this Question on the DBA Stack Exchange: Switch user to 'postgres' user on macOS results in “su: Sorry” error Commented Oct 25, 2018 at 22:35

2 Answers 2

67

try this:

$ sudo su postgres

And specify your own password.

4
  • this does work! bash-3.2$ However how can I fix the problem with createuser -a -d _postgres -> `could not connect to database postgres: FATAL: password authentication failed for user "postgres" Any idea how to fix this?
    – matt
    Commented Oct 14, 2011 at 9:08
  • 1
    Usually when you are logged in as postgres, you have superuser access to the database and doesn't need to provide the password for the postgres user.
    – jishi
    Commented Oct 14, 2011 at 12:31
  • I came from running this tutorial: community.rackspace.com/products/f/25/t/6800 where a postgres is installed and one is asked to login "su - postgres" which asked for a password which in fact does not exist. So sudoing helped: "sudo su - postgres" Commented Sep 13, 2017 at 16:56
  • Thanks so much for this huge tip! I posted the same info on DBA Stack Exchange. Commented Oct 25, 2018 at 22:36
12

Does this work?

First get root access

$ su - 
Password: RootPW
# su - postgres

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