Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Small Perl script that aims to replace and outperform pgFouine
Perl
Branch: master

This branch is 610 commits behind dalibo:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
doc
.gitignore
LICENSE
MANIFEST
META.yml
Makefile.PL
README
pgbadger

README

ABSTRACT
    pgBadger - a fast PostgreSQL log analysis report

SYNOPSIS
    pgbadger [options] logfile [...]

            PostgreSQL log analyzer with fully detailed reports and charts.

    Arguments:

      logfile can be a single log file, a list of files, or a shell command
      returning a list of file.

    Options:

        -l | --logfile filename: path to the PostgreSQL log file to parse. It can
                                 be a plain text log or a gzip compressed file
                                 with the .gz extension. Note that this option is
                                 DEPRECATED: set logfile as a command line argument
                                 instead.
        -f | --format logtype  : possible values: syslog,stderr,csv. Default: stderr
        -o | --outfile filename: define the filename for the output. Default depends
                                 on the output format: out.html or out.txt. To dump
                                 output to stdout use - as filename.
        -i | --ident name      : programname used as syslog ident. Default: postgres
        -h | --help            : show this message and exit.
        -d | --dbname database : only report what concerns the given database
        -u | --dbuser username : only report what concerns the given user
        -t | --top number      : number of queries to store/display. Default: 20
        -s | --sample number   : number of query samples to store/display. Default:3
        -x | --extension       : output format. Values: text or html. Default: html
        -m | --maxlength size  : maximum length of a query: it will be cut above
                                 the given size. Default: no truncate
        -g | --graph           : generate graphs using the Flotr2 javascript library
        -b | --begin datetime  : start date/time for the data to be parsed in log.
        -e | --end datetime    : end date/time for the data to be parsed in log.
        -q | --quiet           : don't print anything to stdout.
        -p | --progress         show a progress bar, quiet mode is automatically
                                 enabled with this option.
        -w | -watch-mode       : only report errors just like logwatch could do.
        -z | --zcat exec_path  : set the full path to the zcat program. Use it if
                                 zcat is not on your path or you want to use gzcat.
        --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 times.
        --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, ...).
        --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.

    Examples:

            pgbadger -p -g /var/log/postgresql.log
            pgbadger -p -g /var/log/postgres.log.2.gz /var/log/postgres.log.1.gz /var/log/postgres.log
            pgbadger -p -g /var/log/postgresql/postgresql-2012-05-*
            pgbadger -p -g --exclude-query="^(COPY|COMMIT)" /var/log/postgresql.log
            pgbadger -p -g -b "2012-06-25 10:56:11" -e "2012-06-25 10:59:11" /var/log/postgresql.log

    Reporting errors every week by cron job:

        30 23 * * 1 /usr/bin/pgbadger -q -w /var/log/postgresql.log -o /var/reports/pg_errors.html

        This suppose 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
    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 able to autodetect your log file format (syslog, stderr or
    csvlog). It is designed to parse huge log files, as well as gzip
    compressed file. See a complete list of features below.

FEATURE
    pgBadger reports everything about your SQL queries:

            Overall statistics.
            The slowest queries.
            Queries that took up the most time.
            The most frequent queries.
            The most frequent errors.

    The following reports are also available with hourly charts:

            Hourly queries statistics.
            Hourly temporary file statistics.
            Hourly checkpoints statistics.
            Locks statistics.
            Queries by type (select/insert/update/delete).
            Sessions per database/user/client.
            Connections per database/user/client.

    All charts are zoomable and can be saved as PNG images.

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.

    If you planned to parse PostgreSQL CSV log files you might need some
    Perl Modules:

            Text::CSV - to parse PostgreSQL CSV log files.

    This module is optional, if you don't have PostgreSQL log in the CSV
    format you don't need to install it.

POSTGRESQL CONFIGURATION
    You must enable some configuration directives in your postgresql.conf
    before starting.

    You must first enable SQL query logging to have something to parse:

            log_min_duration_statement = 0

    Note that pgBadger is not compatible with statements logs provided by
    log_statement and log_duration.

    With 'stderr' log format, log_line_prefix must be at least:

            log_line_prefix = '%t [%p]: [%l-1] '

    Log line prefix could add user and database name as follows:

            log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d '

    or for syslog log file format:

            log_line_prefix = 'user=%u,db=%d '

    Log line prefix for stderr output could also be:

            log_line_prefix = '%t [%p]: [%l-1] db=%d,user=%u '

    or for syslog output:

            log_line_prefix = 'db=%d,user=%u '

    You need to enable other parameters in postgresql.conf to get more
    informations from your log files:

            log_checkpoints = on
            log_connections = on
            log_disconnections = 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.

INSTALLATION
    Download the tarball from github and unpack the archive as follow:

            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.

    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.

    For example, to install everything just like Debian does, proceed as
    follow:

            perl Makefile.PL INSTALLDIRS=vendor

    By default INSTALLDIRS is set to site.

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.

LICENSE
    pgBadger is free software distributed under the simplified BSD License.

Something went wrong with that request. Please try again.