Forgot Admin Password on Postgres (Windows Installation), can't reset

前端 未结 3 721
野的像风
野的像风 2021-01-02 07:06

I have a Windows PostgreSQL installation.

According to some posts, there is no default password set for the \'postgres\' user yet I can\'t connect using an empty pa

3条回答
  •  佛祖请我去吃肉
    2021-01-02 07:33

    Update your pg_hba.conf file to allow for trusted local connections

    [root@server] vim pg_hba.conf
    >> local all all         trust
    

    then restart your PostgreSQL server

    [user@machine] pg_ctl -D C:\PostgreSQL\data restart    (Windows)
    [root@server] service postgresql restart            (Linux)
    

    at this point you can connect to your server as postgres user using a local connection without the need to enter a password (omitting the -h parameter when calling the psql command will use a local connection - if you pass -h then this will match the line host all all 0.0.0.0/0 in your pg_hba.conf file)

    [root@server] psql -U postgres
    

    You can then alter the postgres user role and set the password to whatever you like using the following command in the psql terminal

    [psql] alter role postgres password ;
    

    Once this is done you can restart your PostgreSQL server again

    [user@machine] pg_ctl -D C:\PostgreSQL\data restart     (Windows)
    [root@server] service postgresql restart             (Linux)
    

    and at this point your password should be changed to the new password

提交回复
热议问题