Is there a way to break into a PostgreSQL database if you forgot the password?

后端 未结 2 841
生来不讨喜
生来不讨喜 2021-02-02 14:50

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 n

2条回答
  •  遥遥无期
    2021-02-02 15:17

    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

提交回复
热议问题