提问人:Sphere 提问时间:6/25/2023 最后编辑:invzbl3Sphere 更新时间:6/25/2023 访问量:30
springboot Postgres:一定时间后,服务停止响应,需要重新启动
springboot Postgres : After certain time, service stops responding, required restart
问:
创建了 postgres 序列,GRPC 服务命中此序列器以生成新序列。当它需要新的序列时,grpc 服务被命中,它将提供一个新的序列,现在这个序列可以用作一些序列号/ID 等。长话短说,不需要将此序列保存在任何表或列中,命中服务获取序列。服务工作正常,但 problrm 是每 45-60 分钟后服务需要重新启动。尝试了很多解决方案,提到 Stackoverflow Postgres 连接已在 Spring Boot 中关闭错误
但这无济于事,
收到此错误
HikariPool-1 - Connection is not available, request timed out after 30000ms.",org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions(SqlExceptionHelper.java:142)
response_description: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
有人可以看看建议,这里做错了什么?
提前致谢!!
@Repository
public class SequenceNumberRepository {
@PersistenceContext
private EntityManager entityManager;
@Transactional
public BigInteger getNextSequenceNumber(String sequencer) {
BigInteger sequence = null;
try {
Query query = entityManager.createNativeQuery("SELECT nextval(:param)");
query.setParameter("param", ConstantUtil.SEQUENCER_NUMBER + ConstantUtil.PERIOD_CONSTANT +sequencer);
sequence = (BigInteger) query.getSingleResult();
}catch(Exception e){
e.printStackTrace();
} finally {
entityManager.close();
}
return sequence;
}
}
application.yml
spring:
config:
activate:
on-profile: dev
datasource:
url: "jdbc:postgresql://<server>:<port>/abc_dev?currentSchema=sequence_number"
username: abc
password: abc
test-on-borrow: true
validation-query: SELECT 1;
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
答: 暂无答案
评论
EntityManager
@PersistenceContext