28

I installed and created a Postgresql database on ubuntu. I then created the database using the following command:

sudo su postgres createdb mydatabase

However, I can't figure out where the database was initialized. I would like to be able to edit the hba.conf file and postgresl.conf files.

When I view the database using pgadmin I see the following information:

CREATE DATABASE mydatabase
  WITH OWNER = postgres
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       LC_COLLATE = 'en_US.UTF-8'
       LC_CTYPE = 'en_US.UTF-8'
       CONNECTION LIMIT = -1;

Any thoughts on how I can find the database cluster location?

celenius
  • 387
  • 1
  • 3
  • 7

2 Answers2

34

The postgres.conf file is located here: /etc/postgresql/9.1/main/postgres.conf. In postgres.conf can see a line stating data_directory=<path>

This is the directory where your database files are stored

Alternatively when you are connected to database use

SHOW data_directory

or

pg_lsclusters

to show the directory where your data is stored.

Hope this helps

Rinzwind
  • 293,910
  • 41
  • 570
  • 710
devav2
  • 35,738
  • 17
  • 79
  • 82
  • 1
    For me, it was not `postgres.conf` but `postgresql.conf`. – Abdull Mar 15 '16 at 18:17
  • Thanks,I was able to find this line following your answer, but unfortunately, we cannot cd into this directory:`/var/lib/postgresql/10/main`, I guess it's by design for safety and integrity of the data? – Fisher Coder Jun 15 '20 at 03:50
6
ps auxw|grep postgres|grep -- -D  

returns:

/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main 
-c config_file=/etc/postgresql/9.3/main/postgresql.conf

on Ubuntu 14.04. That command will work on other variants like Fedora

Rinzwind
  • 293,910
  • 41
  • 570
  • 710
tim
  • 61
  • 1
  • 1