【Nacos2.24持久化到Postgres数据库适配——详细版】

前言

公司基于springboot实现了一套单体框架,目前我负责搭建SpringCloud微服务框架,需要用到nacos,但是由于公司特殊性,nacos的持久化只能选择pg,也上网找了一些资料,这里做一下记录,也把坑给大家踩一下。

步骤

拉取源码

拉取最新源码到本地
官方文档:https://nacos.io/zh-cn/docs/quick-start.html
源码地址:https://github.com/alibaba/nacos develop分支
在这里插入图片描述

添加依赖

  • 在项目根下的pom.xml文件中添加如下依赖:
........
<properties>
	<postgresql.version>42.5.1</postgresql.version>
</properties>

........
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>${postgresql.version}</version>
</dependency>
  • 在项目的config模块的pom.xml文件中添加如下依赖:
........
<dependency>
   <groupId>org.postgresql</groupId>
   <artifactId>postgresql</artifactId>
   <version>${postgresql.version}</version>
</dependency>

修改源码

  • 在项目的plugin模块的datasource模块com.alibaba.nacos.plugin.datasource.impl包下新建一个包名为postgres,拷贝同级包mysql下的所有文件到postgres包下,修改类名和文件名为xxxByPostgreSql,如图
    在这里插入图片描述
  • 修改刚拷贝的几个类中LIMIT ?,?写法为OFFSET ? LIMIT ?,代码如下,可以直接复制:

类ConfigInfoAggrMapperByPostgreSql

/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.plugin.datasource.impl.postgres;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

import java.util.List;

/**
* The postgres implementation of ConfigInfoAggrMapper.
*
* @author hyx
**/
public class ConfigInfoAggrMapperByPostgreSql extends AbstractMapper implements ConfigInfoAggrMapper {

   @Override
   public MapperResult findConfigInfoAggrByPageFetchRows(MapperContext context) {
       int startRow =  context.getStartRow();
       int pageSize =  context.getPageSize();
       String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
       String groupId = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
       String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);

       String sql =
               "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "
                       + "group_id= ? AND tenant_id= ? ORDER BY datum_id OFFSET " + startRow + " LIMIT " + pageSize;
       List<Object> paramList = CollectionUtils.list(dataId, groupId, tenantId);
       return new MapperResult(sql, paramList);
   }

   @Override
   public String getDataSource() {
       return DataSourceConstant.POSTGRESQL;
   }
}

**类ConfigInfoBetaMapperByPostgreSql **

/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.plugin.datasource.impl.postgres;

import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

import java.util.ArrayList;
import java.util.List;

/**
* The postgres implementation of ConfigInfoBetaMapper.
*
* @author hyx
**/

public class ConfigInfoBetaMapperByPostgreSql extends AbstractMapper implements ConfigInfoBetaMapper {

   @Override
   public MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext context) {
       int startRow = context.getStartRow();
       int pageSize = context.getPageSize();
       String sql = " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "
               + " FROM ( SELECT id FROM config_info_beta  ORDER BY id OFFSET " + startRow + " LIMIT " + pageSize + " )"
               + "  g, config_info_beta t WHERE g.id = t.id ";
       List<Object> paramList = new ArrayList<>();
       paramList.add(startRow);
       paramList.add(pageSize);

       return new MapperResult(sql, paramList);
   }

   @Override
   public String getDataSource() {
       return DataSourceConstant.POSTGRESQL;
   }
}

类ConfigInfoMapperByPostgreSql

/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.plugin.datasource.impl.postgres;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* The postgres implementation of ConfigInfoMapper.
*
* @author hyx
**/

public class ConfigInfoMapperByPostgreSql extends AbstractMapper implements ConfigInfoMapper {

   private static final String DATA_ID = "dataId";

   private static final String GROUP = "group";

   private static final String APP_NAME = "appName";

   private static final String CONTENT = "content";

   private static final String TENANT = "tenant";

   @Override
   public MapperResult findConfigInfoByAppFetchRows(MapperContext context) {
       final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
       final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
       String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info"
               + " WHERE tenant_id LIKE ? AND app_name= ?" + " OFFSET " + context.getStartRow() + " LIMIT "
               + context.getPageSize();
       return new MapperResult(sql, CollectionUtils.list(tenantId, appName));
   }

   @Override
   public MapperResult getTenantIdList(MapperContext context) {
       String sql = "SELECT tenant_id FROM config_info WHERE tenant_id != '" + NamespaceUtil.getNamespaceDefaultId()
               + "' GROUP BY tenant_id OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize();
       return new MapperResult(sql, Collections.emptyList());
   }

   @Override
   public MapperResult getGroupIdList(MapperContext context) {
       String sql = "SELECT group_id FROM config_info WHERE tenant_id ='" + NamespaceUtil.getNamespaceDefaultId()
               + "' GROUP BY group_id OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize();
       return new MapperResult(sql, Collections.emptyList());
   }

   @Override
   public MapperResult findAllConfigKey(MapperContext context) {
       String sql = " SELECT data_id,group_id,app_name  FROM ( "
               + " SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id OFFSET " + context.getStartRow() + ","
               + context.getPageSize() + " )" + " g, config_info t WHERE g.id = t.id  ";
       return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID)));
   }

   @Override
   public MapperResult findAllConfigInfoBaseFetchRows(MapperContext context) {
       String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
       final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);

       String sql = "SELECT t.id,data_id,group_id,content,md5"
               + " FROM ( SELECT id FROM config_info ORDER BY id offset ? limit ?  ) "
               + " g, config_info t  WHERE g.id = t.id ";
       return new MapperResult(sql, Collections.emptyList());
   }

   @Override
   public MapperResult findAllConfigInfoFragment(MapperContext context) {

       String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key "
               + "FROM config_info WHERE id > ? ORDER BY id ASC OFFSET " + context.getStartRow() + " LIMIT "
               + context.getPageSize();
       return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID)));
   }

   @Override
   public MapperResult findChangeConfigFetchRows(MapperContext context) {
       final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
       final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
       final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
       final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
       final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
       final Timestamp startTime = (Timestamp) context.getWhereParameter(FieldConstant.START_TIME);
       final Timestamp endTime = (Timestamp) context.getWhereParameter(FieldConstant.END_TIME);

       List<Object> paramList = new ArrayList<>();

       final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified FROM config_info WHERE ";
       String where = " 1=1 ";
       if (!StringUtils.isBlank(dataId)) {
           where += " AND data_id LIKE ? ";
           paramList.add(dataId);
       }
       if (!StringUtils.isBlank(group)) {
           where += " AND group_id LIKE ? ";
           paramList.add(group);
       }

       if (!StringUtils.isBlank(tenantTmp)) {
           where += " AND tenant_id = ? ";
           paramList.add(tenantTmp);
       }

       if (!StringUtils.isBlank(appName)) {
           where += " AND app_name = ? ";
           paramList.add(appName);
       }
       if (startTime != null) {
           where += " AND gmt_modified >=? ";
           paramList.add(startTime);
       }
       if (endTime != null) {
           where += " AND gmt_modified <=? ";
           paramList.add(endTime);
       }
       return new MapperResult(
               sqlFetchRows + where + " AND id > " + context.getWhereParameter(FieldConstant.LAST_MAX_ID)
                       + " ORDER BY id ASC" + " OFFSET " + 0 + " LIMIT " + context.getPageSize(), paramList);
   }

   @Override
   public MapperResult listGroupKeyMd5ByPageFetchRows(MapperContext context) {
       String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "
               + "( SELECT id FROM config_info ORDER BY id OFFSET " + context.getStartRow() + " LIMIT "
               + context.getPageSize() + " ) g, config_info t WHERE g.id = t.id";
       return new MapperResult(sql, Collections.emptyList());
   }

   @Override
   public MapperResult findConfigInfoBaseLikeFetchRows(MapperContext context) {
       final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
       final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
       final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);

       final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
       String where = " 1=1 AND tenant_id='" + NamespaceUtil.getNamespaceDefaultId() + "' ";

       List<Object> paramList = new ArrayList<>();

       if (!StringUtils.isBlank(dataId)) {
           where += " AND data_id LIKE ? ";
           paramList.add(dataId);
       }
       if (!StringUtils.isBlank(group)) {
           where += " AND group_id LIKE ";
           paramList.add(group);
       }
       if (!StringUtils.isBlank(content)) {
           where += " AND content LIKE ? ";
           paramList.add(content);
       }
       return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
               paramList);
   }

   @Override
   public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
       final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
       final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
       final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
       final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
       final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);

       List<Object> paramList = new ArrayList<>();

       final String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info";
       StringBuilder where = new StringBuilder(" WHERE ");
       where.append(" tenant_id=? ");
       paramList.add(tenant);
       if (StringUtils.isNotBlank(dataId)) {
           where.append(" AND data_id=? ");
           paramList.add(dataId);
       }
       if (StringUtils.isNotBlank(group)) {
           where.append(" AND group_id=? ");
           paramList.add(group);
       }
       if (StringUtils.isNotBlank(appName)) {
           where.append(" AND app_name=? ");
           paramList.add(appName);
       }
       if (!StringUtils.isBlank(content)) {
           where.append(" AND content LIKE ? ");
           paramList.add(content);
       }
       return new MapperResult(sql + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
               paramList);
   }

   @Override
   public MapperResult findConfigInfoBaseByGroupFetchRows(MapperContext context) {
       String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=?" + " OFFSET "
               + context.getStartRow() + " LIMIT " + context.getPageSize();
       return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.GROUP_ID),
               context.getWhereParameter(FieldConstant.TENANT_ID)));
   }

   @Override
   public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
       final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
       final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
       final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
       final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
       final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);

       List<Object> paramList = new ArrayList<>();

       final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info";
       StringBuilder where = new StringBuilder(" WHERE ");
       where.append(" tenant_id LIKE ? ");
       paramList.add(tenant);

       if (!StringUtils.isBlank(dataId)) {
           where.append(" AND data_id LIKE ? ");
           paramList.add(dataId);

       }
       if (!StringUtils.isBlank(group)) {
           where.append(" AND group_id LIKE ? ");
           paramList.add(group);
       }
       if (!StringUtils.isBlank(appName)) {
           where.append(" AND app_name = ? ");
           paramList.add(appName);
       }
       if (!StringUtils.isBlank(content)) {
           where.append(" AND content LIKE ? ");
           paramList.add(content);
       }
       return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
               paramList);
   }

   @Override
   public MapperResult findAllConfigInfoFetchRows(MapperContext context) {
       String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "
               + " FROM (  SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id offset ? limit ? )"
               + " g, config_info t  WHERE g.id = t.id ";
       return new MapperResult(sql,
               CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID), context.getStartRow(),
                       context.getPageSize()));
   }

   @Override
   public String getDataSource() {
       return DataSourceConstant.POSTGRESQL;
   }

}

类ConfigInfoTagMapperByPostgreSql

/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.plugin.datasource.impl.postgres;

import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

import java.util.Collections;

/**
* The postgres implementation of ConfigInfoTagMapper.
*
* @author hyx
**/

public class ConfigInfoTagMapperByPostgreSql extends AbstractMapper implements ConfigInfoTagMapper {

   @Override
   public MapperResult findAllConfigInfoTagForDumpAllFetchRows(MapperContext context) {
       String sql = " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified "
               + " FROM (  SELECT id FROM config_info_tag  ORDER BY id OFFSET " + context.getStartRow() + " LIMIT "
               + context.getPageSize() + " ) " + "g, config_info_tag t  WHERE g.id = t.id  ";
       return new MapperResult(sql, Collections.emptyList());
   }

   @Override
   public String getDataSource() {
       return DataSourceConstant.POSTGRESQL;
   }
}

**类ConfigTagsRelationMapperByPostgreSql **

/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.plugin.datasource.impl.postgres;

import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

import java.util.ArrayList;
import java.util.List;

/**
* The postgres implementation of ConfigTagsRelationMapper.
*
* @author hyx
**/

public class ConfigTagsRelationMapperByPostgreSql extends AbstractMapper implements ConfigTagsRelationMapper {

   @Override
   public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
       final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
       final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
       final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
       final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
       final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
       final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);

       List<Object> paramList = new ArrayList<>();
       StringBuilder where = new StringBuilder(" WHERE ");
       final String sql =
               "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info  a LEFT JOIN "
                       + "config_tags_relation b ON a.id=b.id";

       where.append(" a.tenant_id=? ");
       paramList.add(tenant);

       if (StringUtils.isNotBlank(dataId)) {
           where.append(" AND a.data_id=? ");
           paramList.add(dataId);
       }
       if (StringUtils.isNotBlank(group)) {
           where.append(" AND a.group_id=? ");
           paramList.add(group);
       }
       if (StringUtils.isNotBlank(appName)) {
           where.append(" AND a.app_name=? ");
           paramList.add(appName);
       }
       if (!StringUtils.isBlank(content)) {
           where.append(" AND a.content LIKE ? ");
           paramList.add(content);
       }
       where.append(" AND b.tag_name IN (");
       for (int i = 0; i < tagArr.length; i++) {
           if (i != 0) {
               where.append(", ");
           }
           where.append('?');
           paramList.add(tagArr[i]);
       }
       where.append(") ");
       return new MapperResult(sql + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
               paramList);
   }

   @Override
   public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
       final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
       final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
       final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
       final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
       final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
       final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);

       List<Object> paramList = new ArrayList<>();

       StringBuilder where = new StringBuilder(" WHERE ");
       final String sqlFetchRows = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content "
               + "FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";

       where.append(" a.tenant_id LIKE ? ");
       paramList.add(tenant);
       if (!StringUtils.isBlank(dataId)) {
           where.append(" AND a.data_id LIKE ? ");
           paramList.add(dataId);
       }
       if (!StringUtils.isBlank(group)) {
           where.append(" AND a.group_id LIKE ? ");
           paramList.add(group);
       }
       if (!StringUtils.isBlank(appName)) {
           where.append(" AND a.app_name = ? ");
           paramList.add(appName);
       }
       if (!StringUtils.isBlank(content)) {
           where.append(" AND a.content LIKE ? ");
           paramList.add(content);
       }

       where.append(" AND b.tag_name IN (");
       for (int i = 0; i < tagArr.length; i++) {
           if (i != 0) {
               where.append(", ");
           }
           where.append('?');
           paramList.add(tagArr[i]);
       }
       where.append(") ");
       return new MapperResult(sqlFetchRows + where + " OFFSET " + context.getStartRow() + " LIMIT " + context.getPageSize(),
               paramList);
   }

   @Override
   public String getDataSource() {
       return DataSourceConstant.POSTGRESQL;
   }
}

**类GroupCapacityMapperByPostgreSql **

/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.plugin.datasource.impl.postgres;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

/**
* The derby implementation of {@link GroupCapacityMapper}.
*
* @author lixiaoshuang
*/
public class GroupCapacityMapperByPostgreSql extends AbstractMapper implements GroupCapacityMapper {

   @Override
   public String getDataSource() {
       return DataSourceConstant.POSTGRESQL;
   }

   @Override
   public MapperResult selectGroupInfoBySize(MapperContext context) {
       String sql = "SELECT id, group_id FROM group_capacity WHERE id > ? LIMIT ?";
       return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize()));
   }
}


**类HistoryConfigInfoMapperByPostgreSql **

/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.plugin.datasource.impl.postgres;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

/**
* The postgres implementation of HistoryConfigInfoMapper.
*
* @author hyx
**/

public class HistoryConfigInfoMapperByPostgreSql extends AbstractMapper implements HistoryConfigInfoMapper {

   @Override
   public MapperResult removeConfigHistory(MapperContext context) {
       String sql = "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?";
       return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.START_TIME),
               context.getWhereParameter(FieldConstant.LIMIT_SIZE)));
   }

   @Override
   public MapperResult pageFindConfigHistoryFetchRows(MapperContext context) {
       String sql =
               "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
                       + "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC  OFFSET "
                       + context.getStartRow() + " LIMIT " + context.getPageSize();
       return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.DATA_ID),
               context.getWhereParameter(FieldConstant.GROUP_ID), context.getWhereParameter(FieldConstant.TENANT_ID)));
   }

   @Override
   public String getDataSource() {
       return DataSourceConstant.POSTGRESQL;
   }
}

**类TenantCapacityMapperByPostgreSql **

/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.plugin.datasource.impl.postgres;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;

/**
* The postgres implementation of TenantCapacityMapper.
*
* @author hyx
**/

public class TenantCapacityMapperByPostgreSql extends AbstractMapper implements TenantCapacityMapper {

   @Override
   public String getDataSource() {
       return DataSourceConstant.POSTGRESQL;
   }

   @Override
   public MapperResult getCapacityList4CorrectUsage(MapperContext context) {
       String sql = "SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ?";
       return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID),
               context.getWhereParameter(FieldConstant.LIMIT_SIZE)));
   }

}


  • 在项目的plugin模块的plugin/datasource/src/main/resources/META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper增加如下内容:
........
com.alibaba.nacos.plugin.datasource.impl.postgres.ConfigInfoAggrMapperByPostgreSql
com.alibaba.nacos.plugin.datasource.impl.postgres.ConfigInfoBetaMapperByPostgreSql
com.alibaba.nacos.plugin.datasource.impl.postgres.ConfigInfoMapperByPostgreSql
com.alibaba.nacos.plugin.datasource.impl.postgres.ConfigInfoTagMapperByPostgreSql
com.alibaba.nacos.plugin.datasource.impl.postgres.ConfigTagsRelationMapperByPostgreSql
com.alibaba.nacos.plugin.datasource.impl.postgres.HistoryConfigInfoMapperByPostgreSql
com.alibaba.nacos.plugin.datasource.impl.postgres.TenantInfoMapperByPostgreSql
com.alibaba.nacos.plugin.datasource.impl.postgres.TenantCapacityMapperByPostgreSql
com.alibaba.nacos.plugin.datasource.impl.postgres.GroupCapacityMapperByPostgreSql
  • 在项目的plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/constants/DataSourceConstant.java增加一个常量
public static final String POSTGRESQL = "postgresql";

来个全家福:
在这里插入图片描述

编译打包

mvn '-Prelease-nacos' clean package install '-Dmaven.test.skip=true'
mvn '-Prelease-nacos' '-Dmaven.test.skip=true' clean install -U
mvn '-Prelease-nacos' '-Dmaven.test.skip=true' clean install -U  '-Dcheckstyle.skip'

我这里没有报错,完美
在这里插入图片描述

打好的包在{nacos}/distribution/target/目录下
在这里插入图片描述

  • 修改初始化SQL脚本

    1.表结构中gmt_creategmt_modified字段的类型为timestamp,默认CURRENT_TIMESTAMP

    2.增加自增id的序列

 	CREATE SEQUENCE "nacos_db"."public"."config_info_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."config_info_id_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."config_info_id_seq"
OWNED BY "nacos_db"."public"."config_info"."id";

ALTER SEQUENCE "nacos_db"."public"."config_info_id_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('config_info_id_seq'::regclass)


CREATE SEQUENCE "nacos_db"."public"."tenant_capacity_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."tenant_capacity_id_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."tenant_capacity_id_seq"
OWNED BY "nacos_db"."public"."tenant_capacity"."id";

ALTER SEQUENCE "nacos_db"."public"."tenant_capacity_id_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('nacos_db.tenant_capacity_id_seq'::regclass)

CREATE SEQUENCE "nacos_db"."public"."group_capacity_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."group_capacity_id_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."group_capacity_id_seq"
OWNED BY "nacos_db"."public"."group_capacity"."id";

ALTER SEQUENCE "nacos_db"."public"."group_capacity_id_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('group_capacity_id_seq'::regclass)


CREATE SEQUENCE "nacos_db"."public"."his_config_info_nid_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."his_config_info_nid_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."his_config_info_nid_seq"
OWNED BY "nacos_db"."public"."his_config_info"."id";

ALTER SEQUENCE "nacos_db"."public"."his_config_info_nid_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('his_config_info_nid_seq'::regclass)


CREATE SEQUENCE "nacos_db"."public"."config_info_aggr_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."config_info_aggr_id_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."config_info_aggr_id_seq"
OWNED BY "nacos_db"."public"."config_info_aggr"."id";

ALTER SEQUENCE "nacos_db"."public"."config_info_aggr_id_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('config_info_aggr_id_seq'::regclass)

CREATE SEQUENCE "nacos_db"."public"."config_info_beta_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."config_info_beta_id_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."config_info_beta_id_seq"
OWNED BY "nacos_db"."public"."config_info_beta"."id";

ALTER SEQUENCE "nacos_db"."public"."config_info_beta_id_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('config_info_beta_id_seq'::regclass)

CREATE SEQUENCE "nacos_db"."public"."config_info_tag_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."config_info_tag_id_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."config_info_tag_id_seq"
OWNED BY "nacos_db"."public"."config_info_tag"."id";

ALTER SEQUENCE "nacos_db"."public"."config_info_tag_id_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('config_info_tag_id_seq'::regclass)

CREATE SEQUENCE "nacos_db"."public"."config_info_tag_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."config_info_tag_id_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."config_info_tag_id_seq"
OWNED BY "nacos_db"."public"."config_info_tag"."id";

ALTER SEQUENCE "nacos_db"."public"."config_info_tag_id_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('config_info_tag_id_seq'::regclass)


CREATE SEQUENCE "nacos_db"."public"."config_tags_relation_nid_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."config_tags_relation_nid_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."config_tags_relation_nid_seq"
OWNED BY "nacos_db"."public"."config_tags_relation"."nid";

ALTER SEQUENCE "nacos_db"."public"."config_tags_relation_nid_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('config_tags_relation_nid_seq'::regclass)

CREATE SEQUENCE "nacos_db"."public"."tenant_info_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

SELECT setval('"nacos_db"."public"."tenant_info_id_seq"', 1, false);

ALTER SEQUENCE "nacos_db"."public"."tenant_info_id_seq"
OWNED BY "nacos_db"."public"."tenant_info"."id";

ALTER SEQUENCE "nacos_db"."public"."tenant_info_id_seq" OWNER TO "postgres";
-- 在对应表的自增id列加上  nextval('tenant_info_id_seq'::regclass)
  • 完整SQL脚本
    懒得去操作就直接执行我提供的找个完整sql脚本
/*
 Navicat Premium Data Transfer

 Source Server         : 127.0.0.1-5432
 Source Server Type    : PostgreSQL
 Source Server Version : 110002
 Source Host           : 127.0.0.1:5432
 Source Catalog        : nacos_db
 Source Schema         : public

 Target Server Type    : PostgreSQL
 Target Server Version : 110002
 File Encoding         : 65001

 Date: 15/08/2023 15:36:33
*/


-- ----------------------------
-- Sequence structure for config_info_aggr_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."config_info_aggr_id_seq";
CREATE SEQUENCE "public"."config_info_aggr_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for config_info_beta_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."config_info_beta_id_seq";
CREATE SEQUENCE "public"."config_info_beta_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for config_info_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."config_info_id_seq";
CREATE SEQUENCE "public"."config_info_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for config_info_tag_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."config_info_tag_id_seq";
CREATE SEQUENCE "public"."config_info_tag_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for config_tags_relation_nid_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."config_tags_relation_nid_seq";
CREATE SEQUENCE "public"."config_tags_relation_nid_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for group_capacity_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."group_capacity_id_seq";
CREATE SEQUENCE "public"."group_capacity_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for his_config_info_nid_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."his_config_info_nid_seq";
CREATE SEQUENCE "public"."his_config_info_nid_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for tenant_capacity_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."tenant_capacity_id_seq";
CREATE SEQUENCE "public"."tenant_capacity_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for tenant_info_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."tenant_info_id_seq";
CREATE SEQUENCE "public"."tenant_info_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Table structure for config_info
-- ----------------------------
DROP TABLE IF EXISTS "public"."config_info";
CREATE TABLE "public"."config_info" (
  "id" int8 NOT NULL DEFAULT nextval('config_info_id_seq'::regclass),
  "data_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "group_id" varchar(128) COLLATE "pg_catalog"."default",
  "content" text COLLATE "pg_catalog"."default" NOT NULL,
  "md5" varchar(32) COLLATE "pg_catalog"."default",
  "gmt_create" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "gmt_modified" timestamp(6) NOT NULL,
  "src_user" text COLLATE "pg_catalog"."default",
  "src_ip" varchar(50) COLLATE "pg_catalog"."default",
  "app_name" varchar(128) COLLATE "pg_catalog"."default",
  "tenant_id" varchar(128) COLLATE "pg_catalog"."default",
  "c_desc" varchar(256) COLLATE "pg_catalog"."default",
  "c_use" varchar(64) COLLATE "pg_catalog"."default",
  "effect" varchar(64) COLLATE "pg_catalog"."default",
  "type" varchar(64) COLLATE "pg_catalog"."default",
  "c_schema" text COLLATE "pg_catalog"."default",
  "encrypted_data_key" text COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."config_info"."id" IS 'id';
COMMENT ON COLUMN "public"."config_info"."data_id" IS 'data_id';
COMMENT ON COLUMN "public"."config_info"."group_id" IS 'group_id';
COMMENT ON COLUMN "public"."config_info"."content" IS 'content';
COMMENT ON COLUMN "public"."config_info"."md5" IS 'md5';
COMMENT ON COLUMN "public"."config_info"."gmt_create" IS '创建时间';
COMMENT ON COLUMN "public"."config_info"."gmt_modified" IS '修改时间';
COMMENT ON COLUMN "public"."config_info"."src_user" IS 'source user';
COMMENT ON COLUMN "public"."config_info"."src_ip" IS 'source ip';
COMMENT ON COLUMN "public"."config_info"."app_name" IS 'app_name';
COMMENT ON COLUMN "public"."config_info"."tenant_id" IS '租户字段';
COMMENT ON COLUMN "public"."config_info"."c_desc" IS 'configuration description';
COMMENT ON COLUMN "public"."config_info"."c_use" IS 'configuration usage';
COMMENT ON COLUMN "public"."config_info"."effect" IS '配置生效的描述';
COMMENT ON COLUMN "public"."config_info"."type" IS '配置的类型';
COMMENT ON COLUMN "public"."config_info"."c_schema" IS '配置的模式';
COMMENT ON COLUMN "public"."config_info"."encrypted_data_key" IS '密钥';
COMMENT ON TABLE "public"."config_info" IS 'config_info';

-- ----------------------------
-- Records of config_info
-- ----------------------------

-- ----------------------------
-- Table structure for config_info_aggr
-- ----------------------------
DROP TABLE IF EXISTS "public"."config_info_aggr";
CREATE TABLE "public"."config_info_aggr" (
  "id" int8 NOT NULL DEFAULT nextval('config_info_aggr_id_seq'::regclass),
  "data_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "group_id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "datum_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "content" text COLLATE "pg_catalog"."default" NOT NULL,
  "gmt_modified" timestamp(6) NOT NULL,
  "app_name" varchar(128) COLLATE "pg_catalog"."default",
  "tenant_id" varchar(128) COLLATE "pg_catalog"."default"
)
;
COMMENT ON COLUMN "public"."config_info_aggr"."id" IS 'id';
COMMENT ON COLUMN "public"."config_info_aggr"."data_id" IS 'data_id';
COMMENT ON COLUMN "public"."config_info_aggr"."group_id" IS 'group_id';
COMMENT ON COLUMN "public"."config_info_aggr"."datum_id" IS 'datum_id';
COMMENT ON COLUMN "public"."config_info_aggr"."content" IS '内容';
COMMENT ON COLUMN "public"."config_info_aggr"."gmt_modified" IS '修改时间';
COMMENT ON COLUMN "public"."config_info_aggr"."app_name" IS 'app_name';
COMMENT ON COLUMN "public"."config_info_aggr"."tenant_id" IS '租户字段';
COMMENT ON TABLE "public"."config_info_aggr" IS '增加租户字段';

-- ----------------------------
-- Records of config_info_aggr
-- ----------------------------

-- ----------------------------
-- Table structure for config_info_beta
-- ----------------------------
DROP TABLE IF EXISTS "public"."config_info_beta";
CREATE TABLE "public"."config_info_beta" (
  "id" int8 NOT NULL DEFAULT nextval('config_info_beta_id_seq'::regclass),
  "data_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "group_id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "app_name" varchar(128) COLLATE "pg_catalog"."default",
  "content" text COLLATE "pg_catalog"."default" NOT NULL,
  "beta_ips" varchar(1024) COLLATE "pg_catalog"."default",
  "md5" varchar(32) COLLATE "pg_catalog"."default",
  "gmt_create" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "gmt_modified" timestamp(6) NOT NULL,
  "src_user" text COLLATE "pg_catalog"."default",
  "src_ip" varchar(50) COLLATE "pg_catalog"."default",
  "tenant_id" varchar(128) COLLATE "pg_catalog"."default",
  "encrypted_data_key" text COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."config_info_beta"."id" IS 'id';
COMMENT ON COLUMN "public"."config_info_beta"."data_id" IS 'data_id';
COMMENT ON COLUMN "public"."config_info_beta"."group_id" IS 'group_id';
COMMENT ON COLUMN "public"."config_info_beta"."app_name" IS 'app_name';
COMMENT ON COLUMN "public"."config_info_beta"."content" IS 'content';
COMMENT ON COLUMN "public"."config_info_beta"."beta_ips" IS 'betaIps';
COMMENT ON COLUMN "public"."config_info_beta"."md5" IS 'md5';
COMMENT ON COLUMN "public"."config_info_beta"."gmt_create" IS '创建时间';
COMMENT ON COLUMN "public"."config_info_beta"."gmt_modified" IS '修改时间';
COMMENT ON COLUMN "public"."config_info_beta"."src_user" IS 'source user';
COMMENT ON COLUMN "public"."config_info_beta"."src_ip" IS 'source ip';
COMMENT ON COLUMN "public"."config_info_beta"."tenant_id" IS '租户字段';
COMMENT ON COLUMN "public"."config_info_beta"."encrypted_data_key" IS '密钥';
COMMENT ON TABLE "public"."config_info_beta" IS 'config_info_beta';

-- ----------------------------
-- Records of config_info_beta
-- ----------------------------

-- ----------------------------
-- Table structure for config_info_tag
-- ----------------------------
DROP TABLE IF EXISTS "public"."config_info_tag";
CREATE TABLE "public"."config_info_tag" (
  "id" int8 NOT NULL DEFAULT nextval('config_info_tag_id_seq'::regclass),
  "data_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "group_id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "tenant_id" varchar(128) COLLATE "pg_catalog"."default",
  "tag_id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "app_name" varchar(128) COLLATE "pg_catalog"."default",
  "content" text COLLATE "pg_catalog"."default" NOT NULL,
  "md5" varchar(32) COLLATE "pg_catalog"."default",
  "gmt_create" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "gmt_modified" timestamp(6) NOT NULL,
  "src_user" text COLLATE "pg_catalog"."default",
  "src_ip" varchar(50) COLLATE "pg_catalog"."default"
)
;
COMMENT ON COLUMN "public"."config_info_tag"."id" IS 'id';
COMMENT ON COLUMN "public"."config_info_tag"."data_id" IS 'data_id';
COMMENT ON COLUMN "public"."config_info_tag"."group_id" IS 'group_id';
COMMENT ON COLUMN "public"."config_info_tag"."tenant_id" IS 'tenant_id';
COMMENT ON COLUMN "public"."config_info_tag"."tag_id" IS 'tag_id';
COMMENT ON COLUMN "public"."config_info_tag"."app_name" IS 'app_name';
COMMENT ON COLUMN "public"."config_info_tag"."content" IS 'content';
COMMENT ON COLUMN "public"."config_info_tag"."md5" IS 'md5';
COMMENT ON COLUMN "public"."config_info_tag"."gmt_create" IS '创建时间';
COMMENT ON COLUMN "public"."config_info_tag"."gmt_modified" IS '修改时间';
COMMENT ON COLUMN "public"."config_info_tag"."src_user" IS 'source user';
COMMENT ON COLUMN "public"."config_info_tag"."src_ip" IS 'source ip';
COMMENT ON TABLE "public"."config_info_tag" IS 'config_info_tag';

-- ----------------------------
-- Records of config_info_tag
-- ----------------------------

-- ----------------------------
-- Table structure for config_tags_relation
-- ----------------------------
DROP TABLE IF EXISTS "public"."config_tags_relation";
CREATE TABLE "public"."config_tags_relation" (
  "id" int8 NOT NULL,
  "tag_name" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "tag_type" varchar(64) COLLATE "pg_catalog"."default",
  "data_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "group_id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "tenant_id" varchar(128) COLLATE "pg_catalog"."default",
  "nid" int8 NOT NULL DEFAULT nextval('config_tags_relation_nid_seq'::regclass)
)
;
COMMENT ON COLUMN "public"."config_tags_relation"."id" IS 'id';
COMMENT ON COLUMN "public"."config_tags_relation"."tag_name" IS 'tag_name';
COMMENT ON COLUMN "public"."config_tags_relation"."tag_type" IS 'tag_type';
COMMENT ON COLUMN "public"."config_tags_relation"."data_id" IS 'data_id';
COMMENT ON COLUMN "public"."config_tags_relation"."group_id" IS 'group_id';
COMMENT ON COLUMN "public"."config_tags_relation"."tenant_id" IS 'tenant_id';
COMMENT ON COLUMN "public"."config_tags_relation"."nid" IS 'nid, 自增长标识';
COMMENT ON TABLE "public"."config_tags_relation" IS 'config_tag_relation';

-- ----------------------------
-- Records of config_tags_relation
-- ----------------------------

-- ----------------------------
-- Table structure for group_capacity
-- ----------------------------
DROP TABLE IF EXISTS "public"."group_capacity";
CREATE TABLE "public"."group_capacity" (
  "id" numeric(20,0) NOT NULL DEFAULT nextval('group_capacity_id_seq'::regclass),
  "group_id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "quota" int8 NOT NULL,
  "usage" int8 NOT NULL,
  "max_size" int8 NOT NULL,
  "max_aggr_count" int8 NOT NULL,
  "max_aggr_size" int8 NOT NULL,
  "max_history_count" int8 NOT NULL,
  "gmt_create" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "gmt_modified" timestamp(6) NOT NULL
)
;
COMMENT ON COLUMN "public"."group_capacity"."id" IS '主键ID';
COMMENT ON COLUMN "public"."group_capacity"."group_id" IS 'Group ID,空字符表示整个集群';
COMMENT ON COLUMN "public"."group_capacity"."quota" IS '配额,0表示使用默认值';
COMMENT ON COLUMN "public"."group_capacity"."usage" IS '使用量';
COMMENT ON COLUMN "public"."group_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值';
COMMENT ON COLUMN "public"."group_capacity"."max_aggr_count" IS '聚合子配置最大个数,,0表示使用默认值';
COMMENT ON COLUMN "public"."group_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
COMMENT ON COLUMN "public"."group_capacity"."max_history_count" IS '最大变更历史数量';
COMMENT ON COLUMN "public"."group_capacity"."gmt_create" IS '创建时间';
COMMENT ON COLUMN "public"."group_capacity"."gmt_modified" IS '修改时间';
COMMENT ON TABLE "public"."group_capacity" IS '集群、各Group容量信息表';

-- ----------------------------
-- Records of group_capacity
-- ----------------------------

-- ----------------------------
-- Table structure for his_config_info
-- ----------------------------
DROP TABLE IF EXISTS "public"."his_config_info";
CREATE TABLE "public"."his_config_info" (
  "id" numeric(20,0) NOT NULL,
  "nid" numeric(20,0) NOT NULL DEFAULT nextval('his_config_info_nid_seq'::regclass),
  "data_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "group_id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "app_name" varchar(128) COLLATE "pg_catalog"."default",
  "content" text COLLATE "pg_catalog"."default" NOT NULL,
  "md5" varchar(32) COLLATE "pg_catalog"."default",
  "gmt_create" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "gmt_modified" timestamp(6) NOT NULL,
  "src_user" text COLLATE "pg_catalog"."default",
  "src_ip" varchar(50) COLLATE "pg_catalog"."default",
  "op_type" char(10) COLLATE "pg_catalog"."default",
  "tenant_id" varchar(128) COLLATE "pg_catalog"."default",
  "encrypted_data_key" text COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."his_config_info"."id" IS 'id';
COMMENT ON COLUMN "public"."his_config_info"."nid" IS 'nid, 自增标识';
COMMENT ON COLUMN "public"."his_config_info"."data_id" IS 'data_id';
COMMENT ON COLUMN "public"."his_config_info"."group_id" IS 'group_id';
COMMENT ON COLUMN "public"."his_config_info"."app_name" IS 'app_name';
COMMENT ON COLUMN "public"."his_config_info"."content" IS 'content';
COMMENT ON COLUMN "public"."his_config_info"."md5" IS 'md5';
COMMENT ON COLUMN "public"."his_config_info"."gmt_create" IS '创建时间';
COMMENT ON COLUMN "public"."his_config_info"."gmt_modified" IS '修改时间';
COMMENT ON COLUMN "public"."his_config_info"."src_user" IS 'source user';
COMMENT ON COLUMN "public"."his_config_info"."src_ip" IS 'source ip';
COMMENT ON COLUMN "public"."his_config_info"."op_type" IS 'operation type';
COMMENT ON COLUMN "public"."his_config_info"."tenant_id" IS '租户字段';
COMMENT ON COLUMN "public"."his_config_info"."encrypted_data_key" IS '密钥';
COMMENT ON TABLE "public"."his_config_info" IS '多租户改造';

-- ----------------------------
-- Records of his_config_info
-- ----------------------------

-- ----------------------------
-- Table structure for permissions
-- ----------------------------
DROP TABLE IF EXISTS "public"."permissions";
CREATE TABLE "public"."permissions" (
  "role" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
  "resource" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "action" varchar(8) COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."permissions"."role" IS 'role';
COMMENT ON COLUMN "public"."permissions"."resource" IS 'resource';
COMMENT ON COLUMN "public"."permissions"."action" IS 'action';

-- ----------------------------
-- Records of permissions
-- ----------------------------

-- ----------------------------
-- Table structure for roles
-- ----------------------------
DROP TABLE IF EXISTS "public"."roles";
CREATE TABLE "public"."roles" (
  "username" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
  "role" varchar(50) COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."roles"."username" IS 'username';
COMMENT ON COLUMN "public"."roles"."role" IS 'role';

-- ----------------------------
-- Records of roles
-- ----------------------------
INSERT INTO "public"."roles" VALUES ('nacos', 'ROLE_ADMIN');

-- ----------------------------
-- Table structure for tenant_capacity
-- ----------------------------
DROP TABLE IF EXISTS "public"."tenant_capacity";
CREATE TABLE "public"."tenant_capacity" (
  "id" numeric(20,0) NOT NULL DEFAULT nextval('tenant_capacity_id_seq'::regclass),
  "tenant_id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "quota" int8 NOT NULL,
  "usage" int8 NOT NULL,
  "max_size" int8 NOT NULL,
  "max_aggr_count" int8 NOT NULL,
  "max_aggr_size" int8 NOT NULL,
  "max_history_count" int8 NOT NULL,
  "gmt_create" timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "gmt_modified" timestamp(6) NOT NULL
)
;
COMMENT ON COLUMN "public"."tenant_capacity"."id" IS '主键ID';
COMMENT ON COLUMN "public"."tenant_capacity"."tenant_id" IS 'Tenant ID';
COMMENT ON COLUMN "public"."tenant_capacity"."quota" IS '配额,0表示使用默认值';
COMMENT ON COLUMN "public"."tenant_capacity"."usage" IS '使用量';
COMMENT ON COLUMN "public"."tenant_capacity"."max_size" IS '单个配置大小上限,单位为字节,0表示使用默认值';
COMMENT ON COLUMN "public"."tenant_capacity"."max_aggr_count" IS '聚合子配置最大个数';
COMMENT ON COLUMN "public"."tenant_capacity"."max_aggr_size" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
COMMENT ON COLUMN "public"."tenant_capacity"."max_history_count" IS '最大变更历史数量';
COMMENT ON COLUMN "public"."tenant_capacity"."gmt_create" IS '创建时间';
COMMENT ON COLUMN "public"."tenant_capacity"."gmt_modified" IS '修改时间';
COMMENT ON TABLE "public"."tenant_capacity" IS '租户容量信息表';

-- ----------------------------
-- Records of tenant_capacity
-- ----------------------------

-- ----------------------------
-- Table structure for tenant_info
-- ----------------------------
DROP TABLE IF EXISTS "public"."tenant_info";
CREATE TABLE "public"."tenant_info" (
  "id" int8 NOT NULL DEFAULT nextval('tenant_info_id_seq'::regclass),
  "kp" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "tenant_id" varchar(128) COLLATE "pg_catalog"."default",
  "tenant_name" varchar(128) COLLATE "pg_catalog"."default",
  "tenant_desc" varchar(256) COLLATE "pg_catalog"."default",
  "create_source" varchar(32) COLLATE "pg_catalog"."default",
  "gmt_create" int8 NOT NULL,
  "gmt_modified" int8 NOT NULL
)
;
COMMENT ON COLUMN "public"."tenant_info"."id" IS 'id';
COMMENT ON COLUMN "public"."tenant_info"."kp" IS 'kp';
COMMENT ON COLUMN "public"."tenant_info"."tenant_id" IS 'tenant_id';
COMMENT ON COLUMN "public"."tenant_info"."tenant_name" IS 'tenant_name';
COMMENT ON COLUMN "public"."tenant_info"."tenant_desc" IS 'tenant_desc';
COMMENT ON COLUMN "public"."tenant_info"."create_source" IS 'create_source';
COMMENT ON COLUMN "public"."tenant_info"."gmt_create" IS '创建时间';
COMMENT ON COLUMN "public"."tenant_info"."gmt_modified" IS '修改时间';
COMMENT ON TABLE "public"."tenant_info" IS 'tenant_info';

-- ----------------------------
-- Records of tenant_info
-- ----------------------------

-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS "public"."users";
CREATE TABLE "public"."users" (
  "username" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
  "password" varchar(500) COLLATE "pg_catalog"."default" NOT NULL,
  "enabled" int2 NOT NULL
)
;
COMMENT ON COLUMN "public"."users"."username" IS 'username';
COMMENT ON COLUMN "public"."users"."password" IS 'password';
COMMENT ON COLUMN "public"."users"."enabled" IS 'enabled';

-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO "public"."users" VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."config_info_aggr_id_seq"
OWNED BY "public"."config_info_aggr"."id";
SELECT setval('"public"."config_info_aggr_id_seq"', 1, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."config_info_beta_id_seq"
OWNED BY "public"."config_info_beta"."id";
SELECT setval('"public"."config_info_beta_id_seq"', 1, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."config_info_id_seq"
OWNED BY "public"."config_info"."id";
SELECT setval('"public"."config_info_id_seq"', 3, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."config_info_tag_id_seq"
OWNED BY "public"."config_info_tag"."id";
SELECT setval('"public"."config_info_tag_id_seq"', 1, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."config_tags_relation_nid_seq"
OWNED BY "public"."config_tags_relation"."nid";
SELECT setval('"public"."config_tags_relation_nid_seq"', 1, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."group_capacity_id_seq"
OWNED BY "public"."group_capacity"."id";
SELECT setval('"public"."group_capacity_id_seq"', 1, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."his_config_info_nid_seq"
OWNED BY "public"."his_config_info"."id";
SELECT setval('"public"."his_config_info_nid_seq"', 2, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."tenant_capacity_id_seq"
OWNED BY "public"."tenant_capacity"."id";
SELECT setval('"public"."tenant_capacity_id_seq"', 1, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."tenant_info_id_seq"
OWNED BY "public"."tenant_info"."id";
SELECT setval('"public"."tenant_info_id_seq"', 2, true);

-- ----------------------------
-- Indexes structure for table config_info
-- ----------------------------
CREATE UNIQUE INDEX "uk_configinfo_datagrouptenant" ON "public"."config_info" USING btree (
  "data_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "group_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tenant_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table config_info
-- ----------------------------
ALTER TABLE "public"."config_info" ADD CONSTRAINT "config_info_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table config_info_aggr
-- ----------------------------
CREATE UNIQUE INDEX "uk_configinfoaggr_datagrouptenantdatum" ON "public"."config_info_aggr" USING btree (
  "data_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "group_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tenant_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "datum_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table config_info_aggr
-- ----------------------------
ALTER TABLE "public"."config_info_aggr" ADD CONSTRAINT "config_info_aggr_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table config_info_beta
-- ----------------------------
CREATE UNIQUE INDEX "uk_configinfobeta_datagrouptenant" ON "public"."config_info_beta" USING btree (
  "data_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "group_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tenant_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table config_info_beta
-- ----------------------------
ALTER TABLE "public"."config_info_beta" ADD CONSTRAINT "config_info_beta_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table config_info_tag
-- ----------------------------
CREATE UNIQUE INDEX "uk_configinfotag_datagrouptenanttag" ON "public"."config_info_tag" USING btree (
  "data_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "group_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tenant_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tag_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table config_info_tag
-- ----------------------------
ALTER TABLE "public"."config_info_tag" ADD CONSTRAINT "config_info_tag_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table config_tags_relation
-- ----------------------------
CREATE INDEX "idx_tenant_id" ON "public"."config_tags_relation" USING btree (
  "tenant_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE UNIQUE INDEX "uk_configtagrelation_configidtag" ON "public"."config_tags_relation" USING btree (
  "id" "pg_catalog"."int8_ops" ASC NULLS LAST,
  "tag_name" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tag_type" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table config_tags_relation
-- ----------------------------
ALTER TABLE "public"."config_tags_relation" ADD CONSTRAINT "config_tags_relation_pkey" PRIMARY KEY ("nid");

-- ----------------------------
-- Indexes structure for table group_capacity
-- ----------------------------
CREATE UNIQUE INDEX "uk_group_id" ON "public"."group_capacity" USING btree (
  "group_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table group_capacity
-- ----------------------------
ALTER TABLE "public"."group_capacity" ADD CONSTRAINT "group_capacity_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table his_config_info
-- ----------------------------
CREATE INDEX "idx_did" ON "public"."his_config_info" USING btree (
  "data_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_gmt_create" ON "public"."his_config_info" USING btree (
  "gmt_create" "pg_catalog"."timestamp_ops" ASC NULLS LAST
);
CREATE INDEX "idx_gmt_modified" ON "public"."his_config_info" USING btree (
  "gmt_modified" "pg_catalog"."timestamp_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table his_config_info
-- ----------------------------
ALTER TABLE "public"."his_config_info" ADD CONSTRAINT "his_config_info_pkey" PRIMARY KEY ("nid");

-- ----------------------------
-- Indexes structure for table permissions
-- ----------------------------
CREATE UNIQUE INDEX "uk_role_permission" ON "public"."permissions" USING btree (
  "role" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "resource" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "action" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Indexes structure for table roles
-- ----------------------------
CREATE UNIQUE INDEX "idx_user_role" ON "public"."roles" USING btree (
  "username" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "role" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Indexes structure for table tenant_capacity
-- ----------------------------
CREATE UNIQUE INDEX "uk_tenant_id" ON "public"."tenant_capacity" USING btree (
  "tenant_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table tenant_capacity
-- ----------------------------
ALTER TABLE "public"."tenant_capacity" ADD CONSTRAINT "tenant_capacity_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table tenant_info
-- ----------------------------
CREATE INDEX "idx_tenant_info_id" ON "public"."tenant_info" USING btree (
  "tenant_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE UNIQUE INDEX "uk_tenant_info_kptenantid" ON "public"."tenant_info" USING btree (
  "kp" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "tenant_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

修改配置

修改nacos\conf目录下的application.properties配置,增加如下配置

spring.datasource.platform=postgresql
db.num=1
db.url.0=jdbc:postgresql://127.0.0.1:5432/nacos_db?currentSchema=public&reWriteBatchedInserts=true&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
db.user.0=postgres
db.password.0=postgres
# 注意添加配置需要
db.pool.config.driverClassName=org.postgresql.Driver

修改配置项:

.....................
### If turn on auth system:
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
.....................
nacos.core.auth.server.identity.key=nacos
nacos.core.auth.server.identity.value=nacos
.....................
nacos.core.auth.plugin.nacos.token.secret.key=VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=

测试运行

执行命令startup.cmd -m standalone
在这里插入图片描述
打开地址:http://localhost:8848/nacos,账号密码均输入nacos
新增一条测试配置
在这里插入图片描述
打开数据库表config_info
在这里插入图片描述

完美

需要注意的是:官方2.2.4版本的是client,对应的server还说2.2.3版本

参考

官方文档

【Nacos】Nacos 2.2.4支持pg数据库适配改造

Nacos-Server最新版替换Postgres指导

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值