PostgreSQL数据库的文件存储在哪里?


当前回答

在“PostgreSQL数据库在Linux上的默认位置”中建议,在Linux下你可以使用以下命令找到:

ps aux | grep postgres | grep -- -D

其他回答

我在docker容器中运行postgres(9.5)(在CentOS上),正如Skippy le Grand Gourou在上面的评论中提到的,这些文件位于/var/lib/postgresql/data/。

$ docker exec -it my-postgres-db-container bash
root@c7d61efe2a5d:/# cd /var/lib/postgresql/data/
root@c7d61efe2a5d:/var/lib/postgresql/data# ls -lh
total 56K
drwx------. 7 postgres postgres   71 Apr  5  2018 base
drwx------. 2 postgres postgres 4.0K Nov  2 02:42 global
drwx------. 2 postgres postgres   18 Dec 27  2017 pg_clog
drwx------. 2 postgres postgres    6 Dec 27  2017 pg_commit_ts
drwx------. 2 postgres postgres    6 Dec 27  2017 pg_dynshmem
-rw-------. 1 postgres postgres 4.4K Dec 27  2017 pg_hba.conf
-rw-------. 1 postgres postgres 1.6K Dec 27  2017 pg_ident.conf
drwx------. 4 postgres postgres   39 Dec 27  2017 pg_logical
drwx------. 4 postgres postgres   36 Dec 27  2017 pg_multixact
drwx------. 2 postgres postgres   18 Nov  2 02:42 pg_notify
drwx------. 2 postgres postgres    6 Dec 27  2017 pg_replslot
drwx------. 2 postgres postgres    6 Dec 27  2017 pg_serial
drwx------. 2 postgres postgres    6 Dec 27  2017 pg_snapshots
drwx------. 2 postgres postgres    6 Sep 16 21:15 pg_stat
drwx------. 2 postgres postgres   63 Nov  8 02:41 pg_stat_tmp
drwx------. 2 postgres postgres   18 Oct 24  2018 pg_subtrans
drwx------. 2 postgres postgres    6 Dec 27  2017 pg_tblspc
drwx------. 2 postgres postgres    6 Dec 27  2017 pg_twophase
-rw-------. 1 postgres postgres    4 Dec 27  2017 PG_VERSION
drwx------. 3 postgres postgres   92 Dec 20  2018 pg_xlog
-rw-------. 1 postgres postgres   88 Dec 27  2017 postgresql.auto.conf
-rw-------. 1 postgres postgres  21K Dec 27  2017 postgresql.conf
-rw-------. 1 postgres postgres   37 Nov  2 02:42 postmaster.opts
-rw-------. 1 postgres postgres   85 Nov  2 02:42 postmaster.pid

在Windows7上,所有数据库都由C:\Program Files (x86)\PostgreSQL\8.2\data\global.下名为pg_database的文件中的一个数字引用然后,您应该在C:\Program Files (x86)\PostgreSQL\8.2\data\base.下根据该数字搜索文件夹名称这就是数据库的内容。

在“PostgreSQL数据库在Linux上的默认位置”中建议,在Linux下你可以使用以下命令找到:

ps aux | grep postgres | grep -- -D

在Windows上,PostgresSQL文档中描述的PGDATA目录在C:\Program Files\PostgreSQL\8.1\data.这样的地方特定数据库的数据位于(例如)C:\Program Files\PostgreSQL\8.1\data\base\ 100929下,我猜100929是数据库号。

一个终端命令:pg_lsclusters(使用Ubuntu)

你需要的是在数据目录下:

Ver Cluster Port Status Owner    Data directory               Log file
10  main    5432 online postgres /var/lib/postgresql/10/main  /var/log/postgresql/postgresql-10-main.log
11  main    5433 online postgres /var/lib/postgresql/11/main  /var/log/postgresql/postgresql-11-main.log