How to Clickhouse SaaS pricing in PostgreSQL

Galaxy Glossary

How can I pull ClickHouse Cloud pricing directly into Postgres for cost analysis?

Fetches and compares ClickHouse Cloud price tiers directly from Postgres so teams can budget storage and compute.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Table of Contents

What is the CLICKHOUSE_SAAS_PRICING() function?

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.

Why query pricing from Postgres?

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.

How do I enable the extension?

Install an HTTP FDW such as postgres_fdw_http, then create the foreign table clickhouse_saas_pricing pointing at https://api.clickhouse.cloud/pricing.

What is the exact syntax?

Use the SELECT-LATERAL form or the convenience SQL function documented below.

Syntax breakdown

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 code

How do I estimate storage costs for an Orders table?

Multiply the per-GB price returned by the function with the table size from pg_total_relation_size.Join on region and currency as needed.

Example: monthly cost of Orders & OrderItems

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;

Best practices

Refresh pricing nightly

Create a materialized view that refreshes once per day to avoid API rate limits.

Store historical prices

Insert each nightly snapshot into a clickhouse_pricing_history table to analyze trends.

Common mistakes

1.Forgetting currency conversion

ClickHouse returns prices in USD by default. Convert to local currency when presenting to finance.

2. Hard-coding region

Teams often assume us-east. Always parameterize region to avoid under-budgeting EU clusters.

See also

pg_stat_user_tables for data sizes
pg_partman for partitioning to reduce hot data costs

.

Why How to Clickhouse SaaS pricing in PostgreSQL is important

How to Clickhouse SaaS pricing in PostgreSQL Example Usage


-- Estimate monthly ClickHouse Cloud bill for all customer data
WITH usage AS (
  SELECT SUM(pg_total_relation_size(oid))::NUMERIC/1e9 AS total_gb
  FROM   pg_class
  WHERE  relname IN ('customers','orders','orderitems','products')
), price AS (
  SELECT price_per_gb
  FROM   CLICKHOUSE_SAAS_PRICING('us-east','on-demand','USD')
  WHERE  service = 'storage')
SELECT ROUND(u.total_gb*p.price_per_gb,2) AS est_monthly_usd
FROM   usage u, price p;

How to Clickhouse SaaS pricing in PostgreSQL Syntax


SELECT *
FROM CLICKHOUSE_SAAS_PRICING(
    region TEXT DEFAULT 'us-east',
    commitment TEXT DEFAULT 'on-demand',
    currency TEXT DEFAULT 'USD'
);
-- Parameters
-- region      : 'us-east' | 'us-west' | 'eu-west' | ...
-- commitment  : 'on-demand' | '1-year'
-- currency    : 'USD' | 'EUR' | 'GBP'

-- Example pulling metered compute price only
SELECT *
FROM CLICKHOUSE_SAAS_PRICING('eu-west', '1-year', 'EUR')
WHERE service = 'compute';

Common Mistakes

Frequently Asked Questions (FAQs)

Does the function require superuser rights?

No. It works under any role with USAGE on the HTTP extension and SELECT on the foreign table.

How often does ClickHouse update public prices?

Prices rarely change, but poll once per day to stay accurate and satisfy caching headers.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.