然后你应该可以使用 psql 作为 postgres 超级用户使用这个 shell 命令登录:sudo -u postgres psql进入 psql 后,发出 SQL 命令:ALTER USER postgres PASSWORD 'newpassword';在这个命令中,postgres 是一个超级用户的名字.如果忘记密码的用户是ritesh,则命令为:ALTER USER ritesh PASSWORD 'newpassword';参考:PostgreSQL 9.1.13 文档,第 19 章客户端身份验证请记住,您需要输入 postgres 并在末尾添加一个 S如果在命令历史或服务器日志中以明文形式保留密码是一个问题,psql 提供了一个交互式元命令来避免这种情况,作为 ALTER USER ... PASSWORD:\password 用户名它通过双盲输入要求输入密码,然后根据 password_encryption 设置并向服务器发出 ALTER USER 命令和密码的散列版本,而不是明文文字版.In Ubuntu, I installed PostgreSQL database and created a superuser for the server.If I forgot the password of the postgresql superuser, how can I reset it (the password) for that user?I tried uninstalling it and then installing it again but the previously created superuser is retained. 解决方案 Assuming you're the administrator of the machine, Ubuntu has granted you the right to sudo to run any command as any user.Also assuming you did not restrict the rights in the pg_hba.conf file (in the /etc/postgresql/9.1/main directory), it should contain this line as the first rule:# Database administrative login by Unix domain socketlocal all postgres peer(About the file location: 9.1 is the major postgres version and main the name of your "cluster". It will differ if using a newer version of postgres or non-default names. Use the pg_lsclusters command to obtain this information for your version/system).Anyway, if the pg_hba.conf file does not have that line, edit the file, add it, and reload the service with sudo service postgresql reload.Then you should be able to log in with psql as the postgres superuser with this shell command:sudo -u postgres psqlOnce inside psql, issue the SQL command:ALTER USER postgres PASSWORD 'newpassword';In this command, postgres is the name of a superuser. If the user whose password is forgotten was ritesh, the command would be:ALTER USER ritesh PASSWORD 'newpassword';References: PostgreSQL 9.1.13 Documentation, Chapter 19. Client AuthenticationKeep in mind that you need to type postgres with a single S at the endIf leaving the password in clear text in the history of commands or the server log is a problem, psql provides an interactive meta-command to avoid that, as an alternative to ALTER USER ... PASSWORD:\password usernameIt asks for the password with a double blind input, then hashes it according to the password_encryption setting and issue the ALTER USER command to the server with the hashed version of the password, instead of the clear text version. 这篇关于PostgreSQL:在 Ubuntu 上重置 PostgreSQL 的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 03:35