requireConcurrentRefreshMatview

Diagnostic Category: lint/safety/requireConcurrentRefreshMatview

Since: vnext

Note

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

Sources: - Inspired from: pgfence/refresh-matview-blocking

Description

REFRESH MATERIALIZED VIEW without CONCURRENTLY acquires an ACCESS EXCLUSIVE lock.

This blocks all reads on the materialized view until the refresh completes. Use REFRESH MATERIALIZED VIEW CONCURRENTLY to allow reads during the refresh. Note: concurrent refresh requires a unique index on the materialized view.

Examples

Invalid

refresh materialized view my_view;
code-block.sql:1:1 lint/safety/requireConcurrentRefreshMatview ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! REFRESH MATERIALIZED VIEW without CONCURRENTLY blocks all reads.

  > 1 │ refresh materialized view my_view;
      │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 

  i Use REFRESH MATERIALIZED VIEW CONCURRENTLY to allow reads during the refresh. This requires a unique index on the view.


Valid

refresh materialized view concurrently my_view;

How to configure


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