Skip to content

Instantly share code, notes, and snippets.

View sfriquet's full-sized avatar

Sylvain Friquet sfriquet

View GitHub Profile
WITH constants AS (
-- define some constants for sizes of things
-- for reference down the query and easy maintenance
SELECT current_setting('block_size')::numeric AS bs, 23 AS hdr, 8 AS ma
),
no_stats AS (
-- screen out table who have attributes
-- which dont have stats, such as JSON
SELECT table_schema, table_name,
n_live_tup::numeric as est_rows,
@sfriquet
sfriquet / citus_cheatsheet.sql
Last active October 25, 2023 09:58
Citus Cheatsheet
-- Set number of shard
ALTER DATABASE citus SET citus.shard_count = 64;
-- Explain across all shards
SET citus.explain_all_tasks TO true;
-- Size of all distributed tables excluding indexes but including TOAST, free space map, and visibility map
SELECT logicalrelid::text tablename, pg_size_pretty(citus_table_size(logicalrelid::text)) size FROM pg_dist_partition group by tablename;
-- Size of all distributed tables including all indexes and TOAST data