【发布时间】:2021-07-28 17:41:36
【问题描述】:
在运行 postgres 查询 VACUUM ANALYZE my_table; 时,我总是在使用 HikariCP 的 spring boot 中遇到同样的错误。
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 它可以工作,但我不想这样做。
如何在不打开auto-commit 的情况下实现运行VACUUM?
【问题讨论】:
-
自动提交有什么问题?如果您需要,只需开始交易。这就是 PostgreSQL 的运作方式。
标签: postgresql spring-boot hikaricp