Skip to content

Commit 44f7993

Browse files
committed
Add option --include-pid to only report events related to a session pid (%p).
Add option --include-session to only report events related to the session id (%c). Both can be used multiple time. Thanks to Henrietta Dombrovskaya for the feature request.
1 parent 81c8d1e commit 44f7993

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ SYNOPSIS
206206
--no-progressbar : disable progressbar.
207207
--dump-raw-csv : parse the log and dump the information into CSV
208208
format. No further processing is done, no report.
209+
--include-pid PID : only report events related to the session pid (%p).
210+
Can be used multiple time.
211+
--include-session ID : only report events related to the session id (%c).
212+
Can be used multiple time.
209213

210214
pgBadger is able to parse a remote log file using a passwordless ssh
211215
connection. Use -r or --remote-host to set the host IP address or

doc/pgBadger.pod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ Options:
208208
--no-progressbar : disable progressbar.
209209
--dump-raw-csv : parse the log and dump the information into CSV
210210
format. No further processing is done, no report.
211+
--include-pid PID : only report events related to the session pid (%p).
212+
Can be used multiple time.
213+
--include-session ID : only report events related to the session id (%c).
214+
Can be used multiple time.
211215

212216
pgBadger is able to parse a remote log file using a passwordless ssh connection.
213217
Use -r or --remote-host to set the host IP address or hostname. There are also

pgbadger

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ my %last_execute_stmt = ();
380380
my $disable_process_title = 0;
381381
my $dump_all_queries = 0;
382382
my $dump_raw_csv = 0;
383+
my $header_done = 0;
384+
my @include_pid = ();
385+
my @include_session = ();
383386

384387
my $compress_extensions = qr/\.(zip|gz|xz|bz2|lz4|zst)$/i;
385388

@@ -565,6 +568,8 @@ my $result = GetOptions(
565568
'keep-comments!' => \$keep_comments,
566569
'no-progressbar!' => \$no_progessbar,
567570
'dump-raw-csv!' => \$dump_raw_csv,
571+
'include-pid=i' => \@include_pid,
572+
'include-session=s' => \@include_session,
568573
);
569574
die "FATAL: use pgbadger --help\n" if (not $result);
570575

@@ -2256,6 +2261,10 @@ Options:
22562261
--no-progressbar : disable progressbar.
22572262
--dump-raw-csv : parse the log and dump the information into CSV
22582263
format. No further processing is done, no report.
2264+
--include-pid PID : only report events related to the session pid (\%p).
2265+
Can be used multiple time.
2266+
--include-session ID : only report events related to the session id (\%c).
2267+
Can be used multiple time.
22592268

22602269
pgBadger is able to parse a remote log file using a passwordless ssh connection.
22612270
Use -r or --remote-host to set the host IP address or hostname. There are also
@@ -17353,6 +17362,13 @@ sub store_queries
1735317362
$cur_info{$t_pid}{query} =~ s/\/\*(.*?)\*\///gs;
1735417363
}
1735517364

17365+
if ($#include_pid >= 0) {
17366+
return 1 if (!grep(/^$t_pid$/, @include_pid));
17367+
}
17368+
if ($#include_session >= 0) {
17369+
return 1 if (!grep(/^$cur_info{$t_pid}{session}$/, @include_session));
17370+
}
17371+
1735617372
# In dump all queries mode we just print the query to output file
1735717373
if ($dump_all_queries && $cur_info{$t_pid}{loglevel} eq 'LOG')
1735817374
{
@@ -19620,7 +19636,8 @@ sub dump_raw_csv
1962019636
# backend type
1962119637
# query id
1962219638

19623-
print "timestamp;username;dbname;pid;client;sessionid;loglevel;sqlstate;duration;query/error;parameters;appname;backendtype;queryid\n";
19639+
print "timestamp;username;dbname;pid;client;sessionid;loglevel;sqlstate;duration;query/error;parameters;appname;backendtype;queryid\n" if (!$header_done);
19640+
$header_done = 1;
1962419641
print "$cur_info{$t_pid}{timestamp};$cur_info{$t_pid}{dbuser};$cur_info{$t_pid}{dbname};";
1962519642
print "$cur_info{$t_pid}{pid};$cur_info{$t_pid}{dbclient};$cur_info{$t_pid}{session};";
1962619643
print "$cur_info{$t_pid}{loglevel};$cur_info{$t_pid}{sqlstate};$cur_info{$t_pid}{duration};";

0 commit comments

Comments
 (0)