### Install pgBadger with Debian-style paths Source: https://github.com/darold/pgbadger/blob/master/README.md Use the INSTALLDIRS argument to install files into /usr/bin and /usr/share. ```bash perl Makefile.PL INSTALLDIRS=vendor ``` -------------------------------- ### Install pgBadger from source Source: https://github.com/darold/pgbadger/blob/master/README.md Standard commands to unpack and install the pgBadger Perl script and man pages. ```bash tar xzf pgbadger-11.x.tar.gz cd pgbadger-11.x/ perl Makefile.PL make && sudo make install ``` -------------------------------- ### Install JSON::XS Module on Debian Source: https://github.com/darold/pgbadger/blob/master/HACKING.md Install the JSON::XS Perl module on Debian-based systems using apt-get. ```bash sudo apt-get install libjson-xs-perl ``` -------------------------------- ### Install JSON::XS Module on RPM Systems Source: https://github.com/darold/pgbadger/blob/master/HACKING.md Install the JSON::XS Perl module on RPM-based systems using yum. ```bash sudo yum install perl-JSON-XS ``` -------------------------------- ### Rebuild project documentation Source: https://github.com/darold/pgbadger/blob/master/CONTRIBUTING.md Execute these commands to regenerate the README files from the updated POD documentation. ```shell $ perl Makefile.PL && make README ``` -------------------------------- ### Run pgBadger Test Suite with prove Source: https://github.com/darold/pgbadger/blob/master/HACKING.md Execute the TAP-compatible test suite for pgBadger using the 'prove' command. ```bash $ prove t/01_lint.t ......... ok t/02_basics.t ....... ok t/03_consistency.t .. ok All tests successful. Files=3, Tests=13, 6 wallclock secs ( 0.01 usr 0.01 sys + 5.31 cusr 0.16 csys = 5.49 CPU) Result: PASS $ ``` -------------------------------- ### Enable additional PostgreSQL logging parameters Source: https://github.com/darold/pgbadger/blob/master/README.md Required settings to capture checkpoints, connections, and other diagnostic information. ```ini log_checkpoints = on log_connections = on log_disconnections = on log_lock_waits = on log_temp_files = 0 log_autovacuum_min_duration = 0 log_error_verbosity = default ``` -------------------------------- ### Manually Run pgBadger Tests Source: https://github.com/darold/pgbadger/blob/master/HACKING.md Manually run the pgBadger test suite by first configuring the build and then executing the tests. ```bash $ perl Makefile.PL && make test Checking if your kit is complete... Looks good Generating a Unix-style Makefile Writing Makefile for pgBadger Writing MYMETA.yml and MYMETA.json cp pgbadger blib/script/pgbadger "/usr/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/pgbadger PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/01_lint.t ......... ok t/02_basics.t ....... ok t/03_consistency.t .. ok All tests successful. Files=3, Tests=13, 6 wallclock secs ( 0.03 usr 0.00 sys + 5.39 cusr 0.14 csys = 5.56 CPU) Result: PASS $ ``` -------------------------------- ### Basic Log Analysis Source: https://github.com/darold/pgbadger/blob/master/README.md Parses a local PostgreSQL log file. ```bash pgbadger /var/log/postgresql.log ``` -------------------------------- ### Create Incremental Binary Data Files Source: https://github.com/darold/pgbadger/blob/master/README.md This command generates incremental data files in binary format from PostgreSQL log files. It uses the --last-parsed option to keep track of the last parsed state, allowing for hourly refreshes. ```bash pgbadger --last-parsed .pgbadger_last_state_file -o sunday/hourX.bin /var/log/pgsql/postgresql-Sun.log ``` -------------------------------- ### Configure PostgreSQL log line prefix Source: https://github.com/darold/pgbadger/blob/master/README.md Define the log_line_prefix format to include required time and process identifiers. ```ini log_line_prefix = '%t [%p]: ' log_line_prefix = '%t [%p]: user=%u,db=%d,app=%a,client=%h ' log_line_prefix = 'user=%u,db=%d,app=%a,client=%h ' log_line_prefix = '%t [%p]: db=%d,user=%u,app=%a,client=%h ' log_line_prefix = 'db=%d,user=%u,app=%a,client=%h ' ``` -------------------------------- ### Generate a cumulative monthly report Source: https://github.com/darold/pgbadger/blob/master/README.md Create a monthly report from incremental report files using the --month-report option. ```bash pgbadger --month-report 2919-05 /path/to/incremental/reports/ ``` -------------------------------- ### Generate Hourly Binary Log Files Source: https://github.com/darold/pgbadger/blob/master/README.md This sequence of commands generates individual binary data files for each hour's log rotation. Each command processes a specific log file and outputs a binary file named according to the hour. ```bash pgbadger -o day1/hour01.bin /var/log/pgsql/pglog/postgresql-2012-03-23_10.log ``` ```bash pgbadger -o day1/hour02.bin /var/log/pgsql/pglog/postgresql-2012-03-23_11.log ``` ```bash pgbadger -o day1/hour03.bin /var/log/pgsql/pglog/postgresql-2012-03-23_12.log ``` -------------------------------- ### Generate HTML Report from Binary Files Source: https://github.com/darold/pgbadger/blob/master/README.md This command generates an HTML report from previously created binary data files. It processes all binary files in the specified directory. ```bash pgbadger sunday/*.bin ``` -------------------------------- ### Clean pgBadger Build Artifacts Source: https://github.com/darold/pgbadger/blob/master/HACKING.md Clean up build artifacts and the old Makefile for pgBadger. ```bash make clean && rm Makefile.old ``` -------------------------------- ### Specify zcat utility path Source: https://github.com/darold/pgbadger/blob/master/README.md Provides a custom path for the zcat utility when dealing with compressed log files, useful if the default utility is not found in the PATH. ```bash --zcat="/usr/local/bin/gunzip -c" ``` ```bash --zcat="/usr/local/bin/bzip2 -dc" ``` ```bash --zcat="C:\\tools\\unzip -p" ``` -------------------------------- ### Custom Log Line Prefix (Syslog) Source: https://github.com/darold/pgbadger/blob/master/README.md Parses log files with a custom prefix format for syslog output. ```bash pgbadger --prefix 'user=%u,db=%d,client=%h,appname=%a' /pglog/postgresql-2012-08-21* ``` -------------------------------- ### Parse from Standard Input Source: https://github.com/darold/pgbadger/blob/master/README.md Parses log data piped from standard input. ```bash cat /var/log/postgres.log | pgbadger - ``` -------------------------------- ### Configure PostgreSQL log duration Source: https://github.com/darold/pgbadger/blob/master/README.md Set the minimum duration for statement logging to capture query statistics. ```ini log_min_duration_statement = 0 ``` -------------------------------- ### Parse Local and Remote Logs Together Source: https://github.com/darold/pgbadger/blob/master/README.md Parses a local PostgreSQL log file and a remote pgbouncer log file simultaneously. ```bash pgbadger /var/log/postgresql/postgresql-10.1-main.log ssh://username@172.12.110.14/pgbouncer.log ``` -------------------------------- ### Analyze CloudNativePG logs Source: https://github.com/darold/pgbadger/blob/master/README.md Process logs generated by the CloudNativePG Kubernetes operator using the jsonlog format. ```bash pgbadger -f jsonlog -o cnpg_out.html cnpg.log ``` -------------------------------- ### Analyze CloudSQL PostgreSQL logs Source: https://github.com/darold/pgbadger/blob/master/README.md Force the jsonlog format when processing CloudSQL logs if auto-detection fails. ```bash pgbadger -f jsonlog -o cloudsql_out.html cloudsql.log ``` -------------------------------- ### Specify Date Range Source: https://github.com/darold/pgbadger/blob/master/README.md Parses a log file within a specified date and time range. ```bash pgbadger -b "2012-06-25 10:56:11" -e "2012-06-25 10:59:11" /var/log/postgresql.log ``` -------------------------------- ### Custom Log Line Prefix Source: https://github.com/darold/pgbadger/blob/master/README.md Parses log files with a custom prefix format for stderr output. ```bash pgbadger --prefix '%t [%p]: user=%u,db=%d,client=%h' /pglog/postgresql-2012-08-21* ``` -------------------------------- ### Generate Monthly Report Source: https://github.com/darold/pgbadger/blob/master/README.md Use this command to generate a monthly cumulative report for a specific month and year. Ensure to include options like -X, -E, or -R if they were used for initial report generation. ```bash pgbadger -X --month-report 2019-08 /var/www/pg_reports/ ``` ```bash pgbadger -E -X --month-report 2019-08 /var/www/pg_reports/ ``` -------------------------------- ### Parse Log Files with Wildcards Source: https://github.com/darold/pgbadger/blob/master/README.md Parses log files matching a wildcard pattern. ```bash pgbadger /var/log/postgresql/postgresql-2012-05-* ``` -------------------------------- ### Parse Multiple Log Files Source: https://github.com/darold/pgbadger/blob/master/README.md Parses multiple local PostgreSQL log files, including rotated and compressed logs. ```bash pgbadger /var/log/postgres.log.2.gz /var/log/postgres.log.1.gz /var/log/postgres.log ``` -------------------------------- ### Set PostgreSQL message locale Source: https://github.com/darold/pgbadger/blob/master/README.md Ensure log messages are in English for proper parsing. ```ini lc_messages='en_US.UTF-8' lc_messages='C' ``` -------------------------------- ### Weekly Incremental Report via Cron Source: https://github.com/darold/pgbadger/blob/master/README.md Schedules a weekly cron job to generate an incremental HTML report using logs from the past 7 days. ```bash 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 ``` -------------------------------- ### Refresh HTML Report from Hourly Binary Files Source: https://github.com/darold/pgbadger/blob/master/README.md This command refreshes an HTML report using multiple hourly binary data files. It consolidates the data from all specified binary files into a single HTML report. ```bash pgbadger -o day1_report.html day1/*.bin ``` -------------------------------- ### Auto-Generated Incremental Reports Source: https://github.com/darold/pgbadger/blob/master/README.md Configures pgbadger to generate daily and weekly incremental reports automatically. ```bash 0 4 * * * /usr/bin/pgbadger -I -q /var/log/postgresql/postgresql.log.1 -O /var/www/pg_reports/ ``` -------------------------------- ### Weekly Error Reporting via Cron Source: https://github.com/darold/pgbadger/blob/master/README.md Schedules a weekly cron job to generate an HTML report of PostgreSQL errors. ```bash 30 23 * * 1 /usr/bin/pgbadger -q -w /var/log/postgresql.log -o /var/reports/pg_errors.html ``` -------------------------------- ### Parse Heroku Logs Source: https://github.com/darold/pgbadger/blob/master/README.md Streams Heroku PostgreSQL logs in logplex format to pgbadger via standard input. ```bash heroku logs -p postgres | pgbadger -f logplex -o heroku.html - ``` -------------------------------- ### Analyze RDS PostgreSQL logs Source: https://github.com/darold/pgbadger/blob/master/README.md Use the -f rds flag to process logs from Amazon RDS instances. ```bash pgbadger -f rds -o rds_out.html rds.log ``` -------------------------------- ### Parse Remote Log via FTP Source: https://github.com/darold/pgbadger/blob/master/README.md Parses a remote log file using FTP protocol with specified username. ```bash pgbadger ftp://username@172.12.110.14/postgresql-10.1-main.log ``` -------------------------------- ### Incremental Reports with Retention Source: https://github.com/darold/pgbadger/blob/master/README.md Generates incremental reports and retains reports for a specified number of weeks. ```bash /usr/bin/pgbadger --retention 2 -I -q /var/log/postgresql/postgresql.log.1 -O /var/www/pg_reports/ ``` -------------------------------- ### Parse Remote Log via HTTP Source: https://github.com/darold/pgbadger/blob/master/README.md Parses a remote log file using HTTP protocol. ```bash pgbadger http://172.12.110.1//var/log/postgresql/postgresql-10.1-main.log ``` -------------------------------- ### Rebuild Incremental Reports Source: https://github.com/darold/pgbadger/blob/master/README.md Rebuilds all incremental HTML reports and updates resource files (JS and CSS). ```bash rm /path/to/reports/*.js rm /path/to/reports/*.css pgbadger -X -I -O /path/to/reports/ --rebuild ``` -------------------------------- ### Parallel Log Processing Source: https://github.com/darold/pgbadger/blob/master/README.md Uses multiple CPU cores to speed up log file parsing. ```bash pgbadger -j 8 /pglog/postgresql-10.1-main.log ``` -------------------------------- ### Exclude Queries Source: https://github.com/darold/pgbadger/blob/master/README.md Parses a log file while excluding specific queries from the report. ```bash pgbadger --exclude-query="^(COPY|COMMIT)" /var/log/postgresql.log ``` -------------------------------- ### Parse Remote Log via SSH Source: https://github.com/darold/pgbadger/blob/master/README.md Parses a remote log file using SSH protocol with a custom port. ```bash pgbadger ssh://username@172.12.110.14:2222//var/log/postgresql/postgresql-10.1-main.log* ``` -------------------------------- ### Exclude Application Name Source: https://github.com/darold/pgbadger/blob/master/README.md Excludes logs from a specific application name, such as 'pg_dump', to simplify report analysis. ```bash pgbadger --exclude-appname "pg_dump" postgresql.log ``` -------------------------------- ### Parse Journalctl Output Source: https://github.com/darold/pgbadger/blob/master/README.md Parses output from journalctl as if it were a log file. ```bash pgbadger --journalctl 'journalctl -u postgresql-9.5' ``` -------------------------------- ### Parse Remote Journalctl Output Source: https://github.com/darold/pgbadger/blob/master/README.md Parses journalctl output from a remote host. ```bash pgbadger -r 192.168.1.159 --journalctl 'journalctl -u postgresql-9.5' ``` -------------------------------- ### Exclude Time Periods from Report Source: https://github.com/darold/pgbadger/blob/master/README.md Excludes specific time periods, such as pg_dump operations, from the report to avoid skewing query performance analysis. ```bash pgbadger --exclude-time "2013-09-.* (23|13):.*" postgresql.log ``` -------------------------------- ### Exclude Time Period from Analysis Source: https://github.com/darold/pgbadger/wiki/20131031-pgbadger-v4 Use the --exclude-time option to exclude log entries matching a given time regular expression from the report analysis. This is useful for filtering out long-running batch processes like pg_dump. ```bash pgbadger --exclude-time "2013-09-.* 13:.*" postgresql.log ``` ```bash pgbadger --exclude-time '2013-09-\d+ 13:[0-3]' --exclude-time '2013-09-\d+ 22:[0-3]' postgresql.log ``` ```bash pgbadger --exclude-time '2013-09-\d+ (13|22):[0-3]' postgresql.log ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.