requireConcurrentDetachPartition

Diagnostic Category: lint/safety/requireConcurrentDetachPartition

Since: vnext

Note

This rule is recommended. A diagnostic error will appear when linting your code.

Sources: - Inspired from: pgfence/detach-partition

Description

Detaching a partition without CONCURRENTLY acquires an ACCESS EXCLUSIVE lock.

ALTER TABLE ... DETACH PARTITION without CONCURRENTLY blocks all reads and writes on the parent table. Use DETACH PARTITION ... CONCURRENTLY (Postgres 14+) to avoid blocking concurrent operations.

Examples

Invalid

alter table my_table detach partition my_partition;
code-block.sql:1:1 lint/safety/requireConcurrentDetachPartition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! Detaching a partition without CONCURRENTLY blocks all table access.

  > 1 │ alter table my_table detach partition my_partition;
      │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 

  i Use DETACH PARTITION ... CONCURRENTLY (Postgres 14+) to avoid blocking reads and writes.


Valid

alter table my_table detach partition my_partition concurrently;

How to configure


{
  "linter": {
    "rules": {
      "safety": {
        "requireConcurrentDetachPartition": "error"
      }
    }
  }
}