Skip to content

Set up a Snowflake destination

A Snowflake destination is written in two ways. The Replicator Service connects through the Snowflake ODBC driver to create, change and empty the destination tables. The rows (baselines, snapshots and incremental changes) are streamed by the Stelo Capture Apply extension for Snowflake (SnowFlakeApply), which uses Snowpipe Streaming and merges the changes with SQL. For key-pair or access-token sign-in details, see Snowflake key-pair and token authentication.

Supported configurations

Supported
Snowflake Snowflake accounts, with standard Snowflake tables. For Iceberg tables or other table types, ask Stelo Support.
Driver on the Stelo VM Snowflake ODBC driver (SnowflakeDSIIDriver on Windows); install it on the Stelo VM (see ODBC drivers). A programmatic access token needs version 3.8.0 or later.
Snapshot replication Yes. The rows are streamed through the source's Capture Agent, so the source needs one (see ODBC and Java connectors).
Incremental replication Yes, through the SnowFlakeApply Apply extension of Stelo Capture.
Apply method Always Merge: the Apply extension streams each table's changes into a work table and runs one MERGE (see How changes are applied).
Authentication Key pair (recommended) or programmatic access token (PAT). A password works for the ODBC connection only where your account still allows password-only sign-in; the Apply extension can't stream with a password. See Snowflake key-pair and token authentication.
Encryption Always: the ODBC driver, the JDBC driver and Snowpipe Streaming connect to Snowflake over HTTPS (port 443).

Docker

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

How changes are applied

What SQDR runs in Snowflake explains the privileges below.

  • The Replicator Service (ODBC connection) creates the destination tables (CREATE TABLE), empties them before a baseline (TRUNCATE or DELETE), changes them when a source table changes (ALTER TABLE) and drops them when a subscription re-creates its table. The connection's role owns the tables.
  • Baselines and snapshots are streamed by the Apply extension straight into the destination table, through its default Snowpipe Streaming pipe (<table>-STREAMING, created and managed by Snowflake).
  • Incremental changes are streamed into a work table next to the destination table, Z__<table> in the same schema. The Apply extension creates it with CREATE OR REPLACE TABLE ... LIKE <table> ENABLE_SCHEMA_EVOLUTION = TRUE and adds two columns for the kind of change and its sequence number. For each batch it runs one MERGE into the destination table that keeps only the last change of each row (matched on the replication key), then truncates the work table, which is kept for the next batch.
  • The MERGE and the other statements run in the session's warehouse.

The Apply extension's optional parameters stagingPrefix (default Z__) and stagingPostfix (default empty) change the work table's name; dropTempTable=true drops it after each batch instead of truncating it.

Firewall rules on the Stelo VM

The Replicator Service and Stelo Capture connect out to Snowflake over HTTPS (port 443): to your account's URL (<account>.snowflakecomputing.com, where <account> is the account identifier) and to other Snowflake hosts. If a firewall limits outbound traffic, ask the Snowflake administrator for the hosts and ports to allow: the output of SELECT SYSTEM$ALLOWLIST();, run in Snowflake.

Prepare Snowflake

Run these steps in Snowflake (a Snowsight worksheet, or SnowSQL) with roles allowed to create users, roles and objects. The examples use the placeholders MY_USER, MY_ROLE, MY_WH, MY_DB and MY_SCHEMA, as on Snowflake key-pair and token authentication.

Snowflake stores unquoted names in uppercase, and SQDR quotes every database, schema and table name: write the names in SQDR exactly as Snowflake shows them (usually uppercase).

Create the user and the role

Use a dedicated service user for replication, with its own role:

USE ROLE USERADMIN;
CREATE ROLE IF NOT EXISTS MY_ROLE;
CREATE USER IF NOT EXISTS MY_USER
  TYPE = SERVICE
  DEFAULT_ROLE = MY_ROLE
  DEFAULT_WAREHOUSE = MY_WH;
GRANT ROLE MY_ROLE TO USER MY_USER;

A service user (TYPE = SERVICE) has no password: it signs in with a key pair or a programmatic access token, which the Replicator Service and the Apply extension use without a prompt. Set up the key pair in the next step.

Use the same user and role for the destination's ODBC connection and the Apply extension: the tables the Replicator Service creates belong to the connection's role, and the Apply extension must fill and merge into them.

Set up the key pair

The Replicator Service and the Apply extension sign in with a key pair: a private key file on the Stelo VM and its public key on the user. You need OpenSSL on any computer (on Windows, Git for Windows includes it), and a role that can change the user (its owner, or USERADMIN). To use a programmatic access token instead, create one (see Token) and skip this part.

The Snowflake administrator can do this part; the private key file goes to the Stelo VM later, when the destination is created.

Generate the key pair

On a computer with OpenSSL:

# Private key, encrypted with a passphrase (you're asked for it): rsa_key.p8
openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 aes256 -inform PEM -out rsa_key.p8

# Public key: rsa_key.pub (you're asked for the passphrase again)
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub

Use AES-256 (-v2 aes256) as shown. For a key without a passphrase, or a passphrase from a script, see More key-pair options.

Keep rsa_key.pub for the next step. Hand the private key file rsa_key.p8 and its passphrase to the SQDR administrator securely and separately (for example, the passphrase through a password manager, not in the same message as the file): a copy of both is enough to sign in as the user. The SQDR administrator copies the file to the SQDR server and stores the passphrase as a secret when creating the destination (see Create the destination).

Attach the public key to the user

Copy the body of rsa_key.pub, without the -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- lines and without line breaks, and set it on the user:

ALTER USER MY_USER SET RSA_PUBLIC_KEY = 'MIIBIjANBgkqh...';
DESC USER MY_USER;   -- RSA_PUBLIC_KEY_FP is now set

To check the key's fingerprint, or replace the key later, see More key-pair options.

Create the warehouse, database and schema

Skip what already exists:

USE ROLE SYSADMIN;
CREATE WAREHOUSE IF NOT EXISTS MY_WH
  WAREHOUSE_SIZE = XSMALL
  AUTO_SUSPEND = 60
  AUTO_RESUME = TRUE
  INITIALLY_SUSPENDED = TRUE;
CREATE DATABASE IF NOT EXISTS MY_DB;
CREATE SCHEMA IF NOT EXISTS MY_DB.MY_SCHEMA;

Keep AUTO_RESUME = TRUE (Snowflake's default), so that a suspended warehouse starts when SQDR runs a statement. Size it for your volume of changes; a larger warehouse runs the MERGE statements faster.

Grant the role its privileges

USE ROLE SYSADMIN;
GRANT USAGE ON WAREHOUSE MY_WH TO ROLE MY_ROLE;
GRANT USAGE ON DATABASE MY_DB TO ROLE MY_ROLE;
GRANT USAGE, CREATE TABLE ON SCHEMA MY_DB.MY_SCHEMA TO ROLE MY_ROLE;

What each privilege is for, and the grants for tables you created yourself: see Privileges.

A network policy on the user is optional with a key pair (and good practice), and needed with a token: see Allow the network access.

Find the account identifier

The connection string and the Apply extension need your account identifier. Snowflake's preferred form is <orgname>-<account_name>:

SELECT CURRENT_ORGANIZATION_NAME() || '-' || CURRENT_ACCOUNT_NAME();

The account URL is <account>.snowflakecomputing.com, for example myorg-myaccount.snowflakecomputing.com. The older form with the account locator (for example xy12345.us-east-2.aws.snowflakecomputing.com) works too, if you use it in both places.

Create the destination

With the key pair set up (see Set up the key pair), or a token created (see Token):

  1. Install the ODBC driver on the Stelo VM: the 64-bit Snowflake ODBC driver, then restart the Replicator Service (see ODBC drivers).

    Docker

    The SQDR container includes the Snowflake ODBC driver.

  2. Copy the private key file (key pair only): put the rsa_key.p8 the Snowflake administrator handed you (see Generate the key pair) on the computer where the Replicator Service runs, in a folder that only the service's account and administrators can read, for example:

    C:\ProgramData\StarQuest\sqdr\keys\rsa_key.p8. Keep SYSTEM (Local System) in the folder's list in every case: the Replicator Service runs as Local System unless you change its account in the SQDR Configuration Tool, and SQDR Plus, which reads the key when the Apply extension uses the key file too, always runs as Local System. If the Replicator Service runs under another account, add that account too:

    icacls C:\ProgramData\StarQuest\sqdr\keys /inheritance:r /grant:r "SYSTEM:(OI)(CI)F" "Administrators:(OI)(CI)F"
    

    Docker

    Put the key in /var/sqdr/keys/rsa_key.p8, on the sq-config volume, so it survives a new container (see Volumes). chmod 700 the folder and chmod 600 rsa_key.p8, owned by the account the Replicator Service runs as. With Snowflake ODBC 4.0 or later this is required: the driver refuses a key file that others can read.

    If the Apply extension uses the key file too, Stelo Capture must be able to read it at the path in its parameters (usually the same computer).

  3. Store the passphrase as a secret, for example SNOWFLAKE_KEY_PWD (with a token, store the token, for example as SNOWFLAKE_PAT).

  4. Name (see Create a destination): choose the DBMS Type Snowflake.
  5. Connection: choose ODBC Driver, the Snowflake driver, and the Template "Snowflake - key pair (Authentication Method: Connection String)". Fill in the fields:

    Field What to enter
    SERVER The account URL, <account>.snowflakecomputing.com (see Find the account identifier).
    DATABASE MY_DB.
    WAREHOUSE MY_WH.
    ROLE MY_ROLE. Set it: without it the session starts with the user's default role.
    UID MY_USER.
    PRIV_KEY_FILE, PRIV_KEY_FILE_PWD The key file and the secret reference for its passphrase.

    You can add SCHEMA=MY_SCHEMA to set the session's default schema. The template also sets AUTHENTICATOR=SNOWFLAKE_JWT, which turns on key-pair sign-in: without it the driver tries a password and fails with 390100. Use PRIV_KEY_FILE_PWD with a key file (PRIV_KEY_PWD doesn't work with one); if the passphrase contains ;, write PRIV_KEY_FILE_PWD={$$SNOWFLAKE_KEY_PWD$$}. Snowflake's keyword names are case-sensitive. The key itself can't be kept in a secret (PRIV_KEY_BASE64): it's longer than a secret can hold.

    With a token: the Snowflake ODBC driver must be version 3.8.0 or later. Choose the Template "Snowflake - access token (PAT) (Authentication Method: Connection String)" instead, skip the key file, and enter the token's secret reference in TOKEN. Don't send the token as a password: Snowflake refuses that for service users (390100).

    With an ODBC DSN: you can keep these settings in a 64-bit System DSN with the Snowflake driver instead (in the SQDR container, in odbc.ini), adding AUTHENTICATOR, PRIV_KEY_FILE and PRIV_KEY_FILE_PWD under HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\<DSN name> if the driver's dialog has no field for them. Secret references aren't resolved inside a DSN, so the passphrase is stored there as plain text: prefer the connection string.

  6. Authentication: choose Connection String (driver-specific) and click Verify.

  7. Tick Advanced and review:
    • Options: in Default Parameters, choose the className com.starquest.sqdr.apply.snowpipe.SnowFlakeApply and the Snowflake login type, and fill in the values. See Apply extension parameters.
    • Default: check that Database is MY_DB and set Object Schema to MY_SCHEMA, in the case Snowflake shows them. New subscriptions and incremental groups create their tables there.

Apply extension parameters

The Apply extension signs in on its own, with the destination's Default Parameters. Incremental groups copy them when they're created and keep their own copy; snapshot subscriptions use the destination's parameters directly. Set them before you create groups. A key-pair set looks like this:

className=com.starquest.sqdr.apply.snowpipe.SnowFlakeApply
user=MY_USER
account=myorg-myaccount
url=myorg-myaccount.snowflakecomputing.com
database=MY_DB
warehouse=MY_WH
role=MY_ROLE
authorization_type=KEY_PAIR
private_key_file=C:\\ProgramData\\StarQuest\\sqdr\\keys\\rsa_key.p8
private_key_pwd=$$SNOWFLAKE_KEY_PWD$$
  • user, role and warehouse: as in the connection string.
  • database: the destination's Database. The Apply extension streams into this database and the schema of each subscription's destination table.
  • account is the account identifier and url the account URL (see Find the account identifier).
  • Login: authorization_type is KEY_PAIR or PAT. For a key pair, private_key_file is the same key file as the ODBC connection, on the computer where Stelo Capture runs (write Windows paths with double backslashes), and private_key_pwd the same secret as PRIV_KEY_FILE_PWD (leave it out for a key without a passphrase). For a token, personal_access_token is the token's secret reference.
  • A value that refers to a secret must be the reference alone ($$name$$).

To change the parameters after groups exist, or rotate a passphrase or token, see Change the parameters later.

Test the connection

Verify tests only the ODBC connection; the Apply extension's sign-in is tested when a subscription first runs. To test both, create a snapshot subscription of a small table to the destination, from a source with a Stelo Capture Capture Agent: the Replicator Service creates the table and the Apply extension streams the rows. Check the row count in Snowflake. If the TRUNCATE works but the INSERT fails, see Role and warehouse.

Change the parameters later

If you change the parameters after groups exist, change each group's copy too: in the group's Parameters, use Load from Destination (see Group properties). To rotate a key passphrase or a token, change the value of the secret the parameters refer to ($$name$$): the groups' copies hold the reference, not the value, so they need no change.

Group settings for Snowflake

When you create an incremental group to this destination:

Check the destination

After the incremental group's first baseline (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). Sign-in errors mean the group's copy of the parameters is out of date or still uses a password (see Troubleshooting).
  2. Rows at the destination. Compare a table's row count with the source:

    SELECT COUNT(*) FROM MY_DB.MY_SCHEMA.MY_TABLE;
    
  3. Changes. Change a few rows at the source. They arrive with the group's next poll (the Poll Interval; see Scheduling).

  4. Sign-ins. In Snowflake, check how the user signed in:

    SELECT event_timestamp, reported_client_type, first_authentication_factor, is_success, error_code, error_message
    FROM TABLE(INFORMATION_SCHEMA.LOGIN_HISTORY_BY_USER(USER_NAME => 'MY_USER'))
    ORDER BY event_timestamp DESC;
    

    REPORTED_CLIENT_TYPE tells the Replicator Service's ODBC sign-ins from the Apply extension's. Both must succeed (IS_SUCCESS = YES), with FIRST_AUTHENTICATION_FACTOR RSA_KEYPAIR for a key pair or PROGRAMMATIC_ACCESS_TOKEN for a token.

Data types

The Replicator Service creates the destination columns with Snowflake types; see Per-database notes. For Snowflake:

  • Timestamps have up to 9 fractional digits.
  • VARIANT, ARRAY and OBJECT are used only for source columns of the same type.
  • With the useMaxVARCHAR service property, VARCHAR columns are created without a length (at Snowflake's maximum), so UTF-8 data never exceeds the column.

Limitations

  • Keys. Snowflake doesn't enforce keys and has no indexes: the Replicator Service creates no index on Snowflake tables, and non-unique source indexes can't be replicated (see Indexes). The MERGE matches rows on the replication key. For a table without a usable key (and without a row identifier column), the Apply extension can only insert: updates arrive as new rows and deletes aren't applied. See Tables without a usable key.
  • Apply method. Incremental groups to Snowflake always use the Apply extension's merge; Batch and Sequence don't apply.
  • Derived columns (column phrases) aren't available (see Derived columns).
  • Capture Agent. Snapshot subscriptions need a source with a Capture Agent.
  • Password sign-in. The Apply extension can't stream with a password; use a key pair or a token.

Troubleshooting

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