Arguments:
logfile can be a single log file, a list of files, or a shell command
- returning a list of file. If you want to pass log content from stdin
+ returning a list of files. If you want to pass log content from stdin
use - as filename. Note that input from stdin will not work with csvlog.
Options:
-a | --average minutes : number of minutes to build the average graphs of
queries and connections.
-b | --begin datetime : start date/time for the data to be parsed in log.
- -c | --dbclient host : only report what concern the given client host.
+ -c | --dbclient host : only report on entries for the given client host.
-C | --nocomment : remove comments like /* ... */ from queries.
- -d | --dbname database : only report what concern the given database
+ -d | --dbname database : only report on entries for the given database.
-e | --end datetime : end date/time for the data to be parsed in log.
-f | --format logtype : possible values: syslog,stderr,csv. Default: stderr.
-G | --nograph : disable graphs on HTML output. Enable by default.
-h | --help : show this message and exit.
- -i | --ident name : programname used as syslog ident. Default: postgres
+ -i | --ident name : program name used as syslog ident. Default: postgres
-l | --last-parsed file: allow incremental log parsing by registering the
last datetime and line parsed. Useful if you want
to watch errors since last run or if you want one
report per day with a log rotated each week.
- -m | --maxlength size : maximum length of a query, it will be cutted above
+ -m | --maxlength size : maximum length of a query, it will be restricted to
the given size. Default: no truncate
-n | --nohighlight : disable SQL code highlighting.
- -N | --appname name : only report what concern the given application name
+ -N | --appname name : only report on entries for given application name
-o | --outfile filename: define the filename for the output. Default depends
- of the output format: out.html, out.txt or out.tsung.
+ on the output format: out.html, out.txt or out.tsung.
To dump output to stdout use - as filename.
-p | --prefix string : give here the value of your custom log_line_prefix
- defined in your postgresql.conf. You may used it only
- if don't have the default allowed formats ot to use
- other custom variables like client ip or application
- name. See examples below.
+ defined in your postgresql.conf. Only use it if you
+ aren't using one of the standard prefixes specified
+ in the pgBadger documentation, such as if your prefix
+ includes additional variables like client ip or
+ application name. See examples below.
-P | --no-prettify : disable SQL queries prettify formatter.
-q | --quiet : don't print anything to stdout, even not a progress bar.
- -s | --sample number : number of query sample to store/display. Default: 3
- -s | --select-only : use it if you want reports on select queries only.
- -t | --top number : number of query to store/display. Default: 20
+ -s | --sample number : number of query samples to store/display. Default: 3
+ -S | --select-only : use it if you want to report select queries only.
+ -t | --top number : number of queries to store/display. Default: 20
-T | --title string : change title of the HTML page report.
- -u | --dbuser username : only report what concern the given user
- -U | --exclude-user username : make report with exclude specified user.
+ -u | --dbuser username : only report on entries for the given user.
+ -U | --exclude-user username : exclude entries for the specified user from report.
-v | --verbose : enable verbose or debug mode. Disabled by default.
-V | --version : show pgBadger version and exit.
-w | --watch-mode : only report errors just like logwatch could do.
--pie-limit num : pie data lower than num% will show a sum instead.
--exclude-query regex : any query matching the given regex will be excluded
from the report. For example: "^(VACUUM|COMMIT)"
- you can use this option multiple time.
+ You can use this option multiple times.
--exclude-file filename: path of the file which contains all the regex to use
to exclude queries from the report. One regex per line.
- --include-query regex : any query that do not match the given regex will be
+ --include-query regex : any query that does not match the given regex will be
excluded from the report. For example: "(table_1|table_2)"
- you can use this option multiple time.
+ You can use this option multiple times.
--include-file filename: path of the file which contains all the regex of the
queries to include from the report. One regex per line.
--disable-error : do not generate error report.
--disable-lock : do not generate lock report.
--disable-temporary : do not generate temporary report.
--disable-checkpoint : do not generate checkpoint report.
- --enable-log_duration : force pgbadger to use log_duration even if
+ --enable-log_duration : force pgBadger to use log_duration even if
log_min_duration_statement format is autodetected.
- --enable-log_min_duration: force pgbadger to use log_min_duration even if
+ --enable-log_min_duration: force pgBadger to use log_min_duration even if
log_duration format is autodetected.
Examples:
0 4 * * 1 /usr/bin/pgbadger -q `find /var/log/ -mtime -7 -name "postgresql.log*"` \
-o /var/reports/pg_errors-`date +%F`.html -l /var/reports/pgbadger_incremental_file.dat
- This suppose that your log file and HTML report are also rotated every
+ This supposes that your log file and HTML report are also rotated every
week.
DESCRIPTION
pgBadger is a PostgreSQL log analyzer built for speed with fully
detailed reports from your PostgreSQL log file. It's a single and small
- Perl script that aims to replace and outperform the old php script
+ Perl script that aims to replace and out-perform the old PHP script
pgFouine.
By the way, we would like to thank Guillaume Smet for all the work he
has done on this really nice tool. We've been using it a long time, it
is a really great tool!
- pgBadger is written in pure Perl language. It uses a javascript library
+ pgBadger is written in pure Perl language. It uses a Javascript library
to draw graphs so that you don't need additional Perl modules or any
other package to install. Furthermore, this library gives us additional
features, such as zooming.
reported are highlighted and beautified automatically.
REQUIREMENT
- PgBadger comes as a single Perl script- you do not need anything else
+ PgBadger comes as a single Perl script- you do not need anything other
than a modern Perl distribution. Charts are rendered using a Javascript
library so you don't need anything. Your browser will do all the work.
This module is optional, if you don't have PostgreSQL log in the CSV
format you don't need to install it.
- Compressed log file format is autodetected following the file exention.
- If pgbadger find a gz extention it will use the zcat utility, with a bz2
- extention it will use bzcat and if the file extention is zip then the
+ Compressed log file format is autodetected from the file extension.
+ If pgBadger find a gz extension it will use the zcat utility, with a bz2
+ extension it will use bzcat and if the file extension is zip then the
unzip utility will be used.
If those utilities are not found in the PATH environment variable then
- use the --zcat command line otption to change this path. For exemple:
+ use the --zcat command line option to change this path. For example:
--zcat="/usr/local/bin/gunzip -c" or --zcat="/usr/local/bin/bzip2 -dc"
--zcat="C:\tools\unzip -p"
By default pgBadger will use the zcat, bzcat and unzip utilities
following the file extension. If you use the default autodetection
compress format you can mixed gz, bz2 or zip files. Specifying a custom
- value to --zcat option will removed this feature of mixed compressed
+ value to --zcat option will remove this feature of mixed compressed
format.
POSTGRESQL CONFIGURATION
log_min_duration_statement = 0
- Note that pgBadger is not compatible with statements logs provided by
+ Note that pgBadger is not compatible with statement logs provided by
log_statement and log_duration. See next chapter for more information.
With 'stderr' log format, log_line_prefix must be at least:
log_line_prefix = 'db=%d,user=%u '
You need to enable other parameters in postgresql.conf to get more
- informations from your log files:
+ information from your log files:
log_checkpoints = on
log_connections = on
log_lock_waits = on
log_temp_files = 0
- Do not enable log_statement and log_duration, their log format will not
+ Do not enable log_statement and log_duration as their log format will not
be parsed by pgBadger.
- Of course your log messages should be in english without locale support:
+ Of course your log messages should be in English without locale support:
lc_messages='C'
- but this is not only recommanded by pgbadger.
+ but this is not only recommended by pgBadger.
log_min_duration_statement versus log_duration
If you want full statistics reports from your log file you must set
log_min_duration_statement = 0. If you just want to report duration and
- number of queries and don't want all detail about queries, set
+ number of queries and don't want all details about queries, set
log_min_duration_statement to -1 and enable log_duration. If you want to
- report only queries that tooks more than 5 seconds for example but still
- want to report all queries duration and number of queries you will need
+ report only queries that took more than 5 seconds for example but still
+ want to report all query durations and number of queries you will need
to generate 2 reports. One using the log_min_duration_statement and the
second using the log_duration. Proceed as follow:
pgbadger --enable-log_duration /var/log/postgresql.log
to generate hourly statistics about the number of queries and duration
- stats. To generate detailled reports about queries use the following
+ stats. To generate detailed reports about queries use the following
command:
pgbadger --enable-log_min_duration /var/log/postgresql.log
Note that enabling log_statement will not help at all and enabling those
two options in the same command will report an error.
- Use those options if you don't want to log each queries to preserve your
- I/O but still want to know the slowest queries upper a certain time and
+ Use those options if you don't want to log every query to preserve your
+ I/O but still want to know the slowest queries over a certain duration and
still have a report on the number of queries and their duration.
- Otherwize if you don't have too much performance lost with a
+ Otherwise if you don't have too much of a performance hit with
log_min_duration_statement set to 0, do not enable log_duration in your
postgresql.conf file.
INSTALLATION
- Download the tarball from github and unpack the archive as follow:
+ Download the tarball from github and unpack the archive as follows:
tar xzf pgbadger-1.x.tar.gz
cd pgbadger-1.x/
perl Makefile.PL
make && sudo make install
- This will copy the Perl script pgbadger in /usr/local/bin/pgbadger
- directory by default and the man page into
- /usr/local/share/man/man1/pgbadger.1. Those are the default installation
- directory for 'site' install.
+ This will copy the Perl script pgbadger to /usr/local/bin/pgbadger
+ by default and the man page into /usr/local/share/man/man1/pgbadger.1.
+ Those are the default installation directories for 'site' install.
If you want to install all under /usr/ location, use INSTALLDIRS='perl'
- as argument of Makefile.PL. The script will be installed into
+ as an argument of Makefile.PL. The script will be installed into
/usr/bin/pgbadger and the manpage into /usr/share/man/man1/pgbadger.1.
For example, to install everything just like Debian does, proceed as
- follow:
+ follows:
perl Makefile.PL INSTALLDIRS=vendor
AUTHORS
pgBadger is an original work from Gilles Darold. It is maintained by the
- good folks at Dalibo and every one who wants to contribute.
+ good folk at Dalibo and everyone who wants to contribute.
LICENSE
pgBadger is free software distributed under the PostgreSQL Licence.
Arguments:
logfile can be a single log file, a list of files, or a shell command
- returning a list of file. If you want to pass log content from stdin
+ returning a list of files. If you want to pass log content from stdin
use - as filename. Note that input from stdin will not work with csvlog.
Options:
-a | --average minutes : number of minutes to build the average graphs of
queries and connections.
-b | --begin datetime : start date/time for the data to be parsed in log.
- -c | --dbclient host : only report what concern the given client host.
+ -c | --dbclient host : only report on entries for the given client host.
-C | --nocomment : remove comments like /* ... */ from queries.
- -d | --dbname database : only report what concern the given database
+ -d | --dbname database : only report on entries for the given database.
-e | --end datetime : end date/time for the data to be parsed in log.
-f | --format logtype : possible values: syslog,stderr,csv. Default: stderr.
-G | --nograph : disable graphs on HTML output. Enable by default.
-h | --help : show this message and exit.
- -i | --ident name : programname used as syslog ident. Default: postgres
+ -i | --ident name : program name used as syslog ident. Default: postgres
-l | --last-parsed file: allow incremental log parsing by registering the
last datetime and line parsed. Useful if you want
to watch errors since last run or if you want one
report per day with a log rotated each week.
- -m | --maxlength size : maximum length of a query, it will be cutted above
+ -m | --maxlength size : maximum length of a query, it will be restricted to
the given size. Default: no truncate
-n | --nohighlight : disable SQL code highlighting.
- -N | --appname name : only report what concern the given application name
+ -N | --appname name : only report on entries for given application name
-o | --outfile filename: define the filename for the output. Default depends
- of the output format: out.html, out.txt or out.tsung.
+ on the output format: out.html, out.txt or out.tsung.
To dump output to stdout use - as filename.
-p | --prefix string : give here the value of your custom log_line_prefix
- defined in your postgresql.conf. You may used it only
- if don't have the default allowed formats ot to use
- other custom variables like client ip or application
- name. See examples below.
+ defined in your postgresql.conf. Only use it if you
+ aren't using one of the standard prefixes specified
+ in the pgBadger documentation, such as if your prefix
+ includes additional variables like client ip or
+ application name. See examples below.
-P | --no-prettify : disable SQL queries prettify formatter.
-q | --quiet : don't print anything to stdout, even not a progress bar.
- -s | --sample number : number of query sample to store/display. Default: 3
- -s | --select-only : use it if you want reports on select queries only.
- -t | --top number : number of query to store/display. Default: 20
+ -s | --sample number : number of query samples to store/display. Default: 3
+ -S | --select-only : use it if you want to report select queries only.
+ -t | --top number : number of queries to store/display. Default: 20
-T | --title string : change title of the HTML page report.
- -u | --dbuser username : only report what concern the given user
- -U | --exclude-user username : make report with exclude specified user.
+ -u | --dbuser username : only report on entries for the given user.
+ -U | --exclude-user username : exclude entries for the specified user from report.
-v | --verbose : enable verbose or debug mode. Disabled by default.
-V | --version : show pgBadger version and exit.
-w | --watch-mode : only report errors just like logwatch could do.
--pie-limit num : pie data lower than num% will show a sum instead.
--exclude-query regex : any query matching the given regex will be excluded
from the report. For example: "^(VACUUM|COMMIT)"
- you can use this option multiple time.
+ You can use this option multiple times.
--exclude-file filename: path of the file which contains all the regex to use
to exclude queries from the report. One regex per line.
- --include-query regex : any query that do not match the given regex will be
+ --include-query regex : any query that does not match the given regex will be
excluded from the report. For example: "(table_1|table_2)"
- you can use this option multiple time.
+ You can use this option multiple times.
--include-file filename: path of the file which contains all the regex of the
queries to include from the report. One regex per line.
--disable-error : do not generate error report.
--disable-lock : do not generate lock report.
--disable-temporary : do not generate temporary report.
--disable-checkpoint : do not generate checkpoint report.
- --enable-log_duration : force pgbadger to use log_duration even if
+ --enable-log_duration : force pgBadger to use log_duration even if
log_min_duration_statement format is autodetected.
- --enable-log_min_duration: force pgbadger to use log_min_duration even if
+ --enable-log_min_duration: force pgBadger to use log_min_duration even if
log_duration format is autodetected.
Examples:
pgbadger /var/log/postgresql/postgresql-2012-05-*
pgbadger --exclude-query="^(COPY|COMMIT)" /var/log/postgresql.log
pgbadger -b "2012-06-25 10:56:11" -e "2012-06-25 10:59:11" /var/log/postgresql.log
- cat /var/log/postgres.log | pgbadger -
+ cat /var/log/postgres.log | pgbadger -
# log prefix with stderr log output
perl pgbadger --prefix '%t [%p]: [%l-1] user=%u,db=%d,client=%h' \
/pglog/postgresql-2012-08-21*
0 4 * * 1 /usr/bin/pgbadger -q `find /var/log/ -mtime -7 -name "postgresql.log*"` \
-o /var/reports/pg_errors-`date +%F`.html -l /var/reports/pgbadger_incremental_file.dat
-This suppose that your log file and HTML report are also rotated every week.
+This supposes that your log file and HTML report are also rotated every week.
=head1 DESCRIPTION
-
-pgBadger is a PostgreSQL log analyzer built for speed with fully detailed reports from your PostgreSQL log file. It's a single and small Perl script that aims to replace and outperform the old php script pgFouine.
+pgBadger is a PostgreSQL log analyzer built for speed with fully detailed reports from your PostgreSQL log file. It's a single and small Perl script that aims to replace and out-perform the old PHP script pgFouine.
By the way, we would like to thank Guillaume Smet for all the work he has done on this really nice tool. We've been using it a long time, it is a really great tool!
-pgBadger is written in pure Perl language. It uses a javascript library to draw graphs so that you don't need additional Perl modules or any other package to install. Furthermore, this library gives us additional features, such as zooming.
+pgBadger is written in pure Perl language. It uses a Javascript library to draw graphs so that you don't need additional Perl modules or any other package to install. Furthermore, this library gives us additional features, such as zooming.
pgBadger is able to autodetect your log file format (syslog, stderr or csvlog). It is designed to parse huge log files, as well as gzip, zip or bzip2 compressed files. See a complete list of features below.
=head1 REQUIREMENT
-PgBadger comes as a single Perl script- you do not need anything else than a modern Perl distribution. Charts are rendered using a Javascript library so you don't need anything. Your browser will do all the work.
+PgBadger comes as a single Perl script - you do not need anything other than a modern Perl distribution. Charts are rendered using a Javascript library so you don't need anything. Your browser will do all the work.
If you planned to parse PostgreSQL CSV log files you might need some Perl Modules:
This module is optional, if you don't have PostgreSQL log in the CSV format you don't need to install it.
-Compressed log file format is autodetected following the file exention. If pgbadger find a gz extention
-it will use the zcat utility, with a bz2 extention it will use bzcat and if the file extention is zip
+Compressed log file format is autodetected from the file exension. If pgBadger find a gz extension
+it will use the zcat utility, with a bz2 extension it will use bzcat and if the file extension is zip
then the unzip utility will be used.
-If those utilities are not found in the PATH environment variable then use the --zcat command line otption
-to change this path. For exemple:
+If those utilities are not found in the PATH environment variable then use the --zcat command line option
+to change this path. For example:
--zcat="/usr/local/bin/gunzip -c" or --zcat="/usr/local/bin/bzip2 -dc"
--zcat="C:\tools\unzip -p"
By default pgBadger will use the zcat, bzcat and unzip utilities following the file extension.
If you use the default autodetection compress format you can mixed gz, bz2 or zip files. Specifying
-a custom value to --zcat option will removed this feature of mixed compressed format.
+a custom value to --zcat option will remove this feature of mixed compressed format.
=head1 POSTGRESQL CONFIGURATION
log_min_duration_statement = 0
-Note that pgBadger is not compatible with statements logs provided by log_statement and log_duration.
+Note that pgBadger is not compatible with statement logs provided by log_statement and log_duration.
See next chapter for more information.
With 'stderr' log format, log_line_prefix must be at least:
log_line_prefix = 'db=%d,user=%u '
-You need to enable other parameters in postgresql.conf to get more informations from your log files:
+You need to enable other parameters in postgresql.conf to get more information from your log files:
log_checkpoints = on
log_connections = on
log_lock_waits = on
log_temp_files = 0
-Do not enable log_statement and log_duration, their log format will not be parsed by pgBadger.
+Do not enable log_statement and log_duration as their log format will not be parsed by pgBadger.
-Of course your log messages should be in english without locale support:
+Of course your log messages should be in English without locale support:
lc_messages='C'
-but this is not only recommanded by pgbadger.
+but this is not only recommended by pgBadger.
=head1 log_min_duration_statement versus log_duration
If you want full statistics reports from your log file you must set log_min_duration_statement = 0.
-If you just want to report duration and number of queries and don't want all detail about queries,
+If you just want to report duration and number of queries and don't want all details about queries,
set log_min_duration_statement to -1 and enable log_duration. If you want to report only queries that
-tooks more than 5 seconds for example but still want to report all queries duration and number of
+took more than 5 seconds for example but still want to report all query durations and number of
queries you will need to generate 2 reports. One using the log_min_duration_statement and the second
using the log_duration. Proceed as follow:
pgbadger --enable-log_duration /var/log/postgresql.log
-to generate hourly statistics about the number of queries and duration stats. To generate detailled
+to generate hourly statistics about the number of queries and duration stats. To generate detailed
reports about queries use the following command:
pgbadger --enable-log_min_duration /var/log/postgresql.log
Note that enabling log_statement will not help at all and enabling those two options in the same
command will report an error.
-Use those options if you don't want to log each queries to preserve your I/O but still want to know
-the slowest queries upper a certain time and still have a report on the number of queries and their
-duration. Otherwize if you don't have too much performance lost with a log_min_duration_statement
+Use those options if you don't want to log every query to preserve your I/O but still want to know
+the slowest queries over a certain duration and still have a report on the number of queries and their
+duration. Otherwise if you don't have too much of a performance hit with log_min_duration_statement
set to 0, do not enable log_duration in your postgresql.conf file.
=head1 INSTALLATION
perl Makefile.PL
make && sudo make install
-This will copy the Perl script pgbadger in /usr/local/bin/pgbadger directory by default and the man page into /usr/local/share/man/man1/pgbadger.1. Those are the default installation directory for 'site' install.
+This will copy the Perl script pgbadger to /usr/local/bin/pgbadger by default and the man page into /usr/local/share/man/man1/pgbadger.1. Those are the default installation directories for 'site' install.
-If you want to install all under /usr/ location, use INSTALLDIRS='perl' as argument of Makefile.PL. The script will be installed into /usr/bin/pgbadger and the manpage into /usr/share/man/man1/pgbadger.1.
+If you want to install all under /usr/ location, use INSTALLDIRS='perl' as an argument of Makefile.PL. The script will be installed into /usr/bin/pgbadger and the manpage into /usr/share/man/man1/pgbadger.1.
-For example, to install everything just like Debian does, proceed as follow:
+For example, to install everything just like Debian does, proceed as follows:
perl Makefile.PL INSTALLDIRS=vendor
=head1 AUTHORS
-pgBadger is an original work from Gilles Darold. It is maintained by the good folks at Dalibo and every one who wants to contribute.
+pgBadger is an original work from Gilles Darold. It is maintained by the good folk at Dalibo and everyone who wants to contribute.
=head1 LICENSE
# With syslog output
# Log line prefix should be: log_line_prefix = 'db=%d,user=%u '
#
-# Additional informations that could be collected and reported
+# Additional information that could be collected and reported
# log_checkpoints = on
# log_connections = on
# log_disconnections = on
} elsif ($from =~ /^(\d{4})-(\d{2})-(\d{2})$/) {
$from = "$1$2$3" . "000000";
} else {
- die "FATAL: bad format for begin datetime, shoud be yyyy-mm-dd hh:mm:ss\n";
+ die "FATAL: bad format for begin datetime, should be yyyy-mm-dd hh:mm:ss\n";
}
}
if ($to) {
} elsif ($to =~ /^(\d{4})-(\d{2})-(\d{2})$/) {
$to = "$1$2$3" . "000000";
} else {
- die "FATAL: bad format for ending datetime, shoud be yyyy-mm-dd hh:mm:ss\n";
+ die "FATAL: bad format for ending datetime, should be yyyy-mm-dd hh:mm:ss\n";
}
}
my @BRACKETS = ('(', ')');
map {$_ = quotemeta($_)} @BRACKETS;
-# Where statistic are stored
+# Where statistics are stored
my %STATS = ();
my $first_log_timestamp = '';
my $last_log_timestamp = '';
my $curdate = localtime(time);
- # Syslog do not have year information, so take care of year overlapping
+ # Syslog does not have year information, so take care of year overlapping
my ($gsec, $gmin, $ghour, $gmday, $gmon, $gyear, $gwday, $gyday, $gisdst) = localtime(time);
$gyear += 1900;
my $CURRENT_DATE = $gyear . sprintf("%02d", $gmon + 1) . sprintf("%02d", $gmday);
# skip non postgresql lines
next if ($prefix_vars{'t_ident'} ne $ident);
- # Syslog do not have year information, so take care of year overlapping
+ # Syslog does not have year information, so take care of year overlapping
$prefix_vars{'t_year'} = $gyear;
$prefix_vars{'t_day'} = sprintf("%02d", $prefix_vars{'t_day'});
$prefix_vars{'t_month'} = $month_abbr{$prefix_vars{'t_month'}};
&parse_log_prefix($prefix_vars{'t_logprefix'});
}
- # Check if the log line shoud be exclude from the report
+ # Check if the log line should be excluded from the report
if (&validate_log_line($prefix_vars{'t_pid'})) {
# Process the log line
&parse_log_prefix($prefix_vars{'t_logprefix'});
}
- # Check if the log line shoud be exclude from the report
+ # Check if the log line should be excluded from the report
if (&validate_log_line($prefix_vars{'t_pid'})) {
$prefix_vars{'t_host'} = 'stderr';
Arguments:
- logfile can be a single log file, a list of files or a shell command
- returning a list of file. If you want to pass log content from stdin
+ logfile can be a single log file, a list of files, or a shell command
+ returning a list of files. If you want to pass log content from stdin
use - as filename. Note that input from stdin will not work with csvlog.
Options:
-a | --average minutes : number of minutes to build the average graphs of
- queries and connections.
+ queries and connections.
-b | --begin datetime : start date/time for the data to be parsed in log.
- -c | --dbclient host : only report what concern the given client host.
+ -c | --dbclient host : only report on entries for the given client host.
-C | --nocomment : remove comments like /* ... */ from queries.
- -d | --dbname database : only report what concern the given database.
+ -d | --dbname database : only report on entries for the given database.
-e | --end datetime : end date/time for the data to be parsed in log.
-f | --format logtype : possible values: syslog,stderr,csv. Default: stderr.
-G | --nograph : disable graphs on HTML output. Enable by default.
-h | --help : show this message and exit.
-i | --ident name : programname used as syslog ident. Default: postgres
-l | --last-parsed file: allow incremental log parsing by registering the
- last datetime and line parsed. Useful if you want
- to watch errors since last run or if you want one
- report per day with a log rotated each week.
- -m | --maxlength size : maximum length of a query, it will be cutted above
- the given size. Default: no truncate
+ last datetime and line parsed. Useful if you want
+ to watch errors since last run or if you want one
+ report per day with a log rotated each week.
+ -m | --maxlength size : maximum length of a query, it will be restricted to
+ the given size. Default: no truncate
-n | --nohighlight : disable SQL code highlighting.
- -N | --appname name : only report what concern the given application name
+ -N | --appname name : only report on entries for given application name
-o | --outfile filename: define the filename for the output. Default depends
- of the output format: out.html, out.txt or out.tsung.
- To dump output to stdout use - as filename.
+ on the output format: out.html, out.txt or out.tsung.
+ To dump output to stdout use - as filename.
-p | --prefix string : give here the value of your custom log_line_prefix
- defined in your postgresql.conf. You may used it only
- if don't have the default allowed formats ot to use
- other custom variables like client ip or application
- name. See examples below.
+ defined in your postgresql.conf. Only use it if you
+ aren't using one of the standard prefixes specified
+ in the pgBadger documentation, such as if your prefix
+ includes additional variables like client ip or
+ application name. See examples below.
-P | --no-prettify : disable SQL queries prettify formatter.
-q | --quiet : don't print anything to stdout, even not a progress bar.
- -s | --sample number : number of query sample to store/display. Default: 3
- -s | --select-only : use it if you want reports on select queries only.
- -t | --top number : number of query to store/display. Default: 20
+ -s | --sample number : number of query samples to store/display. Default: 3
+ -S | --select-only : use it if you want to report select queries only.
+ -t | --top number : number of queries to store/display. Default: 20
-T | --title string : change title of the HTML page report.
- -u | --dbuser username : only report what concern the given user
- -U | --exclude-user username : make report with exclude specified user.
+ -u | --dbuser username : only report on entries for the given user.
+ -U | --exclude-user username : exclude entries for the specified user from report.
-v | --verbose : enable verbose or debug mode. Disabled by default.
-V | --version : show pgBadger version and exit.
- -w | --watch-mode : only report events/errors just like logwatch could do.
+ -w | --watch-mode : only report errors just like logwatch could do.
-x | --extension : output format. Values: text, html or tsung. Default: html
-z | --zcat exec_path : set the full path to the zcat program. Use it if
- zcat or bzcat or unzip is not on your path.
+ zcat or bzcat or unzip is not on your path.
--pie-limit num : pie data lower than num% will show a sum instead.
--exclude-query regex : any query matching the given regex will be excluded
- from the report. For example: "^(VACUUM|COMMIT)"
- you can use this option multiple time.
+ from the report. For example: "^(VACUUM|COMMIT)"
+ You can use this option multiple times.
--exclude-file filename: path of the file which contains all the regex to use
- to exclude queries from the report. One regex per line.
- --include-query regex : any query that do not match the given regex will be
- excluded from the report. For example: "(table_1|table_2)"
- you can use this option multiple time.
+ to exclude queries from the report. One regex per line.
+ --include-query regex : any query that does not match the given regex will be
+ excluded from the report. For example: "(table_1|table_2)"
+ You can use this option multiple times.
--include-file filename: path of the file which contains all the regex of the
- queries to include from the report. One regex per line.
+ queries to include from the report. One regex per line.
--disable-error : do not generate error report.
--disable-hourly : do not generate hourly reports.
--disable-type : do not generate query type report.
--disable-query : do not generate queries reports (slowest, most
- frequent, ...).
+ frequent, ...).
--disable-session : do not generate session report.
--disable-connection : do not generate connection report.
--disable-lock : do not generate lock report.
--disable-temporary : do not generate temporary report.
--disable-checkpoint : do not generate checkpoint report.
- --enable-log_duration : force pgbadger to use log_duration even if
- log_min_duration_statement format is autodetected
- --enable-log_min_duration: force pgbadger to use log_min_duration even if
- log_duration format is autodetected.
+ --enable-log_duration : force pgBadger to use log_duration even if
+ log_min_duration_statement format is autodetected.
+ --enable-log_min_duration: force pgBadger to use log_min_duration even if
+ log_duration format is autodetected.
Examples:
/var/log/postgres.log
pgbadger /var/log/postgresql/postgresql-2012-05-*
pgbadger --exclude-query="^(COPY|COMMIT)" /var/log/postgresql.log
+ pgbadger -b "2012-06-25 10:56:11" -e "2012-06-25 10:59:11" \
+ /var/log/postgresql.log
cat /var/log/postgres.log | pgbadger -
# log prefix with stderr log output
perl pgbadger --prefix '%t [%p]: [%l-1] user=%u,db=%d,client=%h' \
0 4 * * 1 /usr/bin/pgbadger -q `find /var/log/ -mtime -7 -name "postgresql.log*"` \
-o /var/reports/pg_errors-`date +%F`.html -l /var/reports/pgbadger_incremental_file.dat
-This supposes that your log file and HTML report are also rotated every weeks.
+This supposes that your log file and HTML report are also rotated every week.
};
print STDERR "$level: $str\n";
}
-# Normalyze SQL queries by removing parameters
+# Normalize SQL queries by removing parameters
sub normalize_query
{
my $orig_query = shift;
sub dump_as_text
{
- # Global informations
+ # Global information
my $curdate = localtime(time);
my $fmt_nlines = &comma_numbers($nlines);
my $total_time = timestr($td);
print $fh qq{
$report_title
-- Global informations --------------------------------------------------
+- Global information ---------------------------------------------------
Generated on $curdate
Log file: $logfile_str
}
}
- # Show top informations
+ # Show top information
if (!$disable_query && (!$log_duration || $enable_log_min_duration)) {
print $fh "\n- Slowest queries ------------------------------------------------------\n\n";
print $fh "Rank Duration (s) Query\n";
sub dump_error_as_text
{
- # Global informations
+ # Global information
my $curdate = localtime(time);
my $fmt_nlines = &comma_numbers($nlines);
my $total_time = timestr($td);
print $fh qq{
$report_title
-- Global informations --------------------------------------------------
+- Global information ---------------------------------------------------
Generated on $curdate
Log file: $logfile_str
# Dump the html header
&html_header();
- # Global informations
+ # Global information
my $curdate = localtime(time);
my $fmt_nlines = &comma_numbers($nlines);
my $total_time = timestr($td);
next if ($t < $t_min);
last if ($t > $t_max);
- # Average per minutes
+ # Average per minute
$d2 .= "[$t, " . int(($dataavg{average}{"$rd"} || 0) / (60 * $avg_minutes)) . "],";
# Maxi per minute
next if ($t < $t_min);
last if ($t > $t_max);
- # Average per minutes
+ # Average per minute
$d2 .= "[$t, " . int(($dataavg{average}{"$rd"} || 0) / (60 * $avg_minutes)) . "],";
# Maxi per minute
print $fh "</td></tr></table>\n";
}
- # Show top informations
+ # Show top information
if (!$disable_query && (!$log_duration || $enable_log_min_duration)) {
print $fh qq{
<h2 id="SlowestQueriesReport">Slowest queries <a href="#top" title="Back to top">^</a></h2>
# Dump the html header
&html_header();
- # Global informations
+ # Global information
my $curdate = localtime(time);
my $fmt_nlines = &comma_numbers($nlines);
my $total_time = timestr($td);
}
if ($#dbclient >= 0) {
- # Log line do not match the required dbclient
+ # Log line does not match the required dbclient
$prefix_vars{'t_client'} ||= $prefix_vars{'t_hostport'};
if (!$prefix_vars{'t_client'} || !grep(/^$prefix_vars{'t_client'}$/i, @dbclient)) {
delete $cur_info{$t_pid};
}
if ($#dbappname >= 0) {
- # Log line do not match the required dbname
+ # Log line does not match the required dbname
if (!$prefix_vars{'t_appname'} || !grep(/^$prefix_vars{'t_appname'}$/i, @dbappname)) {
delete $cur_info{$t_pid};
return 0;
}
if ($#exclude_user >= 0) {
- # Log line match the excluded dbuser
+ # Log line matches the excluded dbuser
if ($prefix_vars{'t_dbuser'} && grep(/^$prefix_vars{'t_dbuser'}$/i, @exclude_user)) {
delete $cur_info{$t_pid};
return 0;
return;
}
- # Stores pre connection activity
+ # Stores pre-connection activity
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;
return;
}
- # Stores session duration
+ # Store session duration
if (($prefix_vars{'t_loglevel'} eq 'LOG')
&& ($prefix_vars{'t_query'} =~
/disconnection: session time: ([^\s]+) user=([^\s]+) database=([^\s]+) host=([^\s]+) port=(\d+)/))
# Process current query following context
if ($cur_info{$t_pid}{query}) {
- # Remove obsolete connexion storage
+ # Remove obsolete connection storage
delete $conn_received{$cur_info{$t_pid}{pid}};
# The query is complete but we are missing some debug/info/bind parameter logs
$t_duration = $1;
$t_action = $2;
- # Skiping parse and bind logs
+ # Skipping parse and bind logs
return if ($t_action !~ /query|statement|execute|bind/);
} elsif (!$duration_required && ($prefix_vars{'t_query'} =~ s/(query|statement): //is)) {
$t_action = $1;
{
$t_action = $1;
- # Skiping parse and bind logs
+ # Skipping parse and bind logs
return if ($t_action !~ /query|statement|execute|bind/);
} elsif ($prefix_vars{'t_loglevel'} eq 'LOG') {
if ($prefix_vars{'t_query'} !~
my $cur_day_str = "$cur_info{$t_pid}{year}$cur_info{$t_pid}{month}$cur_info{$t_pid}{day}";
my $cur_hour_str = "$cur_info{$t_pid}{hour}";
- # Store the collected informations into global statistics
+ # Store the collected information into global statistics
if ($cur_info{$t_pid}{loglevel} =~ /WARNING|ERROR|FATAL|PANIC|HINT/) {
- # Add log level at beginning of the query and normalyze it
+ # Add log level at beginning of the query and normalize it
$cur_info{$t_pid}{query} = $cur_info{$t_pid}{loglevel} . ": " . $cur_info{$t_pid}{query};
my $normalized_error = &normalize_error($cur_info{$t_pid}{query});
- # Stores total and normalyzed error count
+ # Stores total and normalized error count
$overall_stat{'errors_number'}++;
$overall_stat{'unique_normalized_errors'}{"$normalized_error"}++;
$error_info{$normalized_error}{count}++;
- # Stores normalyzed error count per time
+ # Stores normalized error count per time
$error_info{$normalized_error}{chronos}{"$cur_day_str"}{"$cur_hour_str"}{count}++;
- # Stores normalyzed query samples
+ # Stores normalized query samples
my $cur_last_log_timestamp = "$cur_info{$t_pid}{year}-$cur_info{$t_pid}{month}-$cur_info{$t_pid}{day} " .
"$cur_info{$t_pid}{hour}:$cur_info{$t_pid}{min}:$cur_info{$t_pid}{sec}";
&set_top_error_sample(
# Add a semi-colon at end of the query
$cur_info{$t_pid}{query} .= ';' if (substr($cur_info{$t_pid}{query}, -1, 1) ne ';');
- # Normalyze query
+ # Normalize query
my $normalized = &normalize_query($cur_info{$t_pid}{query});
# Stores global statistics
}
&set_top_slowest($cur_info{$t_pid}{query}, $cur_info{$t_pid}{duration}, $cur_last_log_timestamp, $cur_info{$t_pid}{dbname});
- # Store normalyzed query count
+ # Store normalized query count
$normalyzed_info{$normalized}{count}++;
- # Store normalyzed query total duration
+ # Store normalized query total duration
$normalyzed_info{$normalized}{duration} += $cur_info{$t_pid}{duration};
- # Store normalyzed query count and duration per time
+ # Store normalized query count and duration per time
$normalyzed_info{$normalized}{chronos}{"$cur_day_str"}{"$cur_hour_str"}{count}++;
$normalyzed_info{$normalized}{chronos}{"$cur_day_str"}{"$cur_hour_str"}{duration} += $cur_info{$t_pid}{duration};
- # Store normalyzed query samples
+ # Store normalized query samples
&set_top_sample($normalized, $cur_info{$t_pid}{query}, $cur_info{$t_pid}{duration}, $last_log_timestamp,$cur_info{$t_pid}{dbname});
}
}
-# Normalyze error messages
+# Normalize error messages
sub normalize_error
{
my $orig_query = shift;