Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop constraints before drop column or table #65

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

tbicr
Copy link
Owner

@tbicr tbicr commented Jun 5, 2024

When column or table dropped it also drop with cascade related constraints as foreign keys, index constraints and regular indexes.

Assume that next operations take some time:

  • drop table - physically drop table files
  • drop index or index constraint - physically drop index files

Lets consider possible scenarios:

  • table1 has FK to table2 and we drop any of this tables

    • as cascade operation perform all suboperations will be handled in transaction
    • when we drop FK then EXCLUSIVE LOCK taken for both tables until transaction will be finished
    • we start drop table that do physical operation and take some time on huge table
    • as result any query to other table will wait until EXCLUSIVE LOCK will be released and can be clause of downtime
    • dropping FK before cascade remove locking second table and prevent donwtime
  • table1 has FK to table2 and we drop any column in this relation

    • same logic as in drop table with FK case
  • table has index or index constraint on column we drop

    • as cascade operation perform all suboperations will be handled in transaction
    • when we drop column it also drop indexes and index constraints that can take time on huge table
    • as result any query to this table will wait until EXCLUSIVE LOCK will be released and can be clause of downtime
    • dropping indexes and index constraints before cascade remove or decrease EXCLUSIVE locking and prevent or minimize donwtime

See also #25

@tbicr tbicr force-pushed the drop-constraints-before-drop-column-or-table branch 13 times, most recently from 7903dd6 to 40e55b8 Compare June 7, 2024 20:44
@tbicr tbicr force-pushed the drop-constraints-before-drop-column-or-table branch from 40e55b8 to 44c1dc3 Compare June 7, 2024 20:52
@tbicr tbicr merged commit d53cf68 into master Jun 7, 2024
2 checks passed
@tbicr tbicr deleted the drop-constraints-before-drop-column-or-table branch June 7, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant