0

I have installed Postgres on my Linux system. I forgot the admin password I want to reset the password. How can I do that?

0

1 Answer 1

1
  1. If you want to reset your password you need to go to the pg_hba.conf file. You can do this by giving in the following command into Linux.
sudo subl /etc/postgresql/12/main/pg_hba.conf
  1. After gaining access to the file you must change all local locations from Method md5 to trust so you can enter Postgresql without permission or without being asked for a password. Then place the following command into Linux:
sudo /etc/init.d/postgresql restart
  1. Subsequently, run the succeeding command to get into PostgreSQL:
sudo -u postgres psql
  1. And last but not least run the common SQL Command to reset the password for User:
ALTER USER postgres with PASSWORD 'anewremembrablepassword';

Of course, you could also use another user than postgres if you considerably created one. Make sure you go back to the pg_hba.conf file to change the methods back to md5 so you always give in a password as for better security or leave it and never give in a password.

I hope I could be helpful in solving this matter.

Thanks!

2
  • You should be more generic in your answer. For one, few distributions use System V init scripts these days. Aug 31, 2020 at 6:32
  • For step 1, I found my pg_hba.conf in /var/lib/pgsql/data/pg_hba.conf For step 2, sudo systemctl restart postgresql.service
    – Aserian
    Jan 21 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy