How to get a user's password in PostgreSQL?
I have listed all users in the database. How can I get the password for the plain user test ?
1 Answer 1
The password is encrypted according to the documentation:
The password is always stored encrypted in the system catalogs. The ENCRYPTED keyword has no effect, but is accepted for backwards compatibility. The method of encryption is determined by the configuration parameter password_encryption. If the presented password string is already in MD5-encrypted or SCRAM-encrypted format, then it is stored as-is regardless of password_encryption (since the system cannot decrypt the specified encrypted password string, to encrypt it in a different format). This allows reloading of encrypted passwords during dump/restore.
So, you won’t be able to get the original password of the normal user. What’s stored in the system is an encryption (e.g. MD5) of the original password. If you already know the password, its encrypted value will match. But you cannot get the password that generated the encrypted value. That’s the point of encrypting the password.
As admin, you can ALTER the user’s password, but cannot get the password from the encrypted version.
— Update —
To get the encryptedvalue of the password for the user test , you can do:
How to check postgres user and password? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago .
After concluding installation of postgres I tried to connect using postgres, but I don’t know the password.
2 Answers 2
You will not be able to find out the password he chose. However, you may create a new user or set a new password to the existing user.
Usually, you can login as the postgres user:
Open a Terminal and do sudo su postgres . Now, after entering your admin password, you are able to launch psql and do
This creates a new admin user. If you want to list the existing users, you could also do
unixforum.org
Решено Как подключиться к postgres из мира (Как узнать пароль postgres)
Решено Как подключиться к postgres из мира (Как узнать пароль postgres)
Сообщение azsx » 21.08.2015 17:01
я установил postgresql на ubuntu из консоли. Никто меня про пароли не спрашивал. После этого под супер пользователем я захожу с sudo, то есть
sudo -u postgres psql
при этом ввожу пароль от пользователя в никс (совсем не постгрес). Я хочу открыть доступ к базе постгрепс извне (с других компов в интернете). По инструкции http://knbase.org/8 мне надо создать второго супер юзера
# Переключаемся в системного пользователя postgres
su postgres
# Создаем нового суперпользователя
createuser -P -s postgreadmin
# вводим пароль по запросу
PostgreSQL: How to Recover postgres User Password?

In this post, I am sharing few steps for recovering the forgot password of postgres user (admin user) of PostgreSQL.
Yesterday, I was checking few forums of PostgreSQL and found that few DBAs forgot their password after installation of PostgreSQL.
The postgres user is a superuser of PostgreSQL, and it is a default user also. While installing PostgreSQL, you have to set the password of postgres user, and if you forget the password, you can’t do any operation like create first DB or create first DB User.
How to recover forgotten password of PostgreSQL?
Edit pg_hba.conf file:
Change below line for MD5 to TRUST
Restart the PostgreSQL Server:
Connect the PostgreSQL:
Change the password of postgres user:
Last, rollback the change in pg_hba.conf file and restart the PostgreSQL Server:
nice article, helped alot. thanks
After making this change:
host all all 127.0.0.1/32 trust
I had to use the following command, to log in without a password.
psql -h 127.0.0.1 -U postgres
I Hope This Helps
Leave a Reply Cancel reply

Anvesh Patel
About Me!

I’m Anvesh Patel, a Database Engineer certified by Oracle and IBM. I’m working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. — Hyderabad, India.
About DBRND !

This is a personal blog (www.dbrnd.com).
Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.
Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) — so keep it polite.
The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.