Skip to content

Set up an Amazon Redshift destination

The Replicator Service writes to Amazon Redshift through the SQDR bundled Redshift driver on the Stelo VM. It creates the destination tables, loads baselines and snapshots with multi-row INSERT statements, and applies incremental changes with SQL. It doesn't use COPY or Amazon S3.

Supported configurations

Supported
Database Amazon Redshift. For Redshift Serverless, or a particular deployment, ask Stelo Support.
Driver on the Stelo VM The SQDR bundled Redshift driver (SQDR Redshift), installed and licensed with SQDR. See Databases.
Snapshot replication Yes.
Incremental replication Yes, from any source with a Capture Agent.
Apply methods Batch and Sequence. Merge isn't available for Redshift (see Choosing the apply method).
Authentication Remote Credentials: a Redshift database user and its password.
Encryption Ask Stelo Support for the driver's SSL/TLS settings. Redshift accepts connections with or without SSL unless the cluster's require_SSL parameter is on.

Docker

The SQDR container includes the SQDR bundled Redshift driver (see ODBC drivers in the container).

Prepare the database

The Redshift administrator creates the database user the Replicator Service connects as, and the schema for the destination tables. In Redshift, the user that creates a table owns it and can alter, truncate and drop it, so the simplest setup is a user that owns the schema, and so the tables the Replicator Service creates in it. The privileges follow from the SQL the Replicator Service runs (see What the Replicator Service runs on the database).

Create the user and the schema

Connect to the destination database as a superuser (for example the cluster's admin user) and run:

CREATE USER sqdruser PASSWORD 'Mypassword1';
CREATE SCHEMA myschema AUTHORIZATION sqdruser;

Replace sqdruser, Mypassword1 and myschema with yours (Redshift passwords need upper and lower case letters and a digit). If you name the schema like the user, you can keep the destination's default Object Schema, the user ID. Why each privilege is needed: see Privileges. For a schema or tables another user owns, see Tables in a schema the user doesn't own.

Network

The Stelo VM must reach the cluster's endpoint on its port (5439 in the template). For a cluster in a VPC, the cluster's security group must allow inbound connections from the Stelo VM's address, and the cluster must be reachable from it (publicly accessible, or through a VPN or peering connection).

Create the destination

Create the destination as described in Create a destination, with these choices:

  1. The ODBC driver: the SQDR bundled Redshift driver is installed and licensed with SQDR: there's nothing to install.

    Docker

    The SQDR container includes the SQDR bundled Redshift driver too.

  2. Name: choose the DBMS Type Redshift.

  3. Connection: choose ODBC Driver, the SQDR Redshift driver and its Template, and fill in the fields: HostName (the cluster's endpoint, without the port and database), PortNumber (5439) and Database (see Connection string).

  4. Authentication: Remote Credentials with the database user and its password. Click Verify.

  5. Tick Advanced to check the defaults: on the Default step, Object Schema is the schema where new subscriptions create their tables; set it to myschema unless the schema has the user's name. The tables go in the connection string's database. See Defaults.

The driver's guide, redshiftodbcuser.pdf, is in the Help folder of the SQDR bundled drivers. Verify tests the connection, not the privileges (see Test the privileges).

Connection string

The SQDR bundled Redshift driver's template, with the cluster's endpoint as HostName:

HostName=mycluster.abc123xyz789.us-east-1.redshift.amazonaws.com;PortNumber=5439;Database=dev

Group settings for Amazon Redshift

When you create an incremental group to this destination, keep the DML Replication method on the group's Apply card at Batch (the default), or choose Sequence (see Apply). Merge isn't available for Redshift: changes are applied row by row. For tables with many changes, a scheduled snapshot can be a better fit than an incremental group (see Limitations).

Check the destination

After the first baseline of the incremental group (for snapshots, after the first run):

  1. Group status. On the Groups page, the group shows Actively monitoring and applying change data (see Group status). If a member failed, its replication events show the Redshift error; permission denied for schema means the user can't create tables there.
  2. Rows at the destination. Compare a table's row count with the source:

    SELECT COUNT(*) FROM myschema.mytable;
    
  3. Changes. Change a few rows at the source; they're applied with the group's next poll (the Poll Interval; see Scheduling). Query the rows again to see them.

What the Replicator Service runs on the database

The privileges in Prepare the database follow from these statements:

When Statements
A subscription is saved or a baseline starts (depending on its Destination DDL Options) DROP TABLE and CREATE TABLE for the destination table, named with its schema. No distribution or sort key is set: Redshift's defaults apply.
Before a baseline or snapshot copies the data Truncate table before replication runs TRUNCATE TABLE <table>, which Redshift commits at once. Delete existing data before replication runs one DELETE FROM <table>. See Baseline Replication Options.
During the copy With Use native-loader function, if available (the default): INSERT INTO <table> (...) VALUES (?, ...), (?, ...), ..., as many rows per statement as fit in 2000 parameter markers (the maxMySQLParms service property): 100 rows for a table of 20 columns. With Insert using ODBC: ODBC inserts.
Around the copy No index: Redshift has none, so the Replicator Service creates no index on the replication key (see The key at the destination).
Applying changes with Batch or Sequence INSERT, UPDATE ... WHERE <key> and DELETE ... WHERE <key>, one row at a time, committed per batch.
ALTER processing ALTER TABLE ... ADD COLUMN, ALTER COLUMN ... TYPE, DROP COLUMN and RENAME COLUMN. Redshift can't change a column's nullability: the Replicator Service records the change as a COMMENT ON COLUMN instead. ADD Copy loads a work table SQDRCP_<id> next to the destination table and updates the destination table from it (UPDATE ... FROM).

Data types

The Replicator Service maps the source columns to the types the driver reports; see Data type mapping and its Per-database notes. For Redshift:

  • Character lengths are in bytes. A VARCHAR(n) holds n bytes of UTF-8, so text with non-ASCII characters can need more than the source's length: use the inflation options (see Character data).
  • No LOB types. Redshift has no CLOB or BLOB; its longest character type is VARCHAR(65535). Check the destination type of long source columns on the subscription's Columns tab (see LOB and long columns).

Limitations

  • No Merge. Incremental groups apply changes row by row (Batch or Sequence). AWS recommends against single-row inserts into Redshift (see Use a multi-row insert): for tables with many changes, a scheduled snapshot can be a better fit than an incremental group.
  • No indexes, and keys aren't enforced. Redshift doesn't enforce PRIMARY KEY or UNIQUE constraints, so it never rejects a duplicate: inserting a row that already exists adds a second row instead of failing (and, with Allow UPSERT, being turned into an update). Updates and deletes find their rows by the key columns without an index.
  • TRUNCATE commits. Redshift commits a TRUNCATE at once, and it can't be rolled back.
  • ALTER processing can only make VARCHAR columns longer: Redshift's ALTER COLUMN ... TYPE changes nothing else, so other type changes fail. Nullability changes aren't made (see What the Replicator Service runs on the database).
  • Parallel baselines aren't available for Redshift (see Parallel baselines with slices).

Troubleshooting

Problems and messages, with their causes and fixes, are in Troubleshooting › Cloud and streaming destinations.