diff --git a/README b/README index 3a2c4740..1afb362c 100644 --- a/README +++ b/README @@ -73,6 +73,8 @@ SYNOPSIS -P | --no-prettify : disable SQL queries prettify formatter. -q | --quiet : don't print anything to stdout, not even a progress bar. + -Q | --query-numbering : add numbering of queries to the output when using + options --dump-all-queries or --normalized-only. -r | --remote-host ip : set the host where to execute the cat command on remote logfile to parse locally the file. -R | --retention N : number of weeks to keep in incremental mode. Default diff --git a/README.md b/README.md index 1456606b..7d1719bd 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,8 @@ Options: -P | --no-prettify : disable SQL queries prettify formatter. -q | --quiet : don't print anything to stdout, not even a progress bar. + -Q | --query-numbering : add numbering of queries to the output when using + options --dump-all-queries or --normalized-only. -r | --remote-host ip : set the host where to execute the cat command on remote logfile to parse locally the file. -R | --retention N : number of weeks to keep in incremental mode. Default diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index f390bb22..28531159 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -75,6 +75,8 @@ Options: -P | --no-prettify : disable SQL queries prettify formatter. -q | --quiet : don't print anything to stdout, not even a progress bar. + -Q | --query-numbering : add numbering of queries to the output when using + options --dump-all-queries or --normalized-only. -r | --remote-host ip : set the host where to execute the cat command on remote logfile to parse locally the file. -R | --retention N : number of weeks to keep in incremental mode. Default diff --git a/pgbadger b/pgbadger index f3b37969..92447961 100755 --- a/pgbadger +++ b/pgbadger @@ -360,6 +360,7 @@ my $noexplain = 0; my $log_command = ''; my $wide_char = 0; my $noweekreport = 0; +my $query_numbering = 0; my $NUMPROGRESS = 10; my @DIMENSIONS = (800, 300); @@ -476,6 +477,7 @@ my $result = GetOptions( "p|prefix=s" => \$log_line_prefix, "P|no-prettify!" => \$noprettify, "q|quiet!" => \$quiet, + "Q|query-numbering!" => \$query_numbering, "r|remote-host=s" => \$remote_host, 'R|retention=i' => \$retention, "s|sample=i" => \$sample, @@ -2043,6 +2045,8 @@ Options: -P | --no-prettify : disable SQL queries prettify formatter. -q | --quiet : don't print anything to stdout, not even a progress bar. + -Q | --query-numbering : add numbering of queries to the output when using + options --dump-all-queries or --normalized-only. -r | --remote-host ip : set the host where to execute the cat command on remote logfile to parse locally the file. -R | --retention N : number of weeks to keep in incremental mode. Default @@ -5055,11 +5059,18 @@ Log start from $t_log_min to $t_log_max }; # Dump normalized queries only if requested - if ($dump_normalized_only) { - print $fh "Count\t\tQuery\n"; - print $fh '-'x70,"\n"; + if ($dump_normalized_only) + { + if (!$query_numbering) { + print $fh "Count\t\tQuery\n"; + print $fh '-'x70,"\n"; + } else { + print $fh "#Num\tCount\t\tQuery\n"; + print $fh '-'x80,"\n"; + } foreach my $q (sort { $normalyzed_info{$curdb}{$b}{count} <=> $normalyzed_info{$curdb}{$a}{count} } keys %{$normalyzed_info{$curdb}}) { - print $fh "$normalyzed_info{$curdb}{$q}{count} $q\n"; + print $fh $query_numbering++, "\t" if ($query_numbering); + print $fh "$normalyzed_info{$curdb}{$q}{count}\t$q\n"; } print $fh "\n\n"; print $fh "Report generated by pgBadger $VERSION ($project_url).\n"; @@ -15640,6 +15651,7 @@ sub store_queries } } return if ($cur_info{$t_pid}{query} =~ /^parameters:/); + print $fh "# Query #", $query_numbering++, "\n" if ($query_numbering); print $fh "$cur_info{$t_pid}{query}\n"; $overall_stat{'queries_number'}++; return 1;