我在 RedShift 中有一张桌子。如何查看它使用了多少磁盘空间?
问问题
20260 次
4 回答
49
使用此演示文稿中的查询:http ://www.slideshare.net/AmazonWebServices/amazon-redshift-best-practices
分析集群的磁盘空间使用情况:
select
trim(pgdb.datname) as Database,
trim(pgn.nspname) as Schema,
trim(a.name) as Table,
b.mbytes,
a.rows
from (
select db_id, id, name, sum(rows) as rows
from stv_tbl_perm a
group by db_id, id, name
) as a
join pg_class as pgc on pgc.oid = a.id
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (
select tbl, count(*) as mbytes
from stv_blocklist
group by tbl
) b on a.id = b.tbl
order by mbytes desc, a.db_id, a.name;
分析节点之间的表分布:
select slice, col, num_values, minvalue, maxvalue
from svv_diskusage
where name = '__INSERT__TABLE__NAME__HERE__' and col = 0
order by slice, col;
于 2013-10-22T14:22:34.287 回答
10
我知道这个问题很老,并且已经接受了答案,但我必须指出答案是错误的。查询在那里输出的“mb”实际上是“块数”。只有当块大小为 1MB(这是默认值)时,答案才是正确的。
如果块大小不同(在我的例子中是 256K),你必须将块的数量乘以它的大小(以字节为单位)。我建议对您的查询进行以下更改,其中我将块数乘以以字节为单位的块大小(262144 字节),然后除以 (1024*1024) 以输出以兆字节为单位的总数:
select
trim(pgdb.datname) as Database,
trim(pgn.nspname) as Schema,
trim(a.name) as Table,
b.mbytes as previous_wrong_value,
(b.mbytes * 262144)::bigint/(1024*1024) as "Total MBytes",
a.rows
from (
select db_id, id, name, sum(rows) as rows
from stv_tbl_perm a
group by db_id, id, name
) as a
join pg_class as pgc on pgc.oid = a.id
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (
select tbl, count(blocknum) as mbytes
from stv_blocklist
group by tbl
) b on a.id = b.tbl
order by mbytes desc, a.db_id, a.name;
于 2015-07-30T09:50:20.470 回答
1
向上述查询添加所有者和模式过滤器:
select
cast(use.usename as varchar(50)) as owner,
trim(pgdb.datname) as Database,
trim(pgn.nspname) as Schema,
trim(a.name) as Table,
b.mbytes,
a.rows
from
(select
db_id,
id,
name,
sum(rows) as rows
from stv_tbl_perm a
group by db_id, id, name
) as a
join pg_class as pgc on pgc.oid = a.id
left join pg_user use on (pgc.relowner = use.usesysid)
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
-- leave out system schemas
and pgn.nspowner > 1
join pg_database as pgdb on pgdb.oid = a.db_id
join
(select
tbl,
count as mbytes
from stv_blocklist
group by tbl
) b on a.id = b.tbl
order by mbytes desc, a.db_id, a.name;
于 2014-01-30T10:15:51.893 回答
0
只是想我会对此进行扩展,因为我面临分配不均的问题。我添加了一些链接和字段,以便按节点和切片分析空间。还添加了第 0 列的最大/最小值和每个切片的值数。
select
cast(use.usename as varchar(50)) as owner,
trim(pgdb.datname) as Database,
trim(pgn.nspname) as Schema,
trim(a.name) as Table,
a.node,
a.slice,
b.mbytes,
a.rows,
a.num_values,
a.minvalue,
a.maxvalue
from
(select
a.db_id,
a.id,
s.node,
s.slice,
a.name,
d.num_values,
d.minvalue,
d.maxvalue,
sum(rows) as rows
from stv_tbl_perm a
inner join stv_slices s on a.slice = s.slice
inner join (
select tbl, slice, sum(num_values) as num_values, min(minvalue) as minvalue, max(maxvalue) as maxvalue
from svv_diskusage
where col = 0
group by 1, 2) d on a.id = d.tbl and a.slice = d.slice
group by 1, 2, 3, 4, 5, 6, 7, 8
) as a
join pg_class as pgc on pgc.oid = a.id
left join pg_user use on (pgc.relowner = use.usesysid)
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
-- leave out system schemas
and pgn.nspowner > 1
join pg_database as pgdb on pgdb.oid = a.db_id
join
(select
tbl,
slice,
count(*) as mbytes
from stv_blocklist
group by tbl, slice
) b on a.id = b.tbl
and a.slice = b.slice
order by mbytes desc, a.db_id, a.name, a.node;
于 2015-05-06T17:03:17.913 回答