Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So this might be a stupid question, but I'm really new to this. So I'm making a Postgres database on the postgres server, that I started up with this command:

sudo -u postgres psql

And then I did the command:


Which supposedly created the database. But where is this database? Where can I find it on my computer?

share|improve this question

migrated from Mar 15 '13 at 22:04

This question came from our site for professional and enthusiast programmers.

Why do you want to know that ? Use pg_dump for backup. – Luc M Mar 15 '13 at 1:08
I recommend starting with . And you didn't start PostgreSQL with the psql command, you connected to it; it's a server and psql is the client. – Craig Ringer Mar 15 '13 at 1:17
The "database" is not a single file that you can take with you or look at. A database server manages this differently than e.g. Microsoft Access. – a_horse_with_no_name Mar 15 '13 at 9:30

Where exactly your data is stored depends on how you installed and configured PostgreSQL. Running the

show data_directory

command as the postgres user (from inside the psql tool or another client) will tell you where it is though. For example, if you installed it from the debian or ubuntu repositories you would probably find your data files are somewhere like /var/lib/postgresql/9.2/main.

There probably isn't anything terribly interesting in there though. Sometimes there are a few configuration files like pg_hba.conf (the windows version puts them there at least) but if you're on debian you'll find those under /etc/postgresql/.

If you're expecting your database to be a single file that you can move around between systems, etc, you're probably better off using a simpler embedded database like sqlite.

share|improve this answer

To see where the data directory is, use this query.

show data_directory;

To see all the run-time parameters, use

show all;

You can create tablespaces in other parts of the filesystem. To see the location of tablespaces, which might be somewhere in the filesystem besides the data directory, use this query.

SELECT * FROM pg_tablespace;
share|improve this answer
+1 on mentioning tablespaces (and how to get the information). – Erwin Brandstetter Mar 16 '13 at 2:12

when you execute the "CREATE DATABASE database" command, it uses the pg_default tablespace;

you can create your own tablespace first,such as

CREATE TABLESPACE tbs_01 [ OWNER user_name ] LOCATION 'directory';

and than create your database:

WITH  OWNER = user_name 
      TEMPLATE = template0 
      ENCODING = 'UTF8' 
      TABLESPACE = tbs_01;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.