PostgreSQL数据库的文件存储在哪里?
当前回答
我敢打赌你会问这个问题,因为你已经尝试了pg_ctl start,并收到以下错误:
pg_ctl:未指定数据库目录,环境变量PGDATA未设置
换句话说,您要在pg_ctl start命令中寻找放在-D之后的目录。
在本例中,您要查找的目录包含这些文件。
PG_VERSION pg_dynshmem pg_multixact
pg_snapshots pg_tblspc postgresql.conf
base pg_hba.conf pg_notify
pg_stat pg_twophase postmaster.opts
global pg_ident.conf pg_replslot
pg_stat_tmp pg_xlog postmaster.pid
pg_clog pg_logical pg_serial
pg_subtrans postgresql.auto.conf server.log
您可以通过使用操作系统提供的搜索来定位上面的任何文件和目录来定位它。
例如,在我的例子中(在Mac OS X上安装HomeBrew),这些文件位于/usr/local/var/ postgress中。要启动服务器,我输入:
pg_ctl -D /usr/local/var/postgres -w start
... 这很有效。
其他回答
在我的Linux安装中,它在这里:/var/lib/postgresql/8.x/
你可以用initdb -D "c:/mydb/"
Mac系统:/Library/PostgreSQL/9.0/data/base
不能进入目录,但可以通过:sudo du -hc data查看内容
在Windows7上,所有数据库都由C:\Program Files (x86)\PostgreSQL\8.2\data\global.下名为pg_database的文件中的一个数字引用然后,您应该在C:\Program Files (x86)\PostgreSQL\8.2\data\base.下根据该数字搜索文件夹名称这就是数据库的内容。
一个终端命令: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
我在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
推荐文章
- 如何在Postgres中获得两个字段的MIN() ?
- 截断Postgres数据库中的所有表
- 如何连接列在Postgres选择?
- 将varchar字段的类型更改为整数:"不能自动转换为整数类型"
- PostgreSQL可以索引数组列吗?
- PostgreSQL:角色不允许登录
- 如何查找Postgres / PostgreSQL表及其索引的磁盘大小
- 是使用各有一个模式的多个数据库更好,还是使用一个数据库有多个模式更好?
- 如果字符串包含
- 对于PostgreSQL表来说,多大才算太大?
- 将一列的多个结果行连接为一列,按另一列分组
- 使用pgadmin连接到heroku数据库
- 在PostgreSQL中快速发现表的行数
- 更改varchar列的大小为较低的长度
- 如何首次配置postgresql ?