Skip to content

Instantly share code, notes, and snippets.

@dcube9
Created February 6, 2026 12:13
Show Gist options
  • Select an option

  • Save dcube9/bfe748940ca1180022143b8852352f5b to your computer and use it in GitHub Desktop.

Select an option

Save dcube9/bfe748940ca1180022143b8852352f5b to your computer and use it in GitHub Desktop.
POSTGRESQL - Conta i record e l'occupazione di tutte le tabelle di un database
-- 1) Aggiorna le statistiche di tutte le tabelle del database corrente
ANALYZE;
-- 2) Leggi le stime aggiornate per tutte le tabelle utente,
-- includendo la dimensione totale (tabella + indici + TOAST)
SELECT
s.schemaname AS schema_name,
s.relname AS table_name,
s.n_live_tup AS row_count_estimated,
pg_total_relation_size(c.oid) AS table_size_bytes,
pg_size_pretty(pg_total_relation_size(c.oid)) AS table_size_human
FROM pg_stat_user_tables AS s
JOIN pg_class AS c
ON c.oid = s.relid
ORDER BY s.schemaname, s.relname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment