zoukankan      html  css  js  c++  java
  • jdbc连接池工具与pg fdw连接的问题 二

    上次有简单介绍过关于pg fdw 对于使用连接池故障的问题,经过几天的调试以及摸索 ,印证了上次说的关于
    sql 预编译处理的,目前测试发现主要是对于tds-fdw 扩展引起的异常比较严重,会造成db 异常 ,然后自动恢复,
    同时会造成连接异常,如果还需要使用连接池比较推荐使用hikari,需要我们需要的配置参数是禁用预编译存储处理

    参考配置

    • maven 依赖
      添加HikariCP依赖
     
         <dependency>
                <groupId>com.zaxxer</groupId>
                <artifactId>HikariCP</artifactId>
                <version>3.4.5</version>
            </dependency>
            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>42.2.6</version>
            </dependency>
    • datasource 定义
    @Bean(name = "pgdataSource")
        public DataSource dataSource2() {
            HikariConfig config = new HikariConfig();
            Properties properties  = new Properties();
            properties.setProperty("serverName","127.0.0.1");
            properties.setProperty("portNumber","5434");
            properties.setProperty("user","<username>");
            properties.setProperty("password","<password>");
           // 50的配置有点大,因为pg 多进程架构模型,实际不用那么大,而且推荐基于中间件搞一层proxy 的连接池,可以的有odyssey&&pgbouncer
            config.setMaximumPoolSize(50);
            config.setMaxLifetime(3);
            properties.setProperty("sslmode","disable");
            properties.setProperty("databaseName","order");
            // 此处禁用sql的编译cache
            properties.setProperty("preparedStatementCacheQueries","0");
            config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
            config.setDataSourceProperties(properties);
            config.setConnectionTestQuery("SELECT 1");
            HikariDataSource ds = new HikariDataSource(config);
            return ds;
          }

    说明

    结合验证,理论上也可以直接基于tds-fdsw扩展的一些配置参数进行查询计划的处理,后边待验证

    参考资料

    https://github.com/tds-fdw/tds_fdw/blob/master/ForeignServerCreation.md
    https://github.com/tds-fdw/tds_fdw/blob/master/ForeignTableCreation.md
    https://www.pgbouncer.org/
    https://github.com/yandex/odyssey
    https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby

  • 相关阅读:
    Expanding Rods(二分)
    Monthly Expense(二分)
    sdut1269 走迷宫(dfs)
    走迷宫(dfs)
    C Looooops(扩展欧几里得+模线性方程)
    41. First Missing Positive
    40. Combination Sum II
    39. Combination Sum
    37. Sudoku Solver
    36. Valid Sudoku
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/13822698.html
Copyright © 2011-2022 走看看