4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Redshift/Postgresチートシート

Last updated at Posted at 2016-10-04

各Tableの権限情報を確認

権限とは、オーナー、オーナー以外にアクセスできるユーザ・ロールとその範囲のこと

\dp

各Schemaの権限情報を確認

\dn+

ロールの一覧を確認

\du
または
\dg

Default Privilegeの確認

SELECT 
  nspname,         -- schema name
  defaclobjtype,   -- object type
  defaclacl        -- default access privileges
FROM pg_default_acl a JOIN pg_namespace b ON a.defaclnamespace=b.oid;

参考: http://stackoverflow.com/questions/14555062/display-default-access-privileges-for-relations-sequences-and-functions-in-post

カラム数の多いテーブルへのselect結果を見やすく表示

mysqlだと\Gを使う場面で、Postgres/Redshiftだとどうするか?

\x on
//または\x auto

select...

Describe Table?

\d+ tablename
psql -E '\d+ tablename'

show create table?

pg_dump -h <ホスト> -p 5439 -U <ユーザ> -d <DB名> --schema-only --table <schema名>.<テーブル名>

AWS DMSのエラーログを閲覧

select * from STL_LOAD_ERRORS where query=<クエリID>;
select * from STL_LOADERROR_DETAIL where query=<クエリID>;

直近のエラーをだいたいいい感じに閲覧するためのクエリ

select
  a.query,
  btrim(querytxt) as querytxt,
  btrim(err_reason) as err_reason,
  btrim(line_number) as line_number,
  position,
  colname,
  type,
  btrim(raw_line) as raw_line,
  btrim(raw_field_value) as raw_field_value,
  len(btrim(raw_field_value)) as len,
  btrim(filename) as filename
from stl_load_errors a
join stl_query b on a.query = b.query
order by a.query desc limit 10;

Alterいろいろ

ALTER TABLE mytable RENAME TO foo;
ALTER TABLE mytable OWNER TO myowner;

テーブルのチェックサム

Redshiftのエラーログが記録されるテーブル

COPY文のオプション

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?