Skip to content

New rule: Dropping a foreign key constraint requires an access exclusive lock on the referenced table. #1294

Description

@dreid

Example:

ALTER TABLE table_x
    DROP CONSTRAINT table_x_table_y_column_fkey;

This acquires an AccessExclusiveLock on both table_x, and table_y.

Without inspecting the rest of the schema it's not possible to tell for sure this is a foreign key constraint, or what table it might be referencing.

We do know that Postgres' default constraint naming will always apply the _fkey%d label to the constraint name, and it will do this after truncating the constraint name to make sure there is room for the label

We could have this rule configured with a regex to match foreign key constraints names, and that could also provide a mechanism for configuring the rule if you're using non-default constraint naming.

That config could maybe also be coupled with a rule that enforces non-default constraint naming matches the appropriate pattern?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions