对PostgreSQL缺省表空间的理解

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com]

如果我们不建立自己的表空间,建立表的时候,也不指定表空间。

那么,PostgreSQL 不会建立你的表空间,所建立的表,都放入缺省表空间里。

如果进行查询:

postgres=# select * from pg_tablespace;
  spcname   | spcowner | spcacl | spcoptions 
------------+----------+--------+------------
 pg_default |       10 |        | 
 pg_global  |       10 |        | 
(2 rows)

我们可以看到  spcoptions 是空的,这样似乎无法知道表空间在何处。

可以参考如下这篇文档:http://postgresql.1045698.n5.nabble.com/location-for-pg-default-tablespace-td1882322.html

也就是说, $PGDATA, 或者更确切地说,启动 PostgreSQL 的时候所用的 data目录 , 就是我们要用到的表空间。

此时,我们建立一个表后,他会出现在  ./base目录下的 某个 目录(代表数据库)/某个目录(代表表本身)

例如:

postgres=# select c.relfilenode from pg_class c where c.relname='testtab';
 relfilenode 
-------------
       24604
(1 row)

查看schema

postgres=# select table_schema from information_schema.tables where table_name='testtab';
public

postgres=#

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com]

原文地址:https://www.cnblogs.com/gaojian/p/2739097.html