'Cannot find pg_hba.conf and postgreql.conf file on OS X?

I installed postgres using homebrew. I would like to locate he files pg_hba.conf and postgresql.conf but I cannot find them.

I followed this :

https://askubuntu.com/questions/256534/how-do-i-find-the-path-to-pg-hba-conf-from-the-shell

and this

http://www.kelvinwong.ca/tag/pg_hba-conf/

but I still cannot find it.



Solution 1:[1]

If you can connect to Pg as the superuser (usually postgres) simply SHOW hba_file; to see its location.

Otherwise you have to find out how PostgreSQL is started to locate its data directory.

Solution 2:[2]

Worst case, you can search for it:

find / -type f -name pg_hba.conf 2> /dev/null

Solution 3:[3]

This could be a possible location to find the postgresql.conf/pg_hba.conf file

/opt/homebrew/var/postgres/postgresql.conf  

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

Solution 4:[4]

It's possible to edit those files without knowing their locations with pg admin https://dba.stackexchange.com/questions/61193/how-to-edit-postgresql-conf-with-pgadmin

  • To edit the postgresql.conf file: Choose Tools > Server Configuration > postgresql.conf
  • To edit the pg_hba.conf file: Choose Tools > Server Configuration > pg_hba.conf

Solution 5:[5]

Whatever your OS is, you always can use the psql utility, DBeaver or any other client tool, to type the SQL show command to see the value of any run-time setting.

For example, on my BigSur OSX system, where I have installed PostgreSQL v13 with the EDB installer, these are the locations for postgresql.conf and pg_hba.conf files using the psql utility:

psql -U postgres -c 'show config_file'
Password for user postgres: 
                 config_file                 
---------------------------------------------
 /Library/PostgreSQL/13/data/postgresql.conf
(1 row)
psql -U postgres -c 'show hba_file'
Password for user postgres: 
                hba_file                 
-----------------------------------------
 /Library/PostgreSQL/13/data/pg_hba.conf
(1 row)

Solution 6:[6]

In MacOS Catalina are under the folder:

 ./Library/PostgreSQL/{postgres_version}/share/postgresql/

Solution 7:[7]

Another solution to know the location of postgresql.conf is to start psql and type \show all Then search for the value of 'config_file'. For my docker configuration, this will be /var/lib/postgresql/data/postgresql.conf then I can connect to Docker with docker exec -it postgres bash -c "export TERM=xterm-256color ; bash" and view its content with cat /var/lib/postgresql/data/postgresql.conf

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Craig Ringer
Solution 2 A. Scherbaum
Solution 3
Solution 4 Community
Solution 5
Solution 6 Stefania Izzo
Solution 7 Olivier D