pg_mooncake

Columnstore Table in Postgres

Overview

PackageVersionCategoryLicenseLanguage
pg_mooncake0.2.0OLAPMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
2440pg_mooncakeNoNoYesYesNoNo-
Relatedpg_duckdb pg_duckdb duckdb_fdw pg_analytics columnar citus_columnar pg_parquet orioledb timescaledb

unpublished release

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.2.01817161514pg_mooncakepg_duckdb
RPMPIGSTY0.2.01817161514pg_mooncake_$v-
DEBPIGSTY0.2.01817161514postgresql-$v-pg-mooncake-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
d12.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
d13.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
d13.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u22.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u22.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u24.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u24.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0

Build

You can build the RPM / DEB packages for pg_mooncake using pig build:

pig build pkg pg_mooncake         # build RPM / DEB packages

Install

You can install pg_mooncake directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_mooncake;          # Install for current active PG version
pig ext install -y pg_mooncake -v 18  # PG 18
pig ext install -y pg_mooncake -v 17  # PG 17
pig ext install -y pg_mooncake -v 16  # PG 16
pig ext install -y pg_mooncake -v 15  # PG 15
pig ext install -y pg_mooncake -v 14  # PG 14
dnf install -y pg_mooncake_18       # PG 18
dnf install -y pg_mooncake_17       # PG 17
dnf install -y pg_mooncake_16       # PG 16
dnf install -y pg_mooncake_15       # PG 15
dnf install -y pg_mooncake_14       # PG 14
apt install -y postgresql-18-pg-mooncake   # PG 18
apt install -y postgresql-17-pg-mooncake   # PG 17
apt install -y postgresql-16-pg-mooncake   # PG 16
apt install -y postgresql-15-pg-mooncake   # PG 15
apt install -y postgresql-14-pg-mooncake   # PG 14

Preload:

shared_preload_libraries = 'pg_duckdb, pg_mooncake';

Create Extension:

CREATE EXTENSION pg_mooncake CASCADE;  -- requires: pg_duckdb

Usage

pg_mooncake is a Postgres extension that creates columnstore mirrors of your tables in Iceberg format, designed as a sub-extension of pg_duckdb.

pg_mooncake docs: https://docs.mooncake.dev/

Quick Setup

Install pg_duckdb and pg_mooncake with pig:

pig repo set
pig install pg_duckdb pg_mooncake

Edit postgresql.conf, then restart to take effect

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

Hello Worlds

-- create the extension alone with pg_duckdb
CREATE EXTENSION pg_mooncake CASCADE;

-- Next, create a regular Postgres table trades:
CREATE TABLE trades(
  id bigint PRIMARY KEY,
  symbol text,
  time timestamp,
  price real
);

-- Then, create a columnstore mirror trades_iceberg that stays in sync with trades:
CALL mooncake.create_table('trades_iceberg', 'trades');

-- Now, insert some data into trades:
INSERT INTO trades VALUES
    (1,  'AMD', '2024-06-05 10:00:00', 119),
    (2, 'AMZN', '2024-06-05 10:05:00', 207),
    (3, 'AAPL', '2024-06-05 10:10:00', 203),
    (4, 'AMZN', '2024-06-05 10:15:00', 210);

-- Finally, query it with duckdb
EXPLAIN
    SELECT avg(price) FROM trades_iceberg WHERE symbol = 'AMZN';

You will see the DuckDBScan in the execution plan:

                         QUERY PLAN
------------------------------------------------------------
 Custom Scan (DuckDBScan)  (cost=0.00..0.00 rows=0 width=0)
   DuckDB Execution Plan:

 ┌───────────────────────────┐
 │    UNGROUPED_AGGREGATE    │
 │    ────────────────────   │
 │    Aggregates: avg(#0)    │
 └─────────────┬─────────────┘
 ┌─────────────┴─────────────┐
 │         PROJECTION        │
 │    ────────────────────   │
 │   CAST(price AS DOUBLE) │                           │
 │          ~0 rows          │
 └─────────────┬─────────────┘
 ┌─────────────┴─────────────┐
 │       MOONCAKE_SCAN       │
 │    ────────────────────   │
 │   Table: trades_iceberg   │
 │     Projections: price    │
 │                           │
 │          Filters:         │
symbol='AMZN' │                           │
 │          ~0 rows          │
 └───────────────────────────┘

Last Modified 2026-03-12: add pg extension catalog (95749bf)