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

Postgresql

Postgresql Problem Overview


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?

Postgresql Solutions


Solution 1 - Postgresql

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

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:

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 su and then cd to that directory, and you'll find the pg_hba.conf file.

And one more way:

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

Solution 2 - Postgresql

If you can connect, use SHOW hba_file;.

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

Solution 3 - Postgresql

For macOS 12, you can open the file using nano in your terminal. Example below is if Postgres 12 is installed.

`nano /Library/PostgreSQL/12/data/pg_hba.conf`

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbigpotatoView Question on Stackoverflow
Solution 1 - PostgresqlbigpotatoView Answer on Stackoverflow
Solution 2 - PostgresqlCraig RingerView Answer on Stackoverflow
Solution 3 - PostgresqltokingView Answer on Stackoverflow