Cannot find pg_hba.conf and postgreql.conf file on OS X?
MacosPostgresqlHomebrewMacos Problem Overview
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.
Macos Solutions
Solution 1 - Macos
By default homebrew puts everything in /usr/local
So the postgresql conf files will be /usr/local/var/postgres/
Solution 2 - Macos
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 3 - Macos
Worst case, you can search for it:
find / -type f -name pg_hba.conf 2> /dev/null
Solution 4 - Macos
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 - Macos
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 6 - Macos
In MacOS Catalina are under the folder:
./Library/PostgreSQL/{postgres_version}/share/postgresql/
Solution 7 - Macos
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 8 - Macos
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