数据库的总大小大于Postgresql中每个表大小的总和

时间:2018-05-20 13:02:22

标签: postgresql

总数据库大小:

5620sam=# SELECT pg_size_pretty(pg_database_size('5620sam'));
 pg_size_pretty
----------------
 72 GB
(1 row)

磁盘上的文件大小:

# du --apparent-size -h /var/lib/postgresql/9.5/main/
<...>
74G     /var/lib/postgresql/9.5/main/

但如果我将每个表(带索引)的大小分别加总,我会减少3倍~20 Gb:

5620sam=# SELECT
    table_name,
    pg_size_pretty(table_size) AS table_size,
    pg_size_pretty(indexes_size) AS indexes_size,
    pg_size_pretty(total_size) AS total_size
FROM (
    SELECT
        table_name,
        pg_table_size(table_name) AS table_size,
        pg_indexes_size(table_name) AS indexes_size,
        pg_total_relation_size(table_name) AS total_size
    FROM (
        SELECT ('"' || table_schema || '"."' || table_name || '"') AS table_name
        FROM information_schema.tables
    ) AS all_tables
    ORDER BY total_size DESC
) AS pretty_sizes;

Output - get ~ 20 Gb

另外50千兆字节发生了什么?我在哪里可以找到它们? VACUUM FULL没有帮助,每晚都这样做。

0 个答案:

没有答案