LoginSignup
1
1

More than 5 years have passed since last update.

Redshift 自分用メモ

Last updated at Posted at 2015-10-05

TSV形式でS3にアップロードされたGZファイルの流し込み

Copyを使う

copy テーブル名 (カラム1,カラム2,カラム3,...)
from 's3://バケット名/path/to/ファイル名'
credentials 'aws_access_key_id=アクセスキー'
GZIP
delimiter '\t';

RedshiftデータのTSV形式のGZファイルのS3へのエクスポート

UNLOADを使う

unload ('
select カラム1,カラム2,カラム
from テーブル名
where ...
')
to 's3://バケット名/path/to/ファイル名'
credentials 'aws_access_key_id=アクセスキー'
GZIP
delimiter as '\t';

Redshiftのストレージ使用容量

出典: 公式ドキュメント

select stv_tbl_perm.name as table, count(*) as mb
from stv_blocklist, stv_tbl_perm
where stv_blocklist.tbl = stv_tbl_perm.id
and stv_blocklist.slice = stv_tbl_perm.slice
and stv_tbl_perm.name in ('client_analytics_traffic','client_analytics_reference','client_analytics_traffic_by_page_group','client_analytics_reference_by_page_group','client_site_search_ranking','conflict_site_search_ranking','client_site_findability_score','conflict_site_findability_score')
group by stv_tbl_perm.name
order by 1 asc;

ソート状況の確認クエリ

出典: Amazon Redshift Useful SQL: VACUUM処理が必要なテーブルを洗い出す

/** 0.VACUUM処理が行われていないテーブル群 */
select
  '0_not_sorted' as status,
  sum_result.tablename,
  sum_result.sorted_rows,
  sum_result.rows,
  cast(0 as decimal(5,3)) as sort_percentage
from
(select
  trim(name) as tablename,
  sum(sorted_rows) as sorted_rows,
  sum(rows) as rows
from
  stv_tbl_perm
group by name
order by name) sum_result
where
  sorted_rows = 0
UNION ALL
/** 1.VACUUM処理が行われているテーブル群 */
select
  '1_sorted' as status,
  sum_result.tablename,
  sum_result.sorted_rows,
  sum_result.rows,
  cast(
    cast(sum_result.sorted_rows as double precision) / cast(sum_result.rows as double precision)
    as decimal(5,3)
  ) as sort_percentage
from
(select
  trim(name) as tablename,
  sum(sorted_rows) as sorted_rows,
  sum(rows) as rows
from
  stv_tbl_perm
group by name
order by name) sum_result
where
  sorted_rows != 0
order by
  status asc,
  sort_percentage asc,
  rows desc;

テーブル定義の確認

出典: Redshiftの調査系クエリ3選

SELECT * FROM pg_table_def WHERE tablename = 'テーブル名';
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1