简体   繁体   中英

Move table to different schema in postgres

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!

  • run SELECT pg_backend_pid() before running the ALTER TABLE

  • start the ALTER TABLE statement

  • in a second database session, run SELECT pg_blocking_pids(12345) , where 12345 is the result from the first query

  • cancel all the blocking transactions found with the previous query with SELECT pg_cancel_backend(23456)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM