Windows cmd/powershell 中的 psql 密码错误

Windows psql wrong password in cmd/powershell

我最近遇到了一个很有趣的问题。

当我想通过cmd访问'psql'时,它报告用户'postgres'的密码错误。与服务器安装捆绑在一起的预定义 psql shell 有效。将 pg_hba.conf 设置为 trust 也不起作用。 heroku命令也没有(我试过拉一个远程数据库到本地)。

问题是我在安装时将端口设置为 5433。出于某种原因,psql 命令没有从 postgresql.conf 读取端口。也许有办法改变这种行为,但我采用的解决方案是将 data\postgresql.conf 中的端口更改为 5432 并重新启动服务器。虽然捆绑的 psql shell 现在不起作用,但 cmd 和 heroku 可以连接!

虽然您已经解决了您的问题,但有人尝试在 cmd/powershell/any shell 中启动 psql 可能会有用,例如:

psql postgresql://username:password@dbhost:dbport/dbname

当必须启动 psql 或执行某些命令(通过使用“-c”属性)而不提示密码时,它可能会有所帮助。