Sessions per database/user/client.
Connections per database/user/client.
Autovacuum and autoanalyze per table.
+ Histogram of sessions times.
All charts are zoomable and can be saved as PNG images. SQL queries
reported are highlighted and beautified automatically.
log_line_prefix = '%t [%p]: [%l-1] '
- Log line prefix could add user and database name as follows:
+ Log line prefix could add user, database name and client ip address as
+ follows:
- log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d '
+ log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,client=%h '
or for syslog log file format:
- log_line_prefix = 'user=%u,db=%d '
+ log_line_prefix = 'user=%u,db=%d,client=%h '
Log line prefix for stderr output could also be:
- log_line_prefix = '%t [%p]: [%l-1] db=%d,user=%u '
+ log_line_prefix = '%t [%p]: [%l-1] db=%d,user=%u,client=%h '
or for syslog output:
- log_line_prefix = 'db=%d,user=%u '
+ log_line_prefix = 'db=%d,user=%u,client=%h '
You need to enable other parameters in postgresql.conf to get more
information from your log files:
Sessions per database/user/client.
Connections per database/user/client.
Autovacuum and autoanalyze per table.
+ Histogram of sessions times.
All charts are zoomable and can be saved as PNG images. SQL queries reported are
highlighted and beautified automatically.
log_line_prefix = '%t [%p]: [%l-1] '
-Log line prefix could add user and database name as follows:
+Log line prefix could add user, database name and client ip address as follows:
- log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d '
+ log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,client=%h '
or for syslog log file format:
- log_line_prefix = 'user=%u,db=%d '
+ log_line_prefix = 'user=%u,db=%d,client=%h '
Log line prefix for stderr output could also be:
- log_line_prefix = '%t [%p]: [%l-1] db=%d,user=%u '
+ log_line_prefix = '%t [%p]: [%l-1] db=%d,user=%u,client=%h '
or for syslog output:
- log_line_prefix = 'db=%d,user=%u '
+ log_line_prefix = 'db=%d,user=%u,client=%h '
You need to enable other parameters in postgresql.conf to get more information from your log files:
# Log line prefix should be: log_line_prefix = '%t [%p]: [%l-1] '
# Log line prefix should be: log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d '
# Log line prefix should be: log_line_prefix = '%t [%p]: [%l-1] db=%d,user=%u '
+# If you need report per client Ip adresses you can add client=%h or remote=%h
+# pgbadger will also recognized the following form:
+# log_line_prefix = '%t [%p]: [%l-1] db=%d,user=%u,client=%h '
+# or
+# log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,remote=%h '
# With syslog output
# Log line prefix should be: log_line_prefix = 'db=%d,user=%u '
#
die "FATAL: please choose between no event report and reporting events only.\n";
}
-# Set default search pattern for database and user name in log_line_prefix
+# Set default search pattern for database, user name and host in log_line_prefix
my $regex_prefix_dbname = qr/db=([^,]*)/;
my $regex_prefix_dbuser = qr/user=([^,]*)/;
+my $regex_prefix_dbclient = qr/(?:client|remote)=([^,]*)/;
# Loading excluded query from file if any
if ($exclude_file) {
if ($t_logprefix =~ $regex_prefix_dbname) {
$prefix_vars{'t_dbname'} = $1;
}
- }
-}
-
-# OBSOLETE: to be removed
-sub is_session_closed
-{
- map { return 1 if ($_[0] =~ $_); } @session_closed_msg;
- return 0;
+ # Search for database name
+ if ($t_logprefix =~ $regex_prefix_dbclient) {
+ $prefix_vars{'t_dbclient'} = $1;
+ $prefix_vars{'t_dbclient'} = _gethostbyaddr($prefix_vars{'t_dbclient'}) if ($dns_resolv);
+ }
+ }
}
sub parse_query
$cur_lock_info{$t_pid}{timestamp} = $prefix_vars{'t_timestamp'};
$cur_lock_info{$t_pid}{dbname} = $prefix_vars{'t_dbname'};
$cur_lock_info{$t_pid}{dbuser} = $prefix_vars{'t_dbuser'};
- $cur_lock_info{$t_pid}{dbclient} = $prefix_vars{'t_client'};
+ $cur_lock_info{$t_pid}{dbclient} = $prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'};
$cur_lock_info{$t_pid}{dbappname} = $prefix_vars{'t_appname'};
}
return;
$cur_temp_info{$t_pid}{timestamp} = $prefix_vars{'t_timestamp'};
$cur_temp_info{$t_pid}{dbname} = $prefix_vars{'t_dbname'};
$cur_temp_info{$t_pid}{dbuser} = $prefix_vars{'t_dbuser'};
- $cur_temp_info{$t_pid}{dbclient} = $prefix_vars{'t_client'};
+ $cur_temp_info{$t_pid}{dbclient} = $prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'};
$cur_temp_info{$t_pid}{dbappname} = $prefix_vars{'t_appname'};
return;
}
$cur_lock_info{$t_pid}{timestamp} = $prefix_vars{'t_timestamp'};
$cur_lock_info{$t_pid}{dbname} = $prefix_vars{'t_dbname'};
$cur_lock_info{$t_pid}{dbuser} = $prefix_vars{'t_dbuser'};
- $cur_lock_info{$t_pid}{dbclient} = $prefix_vars{'t_client'};
+ $cur_lock_info{$t_pid}{dbclient} = $prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'};
$cur_lock_info{$t_pid}{dbappname} = $prefix_vars{'t_appname'};
return;
}
$cur_temp_info{$t_pid}{timestamp} = $prefix_vars{'t_timestamp'};
$cur_temp_info{$t_pid}{dbname} = $prefix_vars{'t_dbname'};
$cur_temp_info{$t_pid}{dbuser} = $prefix_vars{'t_dbuser'};
- $cur_temp_info{$t_pid}{dbclient} = $prefix_vars{'t_client'};
+ $cur_temp_info{$t_pid}{dbclient} = $prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'};
$cur_temp_info{$t_pid}{dbappname} = $prefix_vars{'t_appname'};
}
return;
$cur_temp_info{$t_pid}{timestamp} = $prefix_vars{'t_timestamp'};
$cur_temp_info{$t_pid}{dbname} = $prefix_vars{'t_dbname'};
$cur_temp_info{$t_pid}{dbuser} = $prefix_vars{'t_dbuser'};
- $cur_temp_info{$t_pid}{dbclient} = $prefix_vars{'t_client'};
+ $cur_temp_info{$t_pid}{dbclient} = $prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'};
$cur_temp_info{$t_pid}{dbappname} = $prefix_vars{'t_appname'};
return;
}
if (($prefix_vars{'t_loglevel'} eq 'LOG') && ($prefix_vars{'t_query'} =~ /connection received: host=([^\s]+)(?: port=(\d+))?/)) {
return if ($disable_connection);
$conn_received{$t_pid} = $1;
+ $conn_received{$t_pid} = _gethostbyaddr($conn_received{$t_pid}) if ($dns_resolv);
return;
}
}
if ($prefix_vars{'t_query'} =~ / host=([^\s]+)/) {
$host = $1;
- } elsif ($prefix_vars{'t_client'}) {
- $host = $prefix_vars{'t_client'};
+ $host = _gethostbyaddr($host) if ($dns_resolv);
+ } elsif ($prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'}) {
+ $host = $prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'};
+ $host = _gethostbyaddr($host) if ($dns_resolv);
}
if ($extension eq 'tsung') {
$tsung_session{$prefix_vars{'t_pid'}}{connection}{database} = $db;
my $usr = $2;
my $db = $3;
my $host = $4;
+ $host = _gethostbyaddr($host) if ($dns_resolv);
if ($extension eq 'tsung') {
&store_tsung_session($prefix_vars{'t_pid'});
$cur_info{$t_pid}{loglevel} = $prefix_vars{'t_loglevel'};
$cur_info{$t_pid}{dbname} = $prefix_vars{'t_dbname'};
$cur_info{$t_pid}{dbuser} = $prefix_vars{'t_dbuser'};
- $cur_info{$t_pid}{dbclient} = $prefix_vars{'t_client'};
+ $cur_info{$t_pid}{dbclient} = $prefix_vars{'t_client'} || $prefix_vars{'t_dbclient'};
$cur_info{$t_pid}{dbappname} = $prefix_vars{'t_appname'};
$cur_info{$t_pid}{date} = $prefix_vars{'t_date'};
$cur_info{$t_pid}{bind} = $prefix_vars{'t_bind'};