Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psql.exe - password authentication failed in windows

Tags:

postgresql

I'm a noob in PostgreSQL. I installed ver 9.2 on windows7. During installation it asked for password and i entered it. Now whenever i run d:\tools\PostgreSQL9.2\bin\psql.exe it asks for password. When i enter the password it doesn't accept and it shows "password authentication failed for user "user1". I have re-installed twice already. Also i tried entering my system password.

I'm trying to get the below command to work

psql.exe -f db/codedb.sql development

What should i do to get this working ?

like image 579
user1184100 Avatar asked Sep 24 '12 10:09

user1184100


People also ask

How do I fix postgres password authentication failed?

Restart the PostgreSQL service from the Services control panel ( start->run->services. msc ) Connect using psql or pgAdmin4 or whatever you prefer. Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

What is the default password for postgres Windows?

For most systems, the default Postgres user is postgres and a password is not required for authentication. Thus, to add a password, we must first login and connect as the postgres user. If you successfully connected and are viewing the psql prompt, jump down to the Changing the Password section.

Where is psql EXE located?

open command prompt first ( Winkey+R ), then type C:\Program Files\PostgreSQL\10\bin\psql.exe , then press enter and type in password.


3 Answers

Try setting the user name when connecting.

psql.exe -U username -d dbname -f somefile.sql

You've probably set up the default "postgres" user during installation. Not sure if you've created any others.

To add other users and databases just connect to as postgres to the postgres database and do something like:

CREATE USER myuser WITH ENCRYPTED PASSWORD 'secret';
CREATE DATABASE mydb OWNER myuser;

If your machine is secure you might also like to set up a password file

like image 196
Richard Huxton Avatar answered Oct 04 '22 01:10

Richard Huxton


change "trust" instead of "md5" in the pg_hba.conf to connect to the database and change your password.

    --------------------configuration in pg_hba.conf---------------
    local   all         all                               trust  
    local   all         postgres                          trust          
    host    all         all         ::1/128               trust
like image 44
solaimuruganv Avatar answered Oct 04 '22 02:10

solaimuruganv


Here is the simple solution for installation Postgresql without getting errors(cluster errors and authentication errors),i have followed below steps and i got installed postgresql sucessfully

  1. create new user in windows from controlpanel-->user accounts

  2. After logged into new user(whic u hve created) copy postrgresql(.exe) application into any directory(other than 'C') and click on the application to install(dont forget to change the installation directory to which u have copied the application file above).

  3. after completion of installaion change below configurations in postgresql.conf and pg_hba.cof

add like below in your postgresql.conf

listen_addresses = '*'  

add like below in your pg_hba.cof

# IPv4 local connections:
host     all     all     127.0.0.1/32    trust
# IPv6 local connections:
host     all     all     ::1/128     trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
# host   sameuser    postgres    127.0.0.1/32    trust
#host    replication     postgres        ::1/128                 md5 
like image 2
KIRAN KOORA Avatar answered Oct 04 '22 03:10

KIRAN KOORA