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

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指导

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/75365.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

1022.从根到叶的二进制之和

目录 一、题目 二、代码 一、题目 二、代码 /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode() : val(0), left(nullptr), right(nullptr) {}* TreeNode(int x) : val(x), left(nu…

玩转 VS code 之下载篇

VSCode 简介 Visual Studio Code (简称 VS Code / VSC)&#xff0c;是2015 年由微软公司推出的一款免费开源的现代化轻量级代码编辑器&#xff0c;支持几乎所有主流的开发语言的语法高亮、智能代码补全、GIT 等特性&#xff0c;支持插件扩展等等 可用于 Windows&#xff0c;ma…

等保测评标准和规范有哪些?

等保测评标准和规范的出现&#xff0c;为我国信息安全等级保护制度的建立和健全提供了重要的保障。 作为信息安全领域的重要评估标准&#xff0c;等保测评旨在通过对信息系统、网络安全设备和安全产品等的安全性能、安全功能、安全管理、安全控制和安全审计等方面的要求进行检查…

【golang】怎样判断一个变量的类型?

怎样判断一个变量的类型&#xff1f; package mainimport "fmt"var container []string{"zero", "one", "two"} func main() {container : map[int]string{0: "zero", 1: "one", 2: "two"}fmt.Printf…

AWS中Lambda集成SNS

1.创建Lambda 在Lambda中&#xff0c;创建名为AWSSNSDemo的函数 use strict console.log(loading function); var aws require(aws-sdk); var docClient new aws.DynamoDB.DocumentClient(); aws.config.regionap-southeast-1;exports.handler function(event,context,cal…

stop job is running for Advanced key-value store

今天虚拟机磁盘撑满了&#xff0c;本来还能凑合运行&#xff0c;结果重启了下&#xff0c;就报了这个 stop job is running for Advanced key-value store (1min 59s / no limit) 解决方式很简单&#xff0c; 1、虚拟机关电源&#xff0c;任务管理器&#xff0c;关闭VM&#x…

LeetCode_03Java_1572. 矩阵对角线元素的和

给你一个正方形矩阵 mat&#xff0c;请你返回矩阵对角线元素的和。 请你返回在矩阵主对角线上的元素和副对角线上且不在主对角线上元素的和。 输入&#xff1a;mat [[1,2,3],[4,5,6],[7,8,9]] 输出&#xff1a;25 解释&#xff1a;对角线的和为&#xff1a;1 5 9 3 7 2…

我们为什么需要API管理系统?

我们为什么需要API管理系统&#xff1f; 随着web技术的发展&#xff0c;前后端分离成为越来越多互联网公司构建应用的方式。前后端分离的优势是一套Api可被多个客户端复用&#xff0c;分工和协作被细化&#xff0c;大大提高了编码效率&#xff0c;但同时也带来一些“副作用”:…

前端接口修改工具 Requestly具体操作

更新于2023年8月12日18:17:56&#xff0c;插件版本可能会变&#xff0c;界面可能会有所变化 插件下载地址&#xff1a;https://chrome.google.com/webstore/detail/requestly-open-source-htt/mdnleldcmiljblolnjhpnblkcekpdkpa 注意&#xff0c;必须用谷歌浏览器&#xff0c;…

Python-OpenCV中的图像处理-模板匹配

Python-OpenCV中的图像处理-模板匹配 模板匹配单对象的模板匹配多对象的模板匹配 模板匹配 使用模板匹配可以在一幅图像中查找目标函数&#xff1a; cv2.matchTemplate()&#xff0c; cv2.minMaxLoc()模板匹配是用来在一副大图中搜寻查找模版图像位置的方法。 OpenCV 为我们提…

强制Edge或Chrome使用独立显卡【WIN10】

现代浏览器通常将图形密集型任务卸载到 GPU&#xff0c;以改善你的网页浏览体验&#xff0c;从而释放 CPU 资源用于其他任务。 如果你的系统有多个 GPU&#xff0c;Windows 10 可以自动决定最适合 Microsoft Edge 自动使用的 GPU&#xff0c;但这并不一定意味着最强大的 GPU。 …

力扣初级算法(数组拆分)

力扣初级算法&#xff08;数组拆分&#xff09; 每日一算法&#xff1a; 力扣初级算法&#xff08;数组拆分&#xff09; 学习内容&#xff1a; 1.问题描述 给定长度为 2n 的整数数组 nums &#xff0c;你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), …, (an, bn) …

leetcode 6914. 翻倍以链表形式表示的数字

给你一个 非空 链表的头节点 head &#xff0c;表示一个不含前导零的非负数整数。 将链表 翻倍 后&#xff0c;返回头节点 head 。 示例 1&#xff1a; 输入&#xff1a;head [1,8,9] 输出&#xff1a;[3,7,8] 解释&#xff1a;上图中给出的链表&#xff0c;表示数字 189 。返…

ubuntu下FFmpeg安装和使用以及CMakeLists.txt模板

sudo apt install ffmpeg sudo apt-get install libavfilter-devcmakelist模板 CMakeLists.txt cmake_minimum_required(VERSION 3.16) project(ffmpeg_demo)# 设置ffmpeg依赖库及头文件所在目录&#xff0c;并存进指定变量 set(ffmpeg_libs_DIR /usr/lib/x86_64-linux-gnu) …

Springboot MultipartFile文件上传与下载

yml文件配置是否可以上传及上传附件大小 servlet:multipart:# 允许文件上传enabled: true# 单个文件大小max-file-size: 20MB# 设置总上传的文件大小max-request-size: 50MB /*** param files* param request* Description 上传文件* Throws* Return java.util.List* Date 202…

prometheus监控k8s服务并告警到钉钉

一、监控k8s集群 要监控k8s集群需要使用到以下服务用于收集监控的资源信息&#xff0c;node_exporter用于监控k8s集群节点的资源信息&#xff0c;kube-state-metrics用于监控k8s集群的deployment、statefulset、daemonset、pod等的状态&#xff0c;cadvisor用于监控k8s集群的p…

关于Linux文件系统只读问题的修改笔记

1.问题 2. 原因 系统异常关机或者代码修改错误导致硬盘挂载出现问题开启只读模式&#xff0c;但是重启有时候可以解决。 3.解决方法 1. mount查看那个挂载的硬盘出现问题(ro标识只读) mount | grep ro2.找到硬盘&#xff0c;重新挂载即可 sudo mount -o remount,rw /sys/f…

基于Googlenet深度学习网络的人员行为动作识别matlab仿真

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 1. 原理 1.1 深度学习与卷积神经网络&#xff08;CNN&#xff09; 1.2 GoogLeNet 2. 实现过程 2.1 数据预处理 2.2 构建网络模型 2.3 数据输入与训练 2.4 模型评估与调优 3. 应用领域…

python技术栈 之 单元测试中mock的使用

一、什么是mock&#xff1f; mock测试就是在测试过程中&#xff0c;对于某些不容易构造或者不容易获取的对象&#xff0c;用一个虚拟的对象来创建以便测试的测试方法。 二、mock的作用 特别是开发过程中上下游未完成的工序导致当前无法测试&#xff0c;需要虚拟某些特定对象…

3. 爬取自己CSDN博客列表(分页查询)(网站反爬虫策略,需要在代码中添加合适的请求头User-Agent,否则response返回空)

文章目录 步骤打开谷歌浏览器输入网址按F12进入调试界面点击网络&#xff0c;清除历史消息按F5刷新页面找到接口&#xff08;community/home-api/v1/get-business-list&#xff09;接口解读 撰写代码获取博客列表先明确返回信息格式json字段解读 Apipost测试接口编写python代码…