Postgresql: password authentication failed for user “postgres”

前端 未结 19 1481
时光取名叫无心
时光取名叫无心 2020-11-22 13:34

I have installed PostgreSQL 8.4, Postgres client and Pgadmin 3. Authentication failed for user \"postgres\" for both console client and Pgadmin. I have typed user as \"postg

相关标签:
19条回答
  • 2020-11-22 14:12

    Edit the pg_hba.conf file, e.g. with sudo emacs /etc/postgresql/9.3/main/pg_hba.conf

    Change all authentication methods to trust. Change Unix Password for "postgres" user. Restart Server. Login with psql -h localhost -U postgres and use the just set Unix password. If it works you can re-set the pg_hba.conf file to the default values.

    0 讨论(0)
  • 2020-11-22 14:12

    Try to not use the -W parameter and leave the password in blank. Sometimes the user is created with no-password.

    If that doesn't work reset the password. There are several ways to do it, but this works on many systems:

    $ su root
    $ su postgres
    $ psql -h localhost
    > ALTER USER postgres with password 'YourNewPassword';
    
    0 讨论(0)
  • 2020-11-22 14:13

    The response of staff is correct, but if you want to further automate can do:

    $ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"

    Done! You saved User = postgres and password = postgres.

    If you do not have a password for the User postgres ubuntu do:

    $ sudo passwd postgres

    0 讨论(0)
  • 2020-11-22 14:14

    If I remember correctly the user postgres has no DB password set on Ubuntu by default. That means, that you can login to that account only by using the postgres OS user account.

    Assuming, that you have root access on the box you can do:

    sudo -u postgres psql
    

    If that fails with a database "postgres" does not exists error, then you are most likely not on a Ubuntu or Debian server :-) In this case simply add template1 to the command:

    sudo -u postgres psql template1
    

    If any of those commands fail with an error psql: FATAL: password authentication failed for user "postgres" then check the file /etc/postgresql/8.4/main/pg_hba.conf: There must be a line like this as the first non-comment line:

    local   all         postgres                          ident
    

    For newer versions of PostgreSQL ident actually might be peer. That's OK also.

    Inside the psql shell you can give the DB user postgres a password:

    ALTER USER postgres PASSWORD 'newPassword';
    

    You can leave the psql shell by typing CtrlD or with the command \q.

    Now you should be able to give pgAdmin a valid password for the DB superuser and it will be happy too. :-)

    0 讨论(0)
  • 2020-11-22 14:14

    When you install postgresql no password is set for user postgres, you have to explicitly set it on Unix by using the command:

    sudo passwd postgres
    

    It will ask your sudo password and then promt you for new postgres user password. Source

    0 讨论(0)
  • 2020-11-22 14:15

    This was frustrating, most of the above answers are correct but they fail to mention you have to restart the database service before the changes in the pg_hba.conf file will take affect.

    so if you make the changes as mentioned above:

    local all postgres ident
    

    then restart as root ( on centos its something like service service postgresql-9.2 restart ) now you should be able to access the db as the user postgres

    $psql
    psql (9.2.4)
    Type "help" for help.
    
    postgres=# 
    

    Hope this adds info for new postgres users

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