This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- opzionale: assicurati che id sia NOT NULL | |
| ALTER TABLE public.mia_tabella | |
| ALTER COLUMN id SET NOT NULL; | |
| -- aggiungi l'identity (auto-increment) | |
| ALTER TABLE public.mia_tabella | |
| ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY; | |
| SELECT setval( | |
| pg_get_serial_sequence('mia_tabella', 'id'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 1) Aggiorna le statistiche di tutte le tabelle del database corrente | |
| ANALYZE; | |
| -- 2) Leggi le stime aggiornate per tutte le tabelle utente | |
| SELECT | |
| schemaname AS schema_name, | |
| relname AS table_name, | |
| n_live_tup AS row_count_estimated | |
| FROM pg_stat_user_tables | |
| ORDER BY schemaname, relname; |