Skip to content

Commit

Permalink
chore: 新增 PostgreSQL 数据源配置示例
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Feb 17, 2024
1 parent d6b07bd commit ee48c80
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ server:
--- ### 数据源配置
spring.datasource:
type: com.zaxxer.hikari.HikariDataSource
## 动态数据源配置(可配多主多从:m1、s1...纯粹多库:mysql、oracle...混合配置:m1、s1、oracle...)
## 动态数据源配置(可配多主多从:m1、s1...纯粹多库:mysql、oracle...混合配置:m1、s1、oracle...)
dynamic:
# 是否启用 P6Spy(SQL 性能分析组件,该插件有性能损耗,不建议生产环境使用)
p6spy: true
# 设置默认的数据源或者数据源组(默认 master)
# 设置默认的数据源或者数据源组(默认master)
primary: master
# 严格匹配数据源(true:未匹配到指定数据源时抛异常;false:使用默认数据源;默认 false)
strict: false
Expand All @@ -26,6 +26,7 @@ spring.datasource:
username: ${DB_USER:root}
password: ${DB_PWD:123456}
driver-class-name: com.mysql.cj.jdbc.Driver
type: ${spring.datasource.type}
# 从库配置(可配多个,构成多从)
slave_1:
url: jdbc:mysql:https://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
Expand All @@ -34,6 +35,13 @@ spring.datasource:
lazy: true
driver-class-name: com.mysql.cj.jdbc.Driver
type: ${spring.datasource.type}
# # PostgreSQL 库配置
# postgresql:
# url: jdbc:postgresql:https://${DB_HOST:127.0.0.1}:${DB_PORT:5432}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
# username: ${DB_USER:root}
# password: ${DB_PWD:123456}
# driver-class-name: org.postgresql.Driver
# type: ${spring.datasource.type}
# Hikari 连接池配置(完整配置请参阅:https://github.com/brettwooldridge/HikariCP)
hikari:
# 最大连接数量(默认 10,根据实际环境调整)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,37 @@ server:
--- ### 数据源配置
spring.datasource:
type: com.zaxxer.hikari.HikariDataSource
## 动态数据源配置(可配多主多从:m1、s1...纯粹多库:mysql、oracle...混合配置:m1、s1、oracle...)
## 动态数据源配置(可配多主多从:m1、s1...纯粹多库:mysql、oracle...混合配置:m1、s1、oracle...)
dynamic:
# 是否启用 P6Spy(SQL 性能分析组件,该插件有性能损耗,不建议生产环境使用)
p6spy: false
# 设置默认的数据源或者数据源组(默认 master)
# 设置默认的数据源或者数据源组(默认master)
primary: master
# 严格匹配数据源(true:未匹配到指定数据源时抛异常;false:使用默认数据源;默认 false)
strict: false
datasource:
# 主库配置(可配多个,构成多主)
master:
url: jdbc:mysql:https://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
url: jdbc:mysql:https://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
username: ${DB_USER:root}
password: ${DB_PWD:123456}
driver-class-name: com.mysql.cj.jdbc.Driver
type: ${spring.datasource.type}
# 从库配置(可配多个,构成多从)
slave_1:
url: jdbc:mysql:https://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
url: jdbc:mysql:https://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
username:
password:
lazy: true
driver-class-name: com.mysql.cj.jdbc.Driver
type: ${spring.datasource.type}
# # PostgreSQL 库配置
# postgresql:
# url: jdbc:postgresql:https://${DB_HOST:127.0.0.1}:${DB_PORT:5432}/${DB_NAME:continew_admin}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&rewriteBatchedStatements=true&autoReconnect=true&maxReconnects=10&failOverReadOnly=false
# username: ${DB_USER:root}
# password: ${DB_PWD:123456}
# driver-class-name: org.postgresql.Driver
# type: ${spring.datasource.type}
# Hikari 连接池配置(完整配置请参阅:https://github.com/brettwooldridge/HikariCP)
hikari:
# 最大连接数量(默认 10,根据实际环境调整)
Expand Down

0 comments on commit ee48c80

Please sign in to comment.