Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lints/0030_autovacuum_disabled.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ from pg_catalog.pg_class cls
join pg_catalog.pg_namespace nsp on cls.relnamespace = nsp.oid
where
cls.relkind = 'r'
and 'autovacuum_enabled=false' = any(cls.reloptions)
-- Postgres stores the value as written (false, off, 0, no, ...), so
-- parse it as a boolean instead of matching one spelling
and exists (
select 1
from pg_catalog.unnest(cls.reloptions) as opt
where
opt like 'autovacuum_enabled=%'
and not pg_catalog.substr(opt, 20)::boolean
)
and nsp.nspname not in (
'_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_config',
'_timescaledb_internal', 'auth', 'cron', 'extensions', 'graphql',
Expand Down
10 changes: 9 additions & 1 deletion splinter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,15 @@ from pg_catalog.pg_class cls
join pg_catalog.pg_namespace nsp on cls.relnamespace = nsp.oid
where
cls.relkind = 'r'
and 'autovacuum_enabled=false' = any(cls.reloptions)
-- Postgres stores the value as written (false, off, 0, no, ...), so
-- parse it as a boolean instead of matching one spelling
and exists (
select 1
from pg_catalog.unnest(cls.reloptions) as opt
where
opt like 'autovacuum_enabled=%'
and not pg_catalog.substr(opt, 20)::boolean
)
and nsp.nspname not in (
'_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_config',
'_timescaledb_internal', 'auth', 'cron', 'extensions', 'graphql',
Expand Down
21 changes: 21 additions & 0 deletions test/expected/0030_autovacuum_disabled.out
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,25 @@ begin;
(0 rows)

rollback to savepoint b;
savepoint c;
-- NEGATIVE: autovacuum_enabled=on (another spelling of true) — must not fire
create table public.active_on (id int) with (autovacuum_enabled = on);
select * from lint."0030_autovacuum_disabled";
name | title | level | facing | categories | description | detail | remediation | metadata | cache_key
------+-------+-------+--------+------------+-------------+--------+-------------+----------+-----------
(0 rows)

-- POSITIVE: other spellings of false that Postgres stores verbatim — must fire
create table public.events (id int) with (autovacuum_enabled = off);
create table public.logs (id int) with (autovacuum_enabled = 0);
create table public.metrics (id int) with (autovacuum_enabled = 'no');
select name, detail, cache_key from lint."0030_autovacuum_disabled";
name | detail | cache_key
---------------------+-----------------------------------------------------------------------------------+------------------------------------
autovacuum_disabled | Table `public`.`events` has autovacuum_enabled=false set as a storage parameter. | autovacuum_disabled_public_events
autovacuum_disabled | Table `public`.`logs` has autovacuum_enabled=false set as a storage parameter. | autovacuum_disabled_public_logs
autovacuum_disabled | Table `public`.`metrics` has autovacuum_enabled=false set as a storage parameter. | autovacuum_disabled_public_metrics
(3 rows)

rollback to savepoint c;
rollback;
14 changes: 14 additions & 0 deletions test/sql/0030_autovacuum_disabled.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ begin;

rollback to savepoint b;

savepoint c;

-- NEGATIVE: autovacuum_enabled=on (another spelling of true) — must not fire
create table public.active_on (id int) with (autovacuum_enabled = on);
select * from lint."0030_autovacuum_disabled";

-- POSITIVE: other spellings of false that Postgres stores verbatim — must fire
create table public.events (id int) with (autovacuum_enabled = off);
create table public.logs (id int) with (autovacuum_enabled = 0);
create table public.metrics (id int) with (autovacuum_enabled = 'no');
select name, detail, cache_key from lint."0030_autovacuum_disabled";

rollback to savepoint c;

rollback;