当我们系统使用Postgresql数据库又使用多数据库的时候,而你又开启了JAT分布事务,若你Postgresql数据库是默认设置。在系统使用@Transactional注解时会报如下错误.
2020-12-25 21:47:06,526 [ERROR] [http-nio-8081-exec-1] com.j2eefast.framework.exception.RxcExceptionHandler [RxcExceptionHandler.java : 86] JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: One or more resources refused to commit (possibly because of a timeout in the resource - see the log for details). This transaction has been rolled back instead.org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: One or more resources refused to commit (possibly because of a timeout in the resource - see the log for details). This transaction has been rolled back instead.at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1038)at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:743)at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711)at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:633)at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:386)at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
出现这种问题并不是系统的问题,其实是我们的数据库没有设置。我们可以看看数据库的官方配置文件说:
https://postgresqlco.nf/doc/zh/param/max_prepared_transactions/

其实这句话的意思就是如果我们使用事务,应将此事务设置为max_connections以避免阻塞。而max_connections 值系统最大并发数默认是100。
所以只要我们修改Postgresql配置文件,就解决了。
修改:
1.找到你的数据库安装目录修改postgresql.conf
注意:**修改此参数需要重启数据库**。
