2012-12-24 46 views
40

您好我在使用postgres時遇到問題。我不記得我的postgres密碼,也不知道如何更改密碼。我猜我應該更改一個月前設置的md5密碼設置,但我不知道如何找到該文件並使用我的終端打開它。有人可以幫忙嗎?Postgresql:如何使用Mac OS X找到pg_hba.conf文件

回答

73

另一種方式我最近才知道是去終端類型:

ps aux | grep postgres

這表明所有的機器上運行的Postgres處理。從列表中您應該看到格式爲... -D ...的格式。 E.G:

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

的-D意味着目錄。在終端中,執行sudo su,然後cd到該目錄,您將找到pg_hba.conf文件。

而另一種方式:

轉到您的終端類型:locate pg_hba.conf。應該有一些結果。

+1

感謝有用.. [鏈接](http://scratching.psybermonkey.net/2009/06/postgresql-how-to-reset-user-name.html)未來.. –

+4

在最新的Postgres 9.x它將在/ data /目錄中找到 /Library/PostgreSQL/9.4/data/pg_hba.conf – Saad

45

如果可以連接,請使用SHOW hba_file;

如果無法連接,則需要找到數據目錄。這將顯示爲啓動PostgreSQL的postgrespg_ctl命令的-D參數,因此您通常可以通過ps -ef | grep postgres找到它。

+4

使用EnterpriseDB.com安裝程序安裝Postgres 9.2的Mountain Lion Mac上的示例結果:'/ Library/PostgreSQL/9.2/data/pg_hba.conf'。 –

+1

這是找到它的最佳方法,謝謝! –