Postgresql:查找表空间中所有对象的大小

时间:2016-11-25 11:22:39

标签: postgresql

我的默认表空间空间不足。

SELECT pg_size_pretty(pg_tablespace_size('pg_default'));
89 GB
(1 row)

但是,如果我计算此表空间中所有表的pg_relation_size,我只得到16GB

select pg_size_pretty(sum(sz)) 
from (
    select *,(pg_total_relation_size(tablename::varchar)) as sz 
    from pg_tables 
    where tablespace is null 
      and tablename not like 'pg_%' 
     and schemaname != 'information_schema' 
) as foo;

16 GB
(1 row)

其余的在哪里?

我确实计算了索引+数据

1 个答案:

答案 0 :(得分:1)

多个数据库可能使用服务器的默认表空间。检查一下:

select datname, pg_size_pretty(pg_database_size(oid))
from pg_database
union
select null, pg_size_pretty(sum(pg_database_size(oid)))
from pg_database;