Practice Redshift SQL: distribution styles, sort keys, COPY from S3, QUALIFY, and query tuning.
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.
- Create a Redshift Serverless workgroup or a small provisioned cluster (the free trial is enough for these exercises).
- Open the Redshift query editor v2 and connect to the
devdatabase. - Run
examples/01_setup.sqlto create the schema and tables. - Run
examples/02_queries.sqlto seed and query the data. - Run
examples/03_copy.sqlafter uploading a CSV to S3 and replacing the IAM role placeholder. - Stop or delete the workgroup/cluster when you finish to avoid charges.
| 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 |
| 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. |
- Change
orderstoDISTSTYLE ALLand compareEXPLAINplans for the join. - Add a compound sort key
(customer_id, ordered_at)and explain when it helps. - Run
ANALYZE COMPRESSION lab.eventsand apply the suggested encoding. - Use
SVL_QUERY_SUMMARYto find the slowest step in a query.
- 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.
COPYneeds 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.
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.
Part of the database-labs collection: 26 database engines, one index.
MIT (c) 2026 Arya Fatthurahman. See LICENSE.