Забыли пароль учетной записи postgres в PostgreSQL? Выполнить сброс не сложно. Для этого необходимо выполнить пару манипуляций.
1. Правим файл pg_hba.conf
Находим файл в папке Data директории установки PostgreSQL. В Windows путь выглядит примерно так c:\Program Files\PostgreSQL\9.2.4-1.1C\data\
В этом файле нужно найти такие строчки
# IPv4 local connections: host all all 127.0.0.1/32 md5 host all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 md5
Меняем md5 на trust.
2. Удаляем файл pgpass.conf
В Windows этот файл находится в c:\Users\Administrator\AppData\Roaming\postgresql\
Здесь хранится старый пароль от PostgreSQL. Простое изменение хранимого здесь пароля мне не помогло. Поэтому я его просто удалил.
3. Меняем пароль в pgAdmin
Запускаем pgAdmin и нам предлагается ввести пароль. Если отметить галочку сохранить, то пароль будет сохранен в pgpass.conf и больше программой запрашиваться не будет.
Чтобы обеспечить безопасность использования паролей необходимо вернуть алгоритм шифрования md5. Для этого в файле pg_hba.conf параметр trust обратно меняем на md5.
Для подключения на локальном компьютере к PostgreSQL с помощью psql, pg_dump в локальных адресах IPv4 127.0.0.1/32 и IPv6 ::1/128 значение trust нужно оставить.
Спасибо софт-сетап
Join @AdmNtsRu on Telegram
Смотрите также:
Asked
Viewed
101k times
Several days ago I install postgesql 9.2 version on my local computer. (OS windows 7)
Now I forgot my password and I can not login in pgAdmin.
How to change postgresql password on windows 7?
- postgresql
- windows-7
asked Sep 3, 2013 at 8:41
Oto ShavadzeOto Shavadze
40.8k55 gold badges153 silver badges236 bronze badges
3
6 Answers
In the pg_hba.conf
file, change (temporarily) all METHOD
with trust
. EG :
host all all ::1/128 trust
instead of :
host all all ::1/128 md5
You can find where the pg_hba.conf
is located by typing in a psql command line:
SHOW hba_file;
answered Jun 1, 2014 at 11:52
Antoine MartinAntoine Martin
1,9132 gold badges16 silver badges28 bronze badges
1
-
Dont forget to restart service
Apr 1, 2015 at 18:21
Below steps helped me to reset the password-
-
Go to
pg_hba.conf
file at path e.g.C:\Program Files\PostgreSQL\10\data
and add below line at the end,host all postgres 127.0.0.1/32 trust
-
Restart the PostgreSQL service from services control panel (start -> run -> services.msc)
-
Connect using PgAdmin or any software that you prefer and run query,
ALTER USER postgres PASSWORD 'postgres'
-
Remove the line that you added in step 1.
-
Restart PostgreSQL.
answered Apr 1, 2019 at 18:36
Hetal RachhHetal Rachh
1,4131 gold badge17 silver badges24 bronze badges
2
-
I was able to loging using My SQL and run: ALTER USER postgres PASSWORD myPassword. Do I need the »? Because it didn’t work. What worked for me was to login using pgAdmin4 and change inside the server config. After resenting the pg_hba the new password worked.
Mar 8, 2020 at 19:35
-
I think you should replace the «host xxx md5» line. Only adding did not worked for me.
Mar 8, 2020 at 19:44
splash
13k1 gold badge44 silver badges67 bronze badges
answered Sep 3, 2013 at 8:52
BenBen
35k6 gold badges75 silver badges114 bronze badges
6
-
Edit how? I have no idea what to put or remove from that file.
Nov 1, 2013 at 22:23
-
@klerik, the link is to the manual page for pg_hba.conf. It explains everything about pg_hba.conf.
Nov 2, 2013 at 10:15
-
Note that in Windows the
pg_hba.con
file is under thedata
folder, e.g.C:\Program Files\PostgreSQL\9.3\data
Dec 18, 2017 at 20:38
-
Still get an error even after making a new password
Sep 10, 2018 at 1:58
-
Very bad explained answer. I don’t know how it got 14 votes.
Mar 8, 2020 at 19:23
I am using postgres version 14.0 and Windows 10. To reset the password:
-
I opened the windows command prompt and typed: psql -U postgres(postgres is my username)
-
Type in your current password
3 Then type: \password postgres
It brings up the prompts to type the new password and confirm. Note for the psql command to work on the windows command prompt, you need to set the postgres bin folder on the path environment variable. You can just google how to do this.
answered Oct 18, 2021 at 14:16
Run your psql executable file and login into your database using your old password, use the following command to login:
.\psql.exe -U postgres
Then use
ALTER USER <user_name> WITH PASSWORD <'new_password'>
For more information refer this link :
https://www.postgresql.org/docs/8.0/sql-alteruser.html
balintbabics
1,2912 gold badges11 silver badges25 bronze badges
answered Jan 28, 2019 at 8:20
1
-
IF you can still login (hence haven’t forgotten your password), this is probably the easiest and most save.
Feb 24, 2019 at 9:29
In windows postgres stores password for automatic login at following path
(only if you would have selected password save option while installation)
C:\Users\USERNAME\AppData\Roaming\postgresql\pgpass.conf
you can open this file in a text editor and see your password.
answered Sep 19, 2017 at 9:40
2
-
I wasn’t able to find this file nor the
postgresql
folder in my Roaming folder though.Dec 18, 2017 at 20:33
-
thank you, I was able to find the file ‘pgpass.conf’ in another user’s folder
Jan 29, 2019 at 13:55
- The Overflow Blog
- Featured on Meta
Linked
Related
Hot Network Questions
-
Can a defense attorney face any serious repercussions for trying to induce jury nullification?
-
Electric Dryer Issue: Clothes Damp in Sensor Drying Mode
-
How axial precession affects the night sky
-
What do countries gain from UN peacekeeping deployment?
-
What would be an appropriate size for an interplanetary bulk cargo ship?
-
NameValueList in JSS to field type
-
Applying for a PhD as a disabled person
-
A Trivial Pursuit #18 (Sports and Leisure 3/4): Connected
-
Add circles at boundary of cells in voronoi texture
-
Idiom for unexpected solution?
-
Meaning of «schon einmal»
-
Why does causality imply that the system function is analytic?
-
Movie involving a crashed/landed alien craft in an icy cavern
-
How to take good photos of stars out of a cockpit window using the Samsung 21 ultra?
-
When did “word” become a synonym of “promise” for the first time?
-
Why do some Chinese shows avoid using real toponyms?
-
Looking for a good Emacs/AUCTeX setup for LaTeX3
-
How can unrelated language families exist?
-
Why are jurors still asked to operate the law if their primary role is to find facts?
-
How can I write the equation of the parabola passing through list of three points?
-
Eliminating one variable from two simple polynomial equations
-
What do the notes represent if their relationships are different in different tuning systems?
-
Understanding the diffusion error of numerical schemes
-
How would a Bayesian define a fair coin?
more hot questions
Question feed
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Забыли пароль учетной записи postgres в PostgreSQL? Выполнить сброс не сложно. Для этого необходимо выполнить пару манипуляций.
1. Правим файл pg_hba.conf
Находим файл в папке Data директории установки PostgreSQL. В Windows путь выглядит примерно так c:\Program Files\PostgreSQL\9.2.4-1.1C\data\
В этом файле нужно найти такие строчки
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
Меняем md5 на trust.
2. Удаляем файл pgpass.conf
В Windows этот файл находится в c:\Users\Administrator\AppData\Roaming\postgresql\
Здесь хранится старый пароль от PostgreSQL. Простое изменение хранимого здесь пароля мне не помогло. Поэтому я его просто удалил.
3. Меняем пароль в pgAdmin
Запускаем pgAdmin и нам предлагается ввести пароль. Если отметить галочку сохранить, то пароль будет сохранен в pgpass.conf и больше программой запрашиваться не будет.
Чтобы обеспечить безопасность использования паролей необходимо вернуть алгоритм шифрования md5. Для этого в файле pg_hba.conf параметр trust обратно меняем на md5.
Для подключения на локальном компьютере к PostgreSQL с помощью psql, pg_dump в локальных адресах IPv4 127.0.0.1/32 и IPv6 ::1/128 значение trust нужно оставить.
Sometimes you may need to change user password in PostgreSQL, for database management and website administration. In this article, we will look at how to change user password in PostgreSQL. You can use these steps to change postgres password in Ubuntu, Windows and other Linux systems. You can also use it to change default postgres password.
Here are the steps to change user password in PostgreSQL.
1. Log into PostgreSQL
Open terminal and run the following command to log into PostgreSQL. Replace username and dbname with your username and database name respectively.
$ sudo -u username psql dbname
Also read : How to change user to superuser in PostgreSQL
2. Change User Password
We will use the ALTER USER command to change user password. Here is its syntax.
ALTER ROLE username WITH PASSWORD 'password';
In the above command, you need to specify the username whose password you want to change, and also the new password for that user.
Run the following ALTER USER command to change user password. Replace testuser and newpassword with
ALTER USER testuser WITH PASSWORD 'newpassword';
Similarly, if you want to change password for postgres user, modify the above command as shown.
ALTER USER postgres WITH PASSWORD 'newpassword';
Also read : How to Copy data from one table to another in SQL
Sometimes you may need to expire a password after a specific date. In such cases, use VALID UNTIL clause with ALTER USER statement. Here’s the above SQL query modified to set password expiration date as December 31, 2020.
ALTER USER testuser WITH PASSWORD 'newpassword'
VALID UNTIL 'December 31, 2020';
As you can see, it is very easy to change user password in PostgreSQL in Ubuntu, CentOS and other systems.
Need a reporting tool for PostgreSQL? Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!
Related posts:
- About Author
In PostgreSQL, postgres
is the superuser. If you have forgotten the password of postgres
, you can reset it by the following steps.
-
Locate the configuration file
pg_hba.conf
for the PostgreSQL database server.On Windows, the configuration files for the PostgreSQL database server are located in the
data
directory of the PostgreSQL installation directory, for example:C:\Program Files\PostgreSQL\14\data
.On Linux, the configuration file for the PostgreSQL database server is located at
/etc/postgresql/14/main/pg_hba.conf
. -
Back up the configuration file before modifying it so that you can restore it later.
cp pg_hba.conf pg_hba.conf.bak
-
Modifying the configuration file to trust local connections does not require a password. Modify
scram-sha-256
ormd5
in the configuration file totrust
as follows:local all all peer # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust # Allow replication connections from localhost, by a user with the # replication privilege. local replication all peer host replication all 127.0.0.1/32 trust host replication all ::1/128 trust
-
Restart the PostgreSQL database server.
On Windows, you can restart PostgreSQL in the Services List window.
In Linux, you can restart PostgreSQL with the
systemctl restart postgresql
command. -
Log in to the PostgreSQL database server.
You do not need to enter a password.
-
Use the following command to modify the
postgres
user’s password:ALTER USER postgres WITH PASSWORD 'new_password';
-
Restore the
pg_hba.conf
configuration file. Overwrite thepg_hba.conf
file with the contents of thepg_hba.conf.bak
file. -
Restart the PostgreSQL database server. When you log in, PostgreSQL should prompt you for a password.
Conclusion
This article explains the detailed steps to reset the password of superuser postgres
.