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


当前回答

一个终端命令: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

其他回答

要查看数据目录的位置,请使用此查询。

show data_directory;

要查看所有运行时参数,请使用

show all;

您可以创建表空间来在文件系统的其他部分存储数据库对象。要查看可能不在该数据目录中的表空间,请使用此查询。

SELECT *, pg_tablespace_location(oid) FROM pg_tablespace;

Mac系统:/Library/PostgreSQL/9.0/data/base

不能进入目录,但可以通过:sudo du -hc data查看内容

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

ps aux | grep postgres | grep -- -D

特定表/索引的位置可以通过TABLESPACEs进行调整:

CREATE TABLESPACE dbspace LOCATION '/data/dbs';
CREATE TABLE something (......) TABLESPACE dbspace;
CREATE TABLE otherthing (......) TABLESPACE dbspace;

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