0

I'm having difficulty changing the password associated with the postgres user after installing postgres on my windows 10 machine. My apologies in advance as I'm quite unfamiliar with postgres as well as the commands required to work with it.

I've referenced the approved answer in the below article: FATAL: password authentication failed for user "postgres" (postgresql 11 with pgAdmin 4)

I'm stuck on the step that requires me to

Connect using psql or pgAdmin4 or whatever you prefer

Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

I don't quite understand this step. I've taken the following steps

  1. Open cmd
  2. run psql

The system then asks me for password for username jason. Regardless of what I enter, i get the following message:

psql: error: could not connect to server: FATAL:  password authentication failed for user "jason"

At no point do I have an opportunity to enter the following command:

ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

How can I run this command without being asked to enter a password for postgres?

Thanks!

Jason Howard
  • 1,464
  • 1
  • 14
  • 43
  • `psql -U username -d dbname` https://www.postgresql.org/docs/current/app-psql.html – Alex May 16 '21 at 18:49
  • 1
    This prompts me for a password, which I don't have. – Jason Howard May 16 '21 at 18:51
  • 1
    You are not be asked to enter a password for user `postgres` but user `json`. You will need to connect using `psql` as user `postgres` and assuming you know the current password for `postgres` use that. Then do the `ALTER USER` command. – Adrian Klaver May 16 '21 at 18:51
  • I do not know the current password for the user 'postgres'. The point of this exercise it to reset it to something that I know. – Jason Howard May 16 '21 at 18:52
  • Does this answer your question? [PostgreSQL: How to change PostgreSQL user password?](https://stackoverflow.com/questions/12720967/postgresql-how-to-change-postgresql-user-password) – Alex May 16 '21 at 18:53
  • I'm in windows, so these sudo commands don't work unfortunately – Jason Howard May 16 '21 at 19:02
  • 1
    The password for `postgres` would be what you entered in Fig. 5 here [Installation](https://www.enterprisedb.com/docs/supported-open-source/postgresql/installer/02_installing_postgresql_with_the_graphical_installation_wizard/01_invoking_the_graphical_installer/) – Adrian Klaver May 16 '21 at 20:24

1 Answers1

0

The steps below require that you remember what you did when you installed PostgreSQL.

  • Locate the data directory where the installation process created the database cluster. By default, that would be a subdirectory of where you installed the software (which is a bad place)

  • Edit the pg_hba.conf file therein and add this line on top:

    host postgres postgres 127.0.0.1/32 trust
    
  • Reload or restart PostgreSQL.

  • Start cmd.exe and enter

    psql -h 127.0.0.1 -p 5432 -d postgres -U postgres
    

    If psql is not on your PATH, use the absolute path C:\...\psql.

  • Use \password to change the password.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263