I have a table A, that is referencing two other tables B and C. I would like to understand what's happening exactly when i am dropping A.
When dropping A my understanding is that an access exclusive lock needs to be acquired on A and B (mainly to remove triggers ?).
I am curious to know how these locks are done: are locks on B and C acquired at the same time ? or sequentially ?
If that's the former that could explain some deadlock that i am sometimes noticing when dropping tables
Thanks
1 Answer 1
You are right: if you drop a table, all its foreign key constraints are dropped as well, and dropping the system triggers on the referenced table requires an ACCESS EXCLUSIVE
lock there. These locks are all taken during the execution of the DROP TABLE
statement, in the same transaction. These locks will be taken one after the other, so if you have another transaction that needs these tables, you can easily get a deadlock.