This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COPY schema.table ("ts","column_a","column_b") | |
FROM 's3://bucket/prefix' | |
REGION 'us-east-1' /* S3 bucket is in us-east-1 region */ | |
GZIP | |
ESCAPE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE FROM schema.table | |
WHERE ts < (SELECT sysdate - 90); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VACUUM FULL schema.table; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTERNAL TABLE IF NOT EXISTS elb_logs_raw ( | |
request_timestamp string, | |
elb_name string, | |
request_ip string, | |
request_port int, | |
backend_ip string, | |
backend_port int, | |
request_processing_time double, | |
backend_processing_time double, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* create elb raw logs table with partition */ | |
CREATE EXTERNAL TABLE IF NOT EXISTS elb_logs_raw_partition ( | |
request_timestamp string, | |
elb_name string, | |
request_ip string, | |
request_port int, | |
backend_ip string, | |
backend_port int, | |
request_processing_time double, | |
backend_processing_time double, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH total_count_calc AS | |
( | |
SELECT COUNT(*) AS total_count | |
FROM elb_logs_raw_partition | |
WHERE YEAR = '2016' | |
AND MONTH = '12' | |
AND DAY = '15' | |
), | |
status_count_calc AS | |
( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE VIEW admin.v_space_by_schema | |
AS | |
WITH CAPACITY AS | |
( | |
SELECT SUM(capacity) FROM stv_partitions | |
), | |
USAGE AS | |
( | |
SELECT TRIM(pgdb.datname) AS DATABASE, | |
TRIM(pgn.nspname) AS SCHEMA, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT SUM(capacity) FROM stv_partitions; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE VIEW admin.v_tables_to_vacuum | |
AS | |
SELECT (('VACUUM FULL ' || derived_table1.schemaname) || '.') || derived_table1.tablename AS query | |
FROM (SELECT BTRIM(pgdb.datname) AS dbase_name, | |
BTRIM(pgn.nspname) AS schemaname, | |
BTRIM(a.name) AS tablename, | |
a.id AS tbl_oid, | |
b.mbytes AS megabytes, | |
a. "rows" AS rowcount, | |
a.unsorted_rows AS unsorted_rowcount, |