Fetches and compares ClickHouse Cloud price tiers directly from Postgres so teams can budget storage and compute.
CLICKHOUSE_SAAS_PRICING() is a wrapper around the public ClickHouse Cloud pricing API, exposed to Postgres through an HTTP extension or FDW.It returns current pricing by region, commitment level, and currency.
Keeping pricing data in SQL lets engineers join costs to existing usage metrics, run “what-if” scenarios, and present budgets in familiar dashboards without switching tools.
Install an HTTP FDW such as postgres_fdw_http
, then create the foreign table clickhouse_saas_pricing
pointing at https://api.clickhouse.cloud/pricing
.
Use the SELECT-LATERAL form or the convenience SQL function documented below.
SELECT * FROM CLICKHOUSE_SAAS_PRICING(region TEXT DEFAULT 'us-east', commitment TEXT DEFAULT 'on-demand', currency TEXT DEFAULT 'USD');
region
– pricing region (e.g., 'us-east'
, 'eu-west'
)commitment
– 'on-demand'
or '1-year'
currency
– three-letter ISO codeMultiply the per-GB price returned by the function with the table size from pg_total_relation_size
.Join on region and currency as needed.
The query below fetches the on-demand price and calculates the monthly storage cost for the Orders
and OrderItems
tables.
WITH ch_price AS (
SELECT price_per_gb
FROM CLICKHOUSE_SAAS_PRICING('us-east', 'on-demand', 'USD')
WHERE service = 'storage')
SELECT relname AS table,
pg_size_pretty(size) AS current_size,
ROUND(size/1e9*cp.price_per_gb, 2) AS usd_monthly
FROM (
SELECT c.relname,
pg_total_relation_size(c.oid)::NUMERIC AS size
FROM pg_class c
WHERE relname IN ('orders','orderitems')) t
CROSS JOIN ch_price cp;
Create a materialized view that refreshes once per day to avoid API rate limits.
Insert each nightly snapshot into a clickhouse_pricing_history
table to analyze trends.
ClickHouse returns prices in USD by default. Convert to local currency when presenting to finance.
Teams often assume us-east
. Always parameterize region to avoid under-budgeting EU clusters.
• pg_stat_user_tables
for data sizes
• pg_partman
for partitioning to reduce hot data costs
.
No. It works under any role with USAGE on the HTTP extension and SELECT on the foreign table.
Prices rarely change, but poll once per day to stay accurate and satisfy caching headers.