After issuing DROP TABLE
or ALTER TABLE
command pg_stat_activity
table becomes full of Locks
and the query hangs forever. Killing PID
s and reissuing query gives the same result. The problem disappears after the system gets restarted (I restart docker
container for that).
How to investigate this issue?
lock the_table in exclusive mode nowait
before attempting the ALTER or DROP. That way you would get an error immediately if some other transaction still uses that table. Make sure you do that in a transaction to keep the lock if it succeeds.