J'ai une table dans RedShift . Comment puis-je voir combien d'espace disque il utilise?
Utilisez les requêtes de cette présentation: http://www.slideshare.net/AmazonWebServices/Amazon-redshift-best-practices
Analyser l'utilisation de l'espace disque pour le cluster:
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;
Analyser la distribution de la table entre les nœuds:
select slice, col, num_values, minvalue, maxvalue
from svv_diskusage
where name = '__INSERT__TABLE__NAME__HERE__' and col = 0
order by slice, col;
Je sais que cette question est ancienne et a déjà une réponse acceptée, mais je dois préciser que la réponse est fausse… .. Ce que la requête renvoie ici en tant que "mb" est en réalité le "nombre de blocs". La réponse ne serait correcte que si la taille du bloc est de 1 Mo (valeur par défaut).
Si la taille de bloc est différente (dans mon cas, par exemple, 256 Ko), vous devez multiplier le nombre de blocs par sa taille en octets. Je suggère le changement suivant à votre requête où je multiplie le nombre de blocs par la taille de bloc en octets (262144 octets), puis le divise par (1024 * 1024) pour afficher le total en mégaoctets:
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;
Ajouter un propriétaire et un filtre de schéma à la requête ci-dessus:
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;
Je pensais juste que je pourrais développer cela car je suis confronté à un problème de distribution inégale. J'ai ajouté des liens et des champs pour permettre l'analyse de l'espace par nœud et par tranche. Sont également ajoutés les valeurs max/min et le nombre de valeurs par tranche pour la colonne 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;