Debian Codegraph @

doc/pgBadger.pod

raw
1 =head1 NAME
2
3 pgBadger - a fast PostgreSQL log analysis report
4
5 =head1 SYNOPSIS
6
7 Usage: pgbadger [options] logfile [...]
8
9 PostgreSQL log analyzer with fully detailed reports and graphs.
10
11 Arguments:
12
13 logfile can be a single log file, a list of files, or a shell command
14 returning a list of files. If you want to pass log content from stdin
15 use - as filename. Note that input from stdin will not work with csvlog.
16
17 Options:
18
19 -a | --average minutes : number of minutes to build the average graphs of
20 queries and connections. Default 5 minutes.
21 -A | --histo-average min: number of minutes to build the histogram graphs
22 of queries. Default 60 minutes.
23 -b | --begin datetime : start date/time for the data to be parsed in log
24 (either a timestamp or a time)
25 -c | --dbclient host : only report on entries for the given client host.
26 -C | --nocomment : remove comments like /* ... */ from queries.
27 -d | --dbname database : only report on entries for the given database.
28 -D | --dns-resolv : client ip addresses are replaced by their DNS name.
29 Be warned that this can really slow down pgBadger.
30 -e | --end datetime : end date/time for the data to be parsed in log
31 (either a timestamp or a time)
32 -E | --explode : explode the main report by generating one report
33 per database. Global information not related to a
34 database is added to the postgres database report.
35 -f | --format logtype : possible values: syslog, syslog2, stderr, jsonlog,
36 csv, pgbouncer, logplex, rds and redshift. Use this
37 option when pgBadger is not able to detect the log
38 format.
39 -G | --nograph : disable graphs on HTML output. Enabled by default.
40 -h | --help : show this message and exit.
41 -H | --html-outdir path: path to directory where HTML report must be written
42 in incremental mode, binary files stay on directory
43 defined with -O, --outdir option.
44 -i | --ident name : programname used as syslog ident. Default: postgres
45 -I | --incremental : use incremental mode, reports will be generated by
46 days in a separate directory, --outdir must be set.
47 -j | --jobs number : number of jobs to run at same time for a single log
48 file. Run as single by default or when working with
49 csvlog format.
50 -J | --Jobs number : number of log files to parse in parallel. Process
51 one file at a time by default.
52 -l | --last-parsed file: allow incremental log parsing by registering the
53 last datetime and line parsed. Useful if you want
54 to watch errors since last run or if you want one
55 report per day with a log rotated each week.
56 -L | --logfile-list file:file containing a list of log files to parse.
57 -m | --maxlength size : maximum length of a query, it will be restricted to
58 the given size. Default truncate size is 100000.
59 -M | --no-multiline : do not collect multiline statements to avoid garbage
60 especially on errors that generate a huge report.
61 -N | --appname name : only report on entries for given application name
62 -o | --outfile filename: define the filename for the output. Default depends
63 on the output format: out.html, out.txt, out.bin,
64 or out.json. This option can be used multiple times
65 to output several formats. To use json output, the
66 Perl module JSON::XS must be installed, to dump
67 output to stdout, use - as filename.
68 -O | --outdir path : directory where out files must be saved.
69 -p | --prefix string : the value of your custom log_line_prefix as
70 defined in your postgresql.conf. Only use it if you
71 aren't using one of the standard prefixes specified
72 in the pgBadger documentation, such as if your
73 prefix includes additional variables like client IP
74 or application name. MUST contain escape sequences
75 for time (%t, %m or %n) and processes (%p or %c).
76 See examples below.
77 -P | --no-prettify : disable SQL queries prettify formatter.
78 -q | --quiet : don't print anything to stdout, not even a progress
79 bar.
80 -Q | --query-numbering : add numbering of queries to the output when using
81 options --dump-all-queries or --normalized-only.
82 -r | --remote-host ip : set the host where to execute the cat command on
83 remote log file to parse the file locally.
84 -R | --retention N : number of weeks to keep in incremental mode. Defaults
85 to 0, disabled. Used to set the number of weeks to
86 keep in output directory. Older weeks and days
87 directories are automatically removed.
88 -s | --sample number : number of query samples to store. Default: 3.
89 -S | --select-only : only report SELECT queries.
90 -t | --top number : number of queries to store/display. Default: 20.
91 -T | --title string : change title of the HTML page report.
92 -u | --dbuser username : only report on entries for the given user.
93 -U | --exclude-user username : exclude entries for the specified user from
94 report. Can be used multiple time.
95 -v | --verbose : enable verbose or debug mode. Disabled by default.
96 -V | --version : show pgBadger version and exit.
97 -w | --watch-mode : only report errors just like logwatch could do.
98 -W | --wide-char : encode html output of queries into UTF8 to avoid
99 Perl message "Wide character in print".
100 -x | --extension : output format. Values: text, html, bin or json.
101 Default: html
102 -X | --extra-files : in incremental mode allow pgBadger to write CSS and
103 JS files in the output directory as separate files.
104 -z | --zcat exec_path : set the full path to the zcat program. Use it if
105 zcat, bzcat or unzip is not in your path.
106 -Z | --timezone +/-XX : Set the number of hours from GMT of the timezone.
107 Use this to adjust date/time in JavaScript graphs.
108 The value can be an integer, ex.: 2, or a float,
109 ex.: 2.5.
110 --pie-limit num : pie data lower than num% will show a sum instead.
111 --exclude-query regex : any query matching the given regex will be excluded
112 from the report. For example: "^(VACUUM|COMMIT)"
113 You can use this option multiple times.
114 --exclude-file filename: path of the file that contains each regex to use
115 to exclude queries from the report. One regex per
116 line.
117 --include-query regex : any query that does not match the given regex will
118 be excluded from the report. You can use this
119 option multiple times. For example: "(tbl1|tbl2)".
120 --include-file filename: path of the file that contains each regex to the
121 queries to include from the report. One regex per
122 line.
123 --disable-error : do not generate error report.
124 --disable-hourly : do not generate hourly report.
125 --disable-type : do not generate report of queries by type, database
126 or user.
127 --disable-query : do not generate query reports (slowest, most
128 frequent, queries by users, by database, ...).
129 --disable-session : do not generate session report.
130 --disable-connection : do not generate connection report.
131 --disable-lock : do not generate lock report.
132 --disable-temporary : do not generate temporary report.
133 --disable-checkpoint : do not generate checkpoint/restartpoint report.
134 --disable-autovacuum : do not generate autovacuum report.
135 --charset : used to set the HTML charset to be used.
136 Default: utf-8.
137 --csv-separator : used to set the CSV field separator, default: ,
138 --exclude-time regex : any timestamp matching the given regex will be
139 excluded from the report. Example: "2013-04-12 .*"
140 You can use this option multiple times.
141 --include-time regex : only timestamps matching the given regex will be
142 included in the report. Example: "2013-04-12 .*"
143 You can use this option multiple times.
144 --exclude-db name : exclude entries for the specified database from
145 report. Example: "pg_dump". Can be used multiple
146 times.
147 --exclude-appname name : exclude entries for the specified application name
148 from report. Example: "pg_dump". Can be used
149 multiple times.
150 --exclude-line regex : exclude any log entry that will match the given
151 regex. Can be used multiple times.
152 --exclude-client name : exclude log entries for the specified client ip.
153 Can be used multiple times.
154 --anonymize : obscure all literals in queries, useful to hide
155 confidential data.
156 --noreport : no reports will be created in incremental mode.
157 --log-duration : force pgBadger to associate log entries generated
158 by both log_duration = on and log_statement = 'all'
159 --enable-checksum : used to add an md5 sum under each query report.
160 --journalctl command : command to use to replace PostgreSQL logfile by
161 a call to journalctl. Basically it might be:
162 journalctl -u postgresql-9.5
163 --pid-dir path : set the path where the pid file must be stored.
164 Default /tmp
165 --pid-file file : set the name of the pid file to manage concurrent
166 execution of pgBadger. Default: pgbadger.pid
167 --rebuild : used to rebuild all html reports in incremental
168 output directories where there's binary data files.
169 --pgbouncer-only : only show PgBouncer-related menus in the header.
170 --start-monday : in incremental mode, calendar weeks start on
171 Sunday. Use this option to start on a Monday.
172 --iso-week-number : in incremental mode, calendar weeks start on
173 Monday and respect the ISO 8601 week number, range
174 01 to 53, where week 1 is the first week that has
175 at least 4 days in the new year.
176 --normalized-only : only dump all normalized queries to out.txt
177 --log-timezone +/-XX : Set the number of hours from GMT of the timezone
178 that must be used to adjust date/time read from
179 log file before beeing parsed. Using this option
180 makes log search with a date/time more difficult.
181 The value can be an integer, ex.: 2, or a float,
182 ex.: 2.5.
183 --prettify-json : use it if you want json output to be prettified.
184 --month-report YYYY-MM : create a cumulative HTML report over the specified
185 month. Requires incremental output directories and
186 the presence of all necessary binary data files
187 --day-report YYYY-MM-DD: create an HTML report over the specified day.
188 Requires incremental output directories and the
189 presence of all necessary binary data files
190 --noexplain : do not process lines generated by auto_explain.
191 --command CMD : command to execute to retrieve log entries on
192 stdin. pgBadger will open a pipe to the command
193 and parse log entries generated by the command.
194 --no-week : inform pgbadger to not build weekly reports in
195 incremental mode. Useful if it takes too much time.
196 --explain-url URL : use it to override the url of the graphical explain
197 tool. Default: https://explain.depesz.com/
198 --tempdir DIR : set directory where temporary files will be written
199 Default: File::Spec->tmpdir() || '/tmp'
200 --no-process-info : disable changing process title to help identify
201 pgbadger process, some system do not support it.
202 --dump-all-queries : dump all queries found in the log file replacing
203 bind parameters included in the queries at their
204 respective placeholders positions.
205 --keep-comments : do not remove comments from normalized queries. It
206 can be useful if you want to distinguish between
207 same normalized queries.
208 --no-progressbar : disable progressbar.
209 --dump-raw-csv : parse the log and dump the information into CSV
210 format. No further processing is done, no report.
211 --include-pid PID : only report events related to the session pid (%p).
212 Can be used multiple time.
213 --include-session ID : only report events related to the session id (%c).
214 Can be used multiple time.
215 --histogram-query VAL : use custom inbound for query times histogram.
216 Default inbound in milliseconds:
217 0,1,5,10,25,50,100,500,1000,10000
218 --histogram-session VAL : use custom inbound for session times histogram.
219 Default inbound in milliseconds:
220 0,500,1000,30000,60000,600000,1800000,3600000,28800000
221 --no-fork : do not fork any process, for debugging purpose.
222
223 pgBadger is able to parse a remote log file using a passwordless ssh connection.
224 Use -r or --remote-host to set the host IP address or hostname. There are also
225 some additional options to fully control the ssh connection.
226
227 --ssh-program ssh path to the ssh program to use. Default: ssh.
228 --ssh-port port ssh port to use for the connection. Default: 22.
229 --ssh-user username connection login name. Defaults to running user.
230 --ssh-identity file path to the identity file to use.
231 --ssh-timeout second timeout to ssh connection failure. Default: 10 sec.
232 --ssh-option options list of -o options to use for the ssh connection.
233 Options always used:
234 -o ConnectTimeout=$ssh_timeout
235 -o PreferredAuthentications=hostbased,publickey
236 --ssh-sudo Runs all commands on remote host as sudo, will not work
237 with wildcard filenames
238
239 Log file to parse can also be specified using an URI, supported protocols are
240 http[s] and [s]ftp. The curl command will be used to download the file, and the
241 file will be parsed during download. The ssh protocol is also supported and will
242 use the ssh command like with the remote host use. See examples bellow.
243
244 Return codes:
245
246 0: on success
247 1: die on error
248 2: if it has been interrupted using ctr+c for example
249 3: the pid file already exists or can not be created
250 4: no log file was given at command line
251
252 Examples:
253
254 pgbadger /var/log/postgresql.log
255 pgbadger /var/log/postgres.log.2.gz /var/log/postgres.log.1.gz /var/log/postgres.log
256 pgbadger /var/log/postgresql/postgresql-2012-05-*
257 pgbadger --exclude-query="^(COPY|COMMIT)" /var/log/postgresql.log
258 pgbadger -b "2012-06-25 10:56:11" -e "2012-06-25 10:59:11" /var/log/postgresql.log
259 cat /var/log/postgres.log | pgbadger -
260 # Log line prefix with stderr log output
261 pgbadger --prefix '%t [%p]: user=%u,db=%d,client=%h' /pglog/postgresql-2012-08-21*
262 pgbadger --prefix '%m %u@%d %p %r %a : ' /pglog/postgresql.log
263 # Log line prefix with syslog log output
264 pgbadger --prefix 'user=%u,db=%d,client=%h,appname=%a' /pglog/postgresql-2012-08-21*
265 # Use my 8 CPUs to parse my 10GB file faster, much faster
266 pgbadger -j 8 /pglog/postgresql-10.1-main.log
267
268 Use URI notation for remote log file:
269
270 pgbadger http://172.12.110.1//var/log/postgresql/postgresql-10.1-main.log
271 pgbadger ftp://[email protected]/postgresql-10.1-main.log
272 pgbadger ssh://[email protected]:2222//var/log/postgresql/postgresql-10.1-main.log*
273
274 You can use together a local PostgreSQL log and a remote pgbouncer log file to parse:
275
276 pgbadger /var/log/postgresql/postgresql-10.1-main.log ssh://[email protected]/pgbouncer.log
277
278 Reporting errors every week by cron job:
279
280 30 23 * * 1 /usr/bin/pgbadger -q -w /var/log/postgresql.log -o /var/reports/pg_errors.html
281
282 Generate report every week using incremental behavior:
283
284 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
285
286 This supposes that your log file and HTML report are also rotated every week.
287
288 Or better, use the auto-generated incremental reports:
289
290 0 4 * * * /usr/bin/pgbadger -I -q /var/log/postgresql/postgresql.log.1 -O /var/www/pg_reports/
291
292 will generate a report per day and per week.
293
294 In incremental mode, you can also specify the number of weeks to keep in the
295 reports:
296
297 /usr/bin/pgbadger --retention 2 -I -q /var/log/postgresql/postgresql.log.1 -O /var/www/pg_reports/
298
299 If you have a pg_dump at 23:00 and 13:00 each day during half an hour, you can
300 use pgBadger as follow to exclude these periods from the report:
301
302 pgbadger --exclude-time "2013-09-.* (23|13):.*" postgresql.log
303
304 This will help avoid having COPY statements, as generated by pg_dump, on top of
305 the list of slowest queries. You can also use --exclude-appname "pg_dump" to
306 solve this problem in a simpler way.
307
308 You can also parse journalctl output just as if it was a log file:
309
310 pgbadger --journalctl 'journalctl -u postgresql-9.5'
311
312 or worst, call it from a remote host:
313
314 pgbadger -r 192.168.1.159 --journalctl 'journalctl -u postgresql-9.5'
315
316 you don't need to specify any log file at command line, but if you have other
317 PostgreSQL log files to parse, you can add them as usual.
318
319 To rebuild all incremental html reports after, proceed as follow:
320
321 rm /path/to/reports/*.js
322 rm /path/to/reports/*.css
323 pgbadger -X -I -O /path/to/reports/ --rebuild
324
325 it will also update all resource files (JS and CSS). Use -E or --explode
326 if the reports were built using this option.
327
328 pgBadger also supports Heroku PostgreSQL logs using logplex format:
329
330 heroku logs -p postgres | pgbadger -f logplex -o heroku.html -
331
332 this will stream Heroku PostgreSQL log to pgbadger through stdin.
333
334 pgBadger can auto detect RDS and cloudwatch PostgreSQL logs using
335 rds format:
336
337 pgbadger -f rds -o rds_out.html rds.log
338
339 Each CloudSQL Postgresql log is a fairly normal PostgreSQL log, but encapsulated
340 in JSON format. It is autodetected by pgBadger but in case you need to force
341 the log format use `jsonlog`:
342
343 pgbadger -f jsonlog -o cloudsql_out.html cloudsql.log
344
345 This is the same as with the jsonlog extension, the json format is different
346 but pgBadger can parse both formats.
347
348 pgBadger also supports logs produced by CloudNativePG Postgres operator for Kubernetes:
349
350 pgbadger -f jsonlog -o cnpg_out.html cnpg.log
351
352 To create a cumulative report over a month use command:
353
354 pgbadger --month-report 2919-05 /path/to/incremental/reports/
355
356 this will add a link to the month name into the calendar view in
357 incremental reports to look at report for month 2019 May.
358 Use -E or --explode if the reports were built using this option.
359
360 =head1 DESCRIPTION
361
362 pgBadger is a PostgreSQL log analyzer built for speed providing fully
363 detailed reports based on your PostgreSQL log files. It's a small standalone
364 Perl script that outperforms any other PostgreSQL log analyzer.
365
366 It is written in pure Perl and uses a JavaScript library (flotr2) to draw
367 graphs so that you don't need to install any additional Perl modules or
368 other packages. Furthermore, this library gives us more features such
369 as zooming. pgBadger also uses the Bootstrap JavaScript library and
370 the FontAwesome webfont for better design. Everything is embedded.
371
372 pgBadger is able to autodetect your log file format (syslog, stderr, csvlog
373 or jsonlog) if the file is long enough. It is designed to parse huge log
374 files as well as compressed files. Supported compressed formats are gzip,
375 bzip2, lz4, xz, zip and zstd. For the xz format you must have an xz version
376 higher than 5.05 that supports the --robot option. lz4 files must be
377 compressed with the --content-size option for pgbadger to determine the
378 uncompressed file size. For the complete list of features, see below.
379
380
381 All charts are zoomable and can be saved as PNG images.
382
383 You can also limit pgBadger to only report errors or remove any part of the
384 report using command-line options.
385
386 pgBadger supports any custom format set in the log_line_prefix directive of
387 your postgresql.conf file as long as it at least specifies the %t, %m or %n
388 and %p or %c patterns.
389
390 pgBadger allows parallel processing of a single log file or multiple
391 files through the use of the -j option specifying the number of CPUs.
392
393 If you want to save system performance you can also use log_duration instead of
394 log_min_duration_statement to have reports on duration and number of queries only.
395
396 =head1 FEATURE
397
398 pgBadger reports everything about your SQL queries:
399
400 Overall statistics.
401 The most frequent waiting queries.
402 Queries that waited the most.
403 Queries generating the most temporary files.
404 Queries generating the largest temporary files.
405 The slowest queries.
406 Queries that took up the most time.
407 The most frequent queries.
408 The most frequent errors.
409 Histogram of query times.
410 Histogram of sessions times.
411 Users involved in top queries.
412 Applications involved in top queries.
413 Queries generating the most cancellation.
414 Queries most cancelled.
415 The most time consuming prepare/bind queries
416
417 The following reports are also available with hourly charts divided into
418 periods of five minutes:
419
420 SQL queries statistics.
421 Temporary file statistics.
422 Checkpoints statistics.
423 Autovacuum and autoanalyze statistics.
424 Cancelled queries.
425 Error events (panic, fatal, error and warning).
426 Error class distribution.
427
428 There are also some pie charts about distribution of:
429
430 Locks statistics.
431 Queries by type (select/insert/update/delete).
432 Distribution of queries type per database/application
433 Sessions per database/user/client/application.
434 Connections per database/user/client/application.
435 Autovacuum and autoanalyze per table.
436 Queries per user and total duration per user.
437
438 All charts are zoomable and can be saved as PNG images. SQL queries reported are
439 highlighted and beautified automatically.
440
441 pgBadger is also able to parse PgBouncer log files and to create the following
442 reports:
443
444 Request Throughput
445 Bytes I/O Throughput
446 Average Query Duration
447 Simultaneous sessions
448 Histogram of sessions times
449 Sessions per database
450 Sessions per user
451 Sessions per host
452 Established connections
453 Connections per database
454 Connections per user
455 Connections per host
456 Most used reserved pools
457 Most Frequent Errors/Events
458
459 You can also have incremental reports with one report per day and a cumulative
460 report per week. Two multiprocess modes are available to speed up log parsing,
461 one using one core per log file, and the second using multiple cores to parse
462 a single file. These modes can be combined.
463
464 Histogram granularity can be adjusted using the -A command-line option. By default,
465 they will report the mean of each top queries/errors occurring per hour, but you can
466 specify the granularity down to the minute.
467
468 pgBadger can also be used in a central place to parse remote log files using a
469 passwordless SSH connection. This mode can be used with compressed files and in
470 the multiprocess per file mode (-J), but cannot be used with the CSV log format.
471
472 Examples of reports can be found here: https://pgbadger.darold.net/#reports
473
474 =head1 REQUIREMENT
475
476 pgBadger comes as a single Perl script - you do not need anything other than a modern
477 Perl distribution. Charts are rendered using a JavaScript library, so you don't need
478 anything other than a web browser. Your browser will do all the work.
479
480 If you plan to parse PostgreSQL CSV log files, you might need some Perl Modules:
481
482 Text::CSV_XS - to parse PostgreSQL CSV log files.
483
484 This module is optional, if you don't have PostgreSQL log in the CSV format, you don't
485 need to install it.
486
487 If you want to export statistics as JSON file, you need an additional Perl module:
488
489 JSON::XS - JSON serialising/deserialising, done correctly and fast
490
491 This module is optional, if you don't select the json output format, you don't
492 need to install it. You can install it on a Debian-like system using:
493
494 sudo apt-get install libjson-xs-perl
495
496 and on RPM-like system using:
497
498 sudo yum install perl-JSON-XS
499
500 Compressed log file format is autodetected from the file extension. If pgBadger finds
501 a gz extension, it will use the zcat utility; with a bz2 extension, it will use bzcat;
502 with lz4, it will use lz4cat; with zst, it will use zstdcat; if the file extension
503 is zip or xz, then the unzip or xz utility will be used.
504
505 If those utilities are not found in the PATH environment variable, then use the --zcat
506 command-line option to change this path. For example:
507
508 --zcat="/usr/local/bin/gunzip -c" or --zcat="/usr/local/bin/bzip2 -dc"
509 --zcat="C:\tools\unzip -p"
510
511 By default, pgBadger will use the zcat, bzcat, lz4cat, zstdcat and unzip utilities
512 following the file extension. If you use the default autodetection of compression format,
513 you can mix gz, bz2, lz4, xz, zip or zstd files. Specifying a custom value of
514 --zcat option will remove the possibility of mixed compression format.
515
516 Note that multiprocessing cannot be used with compressed files or CSV files as
517 well as under Windows platform.
518
519 =head1 INSTALLATION
520
521 Download the tarball from GitHub and unpack the archive as follow:
522
523 tar xzf pgbadger-11.x.tar.gz
524 cd pgbadger-11.x/
525 perl Makefile.PL
526 make && sudo make install
527
528 This will copy the Perl script pgbadger to /usr/local/bin/pgbadger by default and the
529 man page into /usr/local/share/man/man1/pgbadger.1. Those are the default installation
530 directories for 'site' install.
531
532 If you want to install all under /usr/ location, use INSTALLDIRS='perl' as an argument
533 of Makefile.PL. The script will be installed into /usr/bin/pgbadger and the manpage
534 into /usr/share/man/man1/pgbadger.1.
535
536 For example, to install everything just like Debian does, proceed as follows:
537
538 perl Makefile.PL INSTALLDIRS=vendor
539
540 By default, INSTALLDIRS is set to site.
541
542 =head1 POSTGRESQL CONFIGURATION
543
544 You must enable and set some configuration directives in your postgresql.conf
545 before starting.
546
547 You must first enable SQL query logging to have something to parse:
548
549 log_min_duration_statement = 0
550
551 Here every statement will be logged, on a busy server you may want to increase
552 this value to only log queries with a longer duration. Note that if you have
553 log_statement set to 'all', nothing will be logged through the log_min_duration_statement
554 directive. See the next chapter for more information.
555
556 pgBadger supports any custom format set in the log_line_prefix directive of
557 your postgresql.conf file as long as it at least specifies a time escape sequence
558 (%t, %m or %n) and a process-related escape sequence (%p or %c).
559
560 For example, with 'stderr' log format, log_line_prefix must be at least:
561
562 log_line_prefix = '%t [%p]: '
563
564 Log line prefix could add user, database name, application name and client ip
565 address as follows:
566
567 log_line_prefix = '%t [%p]: user=%u,db=%d,app=%a,client=%h '
568
569 or for syslog log file format:
570
571 log_line_prefix = 'user=%u,db=%d,app=%a,client=%h '
572
573 Log line prefix for stderr output could also be:
574
575 log_line_prefix = '%t [%p]: db=%d,user=%u,app=%a,client=%h '
576
577 or for syslog output:
578
579 log_line_prefix = 'db=%d,user=%u,app=%a,client=%h '
580
581 You need to enable other parameters in postgresql.conf to get more information from your log files:
582
583 log_checkpoints = on
584 log_connections = on
585 log_disconnections = on
586 log_lock_waits = on
587 log_temp_files = 0
588 log_autovacuum_min_duration = 0
589 log_error_verbosity = default
590
591 Do not enable log_statement as its log format will not be parsed by pgBadger.
592
593 Of course your log messages should be in English with or without locale support:
594
595 lc_messages='en_US.UTF-8'
596 lc_messages='C'
597
598 pgBadger parser does not support other locales, like 'fr_FR.UTF-8' for example.
599
600 =head1 LOG STATEMENTS
601
602 Considerations about log_min_duration_statement, log_duration and log_statement
603 configuration directives.
604
605 If you want the query statistics to include the actual query strings, you
606 must set log_min_duration_statement to 0 or more milliseconds.
607
608 If you just want to report duration and number of queries and don't want all
609 details about queries, set log_min_duration_statement to -1 to disable it and
610 enable log_duration in your postgresql.conf file. If you want to add the most
611 common query report, you can either choose to set log_min_duration_statement
612 to a higher value or to enable log_statement.
613
614 Enabling log_min_duration_statement will add reports about slowest queries and
615 queries that took up the most time. Take care that if you have log_statement
616 set to 'all', nothing will be logged with log_min_duration_statement.
617
618 Warning: Do not enable both log_min_duration_statement, log_duration and
619 log_statement all together, this will result in wrong counter values. Note
620 that this will also increase drastically the size of your log.
621 log_min_duration_statement should always be preferred.
622
623 =head1 PARALLEL PROCESSING
624
625 To enable parallel processing you just have to use the -j N option where N is
626 the number of cores you want to use.
627
628 pgBadger will then proceed as follow:
629
630 for each log file
631 chunk size = int(file size / N)
632 look at start/end offsets of these chunks
633 fork N processes and seek to the start offset of each chunk
634 each process will terminate when the parser reach the end offset
635 of its chunk
636 each process write stats into a binary temporary file
637 wait for all children processes to terminate
638 All binary temporary files generated will then be read and loaded into
639 memory to build the html output.
640
641 With that method, at start/end of chunks pgBadger may truncate or omit a
642 maximum of N queries per log file, which is an insignificant gap if you have
643 millions of queries in your log file. The chance that the query that you were
644 looking for is lost is near 0, this is why I think this gap is livable. Most
645 of the time the query is counted twice but truncated.
646
647 When you have many small log files and many CPUs, it is speedier to dedicate
648 one core to one log file at a time. To enable this behavior, you have to use
649 option -J N instead. With 200 log files of 10MB each, the use of the -J option
650 starts being really interesting with 8 cores. Using this method you will be
651 sure not to lose any queries in the reports.
652
653 Here is a benchmark done on a server with 8 CPUs and a single file of 9.5GB.
654
655 Option | 1 CPU | 2 CPU | 4 CPU | 8 CPU
656 --------+---------+-------+-------+------
657 -j | 1h41m18 | 50m25 | 25m39 | 15m58
658 -J | 1h41m18 | 54m28 | 41m16 | 34m45
659
660 With 200 log files of 10MB each, so 2GB in total, the results are slightly
661 different:
662
663 Option | 1 CPU | 2 CPU | 4 CPU | 8 CPU
664 --------+-------+-------+-------+------
665 -j | 20m15 | 9m56 | 5m20 | 4m20
666 -J | 20m15 | 9m49 | 5m00 | 2m40
667
668 So it is recommended to use -j unless you have hundreds of small log files
669 and can use at least 8 CPUs.
670
671 IMPORTANT: when you are using parallel parsing, pgBadger will generate a
672 lot of temporary files in the /tmp directory and will remove them at the
673 end, so do not remove those files unless pgBadger is not running. They are
674 all named with the following template tmp_pgbadgerXXXX.bin so they can be
675 easily identified.
676
677 =head1 INCREMENTAL REPORTS
678
679 pgBadger includes an automatic incremental report mode using option -I or
680 --incremental. When running in this mode, pgBadger will generate one report
681 per day and a cumulative report per week. Output is first done in binary
682 format into the mandatory output directory (see option -O or --outdir),
683 then in HTML format for daily and weekly reports with a main index file.
684
685 The main index file will show a dropdown menu per week with a link to each
686 week report and links to daily reports of each week.
687
688 For example, if you run pgBadger as follows based on a daily rotated file:
689
690 0 4 * * * /usr/bin/pgbadger -I -q /var/log/postgresql/postgresql.log.1 -O /var/www/pg_reports/
691
692 you will have all daily and weekly reports for the full running period.
693
694 In this mode, pgBadger will create an automatic incremental file in the
695 output directory, so you don't have to use the -l option unless you want
696 to change the path of that file. This means that you can run pgBadger in
697 this mode each day on a log file rotated each week, and it will not count
698 the log entries twice.
699
700 To save disk space, you may want to use the -X or --extra-files command-line
701 option to force pgBadger to write JavaScript and CSS to separate files in
702 the output directory. The resources will then be loaded using script and
703 link tags.
704
705 =head2 Rebuilding reports
706
707 Incremental reports can be rebuilt after a pgbadger report fix or a new
708 feature to update all HTML reports. To rebuild all reports where a binary
709 file is still present, proceed as follow:
710
711 rm /path/to/reports/*.js
712 rm /path/to/reports/*.css
713 pgbadger -X -I -O /path/to/reports/ --rebuild
714
715 it will also update all resource files (JS and CSS). Use -E or --explode
716 if the reports were built using this option.
717
718 =head2 Monthly reports
719
720 By default, pgBadger in incremental mode only computes daily and weekly reports.
721 If you want monthly cumulative reports, you will have to use a separate command
722 to specify the report to build. For example, to build a report for August 2019:
723
724 pgbadger -X --month-report 2019-08 /var/www/pg_reports/
725
726 this will add a link to the month name into the calendar view of incremental
727 reports to look at monthly report. The report for a current month can be run
728 every day, it is entirely rebuilt each time. The monthly report is not built by
729 default because it could take a lot of time following the amount of data.
730
731 If reports were built with the per-database option ( -E | --explode ), it must
732 be used too when calling pgbadger to build monthly report:
733
734 pgbadger -E -X --month-report 2019-08 /var/www/pg_reports/
735
736 This is the same when using the rebuild option ( -R | --rebuild ).
737
738 =head1 BINARY FORMAT
739
740 Using the binary format it is possible to create custom incremental and
741 cumulative reports. For example, if you want to refresh a pgBadger
742 report each hour from a daily PostgreSQL log file, you can proceed by
743 running the following commands each hour:
744
745 pgbadger --last-parsed .pgbadger_last_state_file -o sunday/hourX.bin /var/log/pgsql/postgresql-Sun.log
746
747 to generate the incremental data files in binary format. And to generate the fresh HTML
748 report from that binary file:
749
750 pgbadger sunday/*.bin
751
752 Or as another example, if you generate one log file per hour and you want
753 reports to be rebuilt each time the log file is rotated, proceed as
754 follows:
755
756 pgbadger -o day1/hour01.bin /var/log/pgsql/pglog/postgresql-2012-03-23_10.log
757 pgbadger -o day1/hour02.bin /var/log/pgsql/pglog/postgresql-2012-03-23_11.log
758 pgbadger -o day1/hour03.bin /var/log/pgsql/pglog/postgresql-2012-03-23_12.log
759 ...
760
761 When you want to refresh the HTML report, for example, each time after a new binary file
762 is generated, just do the following:
763
764 pgbadger -o day1_report.html day1/*.bin
765
766 Adjust the commands to suit your particular needs.
767
768 =head1 JSON FORMAT
769
770 JSON format is good for sharing data with other languages, which makes it
771 easy to integrate pgBadger result into other monitoring tools, like Cacti
772 or Graphite.
773
774 =head1 AUTHORS
775
776 pgBadger is an original work from Gilles Darold.
777
778 The pgBadger logo is an original creation of Damien Cazeils.
779
780 The pgBadger v4.x design comes from the "Art is code" company.
781
782 This web site is a work of Gilles Darold.
783
784 pgBadger is maintained by Gilles Darold and everyone who wants to contribute.
785
786 Many people have contributed to pgBadger, they are all quoted in the Changelog file.
787
788 =head1 LICENSE
789
790 pgBadger is free software distributed under the PostgreSQL Licence.
791
792 Copyright (c) 2012-2026, Gilles Darold
793
794 A modified version of the SQL::Beautify Perl Module is embedded in pgBadger
795 with copyright (C) 2009 by Jonas Kramer and is published under the terms of
796 the Artistic License 2.0.