pg_mooncake
pg_mooncake
pg_mooncake : Columnstore Table in Postgres
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2440 | pg_mooncake | pg_mooncake | 0.2.0 | OLAP | MIT | Rust |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
---Ld-- | No | No | Yes | Yes | no | no |
| Relationships | |
|---|---|
| Requires | pg_duckdb |
| See Also | pg_duckdb duckdb_fdw pg_analytics columnar citus_columnar pg_parquet orioledb timescaledb |
unpublished release
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.2.0 | 18 17 16 15 14 13 | pg_mooncake | - |
| RPM | PIGSTY | 0.2.0 | 18 17 16 15 14 13 | pg_mooncake_$v* | - |
| DEB | PIGSTY | 0.2.0 | 18 17 16 15 14 13 | postgresql-$v-pg-mooncake | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 | PG13 |
|---|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
el8.aarch64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
el9.x86_64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
el9.aarch64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
el10.x86_64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
el10.aarch64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
d12.x86_64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
d12.aarch64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
d13.x86_64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
d13.aarch64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
u22.x86_64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
u22.aarch64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
u24.x86_64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
u24.aarch64 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | PIGSTY 0.2.0 | MISS |
Source
pig build pkg pg_mooncake; # build rpm / deb with pigInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgdg pigsty -u # add both repo and update cacheInstall this extension with pig:
pig install pg_mooncake; # install via package name, for the active PG version
pig install pg_mooncake -v 18; # install for PG 18
pig install pg_mooncake -v 17; # install for PG 17
pig install pg_mooncake -v 16; # install for PG 16
pig install pg_mooncake -v 15; # install for PG 15
pig install pg_mooncake -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pg_duckdb, pg_mooncake';Create this extension with:
CREATE EXTENSION pg_mooncake CASCADE; -- requires pg_duckdbUsage
pg_mooncake 0.2.0 (unpublished yet) is rewritten in Rust and 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_mooncakeEdit postgresql.conf, then restart to take effect
shared_preload_libraries = 'pg_duckdb,pg_mooncake'
duckdb.allow_community_extensions = true
wal_level = logicalHello 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 updated on