I would like to change schema of few tables in my Postgres DB. Problem is that all the time there are long running queries and as I understand schema change needs exclusive lock.
Question is how can I do it? Of course I can kill all existing queries and try to do schema rename (move table to different schema) but there is a huge chance that in the meantime new queries will appear.
Thanks for help!
CodePudding user response:
run
SELECT pg_backend_pid()before running theALTER TABLEstart the
ALTER TABLEstatementin a second database session, run
SELECT pg_blocking_pids(12345), where 12345 is the result from the first querycancel all the blocking transactions found with the previous query with
SELECT pg_cancel_backend(23456)
