当前位置: 代码网 > it编程>数据库>大数据 > Dbeaver做数据迁移的详细过程记录

Dbeaver做数据迁移的详细过程记录

2024年05月18日 大数据 我要评论
1、选择源头数据库的表、鼠标右击、选择导出数据2、在数据转化弹框中,双击 ‘数据库,数据表’ 那一栏3、选择目标数据库,调整字段类型映射关系4、调整字段的映射关系 目前遇

1、选择源头数据库的表、鼠标右击、选择导出数据

2、在数据转化弹框中,双击 ‘数据库,数据表’ 那一栏

3、选择目标数据库,调整字段类型映射关系

4、调整字段的映射关系

        目前遇到的字段类型,只有 int,bigint   转  number  类型

        再就是varchar2 长度不够的,加长度,超过4000的就改为clob类型

5、勾选‘打开新连接’,‘选择行计数’

6、点击开始

7、注意事项

        a、如果是oracle转oracle,同类型的数据库迁移,就不用管字段类型的映射关系了

        b、如果字段的映射不对就会报错,或者表创建了,但数据没有进去

        c、遇到的字段类型,只有 int,bigint   转  number  类型

        d、有些字段迁移后会变成小写,需要后面手动调整

                        可以用sql查询出所有的小写字段

select column_name,table_name from user_tab_columns where regexp_like(column_name,'[a-z]'); 

        e、varchar2(200)  类型可能存在 实际长度大于限制长度的问题,会报错出来

                超过4000的长度,可以改为  clob 类型

        f、varchar2 类型如果没有限制长度,会报错:“缺少括号”,加就可以了 varchar2(200) 

        g、数据迁移后,对比两个数据库表的数量,可以使用sql查询数量

        h、表迁移后,发现索引都没有迁移

                导致登录的时候报错: 

                        java.lang.illegalargumentexception: obj is null

                处理方式:迁移索引后,问题就自动好了

8、处理方式总结

        a、导出时,可以批量的处理,比如一次处理10个表,遇到报错就停止执行,这样后面再处理报错的表就可以了,其他表会都迁移了。报错的表需要删除了,从新迁移。删除表后,需要刷新数据库。

        b、批量迁移索引

                使用sql 查询出sql server 所有创建索引的语句。下面是sql

with indexinfo as (
    select schema_name(t.schema_id) [schema_name],t.name as [table_name],t1.name as [index_name]
    ,t1.type,t1.type_desc,t1.is_unique,t1.is_primary_key,t1.is_unique_constraint,t1.has_filter,t1.filter_definition
    ,stuff((select ','+t4.name from sys.sysindexkeys t2 
        inner join sys.index_columns  t3 on t2.id=t3.object_id and t2.indid=t3.index_id and t2.colid=t3.column_id
        inner join sys.syscolumns t4 on t2.id=t4.id and t2.colid=t4.colid
        where t2.id=t1.object_id and t1.index_id=t2.indid  and t2.keyno <> 0 order by t3.key_ordinal for xml path('')),1,1,'') as index_cols
    ,stuff((select ','+t4.name from sys.sysindexkeys t2 
        inner join sys.index_columns  t3 on t2.id=t3.object_id and t2.indid=t3.index_id and t2.colid=t3.column_id
        inner join sys.syscolumns t4 on t2.id=t4.id and t2.colid=t4.colid
        where t2.id=t1.object_id and t1.index_id=t2.indid  and t2.keyno = 0 order by t3.key_ordinal for xml path('')),1,1,'')  as include_cols
    from sys.tables as t
    inner join sys.indexes as t1 on (t1.index_id > 0 and t1.is_hypothetical = 0) and (t1.object_id=t.object_id)
    where t1.type in(1,2)
), indexinfo2 as (
select * ,(case 
    when is_primary_key = 1 
        then 'alter table '+[schema_name]+'.'+[table_name]+' add constraint '+[index_name]+' primary key '+(case when [type]=1 then 'clustered' else 'nonclustered' end)+'('+index_cols+');'
    when is_unique = 1 and is_unique_constraint = 1 
        then 'alter table '+[schema_name]+'.'+[table_name]+' add constraint '+[index_name]+' unique '+(case when [type]=1 then 'clustered' else 'nonclustered' end)+'('+index_cols+');'
    when is_unique = 1 and (is_primary_key = 0 or is_unique_constraint = 0)
        then 'create unique '+(case when [type]=1 then 'clustered' else 'nonclustered' end)+' index '+[index_name]+'  on '+[schema_name]+'.'+[table_name]+'('+index_cols+');'
    else 'create '+(case when [type]=1 then 'clustered' else 'nonclustered' end)+' index '+[index_name]+' on '+[schema_name]+'.'+[table_name]+'('+index_cols+') ;'
    end) script
from indexinfo
) select [schema_name],[table_name],[index_name],script
+(case when include_cols is not null then ' include('+include_cols+')' else '' end)
+(case when has_filter = 1then ' where '+filter_definition else '' end)
from indexinfo2
order by [schema_name],[table_name],[type],[index_name],is_primary_key desc,is_unique_constraint desc,is_unique desc

        c、批量处理语句后(两种数库的ddl语句有所差异),可以批量执行。

       可以全部一起执行,或者一次执行50条语句,遇到报错就停止,报错前的语句都执行了,就可以删除了。处理报错后,再执行报错后面的语句。

        有些不好处理的报错,可以先不管,后面在手动对表建索引就可以了

批量执行ddl语句的方式

        新开个窗口放ddl语句,sql编辑器 --> 执行sql脚本

注意事项:

        sql serve 迁移到 oracle  后,在 ‘数据库表管理’ 页面做表创建的时候,ddl语句会报错,因为字段都是小写,且都加了引号,导致oracle不能识别。需要删除  d:\03_workspace\01_fenghua\02_server\fenghua-tmp-server\src\main\java\xyz\elidom\dbist\ddl\impl\ddljdbc.java   文件,删除后重启后端,就可以了,

后面生成的ddl语句,字段就没引号了,oracle就可以正常创建表了。

总结

到此这篇关于dbeaver做数据迁移的文章就介绍到这了,更多相关dbeaver数据迁移内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com