WindowsmacOSLinux

Where Is the PostgreSQL Data Directory?

PostgreSQL data directory defaults on Windows, macOS and Linux, how to print the live path with SQL, and backup rules.

Last updated

PostgreSQL stores databases as a data directory with a version named child holding base, global and pg_wal subfolders. The default parent differs per installer: Program Files on Windows, /var/lib/postgresql on Linux packages, Library/PostgreSQL on Mac EDB builds.

Never copy this tree while the server runs. Use pg_dump for logical backups and file copies only with the service stopped. Run SHOW data_directory inside psql to print the live path instead of trusting installer defaults across versions.

Where PostgreSQL stores this, by platform

Windows
C:\Program Files\PostgreSQL\[version]\data

The version number changes the leaf folder. Stop the postgresql service before any file copy. Config files postgresql.conf and pg_hba.conf sit inside.

macOS
/Library/PostgreSQL/[version]/data

EDB installer default. Homebrew builds use /opt/homebrew/var/postgresql@version instead. Check SHOW data_directory in psql to confirm yours.

Linux
/var/lib/postgresql/[version]/main

Debian and Ubuntu pair this with /etc/postgresql for configs. The postgres user must own every file, so preserve permissions on copies.

Frequently asked questions

How do I find my live data directory?

Connect with psql and run SHOW data_directory. That prints the exact path the running server uses, which beats guessing across installers and versions.

Can I copy the data folder as a backup?

Only with the server fully stopped, and restore to the same major version. For routine safety prefer pg_dump, which restores across versions cleanly.

Notice an outdated path? Let us know.