postgresql - Spring 事务和 postgres(VACUUM,在事务外部运行)
问题描述
运行 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
有效,但我不想这样做。
VACUUM
不开机如何实现跑步auto-commit
?
解决方案
有两种解决方案。
最好的方法是永远不要调用VACUUM
,而是调整AUTOVACUUM
以适当地运行。
第二种解决方案是auto-commit
在使用 PostgreSQL 时使用,但请确保在需要时使用事务范围。在 java 和 spring 的情况下,将使用 annotation @Transactional
。
推荐阅读
- python - Heroku 芹菜工人坠毁
- html - 如何移动
- node.js - 如何通过 kubernetes 将变量传递给 Reactjs
- influxdb-2 - 在 influxdb2 上使用 CLI 配置 Scraper
- arrays - 使用 %s 格式说明符时读取访问冲突
- geolocation - 什么是组合文本/地理位置搜索的最佳方法
- c++ - DirectX 11 曲面细分着色器不工作
- python - 如何按日期对帖子进行排序(FLASK、PYTHON、SQLALCHEMY)
- algorithm - 程序员使用什么排序算法?
- java - SpringBootRequestHandler 的 NoClassDefFoundError