Skip to content

Instantly share code, notes, and snippets.

@odony
Last active May 12, 2018 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odony/11e146371e25d74561e15c0fa399c04d to your computer and use it in GitHub Desktop.
Save odony/11e146371e25d74561e15c0fa399c04d to your computer and use it in GitHub Desktop.
Estimates for FK numbers in 11.0 runbot database (-all)
321069-11-0-703290-all=# SELECT count(*) FROM information_schema.columns WHERE table_schema not in ('information_schema', 'pg_catalog');
count
-------
10027
(1 row)
321069-11-0-703290-all=> select count(*) from information_schema.key_column_usage cons where position_in_unique_constraint is not null;
count
-------
3440
(1 row)
321069-11-0-703290-all=> select count(*) from pg_indexes where schemaname not in ('information_schema', 'pg_catalog') and indexdef not ilike '%UNIQUE INDEX%' and indexdef ilike '%id)';
count
-------
625
(1 row)
321069-11-0-703290-all=> SELECT pg_size_pretty(sum(total_bytes)) AS total
, pg_size_pretty(sum(index_bytes)) AS INDEX
, pg_size_pretty(sum(toast_bytes)) AS toast
, pg_size_pretty(sum(table_bytes)) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
, pg_total_relation_size(reltoastrelid) AS toast_bytes
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE relkind = 'r' and nspname not in ('information_schema', 'pg_catalog')
) a
) a;
total | index | toast | table
--------+-------+-------+-------
164 MB | 73 MB | 15 MB | 76 MB
(1 row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment