@@ -1270,7 +1270,8 @@ package check_postgres;
1270
1270
' filter=s@' , # # used by same_schema only
1271
1271
' suffix=s' , # # used by same_schema only
1272
1272
' replace' , # # used by same_schema only
1273
- ' lsfunc=s' , # # used by wal_files and archive_ready
1273
+ ' lsfunc=s' , # # used by wal_fles and archive_ready
1274
+ ' skipcycled' , # # used by sequence only
1274
1275
);
1275
1276
1276
1277
die $USAGE if ! keys %opt and ! @ARGV ;
@@ -7665,6 +7666,12 @@ sub check_sequence {
7665
7666
# # Warning and critical are percentages
7666
7667
# # Can exclude and include sequences
7667
7668
7669
+ my $skipcycled = $opt {' skipcycled' } || 0;
7670
+ my $percsql = ' ROUND(used/slots*100)' ;
7671
+ if ($skipcycled ) {
7672
+ $percsql = ' CASE WHEN cycle THEN 0 ELSE ' . $percsql . ' END' ;
7673
+ }
7674
+
7668
7675
my ($warning , $critical ) = validate_range
7669
7676
({
7670
7677
type => ' percent' ,
@@ -7719,13 +7726,14 @@ sub check_sequence {
7719
7726
WHERE nspname !~ '^pg_temp.*'
7720
7727
ORDER BY nspname, seqname, typname
7721
7728
} ;
7722
- my $SQL10 = q {
7723
- SELECT seqname, last_value, slots, used, ROUND(used/slots*100) AS percent,
7729
+ my $SQL10 = qq {
7730
+ SELECT seqname, last_value, slots, used, $percsql AS percent,
7724
7731
CASE WHEN slots < used THEN 0 ELSE slots - used END AS numleft
7725
7732
FROM (
7726
7733
SELECT quote_ident(schemaname)||'.'||quote_ident(sequencename) AS seqname, COALESCE(last_value,min_value) AS last_value,
7727
- CEIL((max_value-min_value::numeric+1)/increment_by::NUMERIC) AS slots,
7728
- CEIL((COALESCE(last_value,min_value)-min_value::numeric+1)/increment_by::NUMERIC) AS used
7734
+ cycle,
7735
+ CEIL((max_value-min_value::NUMERIC+1)/increment_by::NUMERIC) AS slots,
7736
+ CEIL((COALESCE(last_value,min_value)-min_value::NUMERIC+1)/increment_by::NUMERIC) AS used
7729
7737
FROM pg_sequences) foo} ;
7730
7738
# # use critic
7731
7739
@@ -7752,12 +7760,13 @@ sub check_sequence {
7752
7760
my $seqname_l = $seqname ;
7753
7761
$seqname_l =~ s / '/ ''/ g ; # SQL literal quoting (name is already identifier-quoted)
7754
7762
push @seq_sql , qq{
7755
- SELECT '$seqname_l ' AS seqname, last_value, slots, used, ROUND(used/slots*100) AS percent,
7763
+ SELECT '$seqname_l ' AS seqname, last_value, slots, used, $percsql AS percent,
7756
7764
CASE WHEN slots < used THEN 0 ELSE slots - used END AS numleft
7757
7765
FROM (
7758
7766
SELECT last_value,
7759
- CEIL((LEAST(max_value, $maxValue )-min_value::numeric+1)/increment_by::NUMERIC) AS slots,
7760
- CEIL((last_value-min_value::numeric+1)/increment_by::NUMERIC) AS used
7767
+ is_cycled AS cycle,
7768
+ CEIL((LEAST(max_value, $maxValue )-min_value::NUMERIC+1)/increment_by::NUMERIC) AS slots,
7769
+ CEIL((last_value-min_value::NUMERIC+1)/increment_by::NUMERIC) AS used
7761
7770
FROM $seqname ) foo
7762
7771
} ;
7763
7772
}
@@ -9967,7 +9976,8 @@ =head2 B<sequence>
9967
9976
The I<--warning > and I<--critical > options should be expressed as percentages. The default values
9968
9977
are B<85% > for the warning and B<95% > for the critical. You may use --include and --exclude to
9969
9978
control which sequences are to be checked. Note that this check does account for unusual B<minvalue >
9970
- and B<increment by > values, but does not care if the sequence is set to cycle or not.
9979
+ and B<increment by > values. By default it does not care if the sequence is set to cycle or not,
9980
+ and by passing I<--skipcycled > sequenced set to cycle are reported with 0% usage.
9971
9981
9972
9982
The output for Nagios gives the name of the sequence, the percentage used, and the number of 'calls'
9973
9983
left, indicating how many more times nextval can be called on that sequence before running into
0 commit comments