I am currently enhancing an application that uses spring and hibernate.There are multiple instances where the application communicates with the db (postgres) via prepared statements. The application until now, communicated with postgres via dbcp.
Change: The application now communicated to postgres via pgbouncer.
i.e.: application -> dbcp -> pgbouncer -> postgres
I understand this wouldn't be the most ideal solution i.e: having 2 poolers. But due to the current architecture we require both of them.
Requirement: pgbouncer does not support prepared statements in transaction mode & therefore have to be eliminated.
Changes to eliminate prepared statement.
1) psql: VERSION = 9.2.6
no change
2) pgbouncer: In the config file set the following attribures
ignore_startup_parameters=extra_float_digits
pool_mode=transaction
server_reset_query=
3) jdbc : The prepared threshold has been set accordingly.
i.e. : jdbc:postgresql://localhost:6541/postgres?prepareThreshold=0
JAVA VERSION = 1.7.0_51
JDBC DRIVER = postgresql-9.3-1102.jdbc41-3.jar
4) dbcp : poolPreparedStatements = false maxOpenPreparedStatements = 0
5) hibernate : no changes
6) spring : no changes
Issue:
Inspite of all these changes I still see prepared statements trying to be created & transactions failing due to that.
"ERROR: prepared statement "S_21" does not exist; nested exception is org.postgresql.util.PSQLException: ERROR: prepared statement "S_21 " does not exist"
I have removed all logical changes that used a prepared statement.
How can I prevent the other prepared statements from being created? Does spring or hibernate internally create prepared statements for their usage? If yes, how do I disable them?
I understand that this post is from a few years ago but I am still facing the same issues. Unfortunately the suggested changes are not working for my current use case.
Facing the following issue: - "Error: Prepared statement xxx does not exist" - "Error: prepared statement xxx already exists"
Tried following the proposed changed but still getting the same error:
Tech Stack:
@Around("@annotation(transactional)")
public Object proceed(ProceedingJoinPoint proceedingJoinPoint, Transactional transactional) throws Throwable {
try {
if(transactional.readOnly()) {
RoutingDataSource.setReplicaRoute();
LOGGER.info("Routing database call to the read replica");
}
return proceedingJoinPoint.proceed();
} finally {
RoutingDataSource.clearReplicaRoute();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With