Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

You search a Mac for pg_hba.conf or postgresql.conf and find nothing

ErrorNo such file or directory

Short answer

PostgreSQL does not keep these files in /etc. By default they sit in the data directory, which depends on how it was installed. If the server runs, SHOW hba_file and SHOW config_file print the paths. If it does not, look in the Homebrew data directory under var/postgresql@version, or in the Postgres.app folder in Application Support.

  • Applies to PostgreSQL 17, PostgreSQL 18, macOS with Homebrew, Postgres.app
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    If the server is running, ask it. SHOW prints the current value of a run-time parameter, and the locations of the configuration files are parameters. Each -c runs one command.

    psql -d postgres -c "SHOW config_file;" -c "SHOW hba_file;" -c "SHOW data_directory;"
  2. 2Match what you see, then jump to its fix

    1. 1Tutorials for Linux point at /etc/postgresql or /etc/postgres, and nothing is there on your MacYou are looking in /etc, but the files live in the data directoryFix
    2. 2You ran brew install postgresql@17 (or another version) and the SHOW command cannot connectPostgreSQL came from Homebrew, so the data directory is under the Homebrew prefixFix
    3. 3You installed from the Postgres.app download, and there is no brew servicePostgreSQL is Postgres.app, which keeps its data in Application SupportFix

What does the error look like?

  • No such file or directory
  • ls: /etc/postgresql: No such file or directory

Cause 1 of 3

You are looking in /etc, but the files live in the data directory

1Check

By default all three configuration files are stored in the database cluster's data directory, and the server finds that directory through the -D option or the PGDATA environment variable. The running server knows its own paths.

psql -d postgres -c "SHOW hba_file;"
echo "$PGDATA"

2Fix

Open the path that SHOW printed. After you edit pg_hba.conf, the server only rereads it on a reload, or on a restart.

# path from SHOW hba_file
open -e "/path/printed/above/pg_hba.conf"
psql -d postgres -c "SELECT pg_reload_conf();"

3Verify

After the reload, the view that shows the parsed pg_hba.conf returns no row with an error.

psql -d postgres -c "SELECT line_number, error FROM pg_hba_file_rules WHERE error IS NOT NULL;"

Confirmed by postgresql.org

Did this fix it?

Cause 2 of 3

PostgreSQL came from Homebrew, so the data directory is under the Homebrew prefix

1Check

Homebrew keeps the data directory in var/postgresql@<major version> below its prefix, and the formula's background service starts the server with that directory. The prefix differs between machines, so ask brew for it instead of guessing.

brew services list
ls "$(brew --prefix)/var/postgresql@17"

2Fix

Read pg_hba.conf and postgresql.conf from that directory. If the directory does not exist, the cluster has not been created yet. The formula's caveats print the initdb command for it, so run exactly the line that brew info shows, then start the service.

brew info postgresql@17
brew services start postgresql@17

3Verify

The files are now in the directory, and SHOW hba_file from the running server prints a path inside it.

ls "$(brew --prefix)/var/postgresql@17"/*.conf
psql -d postgres -c "SHOW hba_file;"

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

PostgreSQL is Postgres.app, which keeps its data in Application Support

1Check

Postgres.app stores the data in a folder named var-XX under Application Support, where XX is the major version. Its window has a Server Settings button that lists the files.

ls ~/Library/Application\ Support/Postgres

2Fix

In Postgres.app, click Server Settings, then use Show next to the config file or the HBA file. After you edit, reload or restart the server so it rereads the file.

open ~/Library/Application\ Support/Postgres

3Verify

Finder shows the var-XX folder, and the two files are inside it.

ls ~/Library/Application\ Support/Postgres/var-17/*.conf

Confirmed by postgresapp.com

Did this fix it?

How do I stop it coming back?

  • Write down the path from SHOW hba_file once, in your project's notes, instead of searching for it each time.
  • Edit pg_hba.conf with a copy open elsewhere, and check pg_hba_file_rules after a reload, because the first matching record wins.
  • Keep one PostgreSQL install per machine, or note which port each one uses, so psql talks to the server whose files you edited.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.