# Stores the top N queries generating the biggest temporary file
sub set_top_tempfile_info
{
- my ($q, $sz, $date, $db, $user, $remote, $app) = @_;
+ my ($q, $sz, $date, $db, $user, $remote, $app, $info) = @_;
- push(@top_tempfile_info, [($sz, $date, $q, $db, $user, $remote, $app)]);
+ push(@top_tempfile_info, [($sz, $date, $q, $db, $user, $remote, $app, $info)]);
my @tmp_top_tempfile_info = sort {$b->[0] <=> $a->[0]} @top_tempfile_info;
@top_tempfile_info = ();
$db .= ", user: $top_tempfile_info[$i]->[4]" if ($top_tempfile_info[$i]->[4]);
$db .= ", remote: $top_tempfile_info[$i]->[5]" if ($top_tempfile_info[$i]->[5]);
$db .= ", app: $top_tempfile_info[$i]->[6]" if ($top_tempfile_info[$i]->[6]);
+ $db .= ", info: $top_tempfile_info[$i]->[7]" if ($top_tempfile_info[$i]->[7]);
$db =~ s/^, / - /;
print $fh ($i + 1), ") ", &comma_numbers($top_tempfile_info[$i]->[0]),
" - $ttl$db - ", $top_tempfile_info[$i]->[2], "\n";
$details .= "<b>User:</b> $normalyzed_info{$k}{samples}{$d}{user}\n" if ($normalyzed_info{$k}{samples}{$d}{user});
$details .= "<b>Remote:</b> $normalyzed_info{$k}{samples}{$d}{remote}\n" if ($normalyzed_info{$k}{samples}{$d}{remote});
$details .= "<b>Application:</b> $normalyzed_info{$k}{samples}{$d}{app}\n" if ($normalyzed_info{$k}{samples}{$d}{app});
- $details .= "<b>Bind query:</b> yes\n" if ($normalyzed_info{$k}{samples}{$d}{bind});
+ $details .= "<b>Info:</b> $top_tempfile_info[$i]->[7]" if ($top_tempfile_info[$i]->[7]);
print $fh qq{
<dt>
<div id="query-c-$rank-$idx" class="sql sql-largesize"><i class="glyphicon icon-copy" title="Click to select query"></i>$query</div>$md5
$details .= " - <b>User:</b> $top_tempfile_info[$i]->[4]" if ($top_tempfile_info[$i]->[4]);
$details .= " - <b>Remote:</b> $top_tempfile_info[$i]->[5]" if ($top_tempfile_info[$i]->[5]);
$details .= " - <b>Application:</b> $top_tempfile_info[$i]->[6]" if ($top_tempfile_info[$i]->[6]);
- $details .= " - <b>Bind yes:</b> yes" if ($top_tempfile_info[$i]->[7]);
$details .= " ]";
+ $details .= "\n<b>Info:</b> $top_tempfile_info[$i]->[7]" if ($top_tempfile_info[$i]->[7]);
my $query = &highlight_code($top_tempfile_info[$i]->[2]);
my $md5 = '';
$md5 = 'md5: ' . md5_hex($top_tempfile_info[$i]->[2]) if ($enable_checksum);
$cur_cancel_info{$t_pid}{dbuser} = $prefix_vars{'t_dbuser'};
$cur_cancel_info{$t_pid}{dbclient} = $prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'};
$cur_cancel_info{$t_pid}{dbappname} = $prefix_vars{'t_appname'};
- } elsif (exists $cur_cancel_info{$t_pid}) {
+ }
+ elsif (exists $cur_cancel_info{$t_pid})
+ {
&store_temporary_and_lock_infos($t_pid);
}
}
}
# Save previous temporary file information with same pid to not overwrite it
- if ($prefix_vars{'t_loglevel'} =~ $main_log_regex) {
- if (($prefix_vars{'t_query'} !~ /temporary file: path .*, size \d+/) && exists $cur_temp_info{$t_pid}) {
+ if ($prefix_vars{'t_loglevel'} =~ $main_log_regex)
+ {
+ if (($prefix_vars{'t_query'} !~ /temporary file: path .*, size \d+/)
+ && exists $cur_temp_info{$t_pid})
+ {
&store_temporary_and_lock_infos($t_pid);
}
- if (($prefix_vars{'t_query'} !~ /acquired [^\s]+ on [^\s]+ .* after [0-9\.]+ ms/) && exists $cur_lock_info{$t_pid}) {
+ if (($prefix_vars{'t_query'} !~ /acquired [^\s]+ on [^\s]+ .* after [0-9\.]+ ms/)
+ && exists $cur_lock_info{$t_pid})
+ {
&store_temporary_and_lock_infos($t_pid);
}
}
return if (!$t_pid);
# Store normalized query temp file size if required
- if (exists $cur_temp_info{$t_pid} && ($cur_temp_info{$t_pid}{query} ne '') && $cur_temp_info{$t_pid}{size}) {
+ if (exists $cur_temp_info{$t_pid} && ($cur_temp_info{$t_pid}{query} ne '')
+ && $cur_temp_info{$t_pid}{size})
+ {
+ # Remove additional information generated by log function call
+ if ($cur_temp_info{$t_pid}{query} =~ s/(\s*PL\/pgSQL function.*)//s)
+ {
+ $cur_temp_info{$t_pid}{info} = $1;
+ }
# Add a semi-colon at end of the query
$cur_temp_info{$t_pid}{query} .= ';' if ($cur_temp_info{$t_pid}{query} !~ /;\s*$/s);
# Anonymize query if requested by the user
- if ($anonymize) {
+ if ($anonymize)
+ {
$cur_temp_info{$t_pid}{query} = &anonymize_query($cur_temp_info{$t_pid}{query});
}
$normalyzed_info{$normalized}{tempfiles}{size} += $cur_temp_info{$t_pid}{size};
$normalyzed_info{$normalized}{tempfiles}{count}++;
- if ($normalyzed_info{$normalized}{tempfiles}{maxsize} < $cur_temp_info{$t_pid}{size}) {
+ if ($normalyzed_info{$normalized}{tempfiles}{maxsize} < $cur_temp_info{$t_pid}{size})
+ {
$normalyzed_info{$normalized}{tempfiles}{maxsize} = $cur_temp_info{$t_pid}{size};
}
if (!exists($normalyzed_info{$normalized}{tempfiles}{minsize})
- || $normalyzed_info{$normalized}{tempfiles}{minsize} > $cur_temp_info{$t_pid}{size}) {
+ || $normalyzed_info{$normalized}{tempfiles}{minsize} > $cur_temp_info{$t_pid}{size})
+ {
$normalyzed_info{$normalized}{tempfiles}{minsize} = $cur_temp_info{$t_pid}{size};
}
- &set_top_tempfile_info($cur_temp_info{$t_pid}{query}, $cur_temp_info{$t_pid}{size}, $cur_temp_info{$t_pid}{timestamp}, $cur_temp_info{$t_pid}{dbname}, $cur_temp_info{$t_pid}{dbuser}, $cur_temp_info{$t_pid}{dbclient}, $cur_temp_info{$t_pid}{dbappname});
+ &set_top_tempfile_info($cur_temp_info{$t_pid}{query}, $cur_temp_info{$t_pid}{size}, $cur_temp_info{$t_pid}{timestamp}, $cur_temp_info{$t_pid}{dbname}, $cur_temp_info{$t_pid}{dbuser}, $cur_temp_info{$t_pid}{dbclient}, $cur_temp_info{$t_pid}{dbappname}, $cur_temp_info{$t_pid}{info});
+
# Check if we don't have sample for this query (occurs when log_min_duration_statement doesn't logged the query)
- if (!exists $normalyzed_info{$normalized}{samples}) {
+ if (!exists $normalyzed_info{$normalized}{samples})
+ {
&set_top_sample($normalized, $cur_temp_info{$t_pid}{query}, $cur_temp_info{$t_pid}{duration}, $cur_temp_info{$t_pid}{timestamp}, $cur_temp_info{$t_pid}{dbname}, $cur_temp_info{$t_pid}{dbuser}, $cur_temp_info{$t_pid}{dbclient},$cur_temp_info{$t_pid}{dbappname});
}
delete $cur_temp_info{$t_pid};