【问题标题】:Unable to execute postgres command无法执行 postgres 命令
【发布时间】:2021-05-16 18:45:05
【问题描述】:

在我的 Windows 10 机器上安装 postgres 后,我很难更改与 postgres 用户关联的密码。提前道歉,因为我对 postgres 以及使用它所需的命令非常陌生。

我在下面的文章中引用了批准的答案: FATAL: password authentication failed for user "postgres" (postgresql 11 with pgAdmin 4)

我被困在需要我这样做的步骤上

Connect using psql or pgAdmin4 or whatever you prefer

Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

我不太明白这一步。我已采取以下步骤

  1. 打开cmd
  2. 运行 psql

然后系统要求我输入用户名 jason 的密码。无论我输入什么,我都会收到以下消息:

psql: error: could not connect to server: FATAL:  password authentication failed for user "jason"

在任何时候我都没有机会输入以下命令:

ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'

如何在不要求输入 postgres 密码的情况下运行此命令?

谢谢!

【问题讨论】:

  • psql -U username -d dbname postgresql.org/docs/current/app-psql.html
  • 这提示我输入密码,但我没有。
  • 系统不会要求您输入用户 postgres 的密码,而是输入用户 json 的密码。您需要使用psql 作为用户postgres 进行连接,并假设您知道postgres 的当前密码,请使用该密码。然后执行ALTER USER 命令。
  • 我不知道用户“postgres”的当前密码。这个练习的重点是将它重置为我知道的东西。
  • postgres 的密码将是您在图 5 中输入的密码 Installation

标签: postgresql


【解决方案1】:

以下步骤要求您记住安装 PostgreSQL 时所做的操作。

  • 找到安装过程创建数据库集群的数据目录。默认情况下,这将是您安装软件的子目录(这是一个不好的地方)

  • 编辑其中的pg_hba.conf 文件并将这一行添加到顶部:

    host postgres postgres 127.0.0.1/32 trust
    
  • 重新加载或重新启动 PostgreSQL。

  • 开始cmd.exe并进入

    psql -h 127.0.0.1 -p 5432 -d postgres -U postgres
    

    如果psql 不在您的PATH 上,请使用绝对路径C:\...\psql

  • 使用\password修改密码。

【讨论】:

    猜你喜欢
    • 2020-06-19
    • 2016-08-20
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    相关资源
    最近更新 更多