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

【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.xdnf.cn/news/14802.html

相关文章:

  • Python入门Day2
  • Python字符与ASCII转换方法
  • Qt 事件
  • Python从入门到精通——第一章 Python简介
  • 从 TCP/IP 协议栈角度深入分析网络文件系统 (NFS)
  • join性能问题,distinct和group by性能,备库自增主键问题
  • 孪生素数猜想 - 张益唐的核心贡献和陶哲轩的改进
  • vue-37(模拟依赖项进行隔离测试)
  • 互联网大厂Java面试实录:Spring Boot与微服务在电商场景中的应用
  • 经典灰狼算法+编码器+双向长短期记忆神经网络,GWO-Transformer-BiLSTM多变量回归预测,作者:机器学习之心!
  • List中的对象进行排序处理
  • Go基础(Gin)
  • Python 机器学习核心入门与实战进阶 Day 1 - 分类 vs 回归
  • 扣子空间PPT生产力升级:AI智能生成与多模态创作新时代
  • 【Linux仓库】进程优先级及进程调度【进程·肆】
  • Linux之Socket编程Tcp
  • Spring Cloud(微服务部署与监控)
  • Superman
  • Rust Web 全栈开发(一):构建 TCP Server
  • 新版本没有docker-desktop-data分发 | docker desktop 镜像迁移
  • MYSQL基础内容
  • Django 安装使用教程
  • OpenHarmony 5.0监听导航栏和状态栏是否显示
  • OpenCV CUDA模块设备层-----高效地计算两个uint 类型值的平均值函数vavg2()
  • android核心技术摘要
  • gin框架 中间件 是在判断路由存在前执行还是存在后执行的研究
  • 机器学习:集成学习方法之随机森林(Random Forest)
  • 【Unity】MiniGame编辑器小游戏(九)打砖块【Breakout】
  • 【前端】基础 - HTML基础标签和样式设置
  • 【新手小白的嵌入式学习之路】-STM32的学习_GPIO 8种模式学习心得