28

Several days ago I install postgesql 9.2 version on my local computer. (OS windows 7)

Now I forgot my password and I can not login in pgAdmin.

How to change postgresql password on windows 7?

Oto Shavadze
  • 40,603
  • 55
  • 152
  • 236
  • 1
    duplicate of http://stackoverflow.com/questions/10845998/i-forgot-the-password-i-entered-during-postgres-installation which has a more explanitive answer ;) – TimoSolo Apr 15 '14 at 08:46
  • https://dba.stackexchange.com/questions/44586/forgotten-postgresql-windows-password – Devesh Jun 07 '18 at 07:33
  • Check this link: [forgotten-postgresql-windows-password](https://dba.stackexchange.com/questions/44586/forgotten-postgresql-windows-password) **It is work for me** – Ramil Aliyev 007 Jan 28 '20 at 11:24

6 Answers6

55

In the pg_hba.conf file, change (temporarily) all METHOD with trust. EG :

host    all             all             ::1/128                 trust

instead of :

host    all             all             ::1/128                 md5

You can find where the pg_hba.conf is located by typing in a psql command line:

SHOW hba_file;
Antoine Martin
  • 1,903
  • 2
  • 16
  • 28
19

Below steps helped me to reset the password-

  1. Go to pg_hba.conf file at path e.g. C:\Program Files\PostgreSQL\10\data and add below line at the end,

    host all postgres 127.0.0.1/32 trust
    
  2. Restart the PostgreSQL service from services control panel (start -> run -> services.msc)

  3. Connect using PgAdmin or any software that you prefer and run query,

    ALTER USER postgres PASSWORD 'postgres'
    
  4. Remove the line that you added in step 1.

  5. Restart PostgreSQL.

Hetal Rachh
  • 1,393
  • 1
  • 17
  • 23
  • I was able to loging using My SQL and run: ALTER USER postgres PASSWORD myPassword. Do I need the ''? Because it didn't work. What worked for me was to login using pgAdmin4 and change inside the server config. After resenting the pg_hba the new password worked. – Pedro77 Mar 08 '20 at 19:35
  • I think you should replace the "host xxx md5" line. Only adding did not worked for me. – Pedro77 Mar 08 '20 at 19:44
12

Edit pg_hba.conf to allow you to connect without a password. Then use ALTER USER to reset the password. Then change pg_hba.conf back again.

For the documentation on pg_hba.conf, see here:

http://www.postgresql.org/docs/devel/static/auth-pg-hba-conf.html

splash
  • 13,037
  • 1
  • 44
  • 67
Ben
  • 34,935
  • 6
  • 74
  • 113
4

I am using postgres version 14.0 and Windows 10. To reset the password:

  1. I opened the windows command prompt and typed: psql -U postgres(postgres is my username)

  2. Type in your current password

3 Then type: \password postgres

enter image description here

It brings up the prompts to type the new password and confirm. Note for the psql command to work on the windows command prompt, you need to set the postgres bin folder on the path environment variable. You can just google how to do this.

AfriPwincess
  • 123
  • 1
  • 6
3

Run your psql executable file and login into your database using your old password, use the following command to login:

 .\psql.exe -U postgres

Then use

ALTER USER <user_name> WITH PASSWORD <'new_password'>

For more information refer this link : https://www.postgresql.org/docs/8.0/sql-alteruser.html

balintbabics
  • 1,291
  • 2
  • 11
  • 25
Shivam_kira
  • 109
  • 3
2

In windows postgres stores password for automatic login at following path (only if you would have selected password save option while installation)

C:\Users\USERNAME\AppData\Roaming\postgresql\pgpass.conf

you can open this file in a text editor and see your password.

Shubham Singh
  • 213
  • 2
  • 13