Postgresql – How to find PostgreSQL’s data directory

mac os xpostgresql

I forgot how I started PostgreSQL the last time (it was months ago) and I don't remember where the data directory is located. The postgres command seems to require the location of the data directory.

I'm on MacOsX if that helps.

/usr/local/postgres doesn't exist on my Mac.

Using the answers provided below, I found that it was here:

/usr/local/var/postgres

Best Answer

If you can connect to the database with superuser access, then

SHOW data_directory;

is the shortest way.

If the server is not running and you forgot where the data directory was, then you really have to guess yourself. An operating system specific convention or the shell history might provide hints.