Postgres - ERROR: prepared statement “S_1” already exists

前端 未结 4 1755
栀梦
栀梦 2020-12-28 15:39

When executing batch queries via JDBC to pgbouncer, I get the following error:

org.postgresql.util.PSQLException: ERROR: prepared statement \"S_1\" already e         


        
4条回答
  •  余生分开走
    2020-12-28 16:26

    New, Better Answer

    To discard session state and effectively forget the "S_1" prepared statement, use server_reset_query option in PgBouncer config.

    Old Answer

    See http://pgbouncer.projects.postgresql.org/doc/faq.html#_how_to_use_prepared_statements_with_transaction_pooling

    Switching into session mode is not an ideal solution. Transacion pooling is much more efficient. But for transaction pooling you need stateless DB calls.

    I think you have three options:

    1. Disable PS in jdbc driver,
    2. manually deallocate them in your Java code,
    3. configure pgbouncer to discard them on transaction end.

    I would try option 1 or option 3 - depending on actual way in which your app uses them.

    For more info, read the docs:

    http://pgbouncer.projects.postgresql.org/doc/config.html (search for server_reset_query),

    or google for this:

    postgresql jdbc +preparethreshold
    

提交回复
热议问题