37

How can I find where Postgres 8.x database files are saved in Ubuntu 10.04 file system?

2 Answers 2

50

In the postgres prompt, just execute this query:

SHOW data_directory;

Check also the Ubuntu manual: https://help.ubuntu.com/10.04/serverguide/C/postgresql.html

Sign up to request clarification or add additional context in comments.

6 Comments

Do i need to execute the SHOW command from the postgres prompt?
Execute this query just like you execute all queries. You could use pgAdmin, psql or whatever client you use. But, why do you need these files? And did you read the Ubuntu manual?
@FrankHeikens: I got a question: if a user can access the postgres database files, can they extract the database structure or other information from those files? Thanks.
SHOW data_directory; after running above command, it is giving me the result below. What does it mean? data_directory ------------------------------ /var/lib/postgresql/9.1/main (1 row)
@TaimoorChangaiz Uh, it means the data files are stored at /var/lib/postgresql/9.1/main
|
11

Here's how I located the directory of my Postgres database files in Ubuntu:

Run the command below in your terminal to switch user to postgres user:

su - postgres

It will request for the postgres user password which you set up when you were setting up PostgreSQL on your machine.

Next, you will need to login into the psql terminal/prompt. This can be accomplished by running the code below:

psql

It will also request for the postgres password which you set up when you were setting up PostgreSQL on your machine.

If you are successfully logged in, you will see a prompt similar to this:

psql (11.5 (Ubuntu 11.5-3.pgdg18.04+1), server 10.10 (Ubuntu 10.10-1.pgdg18.04+1))
Type "help" for help.

postgres=#

At this point you will execute the query below to display the directory where Postgres Database files are stored on your Linux macchine:

SHOW data_directory;

This should display an output similar to this:

data_directory        
-----------------------------
/var/lib/postgresql/10/main
(1 row)

You can now locate the Postgres Database files by navigating the directory that was displayed.

However, the PostgreSQL configuration directory in Ubuntu is located in /etc/postgresql/10/main. Take note that 10 is the version of my PostgreSQL installation on my server. Your version might be 9.5, 11 or 12 or any other version. Run the command psql --version to confirm your PostgreSQL version.

Run the command below to navigate to the directory:

cd ~
cd /etc/postgresql/10/main

That's all.

I hope this helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.