Where is pg_hba.conf Located in PostgreSQL?
The
pg_hba.conf file in PostgreSQL is located in the data directory of your PostgreSQL installation. You can find its exact path by running SHOW hba_file; inside the PostgreSQL command line interface.Syntax
The pg_hba.conf file path can be found using the SQL command below inside the PostgreSQL shell or any SQL client connected to your database.
SHOW hba_file;: Displays the full path to thepg_hba.conffile.
sql
SHOW hba_file;
Output
/var/lib/postgresql/data/pg_hba.conf
Example
This example shows how to connect to PostgreSQL and find the location of pg_hba.conf using the psql command line tool.
sql
\c postgres SHOW hba_file;
Output
hba_file
------------------------------------
/var/lib/postgresql/data/pg_hba.conf
(1 row)
Common Pitfalls
Many users look for pg_hba.conf in random folders or assume it is in the PostgreSQL installation folder. However, it is always inside the data directory, which can vary by system or installation method.
Another mistake is editing the wrong pg_hba.conf file if multiple PostgreSQL versions are installed. Always confirm the path with SHOW hba_file;.
bash and sql
/* Wrong way: guessing the location */ $ cd /usr/local/pgsql $ ls pg_hba.conf ls: cannot access 'pg_hba.conf': No such file or directory /* Right way: find exact path */ SHOW hba_file;
Output
hba_file
------------------------------------
/var/lib/postgresql/data/pg_hba.conf
(1 row)
Quick Reference
| Command | Description |
|---|---|
| SHOW hba_file; | Shows the full path to the pg_hba.conf file. |
| psql -U username -d dbname | Connect to PostgreSQL database using psql. |
| Locate data directory | pg_hba.conf is inside the PostgreSQL data directory. |
| Edit pg_hba.conf | Modify client authentication rules here. |
Key Takeaways
Use the SQL command SHOW hba_file; to find the exact location of pg_hba.conf.
pg_hba.conf is always inside the PostgreSQL data directory, not the installation folder.
Avoid guessing the file location to prevent editing the wrong configuration.
Always reload PostgreSQL after changing pg_hba.conf to apply new settings.