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

后端 未结 3 1727
后悔当初
后悔当初 2021-01-02 19:21

I just installed postgresql on a Macbook with brew install postgresql. Then I try to psql, but it requires password and then show

相关标签:
3条回答
  • 2021-01-02 19:51

    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
    
    0 讨论(0)
  • 2021-01-02 19:55

    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.

    0 讨论(0)
  • 2021-01-02 19:59

    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.

    0 讨论(0)
提交回复
热议问题