Postgresql:如何使用 Mac OS X 查找 pg_hba.conf 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14025972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:55:20  来源:igfitidea点击:

Postgresql: How to find pg_hba.conf file using Mac OS X

postgresql

提问by bigpotato

Hi I am having trouble with postgres. I don't remember my postgres password and don't know how to change the password. I'm guessing I should change the md5 password settings I set a month ago, but I don't know how to find the file and open it using my terminal. Can someone help?

嗨,我在使用 postgres 时遇到了麻烦。我不记得我的 postgres 密码,也不知道如何更改密码。我猜我应该更改我一个月前设置的 md5 密码设置,但我不知道如何找到该文件并使用我的终端打开它。有人可以帮忙吗?

回答by bigpotato

Another way I learned recently is to go to the terminal and type:

我最近学到的另一种方法是去终端输入:

ps aux | grep postgres

ps aux | grep postgres

which shows all the postgres processes running on your machine. From the list you should see one with the format ... -D .... E.G:

它显示了在您的机器上运行的所有 postgres 进程。从列表中您应该看到一个格式为... -D .... 例如:

root            4155   0.0  0.0  2432908     68   ??  S     6May13   0:00.01 sudo su postgres -c /opt/local/lib/postgresql84/bin/postgres -D /opt/local/var/db/postgresql84/defaultdb -p 5432

the -D means directory. In the terminal, do a sudo suand then cd to that directory, and you'll find the pg_hba.conf file.

-D 表示目录。在终端中,执行 asudo su然后 cd 到该目录,您将找到 pg_hba.conf 文件。

And one more way:

还有一种方法:

Go to your terminal and type: locate pg_hba.conf. There should be a few results.

转到您的终端并输入:locate pg_hba.conf。应该有几个结果。

回答by Craig Ringer

If you can connect, use SHOW hba_file;.

如果可以连接,请使用SHOW hba_file;.

If you cannot connect, you need to locate the data directory. That'll be shown as the -Dargument to the postgresor pg_ctlcommand that starts PostgreSQL, so you can generally find it with ps -ef | grep postgres.

如果无法连接,则需要定位到数据目录。这将显示为启动 PostgreSQL-Dpostgresorpg_ctl命令的参数,因此您通常可以使用ps -ef | grep postgres.