From: Guillaume Lelarge Date: Thu, 17 Jan 2013 13:32:11 +0000 (+0100) Subject: Two new reports: VACUUM/ANALYZE per table X-Git-Tag: v3.2~60^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6565b10a9377a3643e20f60903564b0f4f4fe28c;p=pgbadger Two new reports: VACUUM/ANALYZE per table --- diff --git a/pgbadger b/pgbadger index ebdc58b..0a4ea7e 100755 --- a/pgbadger +++ b/pgbadger @@ -22,6 +22,7 @@ # log_disconnections = on # log_lock_waits = on # log_temp_files = 0 +# log_autovacuum_min_duration = 0 #------------------------------------------------------------------------------ use vars qw($VERSION); @@ -89,6 +90,7 @@ my $disable_connection = 0; my $disable_lock = 0; my $disable_temporary = 0; my $disable_checkpoint = 0; +my $disable_autovacuum = 0; my $avg_minutes = 5; my $last_parsed = ''; my $report_title = 'PgBadger: PostgreSQL log analyzer'; @@ -169,6 +171,7 @@ my $result = GetOptions( "disable-lock!" => \$disable_lock, "disable-temporary!" => \$disable_temporary, "disable-checkpoint!" => \$disable_checkpoint, + "disable-autovacuum!" => \$disable_autovacuum, "enable-log_duration!" => \$enable_log_duration, "enable-log_min_duration!" => \$enable_log_min_duration, "client=s" => \@dbclient2, # Backward compatibility @@ -531,6 +534,8 @@ my %application_info = (); my %session_info = (); my %conn_received = (); my %checkpoint_info = (); +my %autovacuum_info = (); +my %autoanalyze_info = (); my @graph_values = (); my %cur_info = (); my $nlines = 0; @@ -1033,6 +1038,7 @@ Options: --disable-lock : do not generate lock report. --disable-temporary : do not generate temporary report. --disable-checkpoint : do not generate checkpoint report. + --disable-autovacuum : do not generate autovacuum report. --enable-log_duration : force pgBadger to use log_duration even if log_min_duration_statement format is autodetected. --enable-log_min_duration: force pgBadger to use log_min_duration even if @@ -2115,8 +2121,19 @@ sub dump_as_html my $db_count = scalar keys %database_info; print $fh qq{
  • Total number of databases: $db_count
  • +}; } -} + if ($autovacuum_info{count}) { + print $fh qq{ +
  • Total number of automatic vacuums: $autovacuum_info{count}
  • +}; + } + if ($autoanalyze_info{count}) { + print $fh qq{ +
  • Total number of automatic analyzes: $autoanalyze_info{count}
  • +}; + } + print $fh qq{ @@ -2593,6 +2610,59 @@ qq{Wrote buffersAddedRemovedRecycledWrit $d1 = ''; $d2 = ''; } + + # VACUUM stats per table + if ($autovacuum_info{count} > 0) { + print $fh qq{ +

    VACUUMs by table ^

    + +
    + + + + + + + }; + my $total_count = 0; + my $total_idxscan = 0; + foreach my $t (sort keys %{$autovacuum_info{tables}}) { + print $fh "\n"; + $total_count += $autovacuum_info{tables}{$t}{vacuums}; + $total_idxscan += $autovacuum_info{tables}{$t}{idxscans}; + } + print $fh "\n"; + print $fh "
    TableVACUUMsIndex scans
    ", $t, + "", $autovacuum_info{tables}{$t}{vacuums}, + "", $autovacuum_info{tables}{$t}{idxscans}, + "
    Total", $total_count, + "", $total_idxscan, "
    \n"; + } + + # ANALYZE stats per table + if ($autoanalyze_info{count} > 0) { + print $fh qq{ +

    ANALYZEs by table ^

    + +
    + + + + + + }; + my $total_count = 0; + my $total_idxscan = 0; + foreach my $t (sort keys %{$autoanalyze_info{tables}}) { + print $fh "\n"; + $total_count += $autoanalyze_info{tables}{$t}{analyzes}; + } + print $fh "\n"; + print $fh "
    TableANALYZEs
    ", $t, + "", $autoanalyze_info{tables}{$t}{analyzes}, + "
    Total", $total_count, + "
    \n"; + } } } @@ -4196,6 +4266,31 @@ sub parse_query return; } + # Store autovacuum information + if ( + ($prefix_vars{'t_loglevel'} eq 'LOG') + && ($prefix_vars{'t_query'} =~ +/automatic vacuum of table "([^\s]+)": index scans: (\d+)/ + ) + ) + { + return if ($disable_autovacuum); + $autovacuum_info{count}++; + $autovacuum_info{tables}{$1}{vacuums} += 1; + $autovacuum_info{tables}{$1}{idxscans} += $2; + } + if ( + ($prefix_vars{'t_loglevel'} eq 'LOG') + && ($prefix_vars{'t_query'} =~ +/automatic analyze of table "([^\s]+)"/ + ) + ) + { + return if ($disable_autovacuum); + $autoanalyze_info{count}++; + $autoanalyze_info{tables}{$1}{analyzes} += 1; + } + # Store checkpoint information if ( ($prefix_vars{'t_loglevel'} eq 'LOG')