forked from bucardo/check_postgres
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_postgres.pl.html
2191 lines (2021 loc) · 108 KB
/
check_postgres.pl.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body style="background-color: white">
<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<ul>
<li><a href="#output_modes">Output Modes</a></li>
<ul>
<li><a href="#nagios_output">Nagios output</a></li>
<li><a href="#mrtg_output">MRTG output</a></li>
<li><a href="#simple_output">Simple output</a></li>
<li><a href="#cacti_output">Cacti output</a></li>
</ul>
</ul>
<li><a href="#database_connection_options">DATABASE CONNECTION OPTIONS</a></li>
<li><a href="#other_options">OTHER OPTIONS</a></li>
<li><a href="#actions">ACTIONS</a></li>
<ul>
<li><a href="#autovac_freeze"><strong>autovac_freeze</strong></a></li>
<li><a href="#backends"><strong>backends</strong></a></li>
<li><a href="#bloat"><strong>bloat</strong></a></li>
<li><a href="#checkpoint"><strong>checkpoint</strong></a></li>
<li><a href="#connection"><strong>connection</strong></a></li>
<li><a href="#custom_query"><strong>custom_query</strong></a></li>
<li><a href="#database_size"><strong>database_size</strong></a></li>
<li><a href="#dbstats"><strong>dbstats</strong></a></li>
<li><a href="#disabled_triggers"><strong>disabled_triggers</strong></a></li>
<li><a href="#disk_space"><strong>disk_space</strong></a></li>
<li><a href="#fsm_pages"><strong>fsm_pages</strong></a></li>
<li><a href="#fsm_relations"><strong>fsm_relations</strong></a></li>
<li><a href="#index_size"><strong>index_size</strong></a></li>
<li><a href="#table_size"><strong>table_size</strong></a></li>
<li><a href="#relation_size"><strong>relation_size</strong></a></li>
<li><a href="#last_vacuum"><strong>last_vacuum</strong></a></li>
<li><a href="#last_autovacuum"><strong>last_autovacuum</strong></a></li>
<li><a href="#last_analyze"><strong>last_analyze</strong></a></li>
<li><a href="#last_autoanalyze"><strong>last_autoanalyze</strong></a></li>
<li><a href="#listener"><strong>listener</strong></a></li>
<li><a href="#locks"><strong>locks</strong></a></li>
<li><a href="#logfile"><strong>logfile</strong></a></li>
<li><a href="#new_version_cp"><strong>new_version_cp</strong></a></li>
<li><a href="#new_version_pg"><strong>new_version_pg</strong></a></li>
<li><a href="#new_version_bc"><strong>new_version_bc</strong></a></li>
<li><a href="#pgbouncer_checksum"><strong>pgbouncer_checksum</strong></a></li>
<li><a href="#prepared_txns"><strong>prepared_txns</strong></a></li>
<li><a href="#query_runtime"><strong>query_runtime</strong></a></li>
<li><a href="#query_time"><strong>query_time</strong></a></li>
<li><a href="#replicate_row"><strong>replicate_row</strong></a></li>
<li><a href="#same_schema"><strong>same_schema</strong></a></li>
<li><a href="#sequence"><strong>sequence</strong></a></li>
<li><a href="#slony_status"><strong>slony_status</strong></a></li>
<li><a href="#txn_time"><strong>txn_time</strong></a></li>
<li><a href="#txn_idle"><strong>txn_idle</strong></a></li>
<li><a href="#rebuild_symlinks"><strong>rebuild_symlinks</strong></a></li>
<li><a href="#rebuild_symlinks_force"><strong>rebuild_symlinks_force</strong></a></li>
<li><a href="#settings_checksum"><strong>settings_checksum</strong></a></li>
<li><a href="#timesync"><strong>timesync</strong></a></li>
<li><a href="#txn_wraparound"><strong>txn_wraparound</strong></a></li>
<li><a href="#wal_files"><strong>wal_files</strong></a></li>
<li><a href="#version"><strong>version</strong></a></li>
</ul>
<li><a href="#basic_filtering">BASIC FILTERING</a></li>
<li><a href="#user_name_filtering">USER NAME FILTERING</a></li>
<li><a href="#test_mode">TEST MODE</a></li>
<li><a href="#files">FILES</a></li>
<li><a href="#environment_variables">ENVIRONMENT VARIABLES</a></li>
<li><a href="#tips_and_tricks">TIPS AND TRICKS</a></li>
<li><a href="#dependencies">DEPENDENCIES</a></li>
<li><a href="#development">DEVELOPMENT</a></li>
<li><a href="#mailing_list">MAILING LIST</a></li>
<li><a href="#history">HISTORY</a></li>
<li><a href="#bugs_and_limitations">BUGS AND LIMITATIONS</a></li>
<li><a href="#author">AUTHOR</a></li>
<li><a href="#nagios_examples">NAGIOS EXAMPLES</a></li>
<li><a href="#license_and_copyright">LICENSE AND COPYRIGHT</a></li>
</ul>
<hr name="index" />
</div>
<!-- INDEX END -->
<p>
</p>
<hr />
<h1><a name="name">NAME</a></h1>
<p><strong>check_postgres.pl</strong> - a Postgres monitoring script for Nagios, MRTG, Cacti, and others</p>
<p>This documents describes check_postgres.pl version 2.15.0</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
## Create all symlinks
check_postgres.pl --symlinks</pre>
<pre>
## Check connection to Postgres database 'pluto':
check_postgres.pl --action=connection --db=pluto</pre>
<pre>
## Same things, but using the symlink
check_postgres_connection --db=pluto</pre>
<pre>
## Warn if > 100 locks, critical if > 200, or > 20 exclusive
check_postgres_locks --warning=100 --critical="total=200;exclusive=20"</pre>
<pre>
## Show the current number of idle connections on port 6543:
check_postgres_txn_idle --port=6543 --output=simple</pre>
<pre>
## There are many other actions and options, please keep reading.</pre>
<pre>
The latest news and documentation can always be found at:
<a href="http://bucardo.org/check_postgres/">http://bucardo.org/check_postgres/</a></pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>check_postgres.pl is a Perl script that runs many different tests against
one or more Postgres databases. It uses the psql program to gather the
information, and outputs the results in one of three formats: Nagios, MRTG,
or simple.</p>
<p>
</p>
<h2><a name="output_modes">Output Modes</a></h2>
<p>The output can be changed by use of the <code>--output</code> option. The default output
is nagios, although this can be changed at the top of the script if you wish. The
current option choices are <strong>nagios</strong>, <strong>mrtg</strong>, and <strong>simple</strong>. To avoid having to
enter the output argument each time, the type of output is automatically set
if no --output argument is given, and if the current directory has one of the
output options in its name. For example, creating a directory named mrtg and
populating it with symlinks via the <em>--symlinks</em> argument would ensure that
any actions run from that directory will always default to an output of "mrtg"
As a shortcut for --output=simple, you can enter --simple, which also overrides
the directory naming trick.</p>
<p>
</p>
<h3><a name="nagios_output">Nagios output</a></h3>
<p>The default output format is for Nagios, which is a single line of information, along
with four specific exit codes:</p>
<ol>
<li><strong><a name="ok" class="item">(OK)</a></strong>
</li>
<li><strong><a name="warning" class="item">(WARNING)</a></strong>
</li>
<li><strong><a name="critical" class="item">(CRITICAL)</a></strong>
</li>
<li><strong><a name="unknown" class="item">(UNKNOWN)</a></strong>
</li>
</ol>
<p>The output line is one of the words above, a colon, and then a short description of what
was measured. Additional statistics information, as well as the total time the command
took, can be output as well: see the documentation on the arguments
<em><a href="#showperf_val">--showperf</a></em>,
<em><a href="#perflimit_i">--perflimit</a></em>, and
<em><a href="#showtime_val">--showtime</a></em>.</p>
<p>
</p>
<h3><a name="mrtg_output">MRTG output</a></h3>
<p>The MRTG output is four lines, with the first line always giving a single number of importance.
When possible, this number represents an actual value such as a number of bytes, but it
may also be a 1 or a 0 for actions that only return "true" or "false", such as check_postgres_version.
The second line is an additional stat and is only used for some actions. The third line indicates
an "uptime" and is not used. The fourth line is a description and usually indicates the name of
the database the stat from the first line was pulled from, but may be different depending on the
action.</p>
<p>Some actions accept an optional <em>--mrtg</em> argument to further control the output.</p>
<p>See the documentation on each action for details on the exact MRTG output for each one.</p>
<p>
</p>
<h3><a name="simple_output">Simple output</a></h3>
<p>The simple output is simply a truncated version of the MRTG one, and simply returns the first number
and nothing else. This is very useful when you just want to check the state of something, regardless
of any threshold. You can transform the numeric output by appending KB, MB, GB, TB, or EB to the output
argument, for example:</p>
<pre>
--output=simple,MB</pre>
<p>
</p>
<h3><a name="cacti_output">Cacti output</a></h3>
<p>The Cacti output consists of one or more items on the same line, with a simple name, a colon, and
then a number. At the moment, the only action with explicit Cacti output is 'dbstats', and using
the --output option is not needed in this case, as Cacti is the only output for this action. For many
other actions, using --simple is enough to make Cacti happy.</p>
<p>
</p>
<hr />
<h1><a name="database_connection_options">DATABASE CONNECTION OPTIONS</a></h1>
<p>All actions accept a common set of database options.</p>
<dl>
<dt><strong><a name="h_name_or_host_name" class="item"><strong>-H NAME</strong> or <strong>--host=NAME</strong></a></strong></dt>
<dd>
<p>Connect to the host indicated by NAME. Can be a comma-separated list of names. Multiple host arguments
are allowed. If no host is given, defaults to the <code>PGHOST</code> environment variable or no host at all
(which indicates using a local Unix socket). You may also use "--dbhost".</p>
</dd>
<dt><strong><a name="p_port_or_port_port" class="item"><strong>-p PORT</strong> or <strong>--port=PORT</strong></a></strong></dt>
<dd>
<p>Connects using the specified PORT number. Can be a comma-separated list of port numbers, and multiple
port arguments are allowed. If no port number is given, defaults to the <code>PGPORT</code> environment variable. If
that is not set, it defaults to 5432. You may also use "--dbport"</p>
</dd>
<dt><strong><a name="db_name_or_dbname_name" class="item"><strong>-db NAME</strong> or <strong>--dbname=NAME</strong></a></strong></dt>
<dd>
<p>Specifies which database to connect to. Can be a comma-separated list of names, and multiple dbname
arguments are allowed. If no dbname option is provided, defaults to the <code>PGDATABASE</code> environment variable.
If that is not set, it defaults to 'postgres' if psql is version 8 or greater, and 'template1' otherwise.</p>
</dd>
<dt><strong><a name="u_username_or_dbuser_username" class="item"><strong>-u USERNAME</strong> or <strong>--dbuser=USERNAME</strong></a></strong></dt>
<dd>
<p>The name of the database user to connect as. Can be a comma-separated list of usernames, and multiple
dbuser arguments are allowed. If this is not provided, it defaults to the <code>PGUSER</code> environment variable, otherwise
it defaults to 'postgres'.</p>
</dd>
<dt><strong><a name="dbpass_password" class="item"><strong>--dbpass=PASSWORD</strong></a></strong></dt>
<dd>
<p>Provides the password to connect to the database with. Use of this option is highly discouraged.
Instead, one should use a .pgpass or pg_service.conf file.</p>
</dd>
<dt><strong><a name="dbservice_name" class="item"><strong>--dbservice=NAME</strong></a></strong></dt>
<dd>
<p>The name of a service inside of the pg_service.conf file. This file is in your home directory by
default and contains a simple list of connection options. You can also pass additional information
when using this option such as --dbservice="maindatabase sslmode=require"</p>
</dd>
</dl>
<p>The database connection options can be grouped: <em>--host=a,b --host=c --port=1234 --port=3344</em>
would connect to a-1234, b-1234, and c-3344. Note that once set, an option
carries over until it is changed again.</p>
<p>Examples:</p>
<pre>
--host=a,b --port=5433 --db=c
Connects twice to port 5433, using database c, to hosts a and b: a-5433-c b-5433-c</pre>
<pre>
--host=a,b --port=5433 --db=c,d
Connects four times: a-5433-c a-5433-d b-5433-c b-5433-d</pre>
<pre>
--host=a,b --host=foo --port=1234 --port=5433 --db=e,f
Connects six times: a-1234-e a-1234-f b-1234-e b-1234-f foo-5433-e foo-5433-f</pre>
<pre>
--host=a,b --host=x --port=5432,5433 --dbuser=alice --dbuser=bob -db=baz
Connects three times: a-5432-alice-baz b-5433-alice-baz x-5433-bob-baz</pre>
<pre>
--dbservice="foo" --port=5433
Connects using the named service 'foo' in the pg_service.conf file, but overrides the port</pre>
<p>
</p>
<hr />
<h1><a name="other_options">OTHER OPTIONS</a></h1>
<p>Other options include:</p>
<dl>
<dt><strong><a name="action_name" class="item"><strong>--action=NAME</strong></a></strong></dt>
<dd>
<p>States what action we are running. Required unless using a symlinked file,
in which case the name of the file is used to figure out the action.</p>
</dd>
<dt><strong><a name="warning_val_or_w_val" class="item"><strong>--warning=VAL or -w VAL</strong></a></strong></dt>
<dd>
<p>Sets the threshold at which a warning alert is fired. The valid options for this
option depends on the action used.</p>
</dd>
<dt><strong><a name="critical_val_or_c_val" class="item"><strong>--critical=VAL or -c VAL</strong></a></strong></dt>
<dd>
<p>Sets the threshold at which a critical alert is fired. The valid options for this
option depends on the action used.</p>
</dd>
<dt><strong><a name="t_val_or_timeout_val" class="item"><strong>-t VAL</strong> or <strong>--timeout=VAL</strong></a></strong></dt>
<dd>
<p>Sets the timeout in seconds after which the script will abort whatever it is doing
and return an UNKNOWN status. The timeout is per Postgres cluster, not for the entire
script. The default value is 10; the units are always in seconds.</p>
</dd>
<dt><strong><a name="h_or_help" class="item"><strong>-h</strong> or <strong>--help</strong></a></strong></dt>
<dd>
<p>Displays a help screen with a summary of all actions and options.</p>
</dd>
<dt><strong><a name="v_or_version" class="item"><strong>-V</strong> or <strong>--version</strong></a></strong></dt>
<dd>
<p>Shows the current version.</p>
</dd>
<dt><strong><a name="v_or_verbose" class="item"><strong>-v</strong> or <strong>--verbose</strong></a></strong></dt>
<dd>
<p>Set the verbosity level. Can call more than once to boost the level. Setting it to three
or higher (in other words, issuing <code>-v -v -v</code>) turns on debugging information for this
program which is sent to stderr.</p>
</dd>
<dt><strong><a name="showperf_val" class="item"><strong>--showperf=VAL</strong></a></strong></dt>
<dd>
<p>Determines if we output additional performance data in standard Nagios format
(at end of string, after a pipe symbol, using name=value).
VAL should be 0 or 1. The default is 1. Only takes effect if using Nagios output mode.</p>
</dd>
<dt><strong><a name="perflimit_i" class="item"><strong>--perflimit=i</strong></a></strong></dt>
<dd>
<p>Sets a limit as to how many items of interest are reported back when using the
<em>showperf</em> option. This only has an effect for actions that return a large
number of items, such as <strong>table_size</strong>. The default is 0, or no limit. Be
careful when using this with the <em>--include</em> or <em>--exclude</em> options, as
those restrictions are done <em>after</em> the query has been run, and thus your
limit may not include the items you want. Only takes effect if using Nagios output mode.</p>
</dd>
<dt><strong><a name="showtime_val" class="item"><strong>--showtime=VAL</strong></a></strong></dt>
<dd>
<p>Determines if the time taken to run each query is shown in the output. VAL
should be 0 or 1. The default is 1. No effect unless <em>showperf</em> is on.
Only takes effect if using Nagios output mode.</p>
</dd>
<dt><strong><a name="test" class="item"><strong>--test</strong></a></strong></dt>
<dd>
<p>Enables test mode. See the <a href="#test_mode">TEST MODE</a> section below.</p>
</dd>
<dt><strong><a name="psql_path" class="item"><strong>--PSQL=PATH</strong></a></strong></dt>
<dd>
<p>Tells the script where to find the psql program. Useful if you have more than
one version of the psql executable on your system, or if there is no psql program
in your path. Note that this option is in all uppercase. By default, this option
is <em>not allowed</em>. To enable it, you must change the <code>$NO_PSQL_OPTION</code> near the
top of the script to 0. Avoid using this option if you can, and instead hard-code
your psql location into the <code>$PSQL</code> variable, also near the top of the script.</p>
</dd>
<dt><strong><a name="symlinks" class="item"><strong>--symlinks</strong></a></strong></dt>
<dd>
<p>Creates symlinks to the main program for each action.</p>
</dd>
<dt><strong><a name="output_val" class="item"><strong>--output=VAL</strong></a></strong></dt>
<dd>
<p>Determines the format of the output, for use in various programs. The default is 'nagios'. No
other systems are supported yet.</p>
</dd>
<dt><strong><a name="mrtg_val" class="item"><strong>--mrtg=VAL</strong></a></strong></dt>
<dd>
<p>Used only for the MRTG or simple output, for a few specific actions.</p>
</dd>
<dt><strong><a name="debugoutput_val" class="item"><strong>--debugoutput=VAL</strong></a></strong></dt>
<dd>
<p>Outputs the exact string returned by psql, for use in debugging. The value is one or more letters,
which determine if the output is displayed or not, where 'a' = all, 'c' = critical, 'w' = warning,
'o' = ok, and 'u' = unknown. Letters can be combined.</p>
</dd>
<dt><strong><a name="get_method_val" class="item"><strong>--get_method=VAL</strong></a></strong></dt>
<dd>
<p>Allows specification of the method used to fetch information for the <code>new_version_cp</code>,
<code>new_version_pg</code>, and <code>new_version_bc</code> checks. The following programs are tried, in order, to
grab the information from the web: GET, wget, fetch, curl, lynx, links. To force the use of just
one (and thus remove the overhead of trying all the others until one of those works),
enter one of the names as the argument to get_method. For example, a BSD box might enter
the following line in their <code>.check_postgresrc</code> file:</p>
<pre>
get_method=fetch</pre>
</dd>
<dt><strong><a name="language_val" class="item"><strong>--language=VAL</strong></a></strong></dt>
<dd>
<p>Set the language to use for all output messages. Normally, this is detected by examining
the environment variables LC_ALL, LC_MESSAGES, and LANG, but setting this option
will override any such detection.</p>
</dd>
</dl>
<p>
</p>
<hr />
<h1><a name="actions">ACTIONS</a></h1>
<p>The script runs one or more actions. This can either be done with the --action
flag, or by using a symlink to the main file that contains the name of the action
inside of it. For example, to run the action "timesync", you may either issue:</p>
<pre>
check_postgres.pl --action=timesync</pre>
<p>or use a program named:</p>
<pre>
check_postgres_timesync</pre>
<p>All the symlinks are created for you in the current directory
if use the option --symlinks</p>
<pre>
perl check_postgres.pl --symlinks</pre>
<p>If the file name already exists, it will not be overwritten. If the file exists
and is a symlink, you can force it to overwrite by using "--action=build_symlinks_force"</p>
<p>Most actions take a <em>--warning</em> and a <em>--critical</em> option, indicating at what
point we change from OK to WARNING, and what point we go to CRITICAL. Note that
because criticals are always checked first, setting the warning equal to the
critical is an effective way to turn warnings off and always give a critical.</p>
<p>The current supported actions are:</p>
<p>
</p>
<h2><a name="autovac_freeze"><strong>autovac_freeze</strong></a></h2>
<p>(<code>symlink: check_postgres_autovac_freeze</code>) Checks how close each database is to the Postgres <strong>autovacuum_freeze_max_age</strong> setting. This
action will only work for databases version 8.2 or higher. The <em>--warning</em> and
<em>--critical</em> options should be expressed as percentages. The 'age' of the transactions
in each database is compared to the autovacuum_freeze_max_age setting (200 million by default)
to generate a rounded percentage. The default values are <strong>90%</strong> for the warning and <strong>95%</strong> for
the critical. Databases can be filtered by use of the <em>--include</em> and <em>--exclude</em> options.
See the <a href="#basic_filtering">BASIC FILTERING</a> section for more details.</p>
<p>Example 1: Give a warning when any databases on port 5432 are above 97%</p>
<pre>
check_postgres_autovac_freeze --port=5432 --warning="97%"</pre>
<p>For MRTG output, the highest overall percentage is reported on the first line, and the highest age is
reported on the second line. All databases which have the percentage from the first line are reported
on the fourth line, separated by a pipe symbol.</p>
<p>
</p>
<h2><a name="backends"><strong>backends</strong></a></h2>
<p>(<code>symlink: check_postgres_backends</code>) Checks the current number of connections for one or more databases, and optionally
compares it to the maximum allowed, which is determined by the
Postgres configuration variable <strong>max_connections</strong>. The <em>--warning</em> and
<em>--critical</em> options can take one of three forms. First, a simple number can be
given, which represents the number of connections at which the alert will be
given. This choice does not use the <strong>max_connections</strong> setting. Second, the
percentage of available connections can be given. Third, a negative number can
be given which represents the number of connections left until <strong>max_connections</strong>
is reached. The default values for <em>--warning</em> and <em>--critical</em> are '90%' and '95%'.
You can also filter the databases by use of the <em>--include</em> and <em>--exclude</em> options.
See the <a href="#basic_filtering">BASIC FILTERING</a> section for more details.</p>
<p>To view only non-idle processes, you can use the <em>--noidle</em> argument. Note that the
user you are connecting as must be a superuser for this to work properly.</p>
<p>Example 1: Give a warning when the number of connections on host quirm reaches 120, and a critical if it reaches 150.</p>
<pre>
check_postgres_backends --host=quirm --warning=120 --critical=150</pre>
<p>Example 2: Give a critical when we reach 75% of our max_connections setting on hosts lancre or lancre2.</p>
<pre>
check_postgres_backends --warning='75%' --critical='75%' --host=lancre,lancre2</pre>
<p>Example 3: Give a warning when there are only 10 more connection slots left on host plasmid, and a critical
when we have only 5 left.</p>
<pre>
check_postgres_backends --warning=-10 --critical=-5 --host=plasmid</pre>
<p>Example 4: Check all databases except those with "test" in their name, but allow ones that are named "pg_greatest". Connect as port 5432 on the first two hosts, and as port 5433 on the third one. We want to always throw a critical when we reach 30 or more connections.</p>
<pre>
check_postgres_backends --dbhost=hong,kong --dbhost=fooey --dbport=5432 --dbport=5433 --warning=30 --critical=30 --exclude="~test" --include="pg_greatest,~prod"</pre>
<p>For MRTG output, the number of connections is reported on the first line, and the fourth line gives the name of the database,
plus the current maximum_connections. If more than one database has been queried, the one with the highest number of
connections is output.</p>
<p>
</p>
<h2><a name="bloat"><strong>bloat</strong></a></h2>
<p>(<code>symlink: check_postgres_bloat</code>) Checks the amount of bloat in tables and indexes. (Bloat is generally the amount
of dead unused space taken up in a table or index. This space is usually reclaimed
by use of the VACUUM command.) This action requires that stats collection be
enabled on the target databases, and requires that ANALYZE is run frequently.
The <em>--include</em> and <em>--exclude</em> options can be used to filter out which tables
to look at. See the <a href="#basic_filtering">BASIC FILTERING</a> section for more details.</p>
<p>The <em>--warning</em> and <em>--critical</em> options can be specified as sizes or percents.
Valid size units are bytes, kilobytes, megabytes, gigabytes, terabytes, exabytes,
petabytes, and zettabytes. You can abbreviate all of those with the first letter. Items
without units are assumed to be 'bytes'. The default values are '1 GB' and '5 GB'. The value
represents the number of "wasted bytes", or the difference between what is actually
used by the table and index, and what we compute that it should be.</p>
<p>Note that this action has two hard-coded values to avoid false alarms on
smaller relations. Tables must have at least 10 pages, and indexes at least 15,
before they can be considered by this test. If you really want to adjust these
values, you can look for the variables <em>$MINPAGES</em> and <em>$MINIPAGES</em> at the top of the
<code>check_bloat</code> subroutine.</p>
<p>Only the top 10 most bloated relations are shown. You can change this number by
using the <em>--perflimit</em> option to set your own limit.</p>
<p>The schema named 'information_schema' is excluded from this test, as the only tables
it contains are small and do not change.</p>
<p>Please note that the values computed by this action are not precise, and
should be used as a guideline only. Great effort was made to estimate the
correct size of a table, but in the end it is only an estimate. The correct
index size is even more of a guess than the correct table size, but both
should give a rough idea of how bloated things are.</p>
<p>Example 1: Warn if any table on port 5432 is over 100 MB bloated, and critical if over 200 MB</p>
<pre>
check_postgres_bloat --port=5432 --warning='100 M', --critical='200 M'</pre>
<p>Example 2: Give a critical if table 'orders' on host 'sami' has more than 10 megs of bloat</p>
<pre>
check_postgres_bloat --host=sami --include=orders --critical='10 MB'</pre>
<p>Example 3: Give a critical if table 'q4' on database 'sales' is over 50% bloated</p>
<pre>
check_postgres_bloat --db=sales --include=q4 --critical='50%'</pre>
<p>For MRTG output, the first line gives the highest number of wasted bytes for the tables, and the
second line gives the highest number of wasted bytes for the indexes. The fourth line gives the database
name, table name, and index name information. If you want to output the bloat ratio instead (how many
times larger the relation is compared to how large it should be), just pass in <code>--mrtg=ratio</code>.</p>
<p>
</p>
<h2><a name="checkpoint"><strong>checkpoint</strong></a></h2>
<p>(<code>symlink: check_postgres_checkpoint</code>) Determines how long since the last checkpoint has
been run. This must run on the same server as the database that is being checked (e.g. the -h
flag will not work). This check is meant to run on a "warm standby" server that is actively
processing shipped WAL files, and is meant to check that your warm standby is truly 'warm'.
The data directory must be set, either by the environment variable <code>PGDATA</code>, or passing
the <code>--datadir</code> argument. It returns the number of seconds since the last checkpoint
was run, as determined by parsing the call to <code>pg_controldata</code>. Because of this, the
pg_controldata executable must be available in the current path. Alternatively, you can
set the environment variable <code>PGCONTROLDATA</code> to the exact location of the pg_controldata
executable, or you can specify <code>PGBINDIR</code> as the directory that it lives in.</p>
<p>At least one warning or critical argument must be set.</p>
<p>This action requires the Date::Parse module.</p>
<p>For MRTG or simple output, returns the number of seconds.</p>
<p>
</p>
<h2><a name="connection"><strong>connection</strong></a></h2>
<p>(<code>symlink: check_postgres_connection</code>) Simply connects, issues a 'SELECT version()', and leaves.
Takes no <em>--warning</em> or <em>--critical</em> options.</p>
<p>For MRTG output, simply outputs a 1 (good connection) or a 0 (bad connection) on the first line.</p>
<p>
</p>
<h2><a name="custom_query"><strong>custom_query</strong></a></h2>
<p>(<code>symlink: check_postgres_custom_query</code>) Runs a custom query of your choosing, and parses the results. The query itself is passed in through
the <code>custom_query</code> argument, and should be kept as simple as possible. If at all possible, wrap it in
a view or a function to keep things easier to manage. The query should return one or two columns: the first
is the result that will be checked, and the second is any performance data you want sent. They must be returned
as columns named <em>result</em> and <em>data</em>.</p>
<p>At least one warning or critical argument must be specified. What these are set to depends on the type of
query you are running. There are four types of custom_queries that can be run, specified by the <code>valtype</code>
argument. If none is specified, this action defaults to 'integer'. The four types are:</p>
<p><strong>integer</strong>:
Does a simple integer comparison. The first column should be a simple integer, and the warning and
critical values should be the same.</p>
<p><strong>string</strong>:
The warning and critical are strings, and are triggered only if the value in the first column matches
it exactly. This is case-sensitive.</p>
<p><strong>time</strong>:
The warning and the critical are times, and can have units of seconds, minutes, hours, or days.
Each may be written singular or abbreviated to just the first letter. If no units are given,
seconds are assumed. The first column should be an integer representing the number of seconds
to check.</p>
<p><strong>size</strong>:
The warning and the critical are sizes, and can have units of bytes, kilobytes, megabytes, gigabytes,
terabytes, or exabytes. Each may be abbreviated to the first letter. If no units are given,
bytes are assumed. The first column should be an integer representing the number of bytes to check.</p>
<p>Normally, an alert is triggered if the values returned are <strong>greater than</strong> or equal to the critical or warning
value. However, an option of <em>--reverse</em> will trigger the alert if the returned value is
<strong>lower than</strong> or equal to the critical or warning value.</p>
<p>Example 1: Warn if any relation over 100 pages is named "rad":</p>
<pre>
check_postgres_custom_query --valtype=string -w "rad" --query="SELECT relname FROM pg_class WHERE relpages > 100" --port=5432</pre>
<p>Example 2: Give a critical if the "foobar" function returns a number over 5MB:</p>
<pre>
check_postgres_custom_query --port=5432 --critical='5MB'--valtype=size --query="SELECT foobar()"</pre>
<p>Example 2: Warn if the function "snazzo" returns less than 42:</p>
<pre>
check_postgres_custom_query --port=5432 --critical=42 --query="SELECT snazzo()" --reverse</pre>
<p>If you come up with a useful custom_query, consider sending in a patch to this program
to make it into a standard action that other people can use.</p>
<p>This action does not support MRTG or simple output yet.</p>
<p>
</p>
<h2><a name="database_size"><strong>database_size</strong></a></h2>
<p>(<code>symlink: check_postgres_database_size</code>) Checks the size of all databases and complains when they are too big.
There is no need to run this command more than once per database cluster.
Databases can be filtered with
the <em>--include</em> and <em>--exclude</em> options. See the <a href="#basic_filtering">BASIC FILTERING</a> section
for more details.
They can also be filtered by the owner of the database with the
<em>--includeuser</em> and <em>--excludeuser</em> options.
See the <a href="#user_name_filtering">USER NAME FILTERING</a> section for more details.</p>
<p>The warning and critical options can be specified as bytes, kilobytes, megabytes,
gigabytes, terabytes, or exabytes. Each may be abbreviated to the first letter as well.
If no unit is given, the units are assumed to be bytes. There are not defaults for this
action: the warning and critical must be specified. The warning value cannot be greater
than the critical value. The output returns all databases sorted by size largest first,
showing both raw bytes and a "pretty" version of the size.</p>
<p>Example 1: Warn if any database on host flagg is over 1 TB in size, and critical if over 1.1 TB.</p>
<pre>
check_postgres_database_size --host=flagg --warning='1 TB' --critical='1.1 t'</pre>
<p>Example 2: Give a critical if the database template1 on port 5432 is over 10 MB.</p>
<pre>
check_postgres_database_size --port=5432 --include=template1 --warning='10MB' --critical='10MB'</pre>
<p>Example 3: Give a warning if any database on host 'tardis' owned by the user 'tom' is over 5 GB</p>
<pre>
check_postgres_database_size --host=tardis --includeuser=tom --warning='5 GB' --critical='10 GB'</pre>
<p>For MRTG output, returns the size in bytes of the largest database on the first line,
and the name of the database on the fourth line.</p>
<p>
</p>
<h2><a name="dbstats"><strong>dbstats</strong></a></h2>
<p>(<code>symlink: check_postgres_dbstats</code>) Reports information from the pg_stat_database view,
and outputs it in a Cacti-friendly manner. No other output is supported, as the output
is informational and does not lend itself to alerts, such as used with Nagios. If no
options are given, all databases are returned, one per line. You can include a specific
database by use of the <code>--include</code> option, or you can use the <a href="#dbname"><code>--dbname</code></a> option.</p>
<p>Eleven items are returned on each line, in the format name:value, separated by a single
space. The items are:</p>
<dl>
<dt><strong><a name="backends" class="item">backends</a></strong></dt>
<dd>
<p>The number of currently running backends for this database.</p>
</dd>
<dt><strong><a name="commits" class="item">commits</a></strong></dt>
<dd>
<p>The total number of commits for this database since it was created or reset.</p>
</dd>
<dt><strong><a name="rollbacks" class="item">rollbacks</a></strong></dt>
<dd>
<p>The total number of rollbacks for this database since it was created or reset.</p>
</dd>
<dt><strong><a name="read" class="item">read</a></strong></dt>
<dd>
<p>The total number of disk blocks read.</p>
</dd>
<dt><strong><a name="hit" class="item">hit</a></strong></dt>
<dd>
<p>The total number of buffer hits.</p>
</dd>
<dt><strong><a name="ret" class="item">ret</a></strong></dt>
<dd>
<p>The total number of rows returned.</p>
</dd>
<dt><strong><a name="fetch" class="item">fetch</a></strong></dt>
<dd>
<p>The total number of rows fetched.</p>
</dd>
<dt><strong><a name="ins" class="item">ins</a></strong></dt>
<dd>
<p>The total number of rows inserted.</p>
</dd>
<dt><strong><a name="upd" class="item">upd</a></strong></dt>
<dd>
<p>The total number of rows updated.</p>
</dd>
<dt><strong><a name="del" class="item">del</a></strong></dt>
<dd>
<p>The total number of rows deleted.</p>
</dd>
<dt><strong><a name="dbname" class="item">dbname</a></strong></dt>
<dd>
<p>The name of the database.</p>
</dd>
</dl>
<p>Note that ret, fetch, ins, upd, and del items will always be 0 if Postgres is version 8.2 or lower, as those stats were
not available in those versions.</p>
<p>If the dbname argument is given, seven additional items are returned:</p>
<dl>
<dt><strong><a name="idx_scan" class="item">idx_scan</a></strong></dt>
<dd>
<p>Total number of user index scans.</p>
</dd>
<dt><strong><a name="idx_tup_read" class="item">idx_tup_read</a></strong></dt>
<dd>
<p>Total number of user index entries returned.</p>
</dd>
<dt><strong><a name="idx_tup_fetch" class="item">idx_tup_fetch</a></strong></dt>
<dd>
<p>Total number of rows fetched by simple user index scans.</p>
</dd>
<dt><strong><a name="idx_blks_read" class="item">idx_blks_read</a></strong></dt>
<dd>
<p>Total number of disk blocks read for all user indexes.</p>
</dd>
<dt><strong><a name="idx_blks_hit" class="item">idx_blks_hit</a></strong></dt>
<dd>
<p>Total number of buffer hits for all user indexes.</p>
</dd>
<dt><strong><a name="seq_scan" class="item">seq_scan</a></strong></dt>
<dd>
<p>Total number of sequential scans against all user tables.</p>
</dd>
<dt><strong><a name="seq_tup_read" class="item">seq_tup_read</a></strong></dt>
<dd>
<p>Total number of tuples returned from all user tables.</p>
</dd>
</dl>
<p>Example 1: Grab the stats for a database named "products" on host "willow":</p>
<pre>
check_postgres_dbstats --dbhost willow --dbname products</pre>
<p>
</p>
<h2><a name="disabled_triggers"><strong>disabled_triggers</strong></a></h2>
<p>(<code>symlink: check_postgres_disabled_triggers</code>) Checks on the number of disabled triggers inside the database.
The <em>--warning</em> and <em>--critical</em> options are the number of such triggers found, and both
default to "1", as in normal usage having disabled triggers is a dangerous event. If the
database being checked is 8.3 or higher, the check is for the number of triggers that are
in a 'disabled' status (as opposed to being 'always' or 'replica'). The output will show
the name of the table and the name of the trigger for each disabled trigger.</p>
<p>Example 1: Make sure that there are no disabled triggers</p>
<pre>
check_postgres_disabled_triggers</pre>
<p>For MRTG output, returns the number of disabled triggers on the first line.</p>
<p>
</p>
<h2><a name="disk_space"><strong>disk_space</strong></a></h2>
<p>(<code>symlink: check_postgres_disk_space</code>) Checks on the available physical disk space used by Postgres. This action requires
that you have the executable "/bin/df" available to report on disk sizes, and it
also needs to be run as a superuser, so it can examine the <strong>data_directory</strong>
setting inside of Postgres. The <em>--warning</em> and <em>--critical</em> options are
given in either sizes or percentages. If using sizes, the standard unit types
are allowed: bytes, kilobytes, gigabytes, megabytes, gigabytes, terabytes, or
exabytes. Each may be abbreviated to the first letter only; no units at all
indicates 'bytes'. The default values are '90%' and '95%'.</p>
<p>This command checks the following things to determine all of the different
physical disks being used by Postgres.</p>
<p><strong>data_directory</strong> - The disk that the main data directory is on.</p>
<p><strong>log directory</strong> - The disk that the log files are on.</p>
<p><strong>WAL file directory</strong> - The disk that the write-ahead logs are on (e.g. symlinked pg_xlog)</p>
<p><strong>tablespaces</strong> - Each tablespace that is on a separate disk.</p>
<p>The output shows the total size used and available on each disk, as well as
the percentage, ordered by highest to lowest percentage used. Each item above
maps to a file system: these can be included or excluded. See the
<a href="#basic_filtering">BASIC FILTERING</a> section for more details.</p>
<p>Example 1: Make sure that no file system is over 90% for the database on port 5432.</p>
<pre>
check_postgres_disk_space --port=5432 --warning='90%' --critical="90%'</pre>
<p>Example 2: Check that all file systems starting with /dev/sda are smaller than 10 GB and 11 GB (warning and critical)</p>
<pre>
check_postgres_disk_space --port=5432 --warning='10 GB' --critical='11 GB' --include="~^/dev/sda"</pre>
<p>For MRTG output, returns the size in bytes of the file system on the first line,
and the name of the file system on the fourth line.</p>
<p>
</p>
<h2><a name="fsm_pages"><strong>fsm_pages</strong></a></h2>
<p>(<code>symlink: check_postgres_fsm_pages</code>) Checks how close a cluster is to the Postgres <strong>max_fsm_pages</strong> setting.
This action will only work for databases of 8.2 or higher, and it requires the contrib
module <strong>pg_freespacemap</strong> be installed. The <em>--warning</em> and <em>--critical</em> options should be expressed
as percentages. The number of used pages in the free-space-map is determined by looking in the
pg_freespacemap_relations view, and running a formula based on the formula used for
outputting free-space-map pageslots in the vacuum verbose command. The default values are <strong>85%</strong> for the
warning and <strong>95%</strong> for the critical.</p>
<p>Example 1: Give a warning when our cluster has used up 76% of the free-space pageslots, with pg_freespacemap installed in database robert</p>
<pre>
check_postgres_fsm_pages --dbname=robert --warning="76%"</pre>
<p>While you need to pass in the name of the database where pg_freespacemap is installed, you only need to run this check once per cluster. Also, checking this information does require obtaining special locks on the free-space-map, so it is recommend you do not run this check with short intervals.</p>
<p>For MRTG output, returns the percent of free-space-map on the first line, and the number of pages currently used on
the second line.</p>
<p>
</p>
<h2><a name="fsm_relations"><strong>fsm_relations</strong></a></h2>
<p>(<code>symlink: check_postgres_fsm_relations</code>) Checks how close a cluster is to the Postgres <strong>max_fsm_relations</strong> setting.
This action will only work for databases of 8.2 or higher, and it requires the contrib module <strong>pg_freespacemap</strong> be
installed. The <em>--warning</em> and <em>--critical</em> options should be expressed as percentages. The number of used relations
in the free-space-map is determined by looking in the pg_freespacemap_relations view. The default values are <strong>85%</strong> for
the warning and <strong>95%</strong> for the critical.</p>
<p>Example 1: Give a warning when our cluster has used up 80% of the free-space relations, with pg_freespacemap installed in database dylan</p>
<pre>
check_postgres_fsm_relations --dbname=dylan --warning="75%"</pre>
<p>While you need to pass in the name of the database where pg_freespacemap is installed, you only need to run this check
once per cluster. Also,
checking this information does require obtaining special locks on the free-space-map, so it is recommend you do not
run this check with short intervals.</p>
<p>For MRTG output, returns the percent of free-space-map on the first line, the number of relations currently used on
the second line.</p>
<p>
</p>
<h2><a name="index_size"><strong>index_size</strong></a></h2>
<p>
</p>
<h2><a name="table_size"><strong>table_size</strong></a></h2>
<p>
</p>
<h2><a name="relation_size"><strong>relation_size</strong></a></h2>
<p>(symlinks: <code>check_postgres_index_size</code>, <code>check_postgres_table_size</code>, and <code>check_postgres_relation_size</code>)
The actions <strong>table_size</strong> and <strong>index_size</strong> are simply variations of the
<strong>relation_size</strong> action, which checks for a relation that has grown too big.
Relations (in other words, tables and indexes) can be filtered with the
<em>--include</em> and <em>--exclude</em> options. See the <a href="#basic_filtering">BASIC FILTERING</a> section
for more details. Relations can also be filtered by the user that owns them,
by using the <em>--includeuser</em> and <em>--excludeuser</em> options.
See the <a href="#user_name_filtering">USER NAME FILTERING</a> section for more details.</p>
<p>The values for the <em>--warning</em> and <em>--critical</em> options are file sizes, and
may have units of bytes, kilobytes, megabytes, gigabytes, terabytes, or exabytes.
Each can be abbreviated to the first letter. If no units are given, bytes are
assumed. There are no default values: both the warning and the critical option
must be given. The return text shows the size of the largest relation found.</p>
<p>If the <em>--showperf</em> option is enabled, <em>all</em> of the relations with their sizes
will be given. To prevent this, it is recommended that you set the
<em>--perflimit</em> option, which will cause the query to do a
<code>ORDER BY size DESC LIMIT (perflimit)</code>.</p>
<p>Example 1: Give a critical if any table is larger than 600MB on host burrick.</p>
<pre>
check_postgres_table_size --critical='600 MB' --warning='600 MB' --host=burrick</pre>
<p>Example 2: Warn if the table products is over 4 GB in size, and give a critical at 4.5 GB.</p>
<pre>
check_postgres_table_size --host=burrick --warning='4 GB' --critical='4.5 GB' --include=products</pre>
<p>Example 3: Warn if any index not owned by postgres goes over 500 MB.</p>
<pre>
check_postgres_index_size --port=5432 --excludeuser=postgres -w 500MB -c 600MB</pre>
<p>For MRTG output, returns the size in bytes of the largest relation, and the name of the database
and relation as the fourth line.</p>
<p>
</p>
<h2><a name="last_vacuum"><strong>last_vacuum</strong></a></h2>
<p>
</p>
<h2><a name="last_autovacuum"><strong>last_autovacuum</strong></a></h2>
<p>
</p>
<h2><a name="last_analyze"><strong>last_analyze</strong></a></h2>
<p>
</p>
<h2><a name="last_autoanalyze"><strong>last_autoanalyze</strong></a></h2>
<p>(symlinks: <code>check_postgres_last_vacuum</code>, <code>check_postgres_last_autovacuum</code>, <code>check_postgres_last_analyze</code>, and
<code>check_postgres_last_autoanalyze</code>)
Checks how long it has been since vacuum (or analyze) was last run on each
table in one or more databases. Use of these actions requires that the target
database is version 8.3 or greater, or that the version is 8.2 and the
configuration variable <strong>stats_row_level</strong> has been enabled. Tables can be filtered with the
<em>--include</em> and <em>--exclude</em> options. See the <a href="#basic_filtering">BASIC FILTERING</a> section
for more details.
Tables can also be filtered by their owner by use of the
<em>--includeuser</em> and <em>--excludeuser</em> options.
See the <a href="#user_name_filtering">USER NAME FILTERING</a> section for more details.</p>
<p>The units for <em>--warning</em> and <em>--critical</em> are specified as times.
Valid units are seconds, minutes, hours, and days; all can be abbreviated
to the first letter. If no units are given, 'seconds' are assumed. The
default values are '1 day' and '2 days'. Please note that there are cases
in which this field does not get automatically populated. If certain tables
are giving you problems, make sure that they have dead rows to vacuum,
or just exclude them from the test.</p>
<p>The schema named 'information_schema' is excluded from this test, as the only tables
it contains are small and do not change.</p>
<p>Note that the non-'auto' versions will also check on the auto versions as well. In other words,
using last_vacuum will report on the last vacuum, whether it was a normal vacuum, or
one run by the autovacuum daemon.</p>
<p>Example 1: Warn if any table has not been vacuumed in 3 days, and give a
critical at a week, for host wormwood</p>
<pre>
check_postgres_last_vacuum --host=wormwood --warning='3d' --critical='7d'</pre>
<p>Example 2: Same as above, but skip tables belonging to the users 'eve' or 'mallory'</p>
<pre>
check_postgres_last_vacuum --host=wormwood --warning='3d' --critical='7d' --excludeusers=eve,mallory</pre>
<p>For MRTG output, returns (on the first line) the LEAST amount of time in seconds since a table was
last vacuumed or analyzed. The fourth line returns the name of the database and name of the table.</p>
<p>
</p>
<h2><a name="listener"><strong>listener</strong></a></h2>
<p>(<code>symlink: check_postgres_listener</code>) Confirm that someone is listening for one or more specific strings. Only one of warning or critical is needed. The format
is a simple string representing the LISTEN target, or a tilde character followed by a string for a regular expression
check.</p>
<p>Example 1: Give a warning if nobody is listening for the string bucardo_mcp_ping on ports 5555 and 5556</p>
<pre>
check_postgres_listener --port=5555,5556 --warning=bucardo_mcp_ping</pre>
<p>Example 2: Give a critical if there are no active LISTEN requests matching 'grimm' on database oskar</p>
<pre>
check_postgres_listener --db oskar --critical=~grimm</pre>
<p>For MRTG output, returns a 1 or a 0 on the first, indicating success or failure. The name of the notice must
be provided via the <em>--mrtg</em> option.</p>
<p>
</p>
<h2><a name="locks"><strong>locks</strong></a></h2>
<p>(<code>symlink: check_postgres_locks</code>) Check the total number of locks on one or more databases. There is no
need to run this more than once per database cluster. Databases can be filtered
with the <em>--include</em> and <em>--exclude</em> options. See the <a href="#basic_filtering">BASIC FILTERING</a> section
for more details.</p>
<p>The <em>--warning</em> and <em>--critical</em> options can be specified as simple numbers,
which represent the total number of locks, or they can be broken down by type of lock.
Valid lock names are <code>'total'</code>, <code>'waiting'</code>, or the name of a lock type used by Postgres.
These names are case-insensitive and do not need the "lock" part on the end,
so <strong>exclusive</strong> will match 'ExclusiveLock'. The format is name=number, with different
items separated by semicolons.</p>
<p>Example 1: Warn if the number of locks is 100 or more, and critical if 200 or more, on host garrett</p>
<pre>
check_postgres_locks --host=garrett --warning=100 --critical=200</pre>
<p>Example 2: On the host artemus, warn if 200 or more locks exist, and give a critical if over 250 total locks exist, or if over 20 exclusive locks exist, or if over 5 connections are waiting for a lock.</p>
<pre>
check_postgres_locks --host=artemus --warning=200 --critical="total=250;waiting=5;exclusive=20"</pre>
<p>For MRTG output, returns the number of locks on the first line, and the name of the database on the fourth line.</p>
<p>
</p>
<h2><a name="logfile"><strong>logfile</strong></a></h2>
<p>(<code>symlink: check_postgres_logfile</code>) Ensures that the logfile is in the expected location and is being logged to.
This action issues a command that throws an error on each database it is
checking, and ensures that the message shows up in the logs. It scans the
various log_* settings inside of Postgres to figure out where the logs should be.
If you are using syslog, it does a rough (but not foolproof) scan of
<em class="file">/etc/syslog.conf</em>. Alternatively, you can provide the name of the logfile
with the <em>--logfile</em> option. This is especially useful if the logs have a
custom rotation scheme driven be an external program. The <strong>--logfile</strong> option
supports the following escape characters: <code>%Y %m %d %H</code>, which represent
the current year, month, date, and hour respectively. An error is always
reported as critical unless the warning option has been passed in as a non-zero
value. Other than that specific usage, the <code>--warning</code> and <code>--critical</code>
options should <em>not</em> be used.</p>
<p>Example 1: On port 5432, ensure the logfile is being written to the file /home/greg/pg8.2.log</p>
<pre>
check_postgres_logfile --port=5432 --logfile=/home/greg/pg8.2.log</pre>
<p>Example 2: Same as above, but raise a warning, not a critical</p>
<pre>
check_postgres_logfile --port=5432 --logfile=/home/greg/pg8.2.log -w 1</pre>
<p>For MRTG output, returns a 1 or 0 on the first line, indicating success or failure. In case of a
failure, the fourth line will provide more detail on the failure encountered.</p>
<p>
</p>
<h2><a name="new_version_cp"><strong>new_version_cp</strong></a></h2>
<p>(<code>symlink: check_postgres_new_version_cp</code>) Checks if a newer version of this program
(check_postgres.pl) is available, by grabbing the version from a small text file
on the main page of the home page for the project. Returns a warning if the returned
version does not match the one you are running. Recommended interval to check is
once a day. See also the information on the <code>--get_method</code> option.</p>
<p>
</p>
<h2><a name="new_version_pg"><strong>new_version_pg</strong></a></h2>
<p>(<code>symlink: check_postgres_new_version_pg</code>) Checks if a newer revision of Postgres
exists for each database connected to. Note that this only checks for revision, e.g.
going from 8.3.6 to 8.3.7. Revisions are always 100% binary compatible and involve no
dump and restore to upgrade. Revisions are made to address bugs, so upgrading as soon
as possible is always recommended. Returns a warning if you do not have the latest revision.
It is recommended this check is run at least once a day. See also the information on
the <code>--get_method</code> option.</p>
<p>
</p>
<h2><a name="new_version_bc"><strong>new_version_bc</strong></a></h2>
<p>(<code>symlink: check_postgres_new_version_bc</code>) Checks if a newer version of the Bucardo
program is available. The current version is obtained by running <code>bucardo_ctl --version</code>.
If a major upgrade is available, a warning is returned. If a revision upgrade is
available, a critical is returned. (Bucardo is a master to slave, and master to master
replication system for Postgres: see <a href="http://bucardo.org">http://bucardo.org</a> for more information).
See also the information on the <code>--get_method</code> option.</p>
<p>
</p>
<h2><a name="pgbouncer_checksum"><strong>pgbouncer_checksum</strong></a></h2>
<p>(<code>symlink: check_postgres_pgbouncer_checksum</code>) Checks that all the
pgBouncer settings are the same as last time you checked.
This is done by generating a checksum of a sorted list of setting names and
their values. Note that you shouldn't specify the database name, it will
automatically default to pgbouncer. Either the <em>--warning</em> or the <em>--critical</em> option
should be given, but not both. The value of each one is the checksum, a
32-character hexadecimal value. You can run with the special <code>--critical=0</code> option
to find out an existing checksum.</p>
<p>This action requires the Digest::MD5 module.</p>
<p>Example 1: Find the initial checksum for pgbouncer configuration on port 6432 using the default user (usually postgres)</p>
<pre>
check_postgres_pgbouncer_checksum --port=6432 --critical=0</pre>
<p>Example 2: Make sure no settings have changed and warn if so, using the checksum from above.</p>
<pre>
check_postgres_pgbouncer_checksum --port=6432 --warning=cd2f3b5e129dc2b4f5c0f6d8d2e64231</pre>
<p>For MRTG output, returns a 1 or 0 indicating success of failure of the checksum to match. A
checksum must be provided as the <code>--mrtg</code> argument. The fourth line always gives the
current checksum.</p>
<p>
</p>
<h2><a name="prepared_txns"><strong>prepared_txns</strong></a></h2>
<p>(<code>symlink: check_postgres_prepared_txns</code>) Check on the age of any existing prepared transactions.
Note that most people will NOT use prepared transactions, as they are part of two-part commit
and complicated to maintain. They should also not be confused with prepared STATEMENTS, which is
what most people think of when they hear prepare. The default value for a warning is 1 second, to
detect any use of prepared transactions, which is probably a mistake on most systems. Warning and
critical are the number of seconds a prepared transaction has been open before an alert is given.</p>
<p>Example 1: Give a warning on detecting any prepared transactions:</p>
<pre>
check_postgres_prepared_txns -w 0</pre>
<p>Example 2: Give a critical if any prepared transaction has been open longer than 10 seconds, but allow
up to 360 seconds for the database 'shrike':</p>
<pre>
check_postgres_listener --critical=10 --exclude=shrike
check_postgres_listener --critical=360 --include=shrike</pre>
<p>For MRTG output, returns the number of seconds the oldest transaction has been open as the first line,
and which database is came from as the final line.</p>
<p>