@@ -1532,23 +1532,26 @@ metrics:
15321532 (regexp_matches(v::text, E'ON (.*?) '))[1] as object_name,
15331533 v::text as recommendation
15341534 from json_array_elements(pg_qualstats_index_advisor() -> 'indexes') v),
1535+ limited_r as (select * from r limit 25),
15351536 rr as (select
15361537 (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
15371538 'create_index'::text as tag_reco_topic,
15381539 string_agg(object_name, ',') as tag_object_name,
15391540 'create indexes for better query performance'::text as recommendation,
15401541 'Use CREATE INDEX CONCURRENTLY <index_name> ON <table_name> (<columns>);'::text as extra_info
1541- from r
1542- limit 50),
1542+ from limited_r),
15431543 last_reco(s) as (
1544- select case when count(*) > 50 then format(' and found %s more...', count(*)-50) end from r)
1544+ select case when count(*) > 25 then format(' and found %s more...', count(*)-25) end from r),
1545+ total_count as (
1546+ select count(*) as total from r)
15451547 select
15461548 epoch_ns,
15471549 tag_reco_topic,
15481550 concat(tag_object_name, s) as tag_object_name,
15491551 recommendation,
1550- extra_info
1551- from rr, last_reco
1552+ extra_info,
1553+ total as total_recommendations
1554+ from rr, last_reco, total_count
15521555 where tag_object_name > '';
15531556 init_sql : " CREATE EXTENSION IF NOT EXISTS pg_qualstats;"
15541557 node_status : primary
@@ -1564,23 +1567,26 @@ metrics:
15641567 nspname::text as object_name
15651568 from pg_namespace
15661569 where nspname = 'public' and nspacl::text ~ E'[,\\{]+=U?C/'),
1570+ limited_r as (select * from r limit 25),
15671571 rr as (select
15681572 (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
15691573 'default_public_schema_privs'::text as tag_reco_topic,
15701574 string_agg(object_name, ',') as tag_object_name,
15711575 'REVOKE CREATE ON SCHEMA public FROM PUBLIC;'::text as recommendation,
15721576 'only authorized users should be allowed to create new objects'::text as extra_info
1573- from r
1574- limit 50),
1577+ from limited_r),
15751578 last_reco(s) as (
1576- select case when count(*) > 50 then format(' and found %s more...', count(*)-50) end from r)
1579+ select case when count(*) > 25 then format(' and found %s more...', count(*)-25) end from r),
1580+ total_count as (
1581+ select count(*) as total from r)
15771582 select
15781583 epoch_ns,
15791584 tag_reco_topic,
15801585 concat(tag_object_name, s) as tag_object_name,
15811586 recommendation,
1582- extra_info
1583- from rr, last_reco
1587+ extra_info,
1588+ total as total_recommendations
1589+ from rr, last_reco, total_count
15841590 where tag_object_name > '';
15851591 node_status : primary
15861592 storage_name : " recommendations"
@@ -1592,26 +1598,29 @@ metrics:
15921598 sqls :
15931599 11 : |
15941600 with r as (select /* pgwatch_generated */
1595- c.oid
1601+ c.oid::regclass::text as object_name
15961602 from pg_trigger t join pg_class c on c.oid = t.tgrelid
15971603 where tgenabled = 'D'),
1604+ limited_r as (select * from r limit 25),
15981605 rr as (select
15991606 (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
16001607 'disabled_triggers'::text as tag_reco_topic,
1601- string_agg(oid::regclass::text , ',') as tag_object_name,
1608+ string_agg(object_name , ',') as tag_object_name,
16021609 'review usage of triggers and consider dropping them if not needed anymore'::text as recommendation,
16031610 'Enable: ALTER TABLE <table_name> ENABLE TRIGGER <trigger_name>; Drop: DROP TRIGGER <trigger_name> ON <table_name>;'::text as extra_info
1604- from r
1605- limit 50),
1611+ from limited_r),
16061612 last_reco(s) as (
1607- select case when count(*) > 50 then format(' and found %s more...', count(*)-50) end from r)
1613+ select case when count(*) > 25 then format(' and found %s more...', count(*)-25) end from r),
1614+ total_count as (
1615+ select count(*) as total from r)
16081616 select
16091617 epoch_ns,
16101618 tag_reco_topic,
16111619 concat(tag_object_name, s) as tag_object_name,
16121620 recommendation,
1613- extra_info
1614- from rr, last_reco
1621+ extra_info,
1622+ total as total_recommendations
1623+ from rr, last_reco, total_count
16151624 where tag_object_name > '';
16161625 node_status : primary
16171626 storage_name : " recommendations"
@@ -1636,23 +1645,26 @@ metrics:
16361645 and not indisprimary
16371646 and not indisreplident
16381647 and not schemaname like '_timescaledb%'),
1648+ limited_r as (select * from r limit 25),
16391649 rr as (select
16401650 (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
16411651 'drop_index'::text as tag_reco_topic,
16421652 string_agg(object_name, ',') as tag_object_name,
16431653 'drop unused or invalid indexes to improve performance'::text as recommendation,
16441654 'Make sure to also check replica pg_stat_user_indexes.idx_scan count if using them for queries'::text as extra_info
1645- from r
1646- limit 50),
1655+ from limited_r),
16471656 last_reco(s) as (
1648- select case when count(*) > 50 then format(' and found %s more...', count(*)-50) end from r)
1657+ select case when count(*) > 25 then format(' and found %s more...', count(*)-25) end from r),
1658+ total_count as (
1659+ select count(*) as total from r)
16491660 select
16501661 epoch_ns,
16511662 tag_reco_topic,
16521663 concat(tag_object_name, s) as tag_object_name,
16531664 recommendation,
1654- extra_info
1655- from rr, last_reco
1665+ extra_info,
1666+ total as total_recommendations
1667+ from rr, last_reco, total_count
16561668 where tag_object_name > '';
16571669 init_sql : " CREATE EXTENSION IF NOT EXISTS pg_qualstats;"
16581670 node_status : primary
@@ -1713,23 +1725,26 @@ metrics:
17131725 r as (select /* pgwatch_generated */
17141726 object_name
17151727 from nested_views),
1728+ limited_r as (select * from r limit 25),
17161729 rr as (select
17171730 (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
17181731 'overly_nested_views'::text as tag_reco_topic,
17191732 string_agg(object_name, ',') as tag_object_name,
17201733 'overly nested views can affect performance'::text as recommendation,
17211734 'Consider flattening views by creating materialized views or combining view logic to reduce dependency depth'::text as extra_info
1722- from r
1723- limit 50),
1735+ from limited_r),
17241736 last_reco(s) as (
1725- select case when count(*) > 50 then format(' and found %s more...', count(*)-50) end from r)
1737+ select case when count(*) > 25 then format(' and found %s more...', count(*)-25) end from r),
1738+ total_count as (
1739+ select count(*) as total from r)
17261740 select
17271741 epoch_ns,
17281742 tag_reco_topic,
17291743 concat(tag_object_name, s) as tag_object_name,
17301744 recommendation,
1731- extra_info
1732- from rr, last_reco
1745+ extra_info,
1746+ total as total_recommendations
1747+ from rr, last_reco, total_count
17331748 where tag_object_name > '';
17341749 node_status : primary
17351750 storage_name : " recommendations"
@@ -1757,23 +1772,26 @@ metrics:
17571772 and c.reltuples >= 1e5 /* ignore smaller tables */
17581773 and not exists ( /* leave out sub-partitions */
17591774 select * from pg_inherits where inhrelid = c.oid)),
1775+ limited_r as (select * from r limit 25),
17601776 rr as (select
17611777 (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
17621778 'partial_index_candidates'::text as tag_reco_topic,
17631779 string_agg(object_name, ',') as tag_object_name,
17641780 'indexes could possibly be declared partial leaving out NULL-s'::text as recommendation,
17651781 'CREATE INDEX CONCURRENTLY <index_name> ON <table_name> (<column>) WHERE <column> IS NOT NULL;'::text as extra_info
1766- from r
1767- limit 50),
1782+ from limited_r),
17681783 last_reco(s) as (
1769- select case when count(*) > 50 then format(' and found %s more...', count(*)-50) end from r)
1784+ select case when count(*) > 25 then format(' and found %s more...', count(*)-25) end from r),
1785+ total_count as (
1786+ select count(*) as total from r)
17701787 select
17711788 epoch_ns,
17721789 tag_reco_topic,
17731790 concat(tag_object_name, s) as tag_object_name,
17741791 recommendation,
1775- extra_info
1776- from rr, last_reco
1792+ extra_info,
1793+ total as total_recommendations
1794+ from rr, last_reco, total_count
17771795 where tag_object_name > '';
17781796 storage_name : " recommendations"
17791797 reco_sprocs_wo_search_path :
@@ -1788,23 +1806,26 @@ metrics:
17881806 from pg_proc p
17891807 where prosecdef and not 'search_path' = ANY(coalesce(proconfig, '{}'::text[]))
17901808 and not pg_catalog.obj_description(p.oid, 'pg_proc') ~ 'pgwatch'),
1809+ limited_r as (select * from r limit 25),
17911810 rr as (select
17921811 (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
17931812 'sprocs_wo_search_path'::text as tag_reco_topic,
17941813 string_agg(object_name, ',') as tag_object_name,
17951814 'functions without fixed search_path can be potentially abused by malicious users if used objects are not fully qualified'::text as recommendation,
17961815 'ALTER FUNCTION <function_name> SET search_path = pg_catalog, pg_temp;'::text as extra_info
1797- from r
1798- limit 50),
1816+ from limited_r),
17991817 last_reco(s) as (
1800- select case when count(*) > 50 then format(' and found %s more...', count(*)-50) end from r)
1818+ select case when count(*) > 25 then format(' and found %s more...', count(*)-25) end from r),
1819+ total_count as (
1820+ select count(*) as total from r)
18011821 select
18021822 epoch_ns,
18031823 tag_reco_topic,
18041824 concat(tag_object_name, s) as tag_object_name,
18051825 recommendation,
1806- extra_info
1807- from rr, last_reco
1826+ extra_info,
1827+ total as total_recommendations
1828+ from rr, last_reco, total_count
18081829 where tag_object_name > '';
18091830 node_status : primary
18101831 storage_name : " recommendations"
@@ -1825,7 +1846,8 @@ metrics:
18251846 'superuser_count'::text as tag_reco_topic,
18261847 '-'::text as tag_object_name,
18271848 'too many superusers detected - review recommended'::text as recommendation,
1828- format('%s active superusers, %s total active users', r.su, r.users) as extra_info
1849+ format('%s active superusers, %s total active users', r.su, r.users) as extra_info,
1850+ 1 as total_recommendations
18291851 from
18301852 r
18311853 where
0 commit comments