Follow these steps to set up a real-time analytics mirror of a Postgres table using pg_mooncake.
- Create the extension:
CREATE EXTENSION pg_mooncake CASCADE;
- Create a source table:
CREATE TABLE trades(
id bigint PRIMARY KEY,
symbol text,
time timestamp,
price real
);
- Create the Iceberg columnstore mirror:
Use
mooncake.create_table to create a mirror that stays in sync with the source table:
CALL mooncake.create_table('trades_iceberg', 'trades');
- Verify synchronization:
Insert data into the source table and query the mirror:
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);
SELECT avg(price) FROM trades_iceberg WHERE symbol = 'AMZN';
CREATE EXTENSION pg_mooncake CASCADE;
CREATE TABLE trades(
id bigint PRIMARY KEY,
symbol text,
time timestamp,
price real
);
CALL mooncake.create_table('trades_iceberg', '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);
SELECT avg(price) FROM trades_iceberg WHERE symbol = 'AMZN';