Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| cookbook:trouver_taille_table_index_tuples [2008/10/14 17:55] – ioguix | cookbook:trouver_taille_table_index_tuples [2008/10/15 16:54] (Version actuelle) – effacée ioguix | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Trouver facilement la taille d'une table, de ses index et son nombre de tuples ====== | ||
| - | On a besoin parfois d' | ||
| - | |||
| - | Tout cela nous permet de réaliser une vue fort sympathique pour l' | ||
| - | |||
| - | <code sql>drop view vue_stats; | ||
| - | |||
| - | create view vue_stats as | ||
| - | SELECT | ||
| - | c.relname as nom, | ||
| - | c.reltuples:: | ||
| - | pg_total_relation_size(c.relname) as volume_total, | ||
| - | pg_relation_size(c.relname) as volume_donnees, | ||
| - | pg_total_relation_size(c.relname)-pg_relation_size(c.relname) as volume_index | ||
| - | FROM pg_catalog.pg_class c | ||
| - | JOIN pg_catalog.pg_roles r ON r.oid = c.relowner | ||
| - | LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace | ||
| - | WHERE c.relkind = ' | ||
| - | AND n.nspname NOT IN (' | ||
| - | AND pg_catalog.pg_table_is_visible(c.oid) | ||
| - | ORDER BY 1, | ||
| - | |||
| - | Merci à klando (Cédric) pour cet ajout, fort sympathique: | ||
| - | |||
| - | <code sql>drop view vue_stats_pretty ; | ||
| - | |||
| - | create view vue_stats_pretty as | ||
| - | SELECT | ||
| - | nom, | ||
| - | tuples, | ||
| - | pg_size_pretty(volume_total) as volume_total, | ||
| - | pg_size_pretty(volume_donnees) as volume_donnees, | ||
| - | pg_size_pretty(volume_index) as volume_index | ||
| - | FROM vue_stats;</ | ||
| - | |||
| - | Enjoy! | ||
| - | |||
| - | -- \\ | ||
| - | Jean-Paul ARGUDO\\ | ||
| - | http:// | ||