首页 > 解决方案 > 表空间在 pg_tables 中显示为空

问题描述

我通过显式传递表空间名称来创建表。但是在检查 pg_tables 和其他 pg_ 表时

Create table test1c (Id integer, name varchar(10)) tablespace testts;

select * 
from pg_tables 
where tablename='test1c';

它应该显示表空间名称,但显示为空

标签: postgresql

解决方案


默认表空间不会显示在pg_tables.tablespace

从手册中引用

包含表的表空间的名称(如果数据库默认为 null

(强调我的)


如果要查看需要pg_database在查询中包含的实际表空间:

select t.schemaname, t.tablename, 
       coalesce(t.tablespace, ts.default_tablespace) as tablespace
from pg_tables t
  cross join (
     select ts.spcname as default_tablespace
     from pg_database d
       join pg_tablespace ts on ts.oid = d.dattablespace
      where d.datname = current_database()
   ) ts
where tablename = 'test1c'
  and schemaname = 'public';

推荐阅读