当前位置: 首页 > news >正文

【MySQL\Oracle\PostgreSQL】迁移到openGauss数据出现的问题解决方案

【MySQL\Oracle\PostgreSQL】迁移到openGauss数据出现的问题解决方案

问题1:序列值不自动刷新问题
下面SQL只针对单库操作以及每个序列只绑定一张表的情况

-- 自动生成的序列,设置序列值
with sequences as (select *from (select table_schema,table_name,column_name,pg_get_serial_sequence(format('%I.%I', table_schema,table_name), column_name) as auto_seq, --<<自动(string_to_array(column_default, E'\''))[2]             as col_seq   --<<手动from information_schema.columnswhere table_schema not in ('pg_catalog', 'information_schema')and column_default ILIKE 'nextval(%'and table_schema = 'usc') t
--                    where auto_seq is not null),maxvals as (select table_schema,table_name,column_name,auto_seq,col_seq,(xpath('/row/max/text()',query_to_xml(format('select max(%I) as max from %I.%I', column_name, table_schema,table_name),true, true, '')))[1]::text::bigint as max_val,(xpath('/row/cur/text()',query_to_xml(format('select last_value as cur from %I.%I',table_schema, col_seq),true, true, '')))[1]::text::bigint as cur_valfrom sequences)
select table_schema,table_name,column_name,auto_seq,col_seq,cur_val,coalesce(max_val, 0) as max_val,setval(col_seq, coalesce(max_val, 1)) --<<设置序列值
from maxvals;

问题2:
字符类型为空字符串迁移后会变成null排查,需要考虑大表问题,防止慢SQL

-- 数据库迁移出现null/空字符串 排除
with t as (select table_schema,table_name,column_name,(xpath('/row/cnt/text()',query_to_xml(format(E'select count(*) as cnt from %I.%I where %I = \'\'', table_schema,table_name, column_name),true, true, '')))[1]::text::bigint as null_cnt
from information_schema.columns
where table_schema not in ('pg_catalog', 'information_schema')and table_schema = 'usc'and is_nullable = 'NO'and udt_name in ('varchar', 'text', 'bpchar'))
select * from t where null_cnt > 0;

问题3:
时间精度问题,导致时间范围查询失败。批量调整时间字段精度

DO
$$DECLAREr RECORD;BEGINFOR r INselect table_name, column_name, udt_namefrom information_schema.columnswhere table_schema not in ('pg_catalog', 'information_schema')and table_schema = 'usc'and udt_name in ('timestamp','timestamptz')LOOPEXECUTE 'ALTER TABLE ' || r.table_name || ' ALTER COLUMN ' || r.column_name || ' TYPE ' || r.udt_name ||'(0)';END LOOP;END
$$;
http://www.dtcms.com/a/266179.html

相关文章:

  • Qt Creator自定义控件开发流程
  • redis缓存三大问题分析与解决方案
  • 车载以太网都有什么协议?
  • 创建 TransactionStatus
  • 【STM32实践篇】:I2C驱动编写
  • NumPy 安装使用教程
  • Debian-10-standard用`networking`服务的`/etc/network/interfaces`配置文件设置多网卡多IPv6
  • 【2.4 漫画SpringBoot实战】
  • CMake之CMakeLists.txt语法规则
  • 网安系列【1】:黑客思维、技术与案例解析
  • DDD实战:CQRS模式在电商报表系统中的高性能实践
  • RNN案例人名分类器(完整步骤)
  • MySQL 8.0 OCP 1Z0-908 题目解析(17)
  • POST请求url放参数场景-笔记
  • Spring SseEmitter 系统详细讲解
  • WPF学习笔记(16)树控件TreeView与数据模板
  • WPF学习笔记(22)项面板模板ltemsPanelTemplate与三种模板总结
  • spring-ai-alibaba 1.0.0.2 学习(八)——接入阿里云信息查询服务
  • 深度学习-逻辑回归
  • RJ45 连接器(水晶头)的引脚定义
  • 从0到1解锁Element-Plus组件二次封装El-Dialog动态调用
  • Gemini CLI初体验
  • 二叉树题解——二叉树的层序遍历【LeetCode】队列实现
  • Java中Stream流的使用
  • Web攻防-文件上传黑白名单MIMEJS前端执行权限编码解析OSS存储分域名应用场景
  • 设计模式(九)
  • 魔术方法__call__
  • Redis缓存架构实战
  • Selenium Base全新升级版:新一代自动化框架实战解析
  • Python 的内置函数 range