每个 Amazon Redshift 存储块的大小为 1MB。每个块只包含一个表中一列的数据。
SVV_DISKUSAGE system view 包含这些块的列表,例如:
select db_id, trim(name) as tablename, col, tbl, max(blocknum)
from svv_diskusage
where name='salesnew'
group by db_id, name, col, tbl
order by db_id, name, col, tbl;
db_id | tablename | col | tbl | max
--------+------------+-----+--------+-----
175857 | salesnew | 0 | 187605 | 154
175857 | salesnew | 1 | 187605 | 154
175857 | salesnew | 2 | 187605 | 154
175857 | salesnew | 3 | 187605 | 154
175857 | salesnew | 4 | 187605 | 154
175857 | salesnew | 5 | 187605 | 79
175857 | salesnew | 6 | 187605 | 79
175857 | salesnew | 7 | 187605 | 302
175857 | salesnew | 8 | 187605 | 302
175857 | salesnew | 9 | 187605 | 302
175857 | salesnew | 10 | 187605 | 3
175857 | salesnew | 11 | 187605 | 2
175857 | salesnew | 12 | 187605 | 296
(13 rows)
存储每列所需的块数取决于数据量和用于该表的compression encoding。
Amazon Redshift 还会存储每个块中存储的数据的 minvalue 和 maxvalue。这在SVV_DISKUSAGE 表中可见。这些值通常称为区域地图,用于识别扫描数据时可以跳过的块。例如,如果WHERE 子句在该列中查找值为5 的行,则可以完全跳过具有minvalue 或6 的块。这在数据压缩时特别有用。
要调查您的数据消耗两个块的原因,请检查:
- 每个区块的
minvalue 和maxvalue
- 每个块中存储的值 (
num_values) 的数量
这些值会让您了解每个块中存储了多少数据,以及这是否符合您的期望。
另外,请查看桌面上使用的分发密钥 (DISTKEY)。如果DISTKEY 设置为ALL,则表数据将在多个节点之间复制。这也可以解释你的块数。
最后,如果数据已从表中删除,那么旧值可能会占用磁盘空间。对表运行VACUUM 命令以删除已删除的数据。
一个很好的参考是:Why does a table in my Amazon Redshift cluster consume more disk storage space than expected?