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:
-
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;
-
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;
-
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 databaseshop; -
You can sign in to the Gluesync Control Plane with a role that can create pipelines;
-
You can run SQL against PostgreSQL (for example with
psql) andcurlagainst the catalog. To read the Iceberg table the guide uses DuckDB with itsicebergextension; 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 |
Guide steps
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.
-
Save the file below as
docker-compose.yml; -
Replace
<minio password>with a password of your choice, in both places; -
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"]
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.
-
Create the namespace
lakehousethrough the REST API of the catalog. Add theAuthorizationheader that your catalog needs, if any. A catalog with a warehouse in its path takes it in the URL, for examplehttps://polaris.example.com/api/catalog/v1/<warehouse>/namespaces; -
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.
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;
UI
-
Open Data pipelines;
-
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;
-
In the search field, enter
postgres; -
Select PostgreSQL CDC agent.
UI
-
In Host name / Address and Port, enter the PostgreSQL server (
localhostand15432in the lab); -
In Database name, enter
shop; -
In Username and Password, enter a user that can read the table and use logical replication;
-
Select Test and continue, then Next.
UI
-
In the search field of 2. Setup target(s), enter
iceberg; -
Select Apache Iceberg agent.
UI
-
In REST catalog URL (https://…), enter the URL of the catalog with its scheme and path. The lab uses
http://localhost; -
In Port, enter the port of the catalog (
18181in the lab). It is used when the URL carries no port of its own; -
In Authentication mode, select the mode of your catalog. The lab uses
NONE; -
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; -
Enter the access key and the secret key of the store.
|
With a managed catalog, keep Storage credentials on |
UI
Skip this step for Amazon S3. An S3-compatible store such as MinIO needs its address and, usually, path-style access.
-
Under Advanced connection properties, select Add property;
-
In Key, select S3 endpoint (S3-compatible stores only), and in Value enter the address of the store (
http://localhost:19000in the lab); -
Select Add property again. In Key, select S3 path-style access and switch Value on;
-
Select Test and continue.
|
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). |
UI
-
Select Next;
-
On 3. Ready, enter
PostgreSQL to Icebergin Pipeline name; -
Select Finish.
UI
-
Select Entities. The page Listing database objects for shop opens;
-
In the Object browser, expand
publicand tickorders. The Field mapping dialog opens; -
In Target Namespace, select
lakehouse; -
In Target Iceberg table, enter
ordersand select Create table "orders".
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.
-
Check the types, then select Confirm. The dialog Create table orders shows the statement Gluesync runs;
-
Select Create table orders;
-
Back on the object browser, select Confirm and continue.
|
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. |
UI
-
In the row of
public.orders, select the start button in Actions. The dialog Sync changes (CDC) opens; -
In Start from, keep Full copy;
-
In Data already in the target, select Empty the table first;
-
Tick I understand that rows in the target will be deleted;
-
Select 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.
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.
-
Start DuckDB and load the extensions;
-
Create a secret for the store and attach the catalog;
-
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);
SQL
-
Insert an order in PostgreSQL and look for it in Iceberg;
-
Update it and check again;
-
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;
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 |
No key column is a |
Readers built on the Iceberg library do not apply a row-level delete on such a key to every row. Use a |
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.
-
Bring the catalog back, or fix the network path between Core Hub and the catalog;
-
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
-
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; -
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 …).
-
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;
-
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.
-
Remove the property;
-
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. |
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 |
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. |
|
Failed to save on Test and continue, naming Additional catalog properties |
A property there carries a secret, or a line is not written as |
|
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. |
Related guides
Contact MOLO17 Support if you need assistance with Apache Iceberg.