2

I would like to set a password for the postgres user on my local database on windows.

Currently I can login to postgres using "psql -U postgres" without the need for a password

My pg_hba file is as follows

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
1
  • I've tried alter user postgres with password ... but this didn't make any difference. Commented Aug 27, 2015 at 10:21

2 Answers 2

4

First login as usual with psql -U postgres and set a password for the user postgres:

ALTER USER postgres PASSWORD 'your-new-password';

Than edit you file pg_hba.conf and add this line:

local   all             postgres                                   md5

Finally restart the postgres server.

Sign up to request clarification or add additional context in comments.

7 Comments

postgres doesn't seem to restart, do I need to put an address?
Do you mean, the restart fails? With a error message?
I'm restarting from the windows task manager - services section, it says stopped in the status when trying to restart
Probably you made a error by editing the file pg_hba.conf
I don't think "local all postgres md5" works on windows
|
0
  1. edit pg_hba.conf file: instead 'md5' use 'trust'. this is for connecting your postgresql server.
  2. reload postgresql
  3. pgAdmin4 has an user interface for this. look belove👇👇 provide your new password here.
  4. restore pg_hba.conf file then reload postgresql. DONE it worked for me.

enter image description hereenter image description here

if you do these things by using command prompt. pay attention this

ALTER USER postgres PASSWORD 'your-new-password';

it could be like

ALTER ROLE postgres PASSWORD 'your-new-password';

because when i look at the postgres from pgAdmin4 it look like a role not user. look at this ss enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.