-
Notifications
You must be signed in to change notification settings - Fork 25
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
migrations.DeleteModel locks DB when it has ForeignKey field #25
Comments
Thanks for reporting, pretty interesting case, I like idea to rewrite sql to do table dropping more safe (don't lock 2 tables for long time) - in case if no issues with different FK options. |
It looks like you need access to system tables to query foreign keys dynamically. Is that something we should expect? I assume some users that are running migrations may not have that permission. Thoughts? |
There are 2 states:
So access to system tables looks that django migrations requires for normal work. Do you have issue with system tables restrictions? |
Make sense. It looks like normal Django migrations make use of introspection. We can get use that get_constraints method, unless you have any objections. |
drop foreign key before drop table and drop foreign key and indexes before drop column was added in 0.16 |
Describe the bug
When dropping a table with a foreign key (pointing to another table) Postgres will lock the foreign table as well as the table being dropped. This causes all queries to be blocked by the operation.
Here is an article describing the problem:
http://db-oriented.com/2018/04/18/excessive-locking-when-dropping-a-table-in-11g/
3 Options for a fix here:
To Reproduce
Removed ModelB
Locked
model_b
table (expected) and lockedmodel_a
for 8 minutesExpected behavior
Not lock
model_a
or throw a lock timeout after 2 seconds (ZERO_DOWNTIME_MIGRATIONS_LOCK_TIMEOUT
)Versions:
The text was updated successfully, but these errors were encountered: