4

I typed the following instruction to set up the postgresql password.

sudo su - postgres
psql -U postgres
alter user postgres with encrypted password 'my_pass';
\q
sudo su - postgres

But I met the error.

[sudo] password for postgres:my_pass

Sorry, try again.

Which thing did I miss?

I actually set the password.

Thanks.

7
  • 1
    alter user is sql command while sudo su - postgres is OS - users are different for os and database. accordingly passwords are. use passwd for OS postgres password Commented Mar 20, 2017 at 15:42
  • edit question. leave only steps what you did and clearly defined goal please Commented Mar 20, 2017 at 15:57
  • So should I change into alter user postgres with encrypted passwd 'my_pass';? But I can't login to execute the statement. Commented Mar 20, 2017 at 16:10
  • what are trying to achieve? to set the password for os user or for db user? Commented Mar 20, 2017 at 16:11
  • I edited the question.I want to change the original os user postgres's password Commented Mar 20, 2017 at 16:16

1 Answer 1

11

to change os user password, run sequentially:

sudo su -

passwd postgres

and enter a new password.

Keep in mind that if you are a sudo user, you wont be asked for a password anyway...

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

2 Comments

I am in a similar situation, however when I type "sudo su -" it asks me for postgres password... any idea what I could do in this case?
because postgres is not sudo user. and you dont need sudo su if you are postgres - just run passwd. Also if you are posttgres, why do U want to change the password? apparently you know it if you login...

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.