After issuing DROP TABLE or ALTER TABLE command pg_stat_activity table becomes full of Locks and the query hangs forever. Killing PIDs 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 nowaitbefore 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. – Sep 03 '20 at 11:46ALTER TABLE tblah ADD COLUMN cblah; ALTER TABLE tblah ALTER COLUMN cblah DEFAULT dblah; UPDATE tblah SET cblah = dblah WHERE cblah IS NULL; ALTER TABLE tblah ALTER COLUM cblah NOT NULL;to queries likedrop table blahoralter table tblah drop column cblah? – Dmitriy Grankin Sep 03 '20 at 12:04