Skip to content

Conversation

@SkyMarshall939
Copy link

Hello,

Here is a proposal for improvements to the last_vacuum & last_analyze services. The purpose is to add support for the --exclude parameter for these services in order to be able to exclude X schemas and/or X relations.

Changes

=> Change NaN to -1 to allow counters to be accumulated in Perl code.
=> Add current_database(), schemaname and relname in the last_[analyze|vacuum] query.
=> Relations with n_live_tup = 0 are no longer taken.

How

Classic use of the service concerned by adding the --exclude parameter which takes REGEXP .

# Exclusion of temp and tmp schemas 
check_pgactivity -s last_vacuum --username dbuser --host myhost --dbname mydb --warning 30d --critical 45d --port 5433 --exclude '.*.temp\|tmp..*'

I remain available for any exchange,

Best regards,

@robinportigliatti
Copy link

robinportigliatti commented May 19, 2025

Relations with n_live_tup = 0 are no longer taken.

It should be taken into considerations. What you don't want is a partition_table (the mother) = 0

@blogh
Copy link
Collaborator

blogh commented May 19, 2025

I think skipping table with zero tuple is a regression. But the option would be nice.

As for the partition thing mentionned by @robinportigliatti, 'Declarative Partition"
cannot be vacuumed, but are still catched by this service. But there is an issue for that : #365. It think, it should have it's own PR.

[[local]:5434 (16.8)] postgres@postgres=# CREATE TABLE ttt (i int) PARTITION BY LIST (i);                                              
CREATE TABLE                                                                                                                           
[[local]:5434 (16.8)] postgres@postgres=# CREATE TABLE ttt_1 PARTITION OF ttt FOR VALUES IN (1,2,3);                                   
CREATE TABLE                                                                                                                           
[[local]:5434 (16.8)] postgres@postgres=# SELECT relname, last_vacuum, vacuum_count FROM pg_stat_user_tables WHERE relname LIKE 'ttt%';
 relname | last_vacuum | vacuum_count                                                                                                  
---------+-------------+--------------                                                                                                 
 ttt     | ø           |            0                                                                                                  
 ttt_1   | ø           |            0                                                                                                  
(2 rows)                                                                                                                               
                                                                                                                                       
[[local]:5434 (16.8)] postgres@postgres=# VACUUM ttt;                                                                                  
VACUUM                                                                                                                                 
[[local]:5434 (16.8)] postgres@postgres=# SELECT relname, last_vacuum, vacuum_count FROM pg_stat_user_tables WHERE relname LIKE 'ttt%';
 relname |          last_vacuum          | vacuum_count                                                                                
---------+-------------------------------+--------------                                                                               
 ttt     | ø                             |            0                                                                                
 ttt_1   | 2025-05-19 08:34:50.655983+00 |            1                                                                                
(2 rows)                                                                                                                               

@SkyMarshall939
Copy link
Author

To keep things simple and clean, I remove the n_live_tup condition and focus the patch on pattern management.

Thanks for your return,

Regards,

my $maintenance_count = 0;
my $maintenance_count_auto = 0;
my $maintenance_max = -1;
my $maintenance_hash = 'null';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the proper way to specify this.
@ioguix ?

}

}
push @perfdata => [ $db, $maintenance_max, 's', $w_limit, $c_limit ];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When maintenance_max=Infinity we display Infinitys.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed. Can you fix this @SkyMarshall939 ?

@blogh
Copy link
Collaborator

blogh commented Jul 1, 2025

@ioguix @Krysztophe That's about all I can do review-wise in perl.

@gleu
Copy link
Collaborator

gleu commented Oct 20, 2025

It needs a rebase.

@blogh
Copy link
Collaborator

blogh commented Dec 9, 2025

rebased

@blogh
Copy link
Collaborator

blogh commented Dec 9, 2025

@SkyMarshall939 If you want to skim through the patch again ... that would be helpful (I don't think I broke anything else but me and perl ...).

which kinda hints at the need for tests for this patch

@blogh
Copy link
Collaborator

blogh commented Dec 10, 2025

just found another few dumb mistakes. will post a fix soon.

I missed a label since pg_class and pg_stat_user_tables both have relname.
I did't shift the array access by one after merging the patch that adds a
pg_is_in_recovery.
I discovered autovivification, I feel dirty now.
@blogh
Copy link
Collaborator

blogh commented Dec 11, 2025

Ok ... fixed ... for good .. hopefully.

I feel dumb, I should have tested.

Also, I feel dirty: I discovered autovivification (accessing an empty nested struct creates it): this is pure madness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants