What directory is the create database stored in, which is created in the psql terminal through the create database ?

    2 answers 2

    psql is a client to the Postgresql database.

    Where, in turn, PostgreSQL itself stores the data with the command:

     show data_directory; 

    This entire directory (also known as PGDATA ) is the data of the DBMS, including all the databases created in this cluster. Be sure to include absolutely all the contents of all the symlinks within this directory! You can find a separate view created by create datebase inside the PGDATA directory, but you must understand that without the entire PGDATA directory, its individual parts are just a bunch of useless binary garbage. For any meaningful manipulations with PostgreSQL data, all PGDATA with all content for all symlinks is required.

    • In PGDATA are simple files. Is this a DB? I thought they would have some kind of extension. - Anton Sorokin
    • This directory is all the data for this postgresql instance. File extensions? And why are they needed? In PGDATA with the exception of recovery.conf (either a couple of signal files starting with PG12 instead of it, "thank you" to me), or, in some installations, pg_hba.conf and postgresql.conf - you don’t need to go at all. So why complicate naming with useless, frivolous extensions? - Shallow
    • data_directory may be empty? - Hellseher
    • @Hellseher looking from where to look. On the way from show data_directory; - can not. This configuration may be absent in configs. - Shallow

    In the terminology of PostgreSQL, this is called a cluster, in other words, the directory where ALL created databases will be stored, it can be a separate disk, NFS, DAS, SAN, etc.

    All possible configurations are stored in the postgresql.conf file:

     postgres:~$ grep data_directory /etc/postgresql/*/main/postgresql.conf data_directory = '/var/lib/postgresql/9.6/main' # use data in another directory postgres@:~$ ls -la /var/lib/postgresql/*/main total 92 drwx------ 19 postgres postgres 4096 Dec 3 01:40 . drwxr-xr-x 3 postgres postgres 4096 Nov 29 22:43 .. drwx------ 6 postgres postgres 4096 Nov 29 22:43 base drwx------ 2 postgres postgres 4096 Dec 1 00:12 global drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_clog drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_commit_ts drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_dynshmem drwx------ 4 postgres postgres 4096 Nov 29 22:43 pg_logical drwx------ 4 postgres postgres 4096 Nov 29 22:43 pg_multixact drwx------ 2 postgres postgres 4096 Dec 1 00:12 pg_notify drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_replslot drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_serial drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_snapshots drwx------ 2 postgres postgres 4096 Dec 1 00:12 pg_stat drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_stat_tmp drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_subtrans drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_tblspc drwx------ 2 postgres postgres 4096 Nov 29 22:43 pg_twophase -rw------- 1 postgres postgres 4 Nov 29 22:43 PG_VERSION drwx------ 3 postgres postgres 4096 Nov 29 22:43 pg_xlog -rw------- 1 postgres postgres 88 Nov 29 22:43 postgresql.auto.conf -rw------- 1 postgres postgres 133 Dec 1 00:12 postmaster.opts -rw------- 1 postgres postgres 91 Dec 1 00:12 postmaster.pid 

    Links