如何在应用程序中将 plan_cache_mode 设置为force_custom_plan?

问题描述 投票:0回答:2

我有一个带有 REST 服务的 Spring Boot 应用程序。我使用 PorstgreSQL 作为 TimescaleDB 的数据库。我正在尝试将 plan_cache_mode 设置为 force_custom_plan 因为我不希望它切换到通用计划。我正在使用 Hikari 来管理数据源。如何在 HikariDataSource 中设置它?

postgresql spring-boot hikaricp timescaledb
2个回答
3
投票

您可以在数据库或用户级别设置参数:

CREATE ROLE|DATABASE somename SET plan_cache_mode = force_custom_plan;

然后,该用户或该数据库的所有新连接都会获得该设置。


0
投票

正如我在这篇文章中所解释的,您可能应该只为需要您重建通用计划的事务设置它。

如果你使用JPA,你可以这样做:

Session session = entityManager.unwrap(Session.class);
 
session.doWork(connection -> {
    try (Statement statement = connection.createStatement()) {
        statement.executeUpdate(
            "SET plan_cache_mode=force_custom_plan"
        );
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.