Lesson 3 of 13 Amazon Redshift

Loading and Unloading Redshift Data Efficiently

This lesson explains how to move data into and out of Redshift efficiently with bulk, parallel operations, which outperform row-by-row inserts by orders of magnitude.

Learning outcomes

After completing this lesson, you will be able to:

  • Apply COPY best practices.
  • Perform upserts with MERGE or staging tables.
  • Export query results with UNLOAD.
  • Load data continuously without batch pipelines.

COPY best practices

The COPY command is the standard way to load data into Redshift. It loads from Amazon S3, and also from Amazon EMR, Amazon DynamoDB and remote hosts over SSH, and it loads in parallel: each slice reads different files at the same time. How the input files are prepared therefore determines how fast a load runs.

Input should be split into several files of similar size, ideally a multiple of the number of slices, so that every slice has equal work; a single large file is read by one slice while the others wait. Files should be compressed, which reduces the data transferred. A manifest file lists exactly which files to load, which prevents partially written or unrelated files under the same prefix from being loaded. COPY is authorised with an IAM role attached to the warehouse, so no access keys appear in SQL.

COPY reads CSV, JSON, Avro, Parquet and ORC, and options such as IGNOREHEADER, DATEFORMAT and MAXERROR handle headers, date formats and a tolerated number of bad rows. Auto-copy, defined as a COPY JOB, loads new files from an S3 prefix automatically as they arrive. When rows are rejected, the reasons are recorded in SYS_LOAD_ERROR_DETAIL, or STL_LOAD_ERRORS on provisioned clusters.

The following diagram compares row-by-row inserts with one parallel COPY.

The nightly load before and after. Before, an application sends one INSERT per row, which takes three hours. After, the data is written to S3 as many Parquet files, a multiple of the number of slices, and one COPY loads them in parallel across all slices in minutes.
File and slice counts are illustrative.
Scenario questions

Fast COPY loads

Exam skills 2.3.1

Choose the COPY practice for each problem.

Log in to try this activity Interactive activities are free with an account.

Upserts

An upsert updates rows that already exist and inserts rows that do not, which is needed when source systems send changed records repeatedly. Redshift handles upserts through a staging table. New and changed data is first loaded into a staging table with COPY. Then a single MERGE statement updates matching rows in the target and inserts the rest; on older designs, the same result is achieved by deleting matching rows from the target and inserting from staging within one transaction.

Single-row INSERT or UPDATE statements should be avoided for bulk data. Each is a separate operation, so they are orders of magnitude slower than COPY, and they create many small, partially filled blocks that waste space and slow queries until the table is vacuumed.

The following diagram shows the staging-table upsert.

The Redshift upsert pattern. New and changed rows are loaded into a staging table with COPY, and one MERGE statement updates matching rows in the target and inserts the rest, so the target is touched in one short operation.
MERGE runs as one statement.
Put in order

A staging-table upsert

Exam skills 2.3.1 · 2.4.2

Put the steps of a Redshift upsert in order.

Log in to try this activity Interactive activities are free with an account.

UNLOAD

UNLOAD is the reverse of COPY: it writes the results of a query to Amazon S3, in parallel from all slices. It is used to share warehouse data with the data lake, with other systems or with other teams. UNLOAD can write Parquet, which keeps the data efficient to query with Athena or Spectrum, or delimited text. PARTITION BY writes the output into Hive-style folders, such as sale_date=2026-10-01/, so query engines can prune partitions.

Output can be encrypted with an AWS KMS key, and MAXFILESIZE controls the size of the files produced, which should be large enough to avoid the overhead of many small files. Like COPY, UNLOAD is authorised with the warehouse's IAM role.

Match the pairs

UNLOAD options

Exam skills 2.3.1

Match each requirement with the UNLOAD option.

Log in to try this activity Interactive activities are free with an account.

Loading without batch pipelines

Two features put data into Redshift continuously without building a batch loading pipeline. Redshift streaming ingestion reads a Kinesis data stream or an MSK topic directly into a materialised view, with no staging in S3 and latency of seconds, which suits near-real-time dashboards. Zero-ETL integrations replicate data from Aurora, RDS, DynamoDB and some SaaS applications into Redshift automatically and continuously, so operational data can be analysed without writing or running ETL jobs. The following table summarises the options.

OptionWhat it does
Redshift streaming ingestionReads Kinesis Data Streams or MSK directly into materialised views, low latency, no S3 staging
Zero-ETL integrationsReplicate Aurora, RDS, DynamoDB and some SaaS sources into Redshift continuously
Worked example

A slow load

A nightly load of 200 GB into Redshift takes three hours. It runs one INSERT per row from an application, a pattern Redshift handles badly.

COPY sales
FROM 's3://lake/curated/sales/dt=2026-10-08/'
IAM_ROLE 'arn:aws:iam::111122223333:role/RedshiftLoad'
FORMAT AS PARQUET;

Writing the data to S3 as many Parquet files (a multiple of the number of slices) and loading with one COPY parallelises the load across all slices; it now takes minutes. Updated rows are loaded into a staging table and merged with MERGE, the standard upsert pattern. For Aurora sources, a zero-ETL integration would remove the nightly load altogether.

Check yourself

How are only specific files loaded with COPY?

Show answer

With a manifest file that lists them.

Exam Tips

Remember for the exam

  • For bulk loads, use COPY from many evenly sized, compressed files in S3.
  • To load only specific files, use COPY with a manifest.
  • The upsert pattern is a staging table followed by MERGE.
  • To export results to the lake as partitioned Parquet, use UNLOAD with PARTITION BY.
  • For near-real-time stream ingestion without S3, use Redshift streaming ingestion.
  • To replicate Aurora to Redshift with no pipeline, use a zero-ETL integration.