Skip to content

Quickstart

This quickstart replicates one Db2 LUW table into PostgreSQL. You will install TwinCommit, check the source, create the target table, take a snapshot, start streaming and verify the result. The same steps apply to every other source and target; only the source: and target: blocks change.

  • A Db2 LUW database with archive logging enabled. See Db2 LUW prerequisites.
  • A PostgreSQL database you can create tables in.
  • A Linux x86-64 host that can reach both, with the IBM Data Server Client installed if it is not the Db2 server itself.
  1. Install TwinCommit

    Terminal window
    curl -fsSL https://get.twincommit.io | sh
    twincommit version

    Other options (Docker, Helm, Homebrew) are on the installation page.

  2. Prepare the source table

    Every replicated table needs a primary key and full row images in the log:

    ALTER TABLE DB2INST1.ORDERS DATA CAPTURE CHANGES;
  3. Write a pipeline file

    Save this as orders.yaml:

    source:
    type: db2
    database: SAMPLE
    user: ${DB2_USER}
    password: ${DB2_PASSWORD}
    target:
    type: postgres
    dsn: postgres://twincommit:${PG_PASSWORD}@pghost:5432/analytics
    tables:
    - source: DB2INST1.ORDERS
    target: sales.orders

    ${VAR} values are read from the environment, so secrets never live in the file.

  4. Check the source

    Terminal window
    twincommit check -config orders.yaml
    ✓ archive logging LOGARCHMETH1=DISK:/db2/archive
    ✓ authority DBADM granted to TWINCOMMIT
    ✓ code page 1208 (UTF-8)
    ✓ DB2INST1.ORDERS primary key, DATA CAPTURE CHANGES
    all checks passed

    Anything that fails is printed with the exact command that fixes it.

  5. Create the target table

    Terminal window
    twincommit ddl -config orders.yaml -apply
  6. Snapshot

    Terminal window
    twincommit snapshot -config orders.yaml

    TwinCommit takes a brief share lock on the table, records the log position, releases the lock and copies the rows.

  7. Stream

    Terminal window
    twincommit run -config orders.yaml

    Change a row in Db2 and query sales.orders in PostgreSQL. The change appears once its transaction commits.

  8. Verify

    In a second terminal:

    Terminal window
    twincommit status -config orders.yaml
    twincommit verify -config orders.yaml