Debian Codegraph @

README.md

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