在运行postgres查询VACUUM ANALYZE my_table;时,我在使用HikariCP进行春季引导时总是会遇到相同的错误。
Caused by: org.postgresql.util.PSQLException: ERROR: VACUUM cannot run inside a transaction block根据我的理解,它应该适用于@Propagation.NEVER,但我无法让它工作。
/**
* Execute non-transactionally, throw an exception if a transaction exists.
* Analogous to EJB transaction attribute of the same name.
*/
NEVER(TransactionDefinition.PROPAGATION_NEVER),如果我将hikari设置为auto-commit: true,它可以工作,但我不想这样做。
如何在不打开VACUUM的情况下实现运行auto-commit?
发布于 2021-05-17 09:30:35
有两种解决办法。
最好的方法是永远不要调用VACUUM,而是调优AUTOVACUUM以使其正常运行。
第二个解决方案是在使用auto-commit时使用PostgreSQL,但要确保在需要时使用事务作用域。在java和spring的情况下,将使用注释@Transactional。
https://stackoverflow.com/questions/67417586
复制相似问题