SpringBoot数据库配置文件

本文详细描述了如何配置Spring框架中的ShardingSphere,包括使用DruidDataSource连接PostgreSQL数据库,以及设置连接池参数和数据分片算法,以便按月份对work_procedure和work_result表进行数据分片。
摘要由CSDN通过智能技术生成

1、日常配置

  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://192.168.2.142:5432/dev?serverTimezone=UTC&characterEncoding=utf-8&stringtype=unspecified
    username: postgres
    password: 123456
    # 连接池
    hikari:
      #连接池名
      pool-name: DateHikariCP
      #最小空闲连接数
      minimum-idle: 5
      # 空闲连接存活最大时间,默认600000(10分钟)
      idle-timeout: 180000
      # 连接池最大连接数,默认是10
      maximum-pool-size: 100
      # 此属性控制从池返回的连接的默认自动提交行为,默认值:true
      auto-commit: true
      # 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
      max-lifetime: 1800000
      # 数据库连接超时时间,默认30秒,即30000
      connection-timeout: 50000
      connection-test-query: SELECT 1

2、shading-jdbc5.0.0配置

spring:
  sharding-sphere:
    datasource:
      names: master
      master:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: org.postgresql.Driver
        url: jdbc:postgresql://127.0.0.1:5432/dev?serverTimezone=UTC&characterEncoding=utf-8&stringtype=unspecified
        username: postgres
        password: 123456
        minimum-idle: 5
        idle-timeout: 180000
        maximum-pool-size: 100
        auto-commit: true
        max-lifetime: 1800000
        connection-timeout: 50000
        connection-test-query: SELECT 1
    rules:
      sharding:
        sharding-algorithms:
          month-sharding-algorithm:
            props:
              strategy: standard
              algorithmClassName: com.base.shading.CreateTimeShardingAlgorithm
            type: CLASS_BASED
        tables:
          unisic_work_procedure:
            actual-data-nodes: master.work_procedure_${2023..2024}_0${1..9},master.work_procedure_${2023..2024}_${10..12}
            table-strategy:
              standard:
                sharding-column: create_time
                sharding-algorithm-name: month-sharding-algorithm
          unisic_work_result:
            actual-data-nodes: master.work_result_${2023..2024}_0${1..9},master.work_result_${2023..2024}_${10..12}
            table-strategy:
              standard:
                sharding-column: create_time
                sharding-algorithm-name: month-sharding-algorithm
        bindingTables:
          - work_procedure, work_result
    props:
      sql-show: false

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值