skills/database-redshift/SKILL.md
Amazon Redshift expert. Deep expertise in columnar storage, distribution styles, sort keys, Redshift Serverless, Spectrum, data sharing, materialized views, and query optimization. WHEN: "Redshift", "Amazon Redshift", "Redshift Serverless", "Redshift Spectrum", "distribution key", "sort key", "DISTKEY", "SORTKEY", "DISTSTYLE", "WLM", "Redshift ML", "STL_", "SVL_", "SYS_", "data sharing Redshift".
npx skillsauth add kilo-org/kilo-marketplace database-redshiftInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a specialist in Amazon Redshift, the fully managed cloud data warehouse. You have deep knowledge of Redshift internals -- MPP columnar architecture, distribution styles, sort keys, compression encodings, query compilation, Redshift Serverless, Spectrum, data sharing, concurrency scaling, AQUA, WLM, Redshift ML, streaming ingestion, zero-ETL integrations, and the SUPER semi-structured data type. As a managed service, Redshift does not follow traditional versioning; features are rolled out continuously by AWS.
When you receive a request:
Classify the request:
references/architecture.mdreferences/diagnostics.mdreferences/best-practices.md../SKILL.mdDetermine deployment model -- Ask whether the user is on Redshift Provisioned (RA3, DC2, DS2 node types) or Redshift Serverless. Many system tables, billing models, and tuning levers differ between the two.
Analyze -- Apply Redshift-specific reasoning. Reference columnar storage, distribution/sort key choices, zone maps, late materialization, query compilation/caching, and slice-level parallelism as relevant.
Recommend -- Provide actionable guidance with specific SQL DDL/DML, system table queries, AWS CLI commands, or console steps.
Verify -- Suggest validation steps using STL/SVL/SYS views, EXPLAIN plans, or CloudWatch metrics.
Amazon Redshift is a massively parallel processing (MPP), columnar, shared-nothing data warehouse:
Distribution determines how table rows are assigned to slices. Correct distribution is the single most impactful design decision for query performance.
| Style | Behavior | Best For |
|---|---|---|
| KEY | Rows with the same key value go to the same slice | Large fact tables joined to dimension tables on a common key |
| EVEN | Round-robin distribution across all slices | Tables with no clear join key; staging tables |
| ALL | Full copy of the table on every compute node | Small dimension tables (<~5M rows) joined frequently |
| AUTO | Redshift starts with ALL, switches to EVEN or KEY as table grows | Default; good for tables whose access patterns are not yet known |
Distribution key selection rules:
-- KEY distribution
CREATE TABLE orders (
order_id BIGINT ENCODE az64,
customer_id BIGINT ENCODE az64,
order_date DATE ENCODE az64,
total_amount DECIMAL(12,2) ENCODE az64
)
DISTSTYLE KEY
DISTKEY (customer_id)
SORTKEY (order_date);
-- ALL distribution for small dimension
CREATE TABLE regions (
region_id SMALLINT ENCODE az64,
region_name VARCHAR(50) ENCODE lzo
)
DISTSTYLE ALL;
Sort keys determine the physical order of rows on disk and power zone map effectiveness.
Compound sort key (default): Multi-column prefix index. Queries must filter on the leading column(s) to benefit. Best for dashboards with consistent filter patterns.
Interleaved sort key: Equal weight to each column. Benefits queries that filter on any subset of sort key columns. Higher maintenance cost -- requires regular VACUUM REINDEX.
Auto sort key: Redshift automatically chooses and maintains sort order based on query patterns. Good default when access patterns are diverse.
-- Compound sort key: queries must filter on order_date (or order_date + status) to benefit
CREATE TABLE orders (...)
COMPOUND SORTKEY (order_date, status, customer_id);
-- Interleaved sort key: any combination of these columns benefits scans
CREATE TABLE events (...)
INTERLEAVED SORTKEY (event_type, region, event_date);
Sort key selection rules:
Redshift stores data compressed. The right encoding dramatically reduces I/O and storage.
| Encoding | Best For | Notes |
|---|---|---|
| AZ64 | Numeric/date/time types | Amazon's proprietary encoding; best general-purpose for numeric data. Default for applicable types. |
| LZO | VARCHAR/CHAR with moderate entropy | General-purpose byte-level compression |
| ZSTD | VARCHAR/CHAR, high compression ratio | Best compression ratio; slightly more CPU than LZO |
| BYTEDICT | Low-cardinality strings (<256 distinct) | Dictionary encoding; 1 byte per value |
| RUNLENGTH | Columns with long runs of repeated values | Stores value + count |
| DELTA / DELTA32K | Sorted numeric/date columns with small increments | Stores deltas between consecutive values |
| MOSTLY8 / MOSTLY16 / MOSTLY32 | Numeric columns where most values fit in smaller width | Packs values into smaller integer widths |
| RAW | No compression | Only for sort key leading columns if needed |
| TEXT255 / TEXT32K | Deprecated; use LZO or ZSTD | Legacy dictionary-based text encodings |
Best practice: Use ENCODE AUTO (the default) and let Redshift choose optimal encodings, or run ANALYZE COMPRESSION <table> to get recommendations for existing tables.
Redshift Serverless eliminates cluster management. Key concepts:
Serverless vs. Provisioned decision factors:
Query data directly in Amazon S3 without loading it into Redshift:
-- Create external schema backed by AWS Glue Data Catalog
CREATE EXTERNAL SCHEMA spectrum_schema
FROM DATA CATALOG
DATABASE 'my_glue_db'
IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftSpectrumRole'
CREATE EXTERNAL DATABASE IF NOT EXISTS;
-- Create external table pointing to S3
CREATE EXTERNAL TABLE spectrum_schema.events (
event_id BIGINT,
event_time TIMESTAMP,
event_type VARCHAR(100),
payload VARCHAR(65535)
)
PARTITIONED BY (year INT, month INT, day INT)
STORED AS PARQUET
LOCATION 's3://my-bucket/events/';
-- Add partitions
ALTER TABLE spectrum_schema.events ADD PARTITION (year=2026, month=4, day=7)
LOCATION 's3://my-bucket/events/year=2026/month=4/day=7/';
-- Query joins local and external tables
SELECT o.customer_id, COUNT(e.event_id)
FROM local_schema.orders o
JOIN spectrum_schema.events e ON o.order_id = e.event_id
WHERE e.year = 2026 AND e.month = 4
GROUP BY 1;
Spectrum best practices:
Cross-cluster and cross-account data sharing without data movement:
-- On the PRODUCER cluster
CREATE DATASHARE my_share SET PUBLICACCESSIBLE = TRUE;
ALTER DATASHARE my_share ADD SCHEMA public;
ALTER DATASHARE my_share ADD TABLE public.orders;
ALTER DATASHARE my_share ADD TABLE public.customers;
-- Grant to a consumer namespace or AWS account
GRANT USAGE ON DATASHARE my_share TO NAMESPACE 'consumer-namespace-guid';
-- or
GRANT USAGE ON DATASHARE my_share TO ACCOUNT '123456789012';
-- On the CONSUMER cluster
CREATE DATABASE shared_db FROM DATASHARE my_share OF NAMESPACE 'producer-namespace-guid';
-- Query shared data
SELECT * FROM shared_db.public.orders WHERE order_date > '2026-01-01';
Data sharing provides live, read-only access to producer data. No data copying or ETL required.
CREATE MATERIALIZED VIEW mv_daily_sales AS
SELECT
order_date,
product_id,
SUM(quantity) AS total_qty,
SUM(total_amount) AS total_revenue,
COUNT(DISTINCT customer_id) AS unique_customers
FROM orders
GROUP BY order_date, product_id;
-- Auto-refresh
ALTER MATERIALIZED VIEW mv_daily_sales AUTO REFRESH YES;
-- Manual refresh
REFRESH MATERIALIZED VIEW mv_daily_sales;
Materialized views can be created on local tables, external (Spectrum) tables, data shares, and other materialized views. The query optimizer automatically rewrites queries to use materialized views when beneficial (automatic query rewriting).
WLM controls query queuing and resource allocation:
CREATE TABLE events_raw (
event_id BIGINT ENCODE az64,
event_data SUPER
)
DISTSTYLE AUTO;
-- Insert JSON directly
INSERT INTO events_raw VALUES (1, JSON_PARSE('{"user":"alice","action":"click","meta":{"page":"/home","duration":3.2}}'));
-- Query with PartiQL dot notation
SELECT
event_id,
event_data.user::VARCHAR AS username,
event_data.action::VARCHAR AS action,
event_data.meta.page::VARCHAR AS page,
event_data.meta.duration::FLOAT AS duration_sec
FROM events_raw
WHERE event_data.action::VARCHAR = 'click';
Ingest directly from Amazon Kinesis Data Streams or Amazon MSK (Managed Streaming for Apache Kafka):
CREATE EXTERNAL SCHEMA kinesis_schema
FROM KINESIS
IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftStreamRole';
CREATE MATERIALIZED VIEW mv_stream_events AUTO REFRESH YES AS
SELECT
approximate_arrival_timestamp,
JSON_PARSE(kinesis_data) AS payload,
partition_key
FROM kinesis_schema."my-stream"
WHERE is_valid_json(kinesis_data);
Zero-ETL replicates data from operational databases to Redshift with near real-time latency and no ETL pipelines to build or maintain:
Setup is via the AWS Console or CLI. Replicated data lands in Redshift as queryable tables.
Create, train, and deploy machine learning models using SQL:
-- Create a model (uses Amazon SageMaker Autopilot under the hood)
CREATE MODEL predict_churn
FROM (
SELECT customer_id, tenure_months, monthly_spend, support_tickets, churned
FROM customer_features
)
TARGET churned
FUNCTION fn_predict_churn
IAM_ROLE 'arn:aws:iam::123456789012:role/RedshiftMLRole'
SETTINGS (
S3_BUCKET 'my-ml-bucket',
MAX_RUNTIME 7200
);
-- Use the model in queries
SELECT customer_id, fn_predict_churn(tenure_months, monthly_spend, support_tickets) AS churn_prob
FROM customer_features
WHERE fn_predict_churn(tenure_months, monthly_spend, support_tickets) > 0.8;
AQUA is a hardware-accelerated cache layer for RA3 nodes that pushes filtering and aggregation down to the storage layer, reducing data movement between storage and compute. AQUA is automatically enabled on RA3 node types. It benefits:
ATO continuously monitors query patterns and automatically applies:
ATO is enabled by default. Monitor its decisions via SVV_ALTER_TABLE_RECOMMENDATIONS.
CREATE OR REPLACE PROCEDURE sp_incremental_load(cutoff_date DATE)
LANGUAGE plpgsql
AS $$
DECLARE
row_count BIGINT;
BEGIN
-- Stage new data
CREATE TEMP TABLE stg_orders AS
SELECT * FROM external_schema.raw_orders
WHERE order_date >= cutoff_date;
GET DIAGNOSTICS row_count = ROW_COUNT;
RAISE INFO 'Staged % rows', row_count;
-- Merge into target
DELETE FROM public.orders
USING stg_orders
WHERE orders.order_id = stg_orders.order_id;
INSERT INTO public.orders
SELECT * FROM stg_orders;
DROP TABLE stg_orders;
RAISE INFO 'Incremental load complete for dates >= %', cutoff_date;
END;
$$;
CALL sp_incremental_load('2026-04-01');
Redshift supports GEOMETRY and GEOGRAPHY types with spatial functions:
CREATE TABLE stores (
store_id INT ENCODE az64,
store_name VARCHAR(100) ENCODE lzo,
location GEOMETRY
)
DISTSTYLE AUTO;
INSERT INTO stores VALUES (1, 'Downtown', ST_GeomFromText('POINT(-73.985 40.748)'));
SELECT store_name, ST_DistanceSphere(location, ST_GeomFromText('POINT(-74.006 40.714)')) / 1000 AS distance_km
FROM stores
ORDER BY distance_km;
| Category | Key Objects | |---|---| | Query history | STL_QUERY, STL_QUERYTEXT, SYS_QUERY_HISTORY, SYS_QUERY_DETAIL | | Query performance | SVL_QUERY_SUMMARY, SVL_QUERY_REPORT, STL_ALERT_EVENT_LOG | | Table design | SVV_TABLE_INFO, SVV_ALTER_TABLE_RECOMMENDATIONS, SVV_DISKUSAGE | | WLM | STL_WLM_QUERY, STV_WLM_QUERY_STATE, STV_WLM_SERVICE_CLASS_CONFIG | | COPY/load | STL_LOAD_ERRORS, STL_LOADERROR_DETAIL, SYS_LOAD_HISTORY | | Locks | STV_LOCKS, STV_BLOCKERS, SVV_TRANSACTIONS | | Spectrum | SVL_S3QUERY_SUMMARY, SVL_S3PARTITION, SVL_S3LOG | | Serverless | SYS_SERVERLESS_USAGE, SYS_QUERY_HISTORY (includes RPU usage) | | Data sharing | SVV_DATASHARES, SVV_DATASHARE_OBJECTS, SVV_DATASHARE_CONSUMERS | | Concurrency scaling | STL_CONCURRENCY_SCALING_USAGE | | Compilation | SVL_COMPILE |
development
Oracle Database guidance for SQL, PL/SQL, SQLcl, ORDS, administration, app development, performance, security, migrations, and agent-safe database workflows. Use when the user asks to write, edit, rewrite, review, format, debug, tune, or explain SQL; create or refactor PL/SQL; use SQLcl, Liquibase, ORDS, JDBC, node-oracledb, Python, Java, .NET, or database frameworks; troubleshoot queries, sessions, locks, waits, indexes, optimizer plans, AWR, ASH, migrations, schemas, users, roles, privileges, backup, recovery, Data Guard, RAC, multitenant, containers, monitoring, auditing, encryption, VPD, or safe agent database operations.
documentation
Patterns for reading and writing oleander Iceberg catalog tables in Spark jobs, including naming conventions, write modes, and catalog hierarchy.
data-ai
Integrate Okta for enterprise identity workflows including OIDC login, group claims, and policy-based access controls. Use when implementing workforce or B2B identity scenarios.
documentation
Use when arranging Apache NiFi processors, process groups, ports, comments, numbering, crossing connections, dense fan-in/fan-out, or reusable readable canvas layouts.