1、背景介绍
在进行国产化改造过程中,我们需要将 oracle 数据库迁移到 oceanbase(oracle 模式)数据库,虽然 oceanbase 对于 oracle 兼容性已经足够好,但依旧还有一些特殊语法或对象需要单独处理,下面是遇到的一些不完全兼容对象的处理逻辑。
2、oracle 中 lob 类数据迁移到 ob 时的处理逻辑
oracle 中 clob 和 blob 类型均可达到 4g 大小(以 oracle 11.2 为例),而 oceanbase 数据库当前版本(3.2.3.x)所支持的大对象数据类型的信息如下表所示:
类型 | blob | clob |
---|---|---|
长度 | 变长 | 变长 |
自定义长度上限(字符) | 48mb | 48mb |
字符集 | binary | 与租户字符集一致 |
考虑到从 oracle 迁移到 oceanbase,如果涉及 lob 类字段,可能会存在当 lob 数据大于 48m 时数据丢失的问题,需要提前发现这类数据并进行处理。
2.1 找到 oracle 中 lob 数据最大长度
我们可以构建一个实验生成 clob 及 blob 类型数据,使用 oracle 自带的 dbms_lob
包获取对应类型的最大值。
2.1.1 构建包含lob类型的数据表
create table t_lob( c_id number, c_clob clob, c_blob blob );
2.1.2 创建造数据存储过程
随机插入 100 条记录到 t_lob
表。
create or replace procedure insert_random_lob_data as begin declare l_random_string varchar2(10000); l_random_blob blob; begin for i in 1..100 loop l_random_string := dbms_random.string('u', dbms_random.value(1, 10000)); dbms_lob.createtemporary(l_random_blob, true); dbms_lob.writeappend(l_random_blob, length(l_random_string), utl_raw.cast_to_raw(l_random_string)); insert into t_lob(c_id, c_clob, c_blob) values(i, l_random_string, l_random_blob); dbms_lob.freetemporary(l_random_blob); end loop; commit; end; end; /
2.1.3 查询该表中 clob 和 blob 字段的最大值
select max(dbms_lob.getlength(c_clob)) as longest_clob, max(dbms_lob.getlength(c_blob)) as longest_blob from t_lob;
2.2 获取整个数据库中 lob 字段值较大的清单
排除了系统用户,获取 lob 字段清单后再基于清单中的 lob 字段单独分析其最大值。
select col.owner, col.table_name, col.column_name, col.data_type, col.avg_col_len, col.char_length, tab.num_rows from dba_tables tab, dba_tab_columns col where tab.owner = col.owner and tab.table_name = col.table_name and col.data_type in ('clob', 'blob') and col.owner not in ('sys', 'system') and col.owner in (select username from dba_users where account_status = 'open') and col.table_name not like 'bin%';
3、oracle 中 disable 约束在 oms 迁移过程中的处理逻辑
在对 oracle 中的约束类非表对象做一致性校验时,发现部分约束在 oms 迁移完成后丢失了,需要分析其 oms 丢失的原因。
3.1 问题分析
从 oms 界面中获取 ddl 的语句可以看到有 2 个 warn,且类型是 discard,表示 oms 判断其是 disable
状态的约束,直接选择了舍弃掉。
-- [warn] [discard] constraint "pk_t_partkey_is_pk" primary key ("crt_dttm") disable novalidate -> [null] -- [warn] [discard] check ("act_id" is not null) disable novalidate -> [null] create table "t_partkey_is_pk" ( "act_id" number(10,0), "srt_id" number(10,0), "srt_orignal_id" number(10,0), "crt_dttm" date, "lastupt_dttm" date )
3.2 问题结论
oracle 侧处于 disable
状态的约束通过 oms 迁移时会被舍弃,不会在 ob 侧创建,在对约束对象比对时,需要额外注意 oracle 端约束的 status 是否处于 disable
状态,本身对业务和功能没有影响。
3.3 约束校验时提前排除 disable 的约束
可以通过以下语句观测源端 oracle 约束状态。
-- 手工将t_partkey_is_pk表的约束都disable alter table zhenxing.t_partkey_is_pk disable novalidate constraint pk_t_partkey_is_pk; alter table zhenxing.t_partkey_is_pk disable constraint sys_c0011109; select owner, table_name, constraint_name, constraint_type, index_name, status from dba_constraints where owner = 'zhenxing' and table_name = 't_partkey_is_pk';
4、oracle 中分区表迁移到 ob 后,带有的自动分区属性丢失
自动分区属性是 oracle 11g 的特性,可以用 interval 语法基于天、月、年做自动分区创建。 在通过 oms 迁移到 ob 后,发现自动分区属性丢失了,会导致当分区未自动创建时导致新增数据没法写入分区表,导致报错。
4.1 问题分析
从 oms 界面中获取 ddl 的语句可以看到有 1 个 warn,且类型是 discard
,表示 oms 判断其不完全兼容,直接选择了舍弃掉。
-- oms 迁移表结构时记录的warn信息,表示自动分区属性由于不兼容会自动discard舍弃 [warn] [discard] interval (numtoyminterval (1,'month')) -> [null]
4.2 问题结论
所以在 oracle 迁移到 ob 前,需要把 oracle 端存在自动分区属性的表提前找出,避免由于迁移到 ob 后分区为未自动创建导致的数据无法插入的报错,并且找出这类分区后,先在 oracle 端创建足够的多分区,避免迁移过程中源端分区数增加导致比对不一致的情况。并记录清单告知业务开发待后续用其他方式定期生成新分区。
4.3 如何找出 oracle 中自动分区的表
4.3.1 oracle 侧模拟自动分区
-- 创建基于天的自动分区表 sql> create table interval_sales ( prod_id number(6), time_id date) partition by range (time_id) interval(numtoyminterval(1, 'month')) (partition p1 values less than (to_date('2015-01-01','yyyy-mm-dd'))); -- 查询当前分区,默认生成了1个定义好的分区 sql> select table_name, partition_name from user_tab_partitions where table_name = 'interval_sales'; table_name partition_name ------------------------------ ------------------------------ interval_sales p1 -- 插入数据(不在默认分区内) sql> insert into interval_sales values(001, to_date('2015-02-01', 'yyyy-mm-dd')); -- 自动生成了新分区 table_name partition_name ------------------------------ ------------------------------ interval_sales p1 interval_sales sys_p221 -- 单独查看该分区数据(验证数据确实存在新分区) sql> select * from interval_sales partition(sys_p221); prod_id time_id ---------- --------- 1 01-feb-15
4.3.2 统计 oracle 侧有哪些表是自动分区的表
/* partition_count: number of partitions in the table. for interval partitioned tables, the value of this column is always 1048575. */ select t1.owner, t1.table_name, t1.interval, t1.partitioning_type, t1.partition_count, t1.subpartitioning_type as sub_type, t1.subpartitioning_key_count sub_count, t1.status from dba_part_tables t1 where 1 = 1 and table_name not like 'bin%' and (interval is not null or partition_count = 1048575);
总结
以上总结分析了 3 种 oracle 对象和 ob 对象不兼容时的处理方法和提前统计发现的操作方式,在迁移前提前发现这类问题能有效避免在迁移过程中报错的问题。
关于 sqle
sqle 是一款全方位的 sql 质量管理平台,覆盖开发至生产环境的 sql 审核和管理。支持主流的开源、商业、国产数据库,为开发和运维提供流程自动化能力,提升上线效率,提高数据质量。
到此这篇关于oracle中部分不兼容对象迁移到oceanbase的三种处理方式的文章就介绍到这了,更多相关oracle对象迁移到oceanbase内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论