ivy_mooncake Use Cases and User Guide

Use ivy_mooncake for workloads such as trading dashboards and operational reports that continuously query recent business data. Applications write to IvorySQL row-store tables and reports query the corresponding Iceberg columnstore mirrors. Plan storage for the mirrors and monitor replication progress.

1. Install and configure

1.1. Build and install from source

These commands target IvorySQL 6.0 (PostgreSQL 19.0) on Linux. Set up the target instance’s development environment, put its bin directory first on PATH, and use an account that can write to the IvorySQL installation directory. Install Rust 1.96.1, Clang/LLVM, libclang, a C++17 compiler, GNU Make, CMake, Ninja, and pkg-config. Building ivy_duckdb as shown below also requires development libraries for OpenSSL, libcurl 7.85.0 or later, and LZ4.

1.1.1. Build and install

Set PG_CONFIG to the absolute path of pg_config in the target IvorySQL 6.0 installation. Confirm that it reports PostgreSQL major version 19.

PG_CONFIG="/path/to/ivorysql-6/bin/pg_config"
"$PG_CONFIG" --version

git clone https://github.com/IvorySQL/ivy_mooncake.git
cd ivy_mooncake
git fetch origin refs/pull/7/head
git switch --detach 27870fdca4d1d2adf26dfa588dd1be430bb0bc98
git submodule update --init --recursive

cargo install --locked cargo-pgrx@0.19.5
cargo pgrx init --pg19="$PG_CONFIG"

make ivy_duckdb PG_VERSION=pg19 PG_CONFIG="$PG_CONFIG"
make install PG_VERSION=pg19 PG_CONFIG="$PG_CONFIG"

If the target instance already has the extension built from the same ivy_duckdb submodule commit (pg_duckdb 1.2.2 with DuckDB 2.0.1), you can skip make ivy_duckdb. Check the source of the installed build to confirm that it uses a DuckDB ABI compatible with the scanner.

1.1.2. Install the mirror scanner

In the same source directory and shell session, build the Mooncake scanner and install it in the DuckDB extension directory. The scanner uses the DuckDB source pinned by the same checkout.

make ivy_duckdb_mooncake

scanner_build=ivy_duckdb_mooncake/build/release
platform="$(cat "$scanner_build/duckdb_platform_out")"
duckdb_version="$(make -s duckdb-version)"
extensions_dir="$("$PG_CONFIG" --sharedir)/pg_duckdb/extensions"

install -D -m 644 \
  "$scanner_build/extension/mooncake/mooncake.duckdb_extension" \
  "$extensions_dir/$duckdb_version/$platform/mooncake.duckdb_extension"

printf "duckdb.extension_directory = '%s'\n" "$extensions_dir"

1.1.3. Configure and verify

Add the duckdb.extension_directory setting printed above to the target instance’s postgresql.conf. Use the settings below for logical replication and extension loading. Merge the preload settings with the existing list and put pg_duckdb before pg_mooncake. Oracle mode also needs liboracle_parser and ivorysql_ora preloaded. duckdb.allow_community_extensions permits installation from the community repository. duckdb.allow_unsigned_extensions permits loading the unsigned scanner you built locally.

shared_preload_libraries = 'pg_duckdb,pg_mooncake'
wal_level = logical
duckdb.allow_community_extensions = true
duckdb.allow_unsigned_extensions = true

Restart IvorySQL and connect as a database superuser to the database that will use the mirror. Create the extension and check the background worker. The result should show socket_listening as true.

CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE;
SELECT mooncake.bgworker_status();

1.2. Run the Docker image

The ivy_mooncake:0.3 image for linux/amd64 is based on IvorySQL 6.0 (PostgreSQL 19.0) and comes with ivy_duckdb and ivy_mooncake preinstalled. Enter a test password and start the container.

read -rsp 'IvorySQL test password: ' IVORYSQL_PASSWORD
printf '\n'
export IVORYSQL_PASSWORD
docker run -d --name ivy_mooncake_03 \
  -e IVORYSQL_PASSWORD \
  -v ivy_mooncake_data:/var/lib/ivorysql/data \
  -v ivy_mooncake_warehouse:/var/lib/ivorysql/mooncake \
  registry.highgo.com/mooncake/ivy_mooncake:0.3
unset IVORYSQL_PASSWORD

docker exec -it ivy_mooncake_03 bash

The ivy_mooncake_data named volume stores database data. The ivy_mooncake_warehouse volume stores Mooncake mirror data.

If the container is already running, enter it with docker exec -it ivy_mooncake_03 bash. With Docker, run the psql commands below inside the container.

2. Create a mirror and verify incremental replication

The two examples below check the initial mirror data and a later update to the source table in PG and Oracle modes. Use a test database where the example tables are absent on the first run. If your client has autocommit disabled, commit the update before waiting for replication.

2.1. Verify Mirror Replication in PG Mode

The image uses port 5432 for PG mode. For a source installation, use the target instance’s PG-mode connection parameters.

psql -X -p 5432 -U ivorysql -d postgres -v ON_ERROR_STOP=1
SELECT version();
SHOW ivorysql.compatible_mode;

CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE;

SELECT extname, extversion
FROM pg_extension
WHERE extname IN ('pg_duckdb', 'pg_mooncake')
ORDER BY extname;

CREATE TABLE htap_test_source (id integer PRIMARY KEY, amount integer);
INSERT INTO htap_test_source VALUES (1, 10), (2, 20);

CALL mooncake.create_table('htap_test_mirror', 'htap_test_source');
SELECT COUNT(*) AS rows, SUM(amount) AS total FROM htap_test_mirror;

UPDATE htap_test_source SET amount = 25 WHERE id = 2;
SELECT COUNT(*) AS rows, SUM(amount) AS total FROM htap_test_mirror;

ivorysql.compatible_mode should return pg. The ivy_mooncake:0.3 image reports pg_duckdb 1.2.2 and pg_mooncake 0.3.0. Both mirror queries report rows = 2, and the total changes from 30 to 35. If the mirror has yet to apply the update, wait for replication and query it again.

2.2. Verify the Mirror and DuckDB Plans in Oracle Mode

Enter \q in psql to return to the shell. The image uses port 1521 for Oracle mode. For a source installation, use the target instance’s Oracle-mode connection parameters.

psql -X -p 1521 -U ivorysql -d postgres -v ON_ERROR_STOP=1
SHOW ivorysql.compatible_mode;
SELECT CAST(42 AS NUMBER(10,0)) FROM dual;

CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE;

CREATE TABLE htap_ora_source (
    id NUMBER(10,0) PRIMARY KEY,
    amount NUMBER(10,2),
    channel VARCHAR2(12)
);

INSERT INTO htap_ora_source VALUES (1, 10.50, 'online');
INSERT INTO htap_ora_source VALUES (2, 20.00, 'store');

SET duckdb.force_execution = off;
EXPLAIN (COSTS OFF)
SELECT channel, SUM(amount) FROM htap_ora_source GROUP BY channel;

SET duckdb.force_execution = on;
EXPLAIN (COSTS OFF)
SELECT channel, SUM(amount) FROM htap_ora_source GROUP BY channel;

SELECT channel, SUM(amount)
FROM htap_ora_source
GROUP BY channel
ORDER BY channel;

SET duckdb.force_execution = off;

CALL mooncake.create_table('htap_ora_mirror', 'htap_ora_source');
SELECT COUNT(*) AS rows, SUM(amount) AS total FROM htap_ora_mirror;

UPDATE htap_ora_source SET amount = 25.00 WHERE id = 2;
SELECT COUNT(*) AS rows, SUM(amount) AS total FROM htap_ora_mirror;

ivorysql.compatible_mode should return oracle. With forced execution off, this query uses HashAggregate and Seq Scan. With it on, the plan shows Custom Scan (DuckDBScan). Both mirror queries report rows = 2, and the total changes from 30.50 to 35.50.

duckdb.force_execution controls whether eligible queries in the current session are forced to run in DuckDB. With it off, ordinary table queries follow the default planning path. The DuckDB scan extension reads Mooncake mirrors.

3. Compare Query Times on Two Million Rows

Stay in Oracle mode. Count distinct customers by region on the same source table.

CREATE EXTENSION IF NOT EXISTS pg_mooncake CASCADE;

CREATE TABLE htap_bench_orders (
    region_id INT,
    customer_id INT,
    amount NUMBER(10,2)
);

INSERT INTO htap_bench_orders
SELECT MOD(n, 32), MOD(n, 180013), MOD(n, 10000) / 100.0
FROM pg_catalog.generate_series(1, 2000000) AS g(n);

ANALYZE htap_bench_orders;

In psql, enable \timing and record the Time after each SELECT. Alternate between the two settings for several runs and take the median for each setting.

\timing on

SET duckdb.force_execution = off;

SELECT region_id, COUNT(DISTINCT customer_id) AS unique_customers
FROM htap_bench_orders
GROUP BY region_id
ORDER BY region_id;

SET duckdb.force_execution = on;

SELECT region_id, COUNT(DISTINCT customer_id) AS unique_customers
FROM htap_bench_orders
GROUP BY region_id
ORDER BY region_id;

EXPLAIN (COSTS OFF)
SELECT region_id, COUNT(DISTINCT customer_id) AS unique_customers
FROM htap_bench_orders
GROUP BY region_id
ORDER BY region_id;

SET duckdb.force_execution = off;
\timing off

Each setting was tested three times in the same local linux/amd64 container. Both returned the same results for all 32 regions.

duckdb.force_execution Three query times Median

off

2.23 s, 1.83 s, 1.71 s

1.83 s

on

0.52 s, 0.30 s, 0.45 s

0.45 s

This query ran about 4.1 times as fast with DuckDB forced execution on. Use Custom Scan (DuckDBScan) in EXPLAIN to check the execution path and the measured SELECT times to compare performance.

4. Check replication

If mirror results stay stale, confirm that the source transaction committed. Then connect to the database that contains the mirror and check the worker, mirror replication progress, and logical replication slots.

SELECT mooncake.bgworker_status();
SELECT * FROM mooncake.list_tables();

SELECT slot_name, active, restart_lsn, confirmed_flush_lsn
FROM pg_replication_slots
WHERE slot_type = 'logical'
  AND database = current_database();

Check socket_listening in the mooncake.bgworker_status() result to see whether the worker’s socket is listening. Find the target mirror in the mooncake.list_tables() result and check its commit and flush LSNs. Check the activity and replication positions of the relevant slot in the current database. See the ivy_mooncake technical design for the data path and recovery behavior.