Everywhere All articles Download Buy — $19

Where apps hide your files

Finding PostgreSQL's data folder

Updated 2026-10-28 · 6 min read

The folder depends on how you installed PostgreSQL: Homebrew, Postgres.app or EnterpriseDB's installer each use a different place. Here is each path, a command that asks the server directly, and how to back it up or free space.

The quickest answer: ask the server

If PostgreSQL is running, this prints the exact folder whatever the install method:

psql -d postgres -c "SHOW data_directory;"

It needs a superuser or a role allowed to read server settings; with Homebrew and Postgres.app your own account normally is one. If no server is running, use the default for your install type:

Homebrew, Apple silicon:  /opt/homebrew/var/postgresql@18
Homebrew, Intel:          /usr/local/var/postgresql@18
Postgres.app:             ~/Library/Application Support/Postgres/var-18
EnterpriseDB installer:   /Library/PostgreSQL/18/data

Replace 18 with your major version. Homebrew's formulae are versioned (postgresql@17, postgresql@18 and so on; plain postgresql is currently an alias for @18), and each creates its cluster in var/postgresql@NN under the prefix. Older installs from the unversioned formula used var/postgres, and the postgresql@14 formula still tells you how to migrate from that folder if it finds one. To list candidates, run ls "$(brew --prefix)/var" | grep -i postgres.

Do not stop at the first folder you find. The Apple silicon Mac used to check this guide also carries an older Intel Homebrew in /usr/local, where both /usr/local/var/postgres and /usr/local/var/postgresql@14 exist, and the running postgresql@14 service turned out to use the older postgres folder because its launch agent still pointed there.

Which install do you have

InstallTelltale
Homebrewbrew list --formula shows a postgresql@NN entry, and ~/Library/LaunchAgents/homebrew.mxcl.postgresql@NN.plist exists if you ran brew services start
Postgres.appAn elephant icon in /Applications and in the menu bar
EnterpriseDBA /Library/PostgreSQL folder and usually the pgAdmin app

The Homebrew prefix is /opt/homebrew on Apple silicon and /usr/local on Intel. A Mac that moved from Intel to Apple silicon with Migration Assistant can have both trees and two sets of data folders. Only one is the one your app talks to, so confirm with SHOW data_directory. For a Homebrew service, defaults read ~/Library/LaunchAgents/homebrew.mxcl.postgresql@NN.plist ProgramArguments shows the folder after -D without starting anything.

What is inside the folder

A data directory is the whole cluster, not one database. The names are the same on every install.

ItemWhat it is
PG_VERSIONA tiny file holding the major version (such as 14)
base/The databases themselves, one numbered folder per database
global/Cluster-wide tables such as roles
pg_wal/The write-ahead log, which grows under heavy writes
postgresql.confMain settings
pg_hba.confWho may connect and how
postmaster.pidWritten when the server starts; one left behind after a crash is stale

The numbers inside base/ are database object IDs, not names. To translate them, connect and run SELECT oid, datname FROM pg_database;. The file names inside are table IDs too, so you cannot pick a table out of the folder by eye.

Logs go elsewhere. Homebrew's formula sends the service log to var/log/postgresql@NN.log under the prefix (on the test Mac's /usr/local install, /usr/local/var/log/postgresql@14.log). Postgres.app writes postgres-server.log inside its data directory.

Connecting once you know the folder

The data directory is not what you point a client at. Clients connect to the running server on localhost port 5432, or to a Unix socket file, which Homebrew's build puts in /tmp. If a tool says it cannot connect, check that the server is running before you worry about the folder: pg_isready answers that in one line, and brew services list shows whether a Homebrew service is started.

Back up with dumps, not file copies

Do not copy the folder while the server is running; the copy may be unusable. The supported routes are:

pg_dump mydb > mydb.sql
pg_dumpall > everything.sql

pg_dump saves one database and pg_dumpall saves every database plus roles. Restore a plain SQL dump with psql, or a custom-format one with pg_restore. Postgres.app bundles the same tools in /Applications/Postgres.app/Contents/Versions/latest/bin, so the commands work there once that folder is on your PATH. A file-level copy is valid only with the server stopped, and only into the same PostgreSQL major version.

Space and what is safe to delete

Check size with du -sh on the folder (the Homebrew clusters on the test Mac were 92 MB and 337 MB). EnterpriseDB's folder belongs to the postgres system user, so it needs sudo du -sh. Space grows from your data, from pg_wal, and from dead rows after many updates. A plain VACUUM makes that space reusable but rarely shrinks the files; VACUUM FULL rewrites a table to return space to macOS, and locks the table while it runs. Dropping a database you no longer need, from inside psql, frees its folder.

Never delete files in base/ or pg_wal/ by hand: the server will refuse to start, and the loss is not recoverable. The one file you may remove is a stale postmaster.pid after a crash, and only when you are sure no postgres process is using that folder (ps aux | grep postgres shows each one with its -D folder).

Upgrading and moving

A new major version needs a new data directory: Homebrew installs postgresql@18 beside postgresql@17, each with its own folder. Move data across with pg_upgrade or with a dump and restore. To relocate a cluster, stop the server, move the folder, and start it with -D pointing at the new place (for a Homebrew service, that path lives in its launch agent). With Postgres.app, add a new server with the + button in its sidebar and move the data by dump and restore, rather than moving the folder under a server it already knows.

Finding it by name

~/Library is left out of Spotlight results, so a Postgres.app cluster never shows up there. In Everywhere, typing PG_VERSION lists that file at the top of every cluster on the Mac (and inside each database folder), including an old cluster left behind by a previous install, and postgresql.conf lands on the settings file. Pressing ⌘T opens a Terminal in that folder. It matches names only, so it shows you where each cluster is but not what is inside the tables.

Common questions

Where is the PostgreSQL data directory on a Mac?

It depends on the install: /opt/homebrew/var/postgresql@NN or /usr/local/var/postgresql@NN for Homebrew, ~/Library/Application Support/Postgres/var-NN for Postgres.app, /Library/PostgreSQL/NN/data for EnterpriseDB. Run SHOW data_directory; in psql for the exact path.

How do I find the data directory if the server is not running?

Look in the folder for your install type and check for a PG_VERSION file, which marks a data directory. ls "$(brew --prefix)/var" | grep -i postgres lists Homebrew's.

Can I copy the PostgreSQL data folder to back it up?

Only with the server stopped, and the copy works only with the same PostgreSQL major version. A pg_dump or pg_dumpall is the safer backup.

Why are my databases numbered folders?

Inside base/ each folder is named after the database's OID. SELECT oid, datname FROM pg_database; shows which is which.

Find any file before you finish typing

Everywhere keeps track of every file on your Mac — including the folders Spotlight hides and drives you have unplugged. Free for a day, then $19 once.

Version 2.20.3 · macOS 13+ · 4.7 MB · notarised

Related

© 2026 Caretopia Network Private Limited Everywhere for Mac Buy a licence Articles Privacy Support