# nacos_database_pg_extends
**Repository Path**: wei-yongpe/nacos_database_pg_extends
## Basic Information
- **Project Name**: nacos_database_pg_extends
- **Description**: nacos数据库扩展插件
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 0
- **Created**: 2024-10-27
- **Last Updated**: 2024-11-02
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
Nacos 从 2.2.0 版本开始,可通过 SPI 机制注入多数据源实现插件,并在引入对应数据源实现后,便可在 Nacos 启动时通过读取 application.properties 配置文件中 spring.datasource.platform 配置项选择加载对应多数据源插件.

> Nacos 官方默认实现 MySQL、Derby ,其他类型数据库接入需要参考下文自己扩展。

## 自定义 PostgreSQL 插件
### 1. 添加 postgresql 插件
> 依赖已上传 maven 中央仓库,请勿使用阿里云代理
| NACOS 版本 | 插件版本 | 是否支持 |
|---------------|-------|------|
| 2.2.0 - 2.3.0 | 0.0.2 | 是 |
| 2.3.1 - 2.3.2 | 0.0.3 | 否 |
| 2.4.0 - 2.4.1 | 0.0.4 | 否 |
```xml
com.watcloud.plugin
nacos-datasource-plugin-pg
${nacos.plugin.version}
org.postgresql
postgresql
```
### 2. 导入 nacos postgresql 数据库脚本
./sql/nacos-pg.sql
### 3. 配置 nacos 数据源链接信息
```yaml
db:
num: 1
url:
0: jdbc:postgresql://127.0.0.1:5432/postgres
user:
0: postgres
password:
0: 123456
pool:
config:
driver-class-name: org.postgresql.Driver
```
```properties
db.num=1
db.url.0=jdbc:postgresql://127.0.0.1:5432/postgres?currentSchema=public&reWriteBatchedInserts=true&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
db.user.0=postgres
db.password.0=123456
# 注意添加配置需要
db.pool.config.driverClassName=org.postgresql.Driver
```
### 4. 指定 nacos 数据源平台
```yaml
spring:
datasource:
platform: postgresql
```
```properties
spring.datasource.platform=postgresql
spring.sql.init.platform=postgresql
```