你好,
原文链接:https://www.f2er.com/postgresql/191917.html我发现实际数据库大小(在HDD上和pg_database_size()调用显示)和大小之间存在很大差异,通过总计pg_total_relation_size()检索的总关系大小来计算.
第一个是62G,最后一个是16G(右边是最大表中删除数据的差异)
select current_database(),pg_size_pretty( sum(total_relation_raw_size)::bigint ) as calculated_database_size,pg_size_pretty( pg_database_size(current_database()) ) as database_size from (select pg_total_relation_size(relid) as total_relation_raw_size from pg_stat_all_tables -- this includes also system tables shared between databases where schemaname != 'pg_toast' ) as stats;
似乎那里有一些悬空数据.出现这种情况后,我们从该数据库中转储并完全抽空了大量未使用的数据.