Skip to content

About

Practice Redshift SQL: distribution styles, sort keys, `COPY` from S3, `QUALIFY`, and query tuning.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arya Fatthurahman

Amazon Redshift Lab

Practice Redshift SQL: distribution styles, sort keys, COPY from S3, QUALIFY, and query tuning.

Database: Amazon Redshift Category: Cloud data warehouse Runs in Cloud License: MIT

What this lab is

Redshift is AWS's columnar data warehouse. Its physical design choices, distribution style, sort key, and compression encoding, have a direct effect on query performance. This lab is cloud-based and focuses on the SQL and DDL patterns you need to reason about those choices.

Quickstart

  1. Create a Redshift Serverless workgroup or a small provisioned cluster (the free trial is enough for these exercises).
  2. Open the Redshift query editor v2 and connect to the dev database.
  3. Run examples/01_setup.sql to create the schema and tables.
  4. Run examples/02_queries.sql to seed and query the data.
  5. Run examples/03_copy.sql after uploading a CSV to S3 and replacing the IAM role placeholder.
  6. Stop or delete the workgroup/cluster when you finish to avoid charges.

Connection details

Field Value
Endpoint <cluster>.xxxx.<region>.redshift.amazonaws.com
Port 5439
Database dev
User awsuser (example)
JDBC URL jdbc:redshift://<endpoint>:5439/dev
psql psql -h <endpoint> -p 5439 -U <user> -d dev

Examples

File What it shows
examples/01_setup.sql Schema, distribution style, sort key, and compression encoding.
examples/02_queries.sql Seed data, QUALIFY, and an approximate distinct count.
examples/03_copy.sql A COPY template. Replace the bucket and IAM role placeholders.

Exercises

  1. Change orders to DISTSTYLE ALL and compare EXPLAIN plans for the join.
  2. Add a compound sort key (customer_id, ordered_at) and explain when it helps.
  3. Run ANALYZE COMPRESSION lab.events and apply the suggested encoding.
  4. Use SVL_QUERY_SUMMARY to find the slowest step in a query.

Notes and limits

  • Redshift is AWS-only. This lab does not include a local emulator because the SQL surface and system tables are Redshift-specific.
  • The free trial has time and credit limits. Delete the workgroup/cluster when done.
  • COPY needs an IAM role with S3 read access. Never put access keys in SQL files.
  • Distribution style and sort key choices depend on the workload; the examples are starting points, not rules.

Run it from anywhere

This lab already runs in the provider's cloud. To use it from another country safely:

  • Keep the account behind MFA and restrict network access to your IP or VPN where the provider allows it.
  • Use a dedicated lab user with the minimum privileges; never reuse personal credentials.
  • Store tokens and passwords in a secret manager or environment variables, never in the repository.
  • Stop or delete the warehouse, cluster, or VM when you finish to control cost.

The shared checklist and provider map are in REMOTE-ACCESS.md.

References


Part of the database-labs collection: 26 database engines, one index.

License

MIT (c) 2026 Arya Fatthurahman. See LICENSE.

About

Practice Redshift SQL: distribution styles, sort keys, `COPY` from S3, `QUALIFY`, and query tuning.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors