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
|
create or replace function pgq.maint_tables_to_vacuum()
returns setof text as $$
-- ----------------------------------------------------------------------
-- Function: pgq.maint_tables_to_vacuum(0)
--
-- Returns list of tablenames that need frequent vacuuming.
--
-- The goal is to avoid hardcoding them into maintenance process.
--
-- Returns:
-- List of table names.
-- ----------------------------------------------------------------------
declare
scm text;
tbl text;
fqname text;
begin
-- assume autovacuum handles them fine
if current_setting('autovacuum') = 'on' then
return;
end if;
for scm, tbl in values
('pgq', 'subscription'),
('pgq', 'consumer'),
('pgq', 'queue'),
('pgq', 'tick'),
('pgq', 'retry_queue'),
('pgq_ext', 'completed_tick'),
('pgq_ext', 'completed_batch'),
('pgq_ext', 'completed_event'),
('pgq_ext', 'partial_batch'),
--('pgq_node', 'node_location'),
--('pgq_node', 'node_info'),
('pgq_node', 'local_state'),
--('pgq_node', 'subscriber_info'),
--('londiste', 'table_info'),
('londiste', 'seq_info'),
--('londiste', 'applied_execute'),
--('londiste', 'pending_fkeys'),
('txid', 'epoch'),
('londiste', 'completed')
loop
select n.nspname || '.' || t.relname into fqname
from pg_class t, pg_namespace n
where n.oid = t.relnamespace
and n.nspname = scm
and t.relname = tbl;
if found then
return next fqname;
end if;
end loop;
return;
end;
$$ language plpgsql;
|