【问题标题】:Unable to reset PSQL password or edit pg_hba.conf file on mac无法在 mac 上重置 PSQL 密码或编辑 pg_hba.conf 文件
【发布时间】:2018-03-29 20:13:09
【问题描述】:

我的问题最初是我无法使用 PostgreSQL,因为我不知道密码——我也没有做过密码。我试图重置或恢复密码,并在尝试执行此操作时遵循了各种建议。

起初我尝试编辑 pg_hba.conf 文件,我使用以下命令找到该文件:

sudo vim /etc/postgresql/9.3/main/pg_hba.conf

但这只是把我带到一个空白屏幕,除了关闭窗口我什么都做不了。

有人告诉我试试:

sudo nano /etc/postgresql/9.3/main/pg_hba.conf

...这更好,因为它在页面底部包含了键盘命令,但是文件是空白的,因此无法编辑。

回到这个之后,我想会导致一些错误,如果我现在回到它,我会得到这个:

E325: ATTENTION
Found a swap file by the name "/var/tmp/pg_hba.conf.swp"
      owned by: root   dated: Tue Oct 17 15:57:30 2017
     file name: /etc/postgresql/9.3/main/pg_hba.conf
      modified: YES
     user name: root   host name: Roberts-MacBook-Pro.local
    process ID: 2668
While opening file "/etc/postgresql/9.3/main/pg_hba.conf"

(1) Another program may be editing the same file.  If this is the case,
be careful not to end up with two different instances of the same
file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r 
/etc/postgresql/9.3/main/pg_hba.conf"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file 
"/var/tmp/pg_hba.conf.swp"
to avoid this message.

Swap file "/var/tmp/pg_hba.conf.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit,
(A)bort:

我尝试通过键入 D 来删除 .swp 文件,但这似乎没有任何作用。

我真的对这一切感到困惑,我真的不知道如何才能了解更多信息以了解我在做什么。当我访问 PostgreSQL 网站时,我阅读了 pp_hba.conf 文件的外观,但我访问该文件的唯一方法是它完全是空的。

我不知道从哪里开始,所以我非常感谢任何可以为我指明正确方向的人的建议,谢谢。

【问题讨论】:

  • 谢谢,但我已经经历了这个阶段。我应该提到这一点。
  • 你还在使用 PostgreSQL 9.3 吗?你是如何安装它的?如果 Mac OS 上的配置位于 /etc 中,我会感到惊讶。
  • 哦,我真傻 - 是的,应该是:Library/PostgreSQL/9.6/data/pg_hba.conf
  • 但它仍然让我在 vim 中看到相同的错误消息(如上)

标签: postgresql


【解决方案1】:

只要 PostgreSQL 已经启动,你就可以通过运行找出你应该编辑的pg_hba.conf

ps -ef | grep 'postgres -D'

在我奇怪的设置中,这会返回:

/opt/boxen/homebrew/opt/postgresql/bin/postgres -D /opt/boxen/homebrew/var/postgres

所以我知道要编辑文件:

/opt/boxen/homebrew/var/postgres/pg_hba.conf

更改允许哪些连接到哪些数据库等。有关详细信息,另请参阅pg_hba.conf docs

【讨论】:

  • 谢谢,但我已经经历了这些阶段,并且我有 pg_hba.conf 文件,但我在编辑它时遇到了麻烦。你提到的文档让我相信我会在文件上看到一些东西,但是当我通过 VIM 或 Nano 访问它时,它完全是空白的。所以我正在尝试解决如何编辑它,以便我可以重置我的 PSQL 密码。有什么想法吗?
  • 它是空白的事实意味着文件不存在(vim 将显示[New File]),或者您没有编辑文件的权限(vim 将显示[Permission Denied])。
  • 实际上VIM在底部显示[新目录]。在这种情况下我该怎么办?
  • [New DIRECTORY] 是如果您尝试编辑的路径中的一个目录不存在,vim 将显示的内容。您可以通过像vim /foo/bar/baz.txt 和与您尝试编辑 pg_hba.conf 时看到的内容相比 - 底线是您认为应该存在的文件,无论出于何种原因,它都不存在。
猜你喜欢
  • 2018-02-19
  • 1970-01-01
  • 2016-03-01
  • 2021-05-01
  • 1970-01-01
  • 2014-11-16
  • 2020-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多