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?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
matt
  • 42,713
  • 103
  • 264
  • 397
  • 1
    Is `FATAL: password authentication failed for user` the reason? – xdazz Oct 14 '11 at 09: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 Oct 14 '11 at 09:30
  • 1
    It's just silly to suggest that this isn't on topic. – ArtOfWarfare Oct 20 '15 at 03: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*](https://dba.stackexchange.com/q/221043/19079) – Basil Bourque Oct 25 '18 at 22:35

2 Answers2

67

try this:

$ sudo su postgres

And specify your own password.

jishi
  • 24,126
  • 6
  • 49
  • 75
  • 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 Oct 14 '11 at 09: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 Oct 14 '11 at 12:31
  • I came from running this tutorial: https://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" – Dirk Schumacher Sep 13 '17 at 16:56
  • Thanks so much for this huge tip! [I posted the same info](https://dba.stackexchange.com/a/221044/19079) on DBA Stack Exchange. – Basil Bourque Oct 25 '18 at 22:36
12

Does this work?

First get root access

$ su - 
Password: RootPW
# su - postgres
A.H.
  • 63,967
  • 15
  • 92
  • 126