web-dev-qa-db-ja.com

redshiftでデータベース、スキーマ、テーブルのサイズを見つける方法

チーム、

私のredshiftバージョンは:

PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.735

データベースサイズ、テーブルスペース、スキーマサイズ、テーブルサイズを調べる方法は?

しかし、以下は赤方偏移では機能しません(上記のバージョンの場合)

SELECT pg_database_size('db_name');
SELECT pg_size_pretty( pg_relation_size('table_name') );

Oracle(DBA_SEGMENTSから)のように調べる代替手段はありますか

tbleサイズについては、以下のクエリがありますが、MBYTESの正確なメニングについてはわかりません。 3行目の場合、MBYTES = 372です。これは372 MBを意味しますか?

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 a.db_id, a.name;
   database    |    schema    |      table       | mbytes |   rows
---------------+--------------+------------------+--------+----------
      postgres | public       | company          |      8 |        1
      postgres | public       | table_data1_1    |      7 |        1
      postgres | proj_schema1 | table_data1    |    372 | 33867540
      postgres | public       | table_data1_2    |     40 |  2000001

(4 rows)
41
user3258784

上記の回答は、使用される表スペースに対して常に正しい答えを与えるとは限りません。 AWSサポートは、このクエリを使用するよう指定しています:

SELECT   TRIM(pgdb.datname) AS Database,
         TRIM(a.name) AS Table,
         ((b.mbytes/part.total::decimal)*100)::decimal(5,2) AS pct_of_total,
         b.mbytes,
         b.unsorted_mbytes
FROM     stv_tbl_perm a
JOIN     pg_database AS pgdb
  ON     pgdb.oid = a.db_id
JOIN     ( SELECT   tbl,
                    SUM( DECODE(unsorted, 1, 1, 0)) AS unsorted_mbytes,
                    COUNT(*) AS mbytes
           FROM     stv_blocklist
           GROUP BY tbl ) AS b
       ON a.id = b.tbl
JOIN     ( SELECT SUM(capacity) AS total
           FROM   stv_partitions
           WHERE  part_begin = 0 ) AS part
      ON 1 = 1
WHERE    a.slice = 0
ORDER BY 4 desc, db_id, name;
60
imcdnzl

はい、あなたの例のmbytesは372Mbです。私が使ってきたものは次のとおりです。

select
  cast(use2.usename as varchar(50)) as owner, 
  pgc.oid,
  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 use2 on (pgc.relowner = use2.usesysid)
 join pg_namespace as pgn on pgn.oid = pgc.relnamespace 
    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; 
19
mike_pdb

データベースとスキームごとにグループ化するかどうかはわかりませんが、テーブルごとに使用方法を取得する簡単な方法を次に示します。

SELECT tbl, name, size_mb FROM
(
  SELECT tbl, count(*) AS size_mb
  FROM stv_blocklist
  GROUP BY tbl
)
LEFT JOIN
(select distinct id, name FROM stv_tbl_perm)
ON id = tbl
ORDER BY size_mb DESC
LIMIT 10;
11
gatoatigrado

他の回答の1つの修正バージョン。これには、データベース名、スキーマ名、テーブル名、合計行数、ディスク上のサイズ、およびソートされていないサイズが含まれます。

-- sort by row count
select trim(pgdb.datname) as Database, trim(pgns.nspname) as Schema, trim(a.name) as Table,
    c.rows, ((b.mbytes/part.total::decimal)*100)::decimal(5,3) as pct_of_total, b.mbytes, b.unsorted_mbytes
    from stv_tbl_perm a
    join pg_class as pgtbl on pgtbl.oid = a.id
    join pg_namespace as pgns on pgns.oid = pgtbl.relnamespace
    join pg_database as pgdb on pgdb.oid = a.db_id
    join (select tbl, sum(decode(unsorted, 1, 1, 0)) as unsorted_mbytes, count(*) as mbytes from stv_blocklist group by tbl) b on a.id=b.tbl
    join (select id, sum(rows) as rows from stv_tbl_perm group by id) c on a.id=c.id
    join (select sum(capacity) as total from stv_partitions where part_begin=0) as part on 1=1
    where a.slice=0
    order by 4 desc, db_id, name;


-- sort by space used
select trim(pgdb.datname) as Database, trim(pgns.nspname) as Schema, trim(a.name) as Table,
    c.rows, ((b.mbytes/part.total::decimal)*100)::decimal(5,3) as pct_of_total, b.mbytes, b.unsorted_mbytes
    from stv_tbl_perm a
    join pg_class as pgtbl on pgtbl.oid = a.id
    join pg_namespace as pgns on pgns.oid = pgtbl.relnamespace
    join pg_database as pgdb on pgdb.oid = a.db_id
    join (select tbl, sum(decode(unsorted, 1, 1, 0)) as unsorted_mbytes, count(*) as mbytes from stv_blocklist group by tbl) b on a.id=b.tbl
    join (select id, sum(rows) as rows from stv_tbl_perm group by id) c on a.id=c.id
    join (select sum(capacity) as total from stv_partitions where part_begin=0) as part on 1=1
    where a.slice=0
    order by 6 desc, db_id, name;
7
Nate Sammons

このリポジトリをチェックアウトすると、役に立つものが見つかるはずです。

https://github.com/awslabs/Amazon-redshift-utils

質問に答えるには、このビューを使用できます。 https://github.com/awslabs/Amazon-redshift-utils/blob/master/src/AdminViews/v_space_used_per_tbl.sql

そして、好きなようにクエリします。例:select * from admin.v_space_used_per_tbl;

7
kerbelp

このクエリははるかに簡単です。

-クラスター上の上位30のテーブルを一覧表示する

SELECT 
 "schema"
,"table"  AS table_name
,ROUND((size/1024.0),2) AS "Size in Gigabytes"
,pct_used AS "Physical Disk Used by This Table"
FROM svv_table_info
ORDER BY pct_used DESC
LIMIT 30;
2
Qiushuo Yu