如果忘记密码,有没有办法闯入一个PostgreSQL数据库? [英] Is there a way to break into a PostgreSQL database if you forgot the password?
问题描述
我有一个客户端有一个PostgreSQL数据库,他不记得我们在数据库设置时使用的密码。有没有办法恢复这些信息,所以我不必吹走他的数据库,从头开始。
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?
数据库在电脑上运行。
推荐答案
步骤1:编辑PostgreSQL配置文件以建立信任关系,无需密码登录:
Step 1: Edit PostgreSQL config file to establish trust relationship to login without password:
vi /var/lib/pgsql/data/pg_hba.conf
vi /var/lib/pgsql/data/pg_hba.conf
旧项:
本地所有postgres密码
local all postgres password
$ b b
更改为:
Change it to:
local all postgres trust
local all postgres trust
步骤2:重新启动PostgreSQL服务器:
Step 2: Restart PostgreSQL Server:
service postgresql restart
service postgresql restart
步骤3:更改密码:
psql -U postgres template1 -c alter user postgres with password'newpassword';
psql -U postgres template1 -c alter user postgres with password ‘newpassword’;
步骤4: / strong>密码已更新。还原配置文件的原始设置:
Step 4: Password has been updated. Revert back the original settings of config file:
vi /var/lib/pgsql/data/pg_hba.conf
vi /var/lib/pgsql/data/pg_hba.conf
旧文章:
local all postgres trust
更改为:
/ p>
local all postgres password
步骤5:重新启动服务器并使用新密码访问PostgreSQL Server。
Step 5: Restart server and use your new password to access PostgreSQL Server.
service postgresql restart
service postgresql restart
这篇关于如果忘记密码,有没有办法闯入一个PostgreSQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!