WARNING

This page is now deprecated and will be removed in the future.

View the current documentation on the MeltanoHub

# Redshift

The target-redshift loader loads extracted data into an Amazon Redshift data warehouse.

# Getting Started

# Prerequisites

If you haven't already, follow the initial steps of the Getting Started guide:

  1. Install Meltano
  2. Create your Meltano project
  3. Add an extractor to pull data from a source

# Installation and configuration

# Using the Command Line Interface

  1. Add the target-redshift loader to your project using meltano add:

    meltano add loader target-redshift
    
  2. Configure the settings below using meltano config.

# Using Meltano UI

  1. Start Meltano UI using meltano ui:

    meltano ui
    
  2. Open the Loaders interface at http://localhost:5000/loaders.

  3. Click the arrow next to the "Add to project" button for "Amazon Redshift".

  4. Configure the settings below in the "Configuration" interface that opens automatically.

# Next steps

Follow the remaining step of the Getting Started guide:

  1. Run a data integration (EL) pipeline

If you run into any issues, learn how to get help.

# Settings

target-redshift requires the configuration of the following settings:

Since the loader will first upload the data to S3 before using a COPY command to load the data into Redshift, some additional AWS specific settings are needed:

and the settings for one of the three possible authentication methods:

Profile Name:

Access Key:

Session Token:

These and other supported settings are documented below. To quickly find the setting you're looking for, use the Table of Contents in the sidebar.

# Minimal configuration

A minimal configuration of target-redshift in your meltano.yml project file will look like this when using AWS profile authentication:





 
 
 
 
 
 
 
 


plugins:
  loaders:
  - name: target-redshift
    variant: transferwise
    config:
      host: my_cluster.redshift.amazonaws.com
      port: 5439
      user: my_user
      dbname: my_database
      # default_target_schema: my_schema    # override if default (see below) is not appropriate
      s3_bucket: my-s3-bucket-name
      # AWS credential settings 
      aws_profile: my_aws_cli_profile

Sensitive values are most appropriately stored in the environment or your project's .env file:

export TARGET_REDSHIFT_PASSWORD=my_password

# Host

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set host <host>

export TARGET_REDSHIFT_HOST=<host>

# Port

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set port 5440

export TARGET_REDSHIFT_PORT=5440

# User

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set user <user>

export TARGET_REDSHIFT_USER=<user>

# Password

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set password <password>

export TARGET_REDSHIFT_PASSWORD=<password>

# Database Name

Redshift database name

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set dbname <dbname>

export TARGET_REDSHIFT_DBNAME=<dbname>

# AWS Profile

AWS profile name for profile based authentication. If not provided, AWS_PROFILE environment variable will be used.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set aws_profile <aws profile>

export TARGET_REDSHIFT_AWS_PROFILE=<aws profile>

# AWS Access Key ID

AWS Access Key Id. Used for S3 and Redshift copy operations. If not provided, AWS_ACCESS_KEY_ID environment variable will be used.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set aws_access_key_id <aws access key>

export TARGET_REDSHIFT_AWS_ACCESS_KEY_ID=<aws access key>

# AWS Secret Access Key

AWS Secret Access Key. Used for S3 and Redshift copy operations. If not provided, AWS_SECRET_ACCESS_KEY environment variable will be used.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set aws_secret_access_key <aws secret access key>

export TARGET_REDSHIFT_AWS_SECRET_ACCESS_KEY=<aws secret access key>

# AWS Session Token

AWS STS token for temporary credentials. If not provided, AWS_SESSION_TOKEN environment variable will be used.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set aws_session_token <aws sts session token>

export TARGET_REDSHIFT_AWS_SESSION_TOKEN=<aws sts session token>

# AWS Redshift Copy Role ARN

AWS Role ARN to be used for the Redshift COPY operation. Used instead of the given AWS keys for the COPY operation if provided - the keys are still used for other S3 operations.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set aws_redshift_copy_role_arn <aws role arn>

export TARGET_REDSHIFT_AWS_REDSHIFT_COPY_ROLE_ARN=<aws role arn>

# S3 ACL

S3 Object ACL to be applied to files created in S3 bucket.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set s3_acl <s3 acl>

export TARGET_REDSHIFT_S3_ACL=<s3 acl>

# S3 Bucket

Unique S3 Bucket name

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set s3_bucket <s3 bucket>

export TARGET_REDSHIFT_S3_BUCKET=<s3 bucket>

# S3 Key Prefix

A static prefix before the generated S3 key names. Using prefixes you can upload files into specific directories in the S3 bucket.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set s3_key_prefix <s3 keyprefix>

export TARGET_REDSHIFT_S3_KEY_PREFIX=<s3 key prefix>

# Copy Options

  • Name: copy_options
  • Environment variable: TARGET_REDSHIFT_COPY_OPTIONS
  • Default: EMPTYASNULL BLANKSASNULL TRIMBLANKS TRUNCATECOLUMNS TIMEFORMAT 'auto' COMPUPDATE OFF STATUPDATE OFF

Parameters to use in the COPY command when loading data to Redshift. Some basic file formatting parameters are fixed values and not recommended overriding them by custom values. They are like: CSV GZIP DELIMITER ',' REMOVEQUOTES ESCAPE

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set copy_options <copy_options>

export TARGET_REDSHIFT_COPY_OPTIONS=<copy_options>

# Default Target Schema

Name of the schema where the tables will be created. If schema_mapping is not defined then every stream sent by the tap is loaded into this schema.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set default_target_schema <schema>

export TARGET_REDSHIFT_DEFAULT_TARGET_SCHEMA=<schema>

# Batch Size Rows

Maximum number of rows in each batch. At the end of each batch, the rows in the batch are loaded into Redshift.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set batch_size_rows 1000

export TARGET_REDSHIFT_BATCH_SIZE_ROWS=1000

# Flush All Streams

Flush and load every stream into Redshift when one batch is full. Warning: This may trigger the COPY command to use files with low number of records.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set flush_all_streams true

export TARGET_REDSHIFT_FLUSH_ALL_STREAMS=true

# Parallelism

The number of threads used to flush tables. 0 will create a thread for each stream, up to parallelism_max. -1 will create a thread for each CPU core. Any other positive number will create that number of threads, up to parallelism_max.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set parallelism -1

export TARGET_REDSHIFT_PARALLELISM=-1

# Max Parallelism

Max number of parallel threads to use when flushing tables.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set max_parallelism 8

export TARGET_REDSHIFT_MAX_PARALLELISM=8

# Default Target Schema Select Permission

  • Name: default_target_schema_select_permission
  • Environment variable: TARGET_REDSHIFT_DEFAULT_TARGET_SCHEMA_SELECT_PERMISSION

Grant USAGE privilege on newly created schemas and grant SELECT privilege on newly created tables to a specific role or a list of roles. If schema_mapping is not defined then every stream sent by the tap is granted accordingly.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-snowflake set default_target_schema_select_permission <roles>

export TARGET_REDSHIFT_DEFAULT_TARGET_SCHEMA_SELECT_PERMISSION=<roles>

# Schema Mapping

Useful if you want to load multiple streams from one tap to multiple Redshift schemas.

If the tap sends the stream_id in <schema_name>-<table_name> format then this option overwrites the default_target_schema value.

Note, that using schema_mapping you can overwrite the default_target_schema_select_permission value to grant SELECT permissions to different groups per schemas or optionally you can create indices automatically for the replicated tables.

This setting can hold an object mapping source schema names to objects with target_schema and (optionally) target_schema_select_permissions keys.

# How to use

Manage this setting directly in your meltano.yml project file:





 
 
 
 
 
 
 
 
 
 
 

plugins:
  loaders:
  - name: target-redshift
    variant: transferwise
    config:
      schema_mapping:
        <source_schema>:
          target_schema: <target_schema>
          target_schema_select_permissions: [<role1>, <role2>] # Optional
        # ...

        # For example:
        public:
          target_schema: repl_pg_public
          target_schema_select_permissions: [grp_stats]

Alternatively, manage this setting using meltano config or an environment variable:

meltano config target-redshift set schema_mapping <source_schema> target_schema <target_schema>
meltano config target-redshift set schema_mapping <source_schema> target_schema_select_permissions '["<role>", ...]'

export TARGET_REDSHIFT_SCHEMA_MAPPING='{"<source_schema>": {"target_schema": "<target_schema>", ...}, ...}'

# Once a schema mapping has been set in `meltano.yml`, environment variables can be used
# to override specific nested properties:
export TARGET_REDSHIFT_SCHEMA_MAPPING_<SOURCE_SCHEMA>_TARGET_SCHEMA=<target_schema>
export TARGET_REDSHIFT_SCHEMA_MAPPING_<SOURCE_SCHEMA>_TARGET_SCHEMA_SELECT_PERMISSIONS='["<role>", ...]'

# For example:
meltano config target-redshift set schema_mapping public target_schema repl_pg_public
meltano config target-redshift set schema_mapping public target_schema_select_permissions '["grp_stats"]'

export TARGET_REDSHIFT_SCHEMA_MAPPING_PUBLIC_TARGET_SCHEMA=new_repl_pg_public

# Disable Table Cache

By default the connector caches the available table structures in Redshift at startup. In this way it doesn't need to run additional queries when ingesting data to check if altering the target tables is required. With disable_table_cache option you can turn off this caching. You will always see the most recent table structures but will cause an extra query runtime.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set disable_table_cache true

export TARGET_REDSHIFT_DISABLE_TABLE_CACHE=true

# Add Metadata Columns

  • Name: add_metadata_columns
  • Environment variable: TARGET_REDSHIFT_ADD_METADATA_COLUMNS
  • Default: false

Metadata columns add extra row level information about data ingestions, (i.e. when was the row read in source, when was inserted or deleted in Redshift etc.) Metadata columns are creating automatically by adding extra columns to the tables with a column prefix _SDC_. The column names are following the stitch naming conventions documented at https://www.stitchdata.com/docs/data-structure/integration-schemas#sdc-columns. Enabling metadata columns will flag the deleted rows by setting the _SDC_DELETED_AT metadata column. Without the add_metadata_columns option the deleted rows from singer taps will not be recongisable in Redshift.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set add_metadata_columns true

export TARGET_REDSHIFT_ADD_METADATA_COLUMNS=true

# Hard Delete

When hard_delete option is true then DELETE SQL commands will be performed in Redshift to delete rows in tables. It's achieved by continuously checking the _SDC_DELETED_AT metadata column sent by the singer tap. Due to deleting rows requires metadata columns, hard_delete option automatically enables the add_metadata_columns option as well.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set hard_delete true

export TARGET_REDSHIFT_HARD_DELETE=true

# Data Flattening Max Level

  • Name: data_flattening_max_level
  • Environment variable: TARGET_REDSHIFT_DATA_FLATTENING_MAX_LEVEL
  • Default: 0

Object type RECORD items from taps can be transformed to flattened columns by creating columns automatically. When value is 0 (default) then flattening functionality is turned off.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set data_flattening_max_level 2

export TARGET_REDSHIFT_DATA_FLATTENING_MAX_LEVEL=2

# Primary Key Required

Log based and Incremental replications on tables with no Primary Key cause duplicates when merging UPDATE events. When set to true, stop loading data if no Primary Key is defined.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set primary_key_required false

export TARGET_REDSHIFT_PRIMARY_KEY_REQUIRED=false

# Validate Records

Validate every single record message to the corresponding JSON schema. This option is disabled by default and invalid RECORD messages will fail only at load time by Redshift. Enabling this option will detect invalid records earlier but could cause performance degradation.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set validate_records true

export TARGET_REDSHIFT_VALIDATE_RECORDS=true

# Skip Updates

Do not update existing records when Primary Key is defined. Useful to improve performance when records are immutable, e.g. events.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set skip_updates true

export TARGET_REDSHIFT_SKIP_UPDATES=true

# Compression

The compression method to use when writing files to S3 and running Redshift COPY. The currently supported methods are gzip or bzip2.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set compression gzip

export TARGET_REDSHIFT_COMPRESSION=gzip

# Slices

The number of slices to split files into prior to running COPY on Redshift. This should be set to the number of Redshift slices. The number of slices per node depends on the node size of the cluster - run SELECT COUNT(DISTINCT slice) slices FROM stv_slices to calculate this.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set slices 2

export TARGET_REDSHIFT_SLICES=2

# Temp Directory

Directory of temporary CSV files with RECORD messages.

# How to use

Manage this setting using Meltano UI, meltano config, or an environment variable:

meltano config target-redshift set temp_dir /tmp/dir

export TARGET_REDSHIFT_TEMP_DIR=/tmp/dir