How to Calculate Snowflake SaaS Pricing in PostgreSQL

Galaxy Glossary

How do I calculate Snowflake SaaS pricing with SQL?

Use SQL to capture Snowflake usage data and calculate compute, storage, and transfer costs directly inside PostgreSQL.

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 components make up Snowflake SaaS pricing?

Snowflake bills on three levers: compute credits (warehouses & tasks), storage (compressed bytes stored), and data transfer (egress to the internet or another region). Understanding each lever helps you build cost models that are easy to query and forecast.

How do I store Snowflake usage data in PostgreSQL?

Export the views METERING_HISTORY and STORAGE_USAGE_HISTORY from Snowflake to CSV or Snowpipe-into-S3, then COPY the files into a PostgreSQL table named snowflake_usage. This table will drive every cost query you write.

CREATE TABLE example

CREATE TABLE snowflake_usage (
usage_date date,
resource_type text, -- COMPUTE, STORAGE, TRANSFER
credits_used numeric,
bytes bigint,
region text,
comment text
);

How do I calculate compute costs?

Multiply credits_used by your contracted credit rate. Storing that rate in a config table lets you change pricing without rewriting queries.

SELECT usage_date,
SUM(credits_used * cr.credit_rate_usd) AS compute_cost_usd
FROM snowflake_usage su
JOIN cost_rates cr ON cr.resource_type = 'COMPUTE'
WHERE resource_type = 'COMPUTE'
GROUP BY usage_date
ORDER BY usage_date;

How can I estimate storage costs?

Snowflake charges per average compressed byte-hours. Convert bytes to GB-months, then multiply by the storage rate.

SELECT date_trunc('month', usage_date) AS month,
ROUND(SUM(bytes) / 1024^3 / 24 / 30, 2) AS avg_gb,
ROUND(SUM(bytes) / 1024^3 / 24 / 30 * cr.credit_rate_usd, 2) AS storage_cost
FROM snowflake_usage su
JOIN cost_rates cr ON cr.resource_type = 'STORAGE'
WHERE resource_type = 'STORAGE'
GROUP BY month;

How do I break down cost by customer or workload?

Tag Snowflake warehouses with the same customer_id as your Customers table. After ingest, join the tag to customer metadata.

SELECT c.name,
SUM(su.credits_used * cr.credit_rate_usd) AS total_cost
FROM snowflake_usage su
JOIN customers c ON c.id = su.comment::int -- tag holds customer_id
JOIN cost_rates cr ON cr.resource_type = su.resource_type
GROUP BY c.name
ORDER BY total_cost DESC;

Best practices for controlling Snowflake spend

Use auto-resume/auto-suspend on warehouses, schedule warehouse sizes by workload, and archive infrequently used tables to cheaper storage tiers. Monitor daily costs with the queries above and automate Slack alerts when spend spikes.

Why How to Calculate Snowflake SaaS Pricing in PostgreSQL is important

How to Calculate Snowflake SaaS Pricing in PostgreSQL Example Usage


-- Attribute Snowflake compute cost to each ecommerce customer by month
WITH monthly_compute AS (
  SELECT  o.customer_id,
          date_trunc('month', su.usage_date) AS month,
          SUM(su.credits_used * cr.credit_rate_usd) AS compute_cost
  FROM    snowflake_usage su
  JOIN    orders        o  ON o.id = su.comment::int
  JOIN    cost_rates    cr ON cr.resource_type = 'COMPUTE'
  WHERE   su.resource_type = 'COMPUTE'
  GROUP   BY o.customer_id, month)
SELECT c.name, month, compute_cost
FROM   monthly_compute mc
JOIN   customers c ON c.id = mc.customer_id
ORDER  BY month, compute_cost DESC;

How to Calculate Snowflake SaaS Pricing in PostgreSQL Syntax


calculate_snowflake_cost(credits_used NUMERIC, storage_gb NUMERIC, transfer_gb NUMERIC [, credit_rate NUMERIC DEFAULT 2.00, storage_rate NUMERIC DEFAULT 0.023, transfer_rate NUMERIC DEFAULT 0.020]) RETURNS NUMERIC

-- Example in ecommerce context
-- Estimate monthly cost for the reporting warehouse powering order dashboards
SELECT calculate_snowflake_cost(
         credits_used => 450,              -- warehouse credits
         storage_gb   => 80,               -- product & order tables
         transfer_gb  => 12,               -- external data shares
         credit_rate  => 2.00,
         storage_rate => 0.023,
         transfer_rate=> 0.020) AS est_cost_usd;

Common Mistakes

Frequently Asked Questions (FAQs)

What is a Snowflake credit?

A credit is a billing unit representing one hour of compute on a Medium warehouse. Larger warehouses consume credits faster; smaller warehouses consume them more slowly.

How often should I export usage data?

Daily exports keep cost dashboards current without overwhelming PostgreSQL. Schedule exports at off-peak hours to minimize load.

Can I forecast next month's bill?

Yes. Use a 30-day moving average of daily costs and project it forward, factoring in any planned warehouse size changes.

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.