For Redshift
This guide will walk you through the process of extracting metadata and query information from your Amazon RedShift cluster
Overview
To integrate RedShift with Single Origin, you'll need to extract the following information from your RedShift cluster and upload 5 separate files:
- Table schemas - Information about tables
- Column schemas - Information about columns and data types
- View schemas - View definitions and dependencies
- Query logs - Historical query execution data
- Query profiles - Query performance and execution statistics
Prerequisites
- Access to your RedShift cluster with appropriate read permissions
Generate Input Data Files
Table Schemas
- Go to the Redshift Editor console.
- Enter the follow SQL query to create the column schema table:
- Click Run to execute the query.
- After execution, click Export and select CSV as saved file format.
SELECT
n.nspname as schema_name,
c.relname as table_name,
c.relkind as table_type,
obj_description(c.oid) as table_comment,
pg_get_userbyid(c.relowner) as table_owner
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE c.relkind = 'r' -- only tables
AND pg_get_userbyid(c.relowner) NOT IN ('rdsdb', 'postgres', 'root')
ORDER BY n.nspname, c.relname;
Column Schemas
- Go to the Redshift Editor console.
- Enter the follow SQL query to create the table schema table:
- Click Run to execute the query.
- After execution, click Export and select CSV as saved file format.
SELECT
n.nspname as schema_name,
c.relname as table_name,
a.attname as column_name,
pg_catalog.format_type(a.atttypid, a.atttypmod) as data_type,
a.attnum as ordinal_position,
CASE WHEN a.attnotnull THEN 'NO' ELSE 'YES' END as is_nullable,
pg_catalog.col_description(a.attrelid, a.attnum) as column_comment,
pg_get_userbyid(c.relowner) as table_owner
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE a.attnum > 0
AND NOT a.attisdropped
AND c.relkind = 'r' -- only tables
AND pg_get_userbyid(c.relowner) NOT IN ('rdsdb', 'postgres', 'root')
ORDER BY n.nspname, c.relname, a.attnum;
View Schemas
- Go to the Redshift Editor console.
- Enter the follow SQL query to create the view schema table:
- Click Run to execute the query.
- After execution, click Export and select CSV as saved file format.
SELECT
schemaname as schema_name,
viewname as view_name,
definition as view_definition,
viewowner as view_owner
FROM pg_views
WHERE view_owner != 'rdsdb'
Query Logs
- Go to the Redshift Editor console.
- Enter the follow SQL query to create the query table:
- Click Run to execute the query.
- After execution, click Export and select CSV as saved file format.
SELECT
query_id,
username,
database_name,
start_time,
end_time,
execution_time,
query_text,
status
FROM sys_query_history
and status = 'success'
ORDER BY start_time DESC
Query Profiles
- Go to the Redshift Editor console.
- Enter the follow SQL query to create the query profile table:
- Click Run to execute the query.
- After execution, click Export and select CSV as saved file format.
SELECT qe.*
FROM sys_query_history q
JOIN sys_query_detail qe ON q.query_id = qe.query_id
order by q.query_id
Updated about 20 hours ago
What’s Next