Postgres password authentication fails

Solution 1:

You are confusing the password for the Unix user "postgres" with the database password for the database user "postgres". These are not the same.

You've locked yourself out, because you enabled md5 authentication for database user postgres without setting a password for the database user postgres.

Add a new line to the top of pg_hba.conf:

local    postgres     postgres     peer

Then restart/reload PostgreSQL:

/etc/init.d/postgresql reload\

and run:

sudo -u postgres psql

From the resulting prompt:

ALTER USER postgres PASSWORD 'my_postgres_password';

remove the line you added to pg_hba.conf and restart Pg again. You can now use the password you set above to connect to PostgreSQL as the postgres user.

To learn more, read the "client authentication" chapter of the user manual and the docs on pg_hba.conf.

Solution 2:

Try to modify the password of the database template1 using this:

$ psql -c "ALTER USER postgres WITH PASSWORD 'yourPassword'" -d template1

Solution 3:

in your pg_hba.conf

# IPv4 local connections:
# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
host    all         all         127.0.0.1/32         trust

if it does not work then try with

host    all         all         your_ip/32         trust

then restart your data base it will work fine.. if you make trust then there is no need for password if you make MD5 then it will ask password...