简体   繁体   English

postgres alter table因连接池而挂起

[英]postgres alter table hangs with connection pooling

Executing simple alter table add column hangs, this could be due to my application uses connection pooling which opens connections and probably locking tables. 执行简单的alter table add列挂起,这可能是由于我的应用程序使用连接池打开了连接并可能锁定了表。 is there any way we can still execute alter table command in postgres while application is still running ? 有什么方法可以在应用程序仍在运行时仍在postgres中执行alter table命令?

Check the view pg_locks to see which concurrent transaction holds a lock the blocks the ALTER TABLE . 检查视图pg_locks以查看哪个并发事务持有ALTER TABLE块的锁。

If your connection pool keeps connections hanging in the state “idle in transaction” (check pg_stat_activity ), there is a bug in the connection pool or the application. 如果您的连接池使连接挂起处于“事务空闲”状态(请检查pg_stat_activity ),则连接池或应用程序中存在错误。 You should fix that, because it causes other problems too, like table bloat because VACUUM cannot do its job. 您应该解决此问题,因为它也会引起其他问题,例如VACUUM无法完成工作而导致表膨胀。

A collection of statements to monitor locks is available in the Postgres Wiki: Postgres Wiki中提供了用于监视锁的语句集合:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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