Create Columnstore Table
In pg_mooncake, columnstore tables are created as real-time mirrors of existing PostgreSQL rowstore (heap or partitioned) tables using the mooncake.create_table procedure.
Procedure Signature
| Parameter | Type | Default | Description |
|---|---|---|---|
dst |
text |
(Required) | Name of the destination columnstore mirror table to create (supports schema.table, defaults to public if unqualified). |
src |
text |
(Required) | Name of the source PostgreSQL rowstore or partitioned table to replicate from (supports schema.table). |
src_uri |
text |
NULL |
Connection URI (postgresql://user:pass@host:port/dbname) of a remote PostgreSQL instance when replicating from an external database. When NULL, replicates from the current local database. |
table_config |
json |
NULL |
Optional JSON object configuring Moonlink storage and ingestion settings (such as write_buffer_size or initial data copy behavior). |
src_uri (Not source_uri)Earlier upstream documentation contained a typo showing source_uri => 'postgresql://...'. The actual parameter name in pg_mooncake’s SQL definition (src/functions.rs) is src_uri. Always use src_uri => 'postgresql://...' when calling mooncake.create_table with named arguments.
1. Mirror a Table in the Same Database
When src_uri is omitted (or NULL), pg_mooncake replicates directly from src in the current database:
What happens when CALL mooncake.create_table('orders_analytics', 'orders') runs:
pg_mooncakeinspects the columns ofordersand createsCREATE TABLE orders_analytics (...) USING mooncake.- If
ordersdoes not have a primary key,pg_mooncakerunsALTER TABLE orders REPLICA IDENTITY FULL(and inv0.3.0, automatically appliesREPLICA IDENTITY FULLto all existing leaf partitions ifordersis partitioned). moonlinkcreates a logical replication slot (pgoutput), copies all existing rows fromorders, and begins streaming ongoingINSERT,UPDATE, andDELETEchanges in real time.
2. Mirror a Table from a Remote PostgreSQL Instance (src_uri)
You can run pg_mooncake on a dedicated analytical PostgreSQL node and mirror tables from a remote production PostgreSQL database (including self-hosted PostgreSQL, AWS RDS, Aurora, Supabase, or Neon):
Requirements on the remote source database:
wal_level = logicalmust be enabled.- The user in
src_urimust haveREPLICATIONprivileges andSELECTpermission onsrc. - If
srchas no primary key,REPLICA IDENTITY FULLmust be set onsrc.
3. Mirror a Partitioned Table
mooncake.create_table supports declarative PostgreSQL partitioned tables (PARTITION BY RANGE, LIST, or HASH). Specify the root partitioned table as src:
create_tableIn pg_mooncake 0.3.0, mooncake.create_table automatically sets REPLICA IDENTITY FULL on all partitions that exist at the time the mirror is created. If you attach or create a new partition later (CREATE TABLE events_2026_12 PARTITION OF events ...) and the partitioned table does not have a primary key, run ALTER TABLE events_2026_12 REPLICA IDENTITY FULL; before executing UPDATE or DELETE statements on that partition.
4. Advanced table_config Options
You can pass a JSON object via table_config to customize Moonlink’s per-table behavior (TableConfig in moonlink_backend/src/table_config.rs), including append-only optimization, background compaction flags, and custom filesystem / S3 / GCS storage backends for Iceberg data and WAL:
| JSON Path | Type | Default | Description |
|---|---|---|---|
mooncake.append_only |
bool |
false (or true if no PK/replica identity) |
When true, treats the table as append-only and skips building primary-key hash indexes. |
mooncake.skip_index_merge |
bool |
false |
When true, disables background Puffin hash-index LSM compaction. |
mooncake.skip_data_compaction |
bool |
false |
When true, disables background Parquet data file compaction. |
iceberg.storage_config |
object |
{"fs": {"root_directory": "$PGDATA/pg_mooncake"}} |
Storage backend (fs, s3, or gcs) for Apache Iceberg v2 metadata and Parquet data files. |
wal.storage_config |
object |
{"fs": {"root_directory": "$PGDATA/pg_mooncake"}} |
Storage backend (fs, s3, or gcs) for Moonlink’s internal WAL segments. |
5. Dropping a Columnstore Mirror Table
To remove a columnstore mirror table and automatically clean up its Moonlink metadata and logical replication slot, simply run DROP TABLE: