PostgreSQL

Articles

Vacuum

vacuum
  for each relation
    vacuum_rel
      full_vacuum_rel (if vacuum full)
        scan_heap
          pg_rusage_init(&ru0);
          ereport(vacuuming tableX);
          vacuum the table
          ereport(all information + pg_rusage_show(&ru0))
        for each index
          vacuum_index
            pg_rusage_init(&ru0);
            clean the index
            ereport(all information + pg_rusage_show(&ru0))
            check for tuple count mismatch
        vacuum_heap or repair_frag
        update free space map
        update statistics in pg_class
        report results to the stat collector
      lazy_vacuum_rel (if vacuum)
        open the indexes
        lazy_scan_heap
          pg_rusage_init(&ru0);
          ereport(vacuuming tableX);
          for each index
            lazy_vacuum_index
              pg_rusage_init(&ru0);
              clean the index
              ereport(all information + pg_rusage_show(&ru0))
          lazy_vacuum_heap
          ereport(all information + pg_rusage_show(&ru0))
        close the indexes
        optionnaly truncate the relation
        update free space map
        update statistics in pg_class
        report results to the stat collector
    vacuum_rel(toast table if any)
      same as above
    analyze_rel (if analyze)

Requêtes intéressantes

Nombre de jours par mois (Gavin)

select to_char(month, 'FMMonth YYYY') as month,
       date_part('day',month + '1 month - 1 day'::interval) as lastday
from (
    select
        (date_part('year', current_date) || '-' || m || '-01')::date as month
    from generate_series(1, 12) m
    ) months;