Postgresql как изменить пароль пользователя postgres windows
Перейти к содержимому

Postgresql как изменить пароль пользователя postgres windows

  • автор:

How To Change User Password in PostgreSQL

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.

How To Change User Password in PostgreSQL

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.

2. Change User Password

We will use the ALTER USER command to change user password. Here is its syntax.

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

Similarly, if you want to change password for postgres user, modify the above command as shown.

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.

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!

Сброс пароля в PostgreSQL

Забыли пароль учетной записи 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 нужно оставить.

7 thoughts on “ Сброс пароля в PostgreSQL ”

Ты не сменил и не сбросил пароль. Ты отключил все механизмы защиты, поэтому он теперь пускает не с новым паролем, а вообще с ЛЮБЫМ. Строка trust как раз и отключает проверку пароля. А файл pgpass.conf нужен для того что бы утилитка pgAdmin могла туда сохранить пароль и не спрашивать его больше. Именно поэтому он храниться в твоем профиле, что бы никто другой не мог туда зяглянуть.
Пароль пользователя меняется командой ALTER USER user_name WITH PASSWORD ‘new_password’;

Удали статью, а то кучи начинающих «АДМИНОВ» понаоткрывают голую жопу по твоим советам.

  1. admin Автор записи 07.07.2019 в 16:05

Прежде чем писать такой комментарий

Строка trust как раз и отключает проверку пароля.

..внимательней читайте статью, там написано

параметр trust обратно меняем на md5

Про файл pgpass.conf тоже в статье сказано.
Так что с голой жопой останутся только такие же невнимательные как ты.

Глохни, петух. Как я смогу изменить пароль, если не могу на сервер зайти без пароля, придурок!

Тебе выше написали, что параметры доступа в pg_hba.conf изменены так, чтобы пустить потом тебя БЕЗ пароля с localhost. Да, когда меняете этот файл, перещапускать БД не забывайте.
Потом влетай в консоль psql -Upostgres -W -hlocalhost c пустым паролем, и меняй себе его наздоровье.
Затем возверни настройки обратно в md5 и перезапусти БД.

Виндовозники привыкли мышкой водить. Нет чтоб в терминале просто и со вкусом ALTER USER user_name WITH PASSWORD ‘new_password’;

На локальном компьютере это оказалось оптимальным решением. Конечно, в сочетании с обычной сменой пароля, когда смог попасть в админку. Если Вы и петух, то очень полезный для сообщества) Спасибо Вам!

Сброс пароля в PostgreSQL на Windows платформах

Забыли пароль учетной записи postgres в PostgreSQL? Выполнить сброс не сложно. Для этого необходимо выполнить пару манипуляций.

1. Правим файл pg_hba.conf

Находим файл в папке Data директории установки PostgreSQL. В Windows путь выглядит примерно так c:\Program Files\PostgreSQL\9.2.4-1.1C\data\

В этом файле нужно найти такие строчки

Меняем 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 нужно оставить.

Reset Forgotten Password For postgres User

Summary: in this tutorial, we will show you step by step how to reset the password of the postgres user in PostgreSQL.

For some reason, after installing PostgreSQL, you may forget the password of the postgres user. In this case, you need to know how to reset the password.

PostgreSQL uses the pg_hba.conf configuration file stored in the database data directory (e.g., C:\Program Files\PostgreSQL\12\data on Windows) to control the client authentication. The hba in pg_hba.conf means host-based authentication.

To reset the password for the postgres user, you need to modify some parameters in this configuration file, login as postgres without a password, and reset the password.

The following steps show you how to reset a password for the postgres user:

Step 1. Backup the pg_hba.conf file by copying it to a different location or just rename it to pg_hba.conf.bk

Step 2. Edit the pg_dba.conf file and change all local connections from md5 to trust. By doing this, you can log in to the PostgreSQL database server without using a password.

Step 3. Restart the PostgreSQL server. If you are on Windows, you can restart the PostgreSQL from Services:

Or run the following command from the window terminal:

The «C:\Program Files\PostgreSQL\12\data» is the data directory.

Step 4. Connect to PostgreSQL database server using any tool such as psql or pgAdmin:

PostgreSQL will not require a password to login.

Step 5. Execute the following command to set a new password for the postgres user.

Step 6. Restore the pg_dba.conf file, restart the PostgreSQL database server and connect to the PostgreSQL database server with the new password.

In this tutorial, you have learned how to reset the password of the postgres user.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *