@@ -379,6 +379,7 @@ my @prefix_q_params = ();
379379my %last_execute_stmt = ();
380380my $disable_process_title = 0;
381381my $dump_all_queries = 0;
382+ my $dump_raw_csv = 0;
382383
383384my $compress_extensions = qr/\.(zip|gz|xz|bz2|lz4|zst)$/i;
384385
@@ -562,7 +563,8 @@ my $result = GetOptions(
562563 'no-process-info!' => \$disable_process_title,
563564 'dump-all-queries!' => \$dump_all_queries,
564565 'keep-comments!' => \$keep_comments,
565- 'no-progressbar!' => \$no_progessbar
566+ 'no-progressbar!' => \$no_progessbar,
567+ 'dump-raw-csv!' => \$dump_raw_csv,
566568);
567569die "FATAL: use pgbadger --help\n" if (not $result);
568570
@@ -2252,6 +2254,8 @@ Options:
22522254 can be useful if you want to distinguish between
22532255 same normalized queries.
22542256 --no-progressbar : disable progressbar.
2257+ --dump-raw-csv : parse the log and dump the information into CSV
2258+ format. No further processing is done, no report.
22552259
22562260pgBadger is able to parse a remote log file using a passwordless ssh connection.
22572261Use -r or --remote-host to set the host IP address or hostname. There are also
@@ -17371,6 +17375,11 @@ sub store_queries
1737117375 $overall_stat{'queries_number'}++;
1737217376 return 1;
1737317377 }
17378+ elsif ($dump_raw_csv)
17379+ {
17380+ &dump_raw_csv($t_pid);
17381+ return 1;
17382+ }
1737417383
1737517384 # Cleanup and pre-normalize the current query
1737617385 $cur_info{$t_pid}{query} =~ s/^\s+//s;
@@ -19589,6 +19598,41 @@ sub html_escape
1958919598 return $toencode;
1959019599}
1959119600
19601+ sub dump_raw_csv
19602+ {
19603+
19604+ my $t_pid = shift;
19605+
19606+ # CSV columns information:
19607+ # ------------------------
19608+ # timestamp without milliseconds
19609+ # username
19610+ # database name
19611+ # Process id
19612+ # Remote host
19613+ # session id
19614+ # Error severity
19615+ # SQL state code
19616+ # Query duration
19617+ # user query / error message
19618+ # bind parameters
19619+ # application name
19620+ # backend type
19621+ # query id
19622+
19623+ print "timestamp;username;dbname;pid;client;sessionid;loglevel;sqlstate;duration;query/error;parameters;appname;backendtype;queryid\n";
19624+ print "$cur_info{$t_pid}{timestamp};$cur_info{$t_pid}{dbuser};$cur_info{$t_pid}{dbname};";
19625+ print "$cur_info{$t_pid}{pid};$cur_info{$t_pid}{dbclient};$cur_info{$t_pid}{session};";
19626+ print "$cur_info{$t_pid}{loglevel};$cur_info{$t_pid}{sqlstate};$cur_info{$t_pid}{duration};";
19627+ my $query = ($cur_info{$t_pid}{query} || $cur_lock_info{$t_pid}{query} || $cur_temp_info{$t_pid}{query}
19628+ || $cur_cancel_info{$t_pid}{query} || "plan:\n" .$cur_plan_info{$t_pid}{plan});
19629+ $query =~ s/[\r\n]/\\n/gs;
19630+ print $query . ";";
19631+ print "\"$cur_info{$t_pid}{parameters}\";\"$cur_info{$t_pid}{dbappname}\";";
19632+ print "$cur_info{$t_pid}{backendtype};$cur_info{$t_pid}{queryid}\n";
19633+ }
19634+
19635+
1959219636# Inclusion of Perl package pgFormatter::Beautify.
1959319637{
1959419638
0 commit comments