Search docs.molo17.com
    Configuration guide Connectors

    Replicate PostgreSQL to Apache Iceberg end to end

    This guide takes you from a PostgreSQL table to an Apache Iceberg table that Gluesync keeps up to date with a snapshot and then every insert, update and delete. It covers the catalog side (the namespace and the table), the connection to an Iceberg REST catalog and its object store, the start of the copy, and how to check the result with an engine that has nothing to do with Gluesync. The last part shows what you see when the catalog is unreachable, when a table cannot be written as mapped, when a storage key is wrong and when a secret is typed in the wrong field, and how to recover each time.

    In this guide

    You will learn how to create the namespace that the target table lives in, connect a PostgreSQL CDC source and an Apache Iceberg target with an REST catalog and static storage keys, let Gluesync create the Iceberg table from the source columns, run a snapshot followed by CDC, read the table and its commits with DuckDB, check inserts, updates and deletes, choose a table layout that Gluesync can write, and recover from the failures that you are most likely to meet.

    Quick information

    Goal

    Replicate a PostgreSQL table to an Apache Iceberg table in a REST catalog, with a snapshot and live changes

    Audience

    Data engineers and Gluesync users who build lakehouse pipelines

    Level

    Intermediate

    Time required

    About 45 minutes

    Area

    Iceberg REST catalog → Control Plane → Data pipelines → Apache Iceberg target

    Applies to

    Gluesync 2.3.3 and later

    Before you begin

    Make sure that:

    1. You have an Iceberg REST catalog that Core Hub can reach, such as Apache Polaris, Lakekeeper, Nessie, Unity Catalog, AWS Glue or Amazon S3 Tables, with its tables on Amazon S3 or an S3-compatible store. To try the guide without one, follow the optional first step;

    2. You know how Gluesync authenticates to the catalog and to the store. The guide uses a catalog without authentication and static storage keys; the other modes are listed in Authentication and Storage credentials;

    3. You have a PostgreSQL database set up for change data capture with wal2json, as described in PostgreSQL CDC: WAL-based setup. The examples use the database shop;

    4. You can sign in to the Gluesync Control Plane with a role that can create pipelines;

    5. You can run SQL against PostgreSQL (for example with psql) and curl against the catalog. To read the Iceberg table the guide uses DuckDB with its iceberg extension; Apache Spark, Trino or any engine that reads Iceberg works as well.

    The screenshots come from a lab where Core Hub, the catalog and the store run on the same host, so the addresses are localhost with the ports 15432 (PostgreSQL), 18181 (catalog) and 19000 (store). Use the names and ports of your services.

    Guide steps

    Optional: start a test catalog and object store

    Docker

    Skip this step if you already have a catalog. It starts the reference REST catalog of the Apache Iceberg project with its tables on MinIO, with no authentication. Its catalog lives in memory, so it is empty after every restart: use it for tests only.

    1. Save the file below as docker-compose.yml;

    2. Replace <minio password> with a password of your choice, in both places;

    3. Run docker compose up -d.

    services:
      minio:
        image: minio/minio
        command: server /data
        environment:
          MINIO_ROOT_USER: gluesync
          MINIO_ROOT_PASSWORD: <minio password>
        ports: ["19000:9000"]
      createbucket:
        image: minio/mc
        depends_on: [minio]
        entrypoint: >
          /bin/sh -c "until mc alias set lab http://minio:9000 gluesync '<minio password>'; do sleep 1; done
          && mc mb --ignore-existing lab/warehouse"
      rest:
        image: apache/iceberg-rest-fixture:1.10.0
        depends_on: [createbucket]
        environment:
          AWS_ACCESS_KEY_ID: gluesync
          AWS_SECRET_ACCESS_KEY: <minio password>
          AWS_REGION: us-east-1
          CATALOG_WAREHOUSE: s3://warehouse/
          CATALOG_IO__IMPL: org.apache.iceberg.aws.s3.S3FileIO
          CATALOG_S3_ENDPOINT: http://minio:9000
          CATALOG_S3_PATH__STYLE__ACCESS: "true"
        ports: ["18181:8181"]
    Expected result

    curl http://localhost:18181/v1/config answers with a JSON document, and curl http://localhost:18181/v1/namespaces returns {"namespaces":[],…​}.

    Create the namespace in the catalog

    REST

    An Iceberg table lives in a namespace, the equivalent of a schema. When you map an entity in the Control Plane, Target Namespace lists the namespaces of the catalog, and it is disabled while the catalog has none. Create the namespace first.

    1. Create the namespace lakehouse through the REST API of the catalog. Add the Authorization header that your catalog needs, if any. A catalog with a warehouse in its path takes it in the URL, for example https://polaris.example.com/api/catalog/v1/<warehouse>/namespaces;

    2. List the namespaces to check it.

    curl -X POST http://localhost:18181/v1/namespaces \
      -H 'Content-Type: application/json' \
      -d '{"namespace": ["lakehouse"]}'
    
    curl http://localhost:18181/v1/namespaces

    You can also create it with the tools of your catalog, or with an engine, for example CREATE NAMESPACE lakehouse in Apache Spark or CREATE SCHEMA in Trino.

    Expected result

    The list contains ["lakehouse"].

    Field mapping dialog with the PostgreSQL table public.orders as the source and an empty
    Figure 1. Annotation 1 is Target Namespace, disabled because the catalog has no namespace yet.
    Optional: create the sample table

    SQL

    Skip this step if you already have the table to replicate. It creates public.orders in the database shop, with 1,000 rows.

    CREATE TABLE public.orders (
      id          bigint        PRIMARY KEY,
      customer    varchar(100)  NOT NULL,
      country     varchar(2),
      amount      numeric(12,2),
      status      varchar(10),
      created_at  timestamptz   NOT NULL DEFAULT now()
    );
    
    INSERT INTO public.orders
    SELECT g,
           'Customer ' || g,
           (ARRAY['IT','DE','FR','US','GB','ES','NL','JP'])[1 + g % 8],
           round(10 + (g * 37 % 490) + (g % 100) / 100.0, 2),
           (ARRAY['new','paid','shipped','delivered'])[1 + g % 4],
           timestamptz '2026-01-01 00:00:00+00' + g * interval '1 hour'
    FROM generate_series(1, 1000) AS g;
    Expected result

    SELECT count(*), sum(amount) FROM public.orders returns 1000 and 254445.00.

    Open the pipeline wizard and select the PostgreSQL source

    UI

    1. Open Data pipelines;

    2. Select the + button (Create pipeline) above the list of pipelines, or Create your first pipeline when there is none. The Agents setup wizard opens on 1. Setup source;

    3. In the search field, enter postgres;

    4. Select PostgreSQL CDC agent.

    Agents setup wizard on the step Setup source
    Figure 2. Annotation 1 is the search and 2 the PostgreSQL CDC agent.
    Expected result

    The connection form of PostgreSQL opens on Base settings.

    Enter the source connection and test it

    UI

    1. In Host name / Address and Port, enter the PostgreSQL server (localhost and 15432 in the lab);

    2. In Database name, enter shop;

    3. In Username and Password, enter a user that can read the table and use logical replication;

    4. Select Test and continue, then Next.

    PostgreSQL connection form with host localhost
    Figure 3. Annotation 1 is the host, 2 the port, 3 the database, 4 the user, 5 the password and 6 the test button.
    Expected result

    The wizard shows the card PostgreSQL with the user and the address of the server and a green check mark, then moves to 2. Setup target(s).

    Select the Apache Iceberg target

    UI

    1. In the search field of 2. Setup target(s), enter iceberg;

    2. Select Apache Iceberg agent.

    Setup target step with iceberg in the search field marked 1 and the Apache Iceberg agent tile marked 2
    Figure 4. Annotation 1 is the search and 2 the Apache Iceberg agent.
    Expected result

    The connection form of Apache Iceberg opens, with REST catalog URL (https://…​), Port, Authentication mode and Storage credentials.

    Enter the catalog and the storage credentials

    UI

    1. In REST catalog URL (https://…​), enter the URL of the catalog with its scheme and path. The lab uses http://localhost;

    2. In Port, enter the port of the catalog (18181 in the lab). It is used when the URL carries no port of its own;

    3. In Authentication mode, select the mode of your catalog. The lab uses NONE;

    4. In Storage credentials, select how Gluesync gets to the files. The lab uses STATIC_KEYS, which shows S3 access key ID and S3 secret access key;

    5. Enter the access key and the secret key of the store.

    Apache Iceberg connection form with the catalog URL http://localhost
    Figure 5. Annotation 1 is the catalog URL, 2 the port, 3 the authentication mode, 4 the storage credentials mode, 5 the access key and 6 the secret key.

    With a managed catalog, keep Storage credentials on VENDED_CREDENTIALS (the default) when the catalog hands out credentials for each table: Gluesync then needs no storage key at all. See Storage credentials.

    Point the connection at an S3-compatible store

    UI

    Skip this step for Amazon S3. An S3-compatible store such as MinIO needs its address and, usually, path-style access.

    1. Under Advanced connection properties, select Add property;

    2. In Key, select S3 endpoint (S3-compatible stores only), and in Value enter the address of the store (http://localhost:19000 in the lab);

    3. Select Add property again. In Key, select S3 path-style access and switch Value on;

    4. Select Test and continue.

    Advanced connection properties with the key S3 endpoint and the value http://localhost:19000 marked 1 and 2
    Figure 6. Annotation 1 and 2 are the S3 endpoint and its value, 3 and 4 the path-style access and its switch.
    Expected result

    The wizard shows the card Apache Iceberg with the address of the catalog and a green check mark.

    Setup target step with the Apache Iceberg card and its green check mark marked 1 and the Next button marked 2
    Figure 7. Annotation 1 is the tested target connection and 2 the Next button.

    The test signs in to the catalog and lists its namespaces. It does not touch the object store, so a wrong storage key passes it and shows up only when the first rows are written (see The storage refuses the key).

    Name the pipeline

    UI

    1. Select Next;

    2. On 3. Ready, enter PostgreSQL to Iceberg in Pipeline name;

    3. Select Finish.

    Ready step with the pipeline name PostgreSQL to Iceberg marked 1 and the Finish button marked 2
    Figure 8. Annotation 1 is the pipeline name and 2 the Finish button.
    Expected result

    The pipeline opens, with no entity yet.

    Map the table and let Gluesync create the Iceberg table

    UI

    1. Select Entities. The page Listing database objects for shop opens;

    2. In the Object browser, expand public and tick orders. The Field mapping dialog opens;

    3. In Target Namespace, select lakehouse;

    4. In Target Iceberg table, enter orders and select Create table "orders".

    Field mapping dialog with Target Namespace lakehouse marked 1
    Figure 9. Annotation 1 is the namespace, 2 the table name and 3 the option that creates the table.

    The mapping proposes an Iceberg type for every column: long for bigint, string for the text columns, decimal(12, 2) for numeric(12,2) and timestamptz for timestamp with time zone. You can change a type in Target type before the table is created.

    1. Check the types, then select Confirm. The dialog Create table orders shows the statement Gluesync runs;

    2. Select Create table orders;

    3. Back on the object browser, select Confirm and continue.

    Field mapping dialog with the notice New table orders will be created on confirm marked 1
    Figure 10. Annotation 1 is the notice that the table will be created, 2 the proposed Iceberg types and 3 Confirm.
    Create table orders dialog with the read-only statement CREATE TABLE lakehouse.orders USING iceberg followed by its JSON schema marked 1 and the button Create table orders marked 2
    Figure 11. Annotation 1 is the read-only statement and 2 the button that runs it.
    Object browser with orders ticked and its target lakehouse / orders marked 1
    Figure 12. Annotation 1 is the mapped target and 2 Confirm and continue.
    Expected result

    curl http://localhost:18181/v1/namespaces/lakehouse/tables lists orders. The table has format version 2, merge-on-read delete, update and merge modes, the property gluesync.managed set to true, and id as its identifier field. The pipeline shows the entity public.orders in the group Hold.

    The statement is read-only in the Control Plane. To partition the table or set other properties, create the table yourself before you map the entity (see Choose a table layout Gluesync can write), then select it in Target Iceberg table instead of creating it.

    Start the snapshot and CDC

    UI

    1. In the row of public.orders, select the start button in Actions. The dialog Sync changes (CDC) opens;

    2. In Start from, keep Full copy;

    3. In Data already in the target, select Empty the table first;

    4. Tick I understand that rows in the target will be deleted;

    5. Select Start entity.

    Pipeline PostgreSQL to Iceberg with the entity public.orders in the Hold group marked 1 and its start button marked 2
    Figure 13. Annotation 1 is the entity and 2 its start button.
    Sync changes (CDC) dialog with Full copy marked 1
    Figure 14. Annotation 1 is Full copy, 2 Empty the table first, 3 the confirmation and 4 Start entity.

    Empty the table first empties the table in one commit and then appends the rows, with no delete files: the fastest copy to load and to read. Keep and merge keeps what the table holds and replaces each row by its key, which writes an equality delete for every batch. See Snapshots.

    Expected result

    After a few seconds the entity moves to the group Active and the pipeline reads 1 out of 1 operational.

    Pipeline with the group Active (1) marked 1 and the entity public.orders with its CDC status icon marked 2
    Figure 15. Annotation 1 is the Active group and 2 the running entity.
    Check the snapshot with an independent engine

    SQL

    Read the table with DuckDB through the same catalog. DuckDB applies the delete files that Gluesync writes, so it returns what any reader of the table sees.

    1. Start DuckDB and load the extensions;

    2. Create a secret for the store and attach the catalog;

    3. Count the rows and sum the amounts, then list the commits of the table.

    INSTALL httpfs; LOAD httpfs; INSTALL iceberg; LOAD iceberg;
    
    CREATE SECRET lake_storage (TYPE s3, KEY_ID 'gluesync', SECRET '<minio password>',
      ENDPOINT 'localhost:19000', URL_STYLE 'path', USE_SSL false, REGION 'us-east-1');
    ATTACH 'warehouse' AS lake (TYPE iceberg, ENDPOINT 'http://localhost:18181', AUTHORIZATION_TYPE 'none');
    
    SELECT count(*), sum(amount) FROM lake.lakehouse.orders;
    SELECT sequence_number, timestamp_ms FROM iceberg_snapshots(lake.lakehouse.orders);
    Expected result

    The count is 1000 and the sum 254445.00, as in PostgreSQL. The table has two commits: a delete that emptied it (with nothing to remove on a new table) and an append of the 1,000 rows. The operation of each commit is in the metadata.snapshots of curl http://localhost:18181/v1/namespaces/lakehouse/tables/orders.

    Check inserts, updates and deletes

    SQL

    1. Insert an order in PostgreSQL and look for it in Iceberg;

    2. Update it and check again;

    3. Delete it and check that it is gone.

    -- PostgreSQL
    INSERT INTO public.orders (id, customer, country, amount, status) VALUES (1001, 'Customer 1001', 'IT', 99.90, 'new');
    -- DuckDB, a few seconds later
    SELECT id, amount, status FROM lake.lakehouse.orders WHERE id = 1001;
    
    -- PostgreSQL
    UPDATE public.orders SET status = 'paid', amount = 109.90 WHERE id = 1001;
    -- DuckDB
    SELECT id, amount, status, count(*) OVER () FROM lake.lakehouse.orders WHERE id = 1001;
    
    -- PostgreSQL
    DELETE FROM public.orders WHERE id = 1001;
    -- DuckDB
    SELECT count(*) FROM lake.lakehouse.orders WHERE id = 1001;
    Expected result

    The insert returns 1001 | 99.90 | new, the update 1001 | 109.90 | paid on a single row, and the delete 0. In our test each change was in the table when we looked six seconds later, as one commit: the insert and the update as an overwrite that adds a data file and an equality delete file, the delete as a delete that adds an equality delete file only.

    How Gluesync writes to Iceberg

    What happens on the source What Gluesync commits to the table

    Snapshot with Empty the table first

    One commit that removes every row, then the rows appended batch by batch, with no delete files. Gluesync falls back to replacing rows by key as soon as appending is not known to be safe: a snapshot that resumes, a failed write, a page read again after a failed read.

    Snapshot with Keep and merge

    Each batch replaces its rows by key: an equality delete on the key plus the rows.

    Insert or update

    An equality delete on the key plus the new row (merge-on-read). A row changed twice in one batch is resolved inside the batch, so the last change is the one left.

    Delete

    An equality delete on the key.

    Every batch

    One atomic commit per table: a reader sees the whole batch or none of it. A batch written again after a restart leaves every row once.

    Every commit adds an Iceberg snapshot, and the delete files accumulate. Gluesync does not compact tables or expire their snapshots: run the table maintenance of Iceberg on a schedule (see Apache Iceberg target).

    Choose a table layout Gluesync can write

    A table that Gluesync creates always qualifies. A table that you create, for example to partition it, must meet these rules. Gluesync checks them at the first write of an entity and before a snapshot empties the table, and refuses a table that breaks one with the title Table Not Writable (see The table cannot be written as mapped).

    Rule Why

    The table has a key: its identifier fields, or the key columns of the entity

    A row is updated and deleted by its key. Without one, inserts are appended and updates and deletes are refused.

    Every partition column is part of the key

    A row is updated and deleted within its partition. To partition orders, partition it by a transform of id, such as bucket(4, id).

    No key column is a uuid or a fixed

    Readers built on the Iceberg library do not apply a row-level delete on such a key to every row. Use a string or a binary column.

    The table is of format version 2 or 3, and writes Parquet or Avro files

    Version 1 has no row-level deletes; ORC is not written.

    The table holds no data file of an earlier partition spec

    A row-level delete only reaches the files of its own spec. Rewrite the data files into the current spec first.

    Map every column of the table. A row is written whole, so a column of the table that the entity does not map is null in every row the entity writes, and Gluesync warns of it once in its log.

    Recover from the failures you are most likely to meet

    The catalog is unreachable

    When the catalog stops answering, the batch in progress waits for it. In our test, with the catalog paused, the write failed after about three minutes. The entity then moves to the group Error, and the notification Catalog Request Failed appears with the message Error occurred while processing GET request. Gluesync keeps retrying.

    Pipeline with the group Error (1) marked 1 and the notification Catalog Request Failed for public.orders marked 2
    Figure 16. Annotation 1 is the entity in the Error group and 2 the notification.
    1. Bring the catalog back, or fix the network path between Core Hub and the catalog;

    2. Wait. In our test replication resumed within seconds of the catalog answering again, and a row inserted on PostgreSQL while the catalog was down reached the table. Nothing has to be restarted.

    The table cannot be written as mapped

    An entity mapped onto a table that breaks a rule of Choose a table layout Gluesync can write stops at its first write with the notification Table Not Writable, and the message says what to change. The table is left as it was: it is checked before a snapshot empties it. In our test a table partitioned by carrier, with the key id, gave:

    Entity public.shipments (477c532a): the partition columns [carrier] of shipments must be part of the key, as a row is updated and deleted within its partition
    Notifications hub with the notification Table Not Writable expanded
    Figure 17. Annotation 1 is the title and 2 the message. Select the notification to open it in the Notifications hub.
    1. Change the table as the message says. For a partition column outside the key, recreate the table partitioned by a key column, for example bucket(4, id), or add the partition column to the key of the entity;

    2. Wait. Gluesync retries the entity: in our test, once the table was recreated with a partition on id, the next retry copied all its rows without any action in Gluesync.

    The storage refuses the key

    The connection test does not reach the object store, so a wrong or expired storage key surfaces at the first write. The notification is Storage Access Denied, and the message is the one of the store, for example from MinIO or Amazon S3: The request signature we calculated does not match the signature you provided. Check your key and signing method. (Service: S3, Status Code: 403 …​).

    Notifications hub with Storage Access Denied expanded
    Figure 18. Annotation 1 is the title and 2 the answer of the store.
    1. Correct S3 access key ID and S3 secret access key in the target connection, or give the principal of the catalog the right to vend credentials for the table location;

    2. If the entity stays in the group Error, pause it and start it again with Start from set to Where it stopped.

    A secret is refused in Additional catalog properties

    Additional catalog properties (key=value, one per line) is returned as typed when the connection is read back, while the credentials fields are masked. So a property whose name says it carries a secret (token, credential, secret, password, api-key, access-key, private-key, authorization) is refused when you select Test and continue, with Failed to save and the line that holds it.

    Apache Iceberg connection form with the banner Failed to save: Additional catalog properties
    Figure 19. Annotation 1 is the refusal, which names the line and the key but never the value.
    1. Remove the property;

    2. Enter the secret in the field made for it: Client secret, bearer token, password or AWS secret access key for the catalog, S3 secret access key for the store.

    The Control Plane shows Additional catalog properties on a single line, so it takes one property there. A connection created through the REST API takes several, one per line.

    Verify the result
    • The namespace lakehouse exists in the catalog and holds the table orders.

    • The entity public.orders is in the group Active.

    • DuckDB, or another engine, counts as many rows in Iceberg as in PostgreSQL, with the same totals.

    • An insert, an update and a delete on PostgreSQL each reach the Iceberg table within seconds.

    Troubleshooting

    Problem Possible cause What to do

    Target Namespace is disabled in the Field mapping dialog

    The catalog has no namespace.

    Create one, as in Create the namespace in the catalog, then reopen the dialog.

    Create table does not appear in Target Iceberg table

    A table with that name already exists in the namespace.

    Select the existing table, or enter another name.

    The notification Catalog Request Failed repeats

    The catalog does not answer, or answers with an error of its own.

    See The catalog is unreachable. Check the URL, the port and the authentication of the connection.

    The notification Table Not Writable

    The table breaks a rule of its layout: a partition column outside the key, a uuid or fixed key, format version 1, ORC files, files of an earlier partition spec, a column the table does not have.

    Follow the message. See The table cannot be written as mapped.

    The notification Storage Access Denied

    The storage key is wrong or expired, or the principal cannot write to the table location.

    See The storage refuses the key.

    Failed to save on Test and continue, naming Additional catalog properties

    A property there carries a secret, or a line is not written as key=value.

    See A secret is refused in Additional catalog properties.

    A column is empty in Iceberg although the source has values

    The column is not mapped by the entity.

    Map every column of the table: a row is written whole.

    Contact MOLO17 Support if you need assistance with Apache Iceberg.