SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
, pg_total_relation_size(reltoastrelid) AS toast_bytes
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE relkind = 'r' and relname in ('table_with_null','table_with_default')
) a
) a;
4 - 有了答案,放下表格:
DROP TABLE TABLE_WITH_NULL;
DROP TABLE TABLE_WITH_DEFAULT;
SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
, pg_total_relation_size(reltoastrelid) AS toast_bytes
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE relkind = 'r' and relname in ('TABLE1','TABLE2')
) a
) a;
AMG 的回答效果很好,但有一些错误/拼写/大小写错误。我尝试编辑它,但编辑被拒绝了。?
这是他的建议(可以直接复制/粘贴到 SQL 编辑器中)和结果。
1 - 创建 2 个表:
2 - 为每个表制作 100 万个插入:
3 - 使用此查询检查表磁盘使用情况:(在https://wiki.postgresql.org/wiki/Disk_Usage中找到)
4 - 有了答案,放下表格:
这是我的结果。(PostgreSQL 10.5)……
所以这个问题的直接答案是空数组
{}
比NULL
. ?进一步阅读:大型表中完全空的列如何影响性能?
你为什么不自己检查一下?
1 - 创建 2 个表:
2 - 为每个表制作 100 万个插入:
3 - 使用此查询检查表磁盘使用情况:(在https://wiki.postgresql.org/wiki/Disk_Usage中找到)
4 - 只要你确信就删除表: