my $rebuild = 0;
my $week_start_monday = 0;
my $use_sessionid_as_pid = 0;
+my $dump_normalized_only = 0;
my $NUMPROGRESS = 10000;
my @DIMENSIONS = (800, 300);
'rebuild!' => \$rebuild,
'pgbouncer-only!' => \$pgbouncer_only,
'start-monday!' => \$week_start_monday,
+ 'normalized-only!' => \$dump_normalized_only,
);
die "FATAL: use pgbadger --help\n" if (not $result);
}
}
+# Force text output with normalized query list only
+# and disable incremental report
+if ($dump_normalized_only) {
+ $extension = 'txt';
+ $incremental = 0;
+ $report_title = 'Normalized query report' if (!$report_title);
+}
+
# Set default filename of the output file
$outfile ||= 'out.' . $extension;
&logmsg('DEBUG', "Output '$extension' reports will be written to $outfile");
--pgbouncer-only : only show pgbouncer related menu in the header.
--start-monday : in incremental mode, calendar's weeks start on
sunday. Use this otpion to start on monday.
+ --normalized-only : only dump all normalized query to out.txt
pgBadger is able to parse a remote log file using a passwordless ssh connection.
Use the -r or --remote-host to set the host ip address or hostname. There's also
Log file: $logfile_str
Parsed $fmt_nlines log entries in $total_time
Log start from $overall_stat{'first_log_ts'} to $overall_stat{'last_log_ts'}
+
};
+ # Dump normalized queries only if requested
+ if ($dump_normalized_only) {
+ print $fh "Count\t\tQuery\n";
+ print $fh '-'x70,"\n";
+ foreach my $q (sort { $normalyzed_info{$b}{count} <=> $normalyzed_info{$a}{count} } keys %normalyzed_info) {
+ print $fh "$normalyzed_info{$q}{count} $q\n";
+ }
+ print $fh "\n\n";
+ print $fh "Report generated by pgBadger $VERSION ($project_url).\n";
+ return;
+ }
+
# Overall statistics
my $fmt_unique = &comma_numbers(scalar keys %normalyzed_info);
my $fmt_queries = &comma_numbers($overall_stat{'queries_number'});
$cur_info{$t_pid}{year} = $prefix_vars{'t_year'} if (!$cur_info{$t_pid}{year});
$cur_info{$t_pid}{month} = $prefix_vars{'t_month'} if (!$cur_info{$t_pid}{month});
$cur_info{$t_pid}{day} = $prefix_vars{'t_day'} if (!$cur_info{$t_pid}{day});
- $cur_info{$t_pid}{hour} = $prefix_vars{'t_hour'} if (($cur_info{$t_pid}{hour} eq ''));
- $cur_info{$t_pid}{min} = $prefix_vars{'t_min'} if (!$cur_info{$t_pid}{min} eq '');
- $cur_info{$t_pid}{sec} = $prefix_vars{'t_sec'} if (!$cur_info{$t_pid}{sec} eq '');
+ $cur_info{$t_pid}{hour} = $prefix_vars{'t_hour'} if (!exists $cur_info{$t_pid}{sec} || ($cur_info{$t_pid}{hour} eq ''));
+ $cur_info{$t_pid}{min} = $prefix_vars{'t_min'} if (!exists $cur_info{$t_pid}{sec} || ($cur_info{$t_pid}{min} eq ''));
+ $cur_info{$t_pid}{sec} = $prefix_vars{'t_sec'} if (!exists $cur_info{$t_pid}{sec} || ($cur_info{$t_pid}{sec} eq ''));
$cur_info{$t_pid}{timestamp} = $prefix_vars{'t_timestamp'} if (!$cur_info{$t_pid}{timestamp});
$cur_info{$t_pid}{ident} = $prefix_vars{'t_ident'} if (!$cur_info{$t_pid}{ident});
$cur_info{$t_pid}{query} = $prefix_vars{'t_query'} if (!$cur_info{$t_pid}{query});
return 1 if (!$cur_info{$t_pid}{year});
- # Cleanup and normalize the current query
+ # Cleanup and pre-normalize the current query
$cur_info{$t_pid}{query} =~ s/^\s+//s;
$cur_info{$t_pid}{query} =~ s/[\s;]+$//s;
+
+ # Just store normalized query when --normalized-only is used
+ if ($dump_normalized_only && $cur_info{$t_pid}{query}) {
+
+ # Add a semi-colon at end of the query
+ $cur_info{$t_pid}{query} .= ';' if ($cur_info{$t_pid}{query} !~ /;\s*$/s);
+
+ # Normalize query
+ my $normalized = &normalize_query($cur_info{$t_pid}{query});
+
+ # Store normalized query count
+ $normalyzed_info{$normalized}{count}++;
+
+ return 1;
+ }
+
# Replace bind parameters values in the query if any
if (exists $cur_info{$t_pid}{parameters} && ($cur_info{$t_pid}{parameters} =~ /[,\s]*\$(\d+)\s=\s/)) {
my @t_res = split(/[,\s]*\$(\d+)\s=\s/, $cur_info{$t_pid}{parameters});