User Tools

Site Tools


sysadmin:postgresql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
sysadmin:postgresql [2014/11/05 09:40] – tabelle vuote ferodasysadmin:postgresql [2014/11/25 09:38] – [Occupazione disco per tabelle] - tolto LIMIT 20 feroda
Line 1: Line 1:
-====== Basi di configurazione ======+====== PostgreSQL - Basi di configurazione ======
  
   - eseguire ''/usr/local/sbin/postgresql_shmall_shmmax.sh >> /etc/sysctl.conf''   - eseguire ''/usr/local/sbin/postgresql_shmall_shmmax.sh >> /etc/sysctl.conf''
Line 10: Line 10:
   * Performance Tuning: http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server   * Performance Tuning: http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server
   * Ottimo articolo segnalato da AndreaF http://www.revsys.com/writings/postgresql-performance.html   * Ottimo articolo segnalato da AndreaF http://www.revsys.com/writings/postgresql-performance.html
 +  * Index Maintenance https://wiki.postgresql.org/wiki/Index_Maintenance
  
  
 ===== Query utili su indici e loro utilizzo  ===== ===== Query utili su indici e loro utilizzo  =====
 +
 +Indici presenti
 +
 +    [0] SELECT * FROM pg_indexes;
  
 ==== Ricerca indici doppi ==== ==== Ricerca indici doppi ====
Line 32: Line 37:
     SELECT relid,schemaname,relname,idx_scan,idx_tup_read,idx_tup_fetch FROM pg_stat_all_indexes ORDER BY idx_scan desc;     SELECT relid,schemaname,relname,idx_scan,idx_tup_read,idx_tup_fetch FROM pg_stat_all_indexes ORDER BY idx_scan desc;
  
-Indici presenti 
- 
-    SELECT * FROM pg_indexes; 
-     
 Filtra solo quelli utilizzati almeno una volta Filtra solo quelli utilizzati almeno una volta
          
Line 64: Line 65:
 ===== Esecuzione query al ... ===== ===== Esecuzione query al ... =====
  
 +    * [0] = ... indici totali
     * [1] = ... indici doppi     * [1] = ... indici doppi
     * [2] = ... indici non usati     * [2] = ... indici non usati
Line 69: Line 71:
     * [4] = ... indici usati ma non efficaci     * [4] = ... indici usati ma non efficaci
     * [5] = ... tabelle vuote     * [5] = ... tabelle vuote
 +
 +====== Occupazione disco per tabelle ======
 +
 +Restituisce un elenco ordinato in modo discendente di:
 +
 +  * schema (aka "directory")
 +  * tabella
 +  * occupazione su disco
 +  * occupazione totale compresi indici
 +  * numero stimato di righe
 +
 +    SELECT table_schema, table_name, 
 +      (size/1024)::varchar || ' kB' as size,
 +      (total_size/1024)::varchar || ' kB' as total_size,
 +      (CASE WHEN pg_class.reltuples > 0 THEN
 +          basic_infos.size/(8192*relpages*reltuples)
 +          ELSE 0
 +          END
 +      )::bigint AS estimated_row_count
 +      FROM (
 +        SELECT table_schema, table_name, 
 +            pg_relation_size('"' || table_schema || '"."' || table_name || '"') as size,
 +            pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') as total_size
 +            FROM information_schema.tables 
 +            WHERE table_schema NOT IN ('information_schema', 'pg_catalog'
 +        ORDER BY size DESC, total_size DESC
 +    ) AS basic_infos 
 +        JOIN pg_class
 +        ON ('"' || table_schema || '"."' || table_name || '"')::regclass = pg_class.oid
 +
 +Questa query funziona su PostgreSQL 8.4. E credo valga anche per PostgreSQL >= 9.0. Potrebbe essere interessante pubblicarla da qualche parte.
 +
 +
 +====== Informazioni varie... ======
  
 ===== Query comode x debug ===== ===== Query comode x debug =====