Skip to content

Instantly share code, notes, and snippets.

@philsch
Last active November 23, 2017 15:41
Show Gist options
  • Save philsch/9285a53452a3caa3c3bbd4d1fe668ddd to your computer and use it in GitHub Desktop.
Save philsch/9285a53452a3caa3c3bbd4d1fe668ddd to your computer and use it in GitHub Desktop.
Redshift snippets
----# LOAD / UNLOAD DATA #----
-- UNLOAD using IAM session
UNLOAD ('SELECT * FROM your_table where tstamp between ''2017-02-01 12:00'' and ''2017-02-02 13:00'' ')
TO 's3://your_bucket/dump/'
CREDENTIALS 'aws_access_key_id=XXXXXXX;aws_secret_access_key=XXXXXX;token=XXXXXXX'
MANIFEST
ESCAPE;
----# MAINTENANCE #----
-- Check internal execution state of query
SELECT * FROM STV_EXEC_STATE WHERE query = 123456 ORDER BY slice,segment,step;
-- Check locks #1
SELECT table_id, last_update, lock_owner, lock_owner_pid, lock_status FROM stv_locks;
-- Check locks #2
SELECT * from pg_locks;
-- Check for lock conflicts
select * from STL_TR_CONFLICT where table_id=123;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment