静态网站怎么更新,wordpress速度太慢,商城建设方案,网站开发毕业设计任务书范文1 说明
前两天领导发邮件要求导出O库一批表和索引的ddl语句做国产化测试#xff0c;涉及6个系统#xff0c;6千多张表#xff0c;还好涉及的用户并不多#xff0c;要不然很麻烦。 如此大费周折原因#xff0c;是某国产库无法做元数据迁移。。。额#xff0c;只能我手动导…1 说明
前两天领导发邮件要求导出O库一批表和索引的ddl语句做国产化测试涉及6个系统6千多张表还好涉及的用户并不多要不然很麻烦。 如此大费周折原因是某国产库无法做元数据迁移。。。额只能我手动导出拿去给他们同步。
考虑的方案有两个
使用get_ddl查询出语句。使用数据泵导元数据。
两种方式各有优点分场景使用。
2 get_ddl查询
在需要查询的表不多且不用导索引时get_ddl方式比较省力。
缺点就是步骤比较多表、索引、注释等都需要单独做查询段属性之类的信息无法屏蔽。最大的问题是比较慢我导出1000张表及其相关索引花了差不多4个小时时间主要花在查询索引ddl上。
2.1 创建表清单表
将需要生成ddl的表粘到下面表中
create table lu9up.cs_tab_250210
(owner varchar2(30) not null,table_name varchar2(30) not null
);select * from lu9up.cs_tab_250210 for update;2.2 部署脚本
进入到某个目录下创建script_cs_250210.sql脚本用于跑get_ddl
cat script_cs_250210.sql EOF
declarescripts varchar2(4000);cursor tab isselect owner,table_name,dbms_metadata.get_ddl(TABLE, table_name, owner) || ; table_scriptsfrom lu9up.cs_tab_250210--where owner and table_name order by owner;
beginfor i in tab loopdbms_output.put_line(chr(10) || ---- || i.owner || . ||i.table_name);dbms_output.put_line(i.table_scripts);for j in (select to_char(dbms_metadata.get_ddl(t.index_type,t.index_name,t.owner)) || ; scriptsfrom (select owner, index_name, INDEX index_typefrom dba_indexes bwhere owner i.ownerand not exists(select 1from dba_constraints cwhere b.owner i.ownerand b.index_name c.constraint_name)and table_name i.table_nameorder by 3, 2) t) loopdbms_output.put_line(j.scripts);end loop;end loop;
end;
/
EOF创建script_cs_250210.sh脚本调用script_cs_250210.sql脚本
#!/bin/bash
export ORACLE_SIDxxxdb
sqlplus -s / as sysdbba EOF
set lines 500
set serveroutput on
spool cs_tab_250210.sql
script_cs_250210.sql
spool off
EOF2.3 导出元数据到sql文件
执行script_cs_250210.sh脚本
nohup sh script_cs_250210.sh 结果在cs_tab_250210.sql文件。
3 数据泵导出
如果涉及到的表、索引很多的情况下使用数据泵比较快几千张表十来分钟就可以导出完毕了且可读性比较高。
3.1 创建表清单表
将需要生成ddl的表粘到下面表中
create table lu9up.cs_tab_250210
(owner varchar2(30) not null,table_name varchar2(30) not null
);select * from lu9up.cs_tab_250210 for update;3.2 创建导出目录
创建一个具有oracle权限的导出目录
create directory csdir as /home/oracle/lu9up;
grant read,write on directory csdir to lu9up;
grant datapump_exp_full_database to lu9up;
grant datapump_imp_full_database to lu9up;select * from dba_directories;3.3 生成执行语句
由于得按schema导出执行以下sql可生成不同schema的数据泵执行语句
select --||owner|| chr(10) ||cat cs_||owner||_exp_250210.par EOF || chr(10) ||directoryCSDIR || chr(10) || schemas||owner|| || chr(10) ||includetable:in (select table_name from lu9up.cs_tab_250210 where owner ||owner||) ||chr(10) || parallel8 || chr(10) || clustern || chr(10) ||contentmetadata_only || chr(10) ||dumpfilecs_||owner||_exp_250210.dmp || chr(10) ||logfilecs_||owner||_exp_250210.log || chr(10) || EOF || chr(10) ||chr(10) ||expdp lu9up/oracle parfilecs_||owner||_exp_250210.par ||chr(10) ||chr(10)||chr(10)|| cat cs_||owner||_imp_250210.par EOF || chr(10) ||directoryCSDIR || chr(10)|| dumpfilecs_||owner||_exp_250210.dmp ||chr(10) || parallel8 || chr(10) ||excludegrant,statistics || chr(10) ||transformsegment_attributes:n|| chr(10) ||sqlfile||owner||.sql || chr(10) ||logfilecs_||owner||_imp_250210.log || chr(10) ||EOF || chr(10) ||chr(10) ||impdp lu9up/oracle parfilecs_||owner||_imp_250210.parfrom (select owner, count(*) ctfrom lu9up.cs_tab_250210group by ownerorder by ct desc);有多个用户的时候就非常方便可以直接拿去执行不用再修改脚本。
其实也可以直接用dblinkimpdp不落地导sqlfile省去了expdp的步骤。
3.4 脚本部署
把cs_xxx_exp_250210.par和cs_xxx_imp_250210.par两个文件部署到数据库服务器确认有oracle用户权限。 3.5 执行导出
脚本分两个一个是使用expdp导出元数据到dmp文件然后再用impdp将dmp文件转化为sqlfile。
expdp
expdp lu9up/oracle parfilecs_xxx_exp_250210.parimpdp
impdp lu9up/oracle parfilecs_xxx_imp_250210.par结果生成到导出目录csdir中xxx.sql文件。
4 总结
总的来说使用数据泵导出元数据比较符合规范内容比较完整阅读性高且可以使用参数控制输出的内容。 get_ddl在少量表和索引的情况下相对比较方便快捷。 文章转载自: http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn http://www.morning.tzlfc.cn.gov.cn.tzlfc.cn http://www.morning.skfkx.cn.gov.cn.skfkx.cn http://www.morning.swkpq.cn.gov.cn.swkpq.cn http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn http://www.morning.mjdbd.cn.gov.cn.mjdbd.cn http://www.morning.xnqjs.cn.gov.cn.xnqjs.cn http://www.morning.mdwtm.cn.gov.cn.mdwtm.cn http://www.morning.mnygn.cn.gov.cn.mnygn.cn http://www.morning.ngcw.cn.gov.cn.ngcw.cn http://www.morning.rdlong.com.gov.cn.rdlong.com http://www.morning.wlqbr.cn.gov.cn.wlqbr.cn http://www.morning.junmap.com.gov.cn.junmap.com http://www.morning.sfnjr.cn.gov.cn.sfnjr.cn http://www.morning.zqfjn.cn.gov.cn.zqfjn.cn http://www.morning.mhnb.cn.gov.cn.mhnb.cn http://www.morning.lfdrq.cn.gov.cn.lfdrq.cn http://www.morning.hsrpc.cn.gov.cn.hsrpc.cn http://www.morning.lcplz.cn.gov.cn.lcplz.cn http://www.morning.xysxj.com.gov.cn.xysxj.com http://www.morning.wchsx.cn.gov.cn.wchsx.cn http://www.morning.zcqtr.cn.gov.cn.zcqtr.cn http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn http://www.morning.qfwfj.cn.gov.cn.qfwfj.cn http://www.morning.kwblwbl.cn.gov.cn.kwblwbl.cn http://www.morning.mdtfh.cn.gov.cn.mdtfh.cn http://www.morning.prjty.cn.gov.cn.prjty.cn http://www.morning.dddcfr.cn.gov.cn.dddcfr.cn http://www.morning.mydgr.cn.gov.cn.mydgr.cn http://www.morning.dplmq.cn.gov.cn.dplmq.cn http://www.morning.xrnh.cn.gov.cn.xrnh.cn http://www.morning.fbmjl.cn.gov.cn.fbmjl.cn http://www.morning.mdtfh.cn.gov.cn.mdtfh.cn http://www.morning.ywzqk.cn.gov.cn.ywzqk.cn http://www.morning.zqbrd.cn.gov.cn.zqbrd.cn http://www.morning.sjwws.cn.gov.cn.sjwws.cn http://www.morning.tmsxn.cn.gov.cn.tmsxn.cn http://www.morning.grnhb.cn.gov.cn.grnhb.cn http://www.morning.rnnq.cn.gov.cn.rnnq.cn http://www.morning.myxps.cn.gov.cn.myxps.cn http://www.morning.wdhlc.cn.gov.cn.wdhlc.cn http://www.morning.jcnmy.cn.gov.cn.jcnmy.cn http://www.morning.gtwtk.cn.gov.cn.gtwtk.cn http://www.morning.haolipu.com.gov.cn.haolipu.com http://www.morning.pjwrl.cn.gov.cn.pjwrl.cn http://www.morning.jcxqc.cn.gov.cn.jcxqc.cn http://www.morning.zdsqb.cn.gov.cn.zdsqb.cn http://www.morning.dshxj.cn.gov.cn.dshxj.cn http://www.morning.xnbd.cn.gov.cn.xnbd.cn http://www.morning.zczkm.cn.gov.cn.zczkm.cn http://www.morning.tgtrk.cn.gov.cn.tgtrk.cn http://www.morning.gbwfx.cn.gov.cn.gbwfx.cn http://www.morning.nyfyq.cn.gov.cn.nyfyq.cn http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn http://www.morning.zlsmx.cn.gov.cn.zlsmx.cn http://www.morning.gkjyg.cn.gov.cn.gkjyg.cn http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn http://www.morning.hkysq.cn.gov.cn.hkysq.cn http://www.morning.pcxgj.cn.gov.cn.pcxgj.cn http://www.morning.krdb.cn.gov.cn.krdb.cn http://www.morning.fmdvbsa.cn.gov.cn.fmdvbsa.cn http://www.morning.dtrz.cn.gov.cn.dtrz.cn http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn http://www.morning.bndkf.cn.gov.cn.bndkf.cn http://www.morning.lmhh.cn.gov.cn.lmhh.cn http://www.morning.tfgkq.cn.gov.cn.tfgkq.cn http://www.morning.mbhdl.cn.gov.cn.mbhdl.cn http://www.morning.npkrm.cn.gov.cn.npkrm.cn http://www.morning.tqygx.cn.gov.cn.tqygx.cn http://www.morning.mtyhk.cn.gov.cn.mtyhk.cn http://www.morning.nkrmh.cn.gov.cn.nkrmh.cn http://www.morning.tsflw.cn.gov.cn.tsflw.cn http://www.morning.txjrc.cn.gov.cn.txjrc.cn http://www.morning.wqrk.cn.gov.cn.wqrk.cn http://www.morning.pcrzf.cn.gov.cn.pcrzf.cn http://www.morning.qwzpd.cn.gov.cn.qwzpd.cn http://www.morning.srhqm.cn.gov.cn.srhqm.cn http://www.morning.huxinzuche.cn.gov.cn.huxinzuche.cn http://www.morning.frpfk.cn.gov.cn.frpfk.cn http://www.morning.cbqqz.cn.gov.cn.cbqqz.cn