docs/reference/rules/avoid-attaching-partition.md
Diagnostic Category: lint/safety/avoidAttachingPartition
Since: vnext
[!NOTE] This rule is recommended. A diagnostic error will appear when linting your code.
Sources:
Attaching a partition acquires an ACCESS EXCLUSIVE lock on the parent table.
ALTER TABLE ... ATTACH PARTITION locks the parent table, blocking all reads and writes.
For large tables, this can cause significant downtime. Consider creating the partition
with the correct constraints upfront, or use a staging table approach.
alter table my_table attach partition my_partition for values from ('2024-01-01') to ('2025-01-01');
code-block.sql:1:1 lint/safety/avoidAttachingPartition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Attaching a partition acquires an ACCESS EXCLUSIVE lock on the parent table.
> 1 │ alter table my_table attach partition my_partition for values from ('2024-01-01') to ('2025-01-01');
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
i This blocks all reads and writes on the parent table. Consider adding a matching CHECK constraint to the child table before attaching to minimize lock duration.
select 1;
{
"linter": {
"rules": {
"safety": {
"avoidAttachingPartition": "error"
}
}
}
}