如果你忘记了密码,有没有办法闯入PostgreSQL数据库?[英] Is there a way to break into a PostgreSQL database if you forgot the password?

本文是小编为大家收集整理的关于如果你忘记了密码,有没有办法闯入PostgreSQL数据库?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有一个具有PostgreSQL数据库的客户端,他不记得我们在设置数据库时使用的密码.有没有办法恢复该信息,因此我不必吹走他的数据库并从头开始?

数据库在PC上运行.

推荐答案

步骤1:编辑PostgreSQL配置文件,以建立与登录密码的信任关系:

:

vi/var/lib/pgsql/data/pg_hba.conf

旧线:

本地所有Postgres密码

将其更改为:

本地所有Postgres Trust

步骤2:重新启动PostgreSQL服务器:

服务postgresql restart

步骤3:更改密码:

PSQL -U Postgres Template1 -c Alter用户Postgres带有密码" newpassword";

步骤4:密码已更新.还原配置文件的原始设置:

vi/var/lib/pgsql/data/pg_hba.conf

旧线:

本地所有Postgres Trust

将其更改为:

本地所有Postgres密码

步骤5:重新启动服务器并使用新密码访问PostgreSQL Server.

服务postgresql restart

source

其他推荐答案

对于9.2,在Windows中:

停止服务:

净停止Postgresql-X64-9

修改配置文件, 更改data/pg_hba.conf,基本上是md5以信任:

主机全部127.0.0.1/32 Trust

主持所有:: 1/128 Trust

开始服务:

网络启动PostgreSQL-X64-9

执行SQL语句以在SQL控制台或使用PSQL上设置所需密码:

使用密码" newpassword"; alter用户邮政;

放回原始配置文件.

本文地址:https://www.itbaoku.cn/post/597589.html

问题描述

I have a client that has a PostgreSQL database and he cannot remember the password that we used when the database was setup. Is there a way to recover that information so I do not have to blow away his database and start from scratch?

The database is running on a PC.

推荐答案

Step 1: Edit PostgreSQL config file to establish trust relationship to login without password:

vi /var/lib/pgsql/data/pg_hba.conf

Old Line:

local all postgres password

Change it to:

local all postgres trust

Step 2: Restart PostgreSQL Server:

service postgresql restart

Step 3: Change password:

psql -U postgres template1 -c alter user postgres with password ‘newpassword’;

Step 4: Password has been updated. Revert back the original settings of config file:

vi /var/lib/pgsql/data/pg_hba.conf

Old Line:

local all postgres trust

Change it to:

local all postgres password

Step 5: Restart server and use your new password to access PostgreSQL Server.

service postgresql restart

Source

其他推荐答案

For 9.2, in windows:

Stop the service:

Net stop postgresql-x64-9

Modify the config file, change data/pg_hba.conf, basically md5 to trust:

host all all 127.0.0.1/32 trust

host all all ::1/128 trust

Start the service:

Net start postgresql-x64-9

Execute the sql statement to set your desired password, on a sql console or using psql:

alter user postgres with password ‘newpassword’;

Put back the original config file.