Instead of finding if vacuuming the tables, turn off the automatic vacuum for the tables involved:
alter table table_name_pattern set ( autovacuum_enabled = false, toast.autovacuum_enabled = false );
a table template is a glob template, for example tbl* . At the end of the request, turn on the automatic vacuum again
alter table table_name_pattern set ( autovacuum_enabled = true, toast.autovacuum_enabled = true );
Edit in response to comments:
A query to find out if the involved tables are vacuumed is unnecessary and unhelpful. If it is known that one or more of the tables involved is vacuumed, what should be done? Wait and keep repeating the query until no one has vacuumed? And when none of them starts a long request, in order to find out after a while that the automatic vacuum has just been released? Pointlessly. Why not just turn off the automatic vacuum and avoid all the hassle?
There is no ethical superiority in doing it hard, especially if the hard way gives worse results than the simple one. Simplified code is easier to use and understand, but it is not always easy to build. Many times the opposite, requiring more intellectual effort or willingness, and then more complex.
If the autovacuum parameter is changed inside the transaction and that the transaction is canceled, the setting will revert to what it was before the transaction began.
drop table if exists t; create table t (id int); begin; alter table t set ( autovacuum_enabled = false, toast.autovacuum_enabled = false ); \d+ t Table "public.t" Column | Type | Modifiers | Storage | Stats target | Description
But this setting inside the transaction will not be visible outside the transaction, so I think autovacuum will still work. If this is true, then the parameter must be executed outside the transaction and controlled by the task, which will return it regardless of what happens with a long request.
Clodoaldo neto
source share