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

posted on   荣锋亮  阅读(338)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-10-15 ent 基本使用十九 事务处理
2019-10-15 ent 基本使用十四 edge
2019-10-15 ent 基本使用十八 查询谓词
2019-10-15 ent 基本使用十七 分页与排序
2019-10-15 ent 基本使用十六 聚合
2019-10-15 ent 基本使用十五 一个图遍历的例子
2019-10-15 ent 基本使用十三 debug 模式

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示