Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why postgresql on mac asks me for password after fresh install?

Tags:

postgresql

I just installed postgresql on a Macbook with brew install postgresql. Then I try to psql, but it requires password and then show psql: FATAL: password authentication failed for user "<myname>".

I have not set up anything, and inputting my mac password does nothing. What should I do now?

like image 620
Romulus Urakagi Ts'ai Avatar asked Oct 17 '17 02:10

Romulus Urakagi Ts'ai


3 Answers

So your username probably does not exist, as the default username that ships with the db is postgres.

Further, I was prevented from the submission of an empty password, which is blank by default for the postgres user.

You might try

cd ~/
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
Password: YOUR_LOGIN_PWD_HERE (required for sudo)

and then to use

psql -U postgres
password: postgres

I'm not 100% sure of which SO answer I got this from, perhaps here. Hope this helps.

like image 195
nrako Avatar answered Oct 15 '22 05:10

nrako


The above did not work for me. The below steps worked for me:

Step 1: Uninstall Postgres using the following steps:

sudo /Library/PostgreSQL/10/uninstall-postgresql.app/Contents/MacOS/uninstall-postgresql

PS: my postgres version is 10

Step 2: Remove Postgresql user

System Preference > userse & Groups > Unlock > remove postgresql user by clicking "-"

Step 3: Remove existing databases

rm -rf /usr/local/var/postgres/*

Step 4: Install and Start Postgres using brew

brew update
brew install postgresql
brew services start postgresql

Step 5: Create database

initdb /usr/local/var/postgres -E utf8

You can start accessing postgres

psql -h localhost -d postgres
like image 8
Pramida Avatar answered Oct 15 '22 05:10

Pramida


The answer by Pramida almost worked for me... the difference is I was using 9.6 Postgres.

So I ran:

sudo /Library/PostgreSQL/9.6/uninstall-postgresql.app/Contents/MacOS/installbuilder.sh

and somehow that got rid of my username and almost all of postgres user. I think

I then blew away the directory

sudo rm -rf /Library/PostgreSQL/9.6

And then I installed using brew above.

like image 2
Steve Iribarne Avatar answered Oct 15 '22 05:10

Steve Iribarne