Heim > Datenbank > MySQL-Tutorial > Hauptteil

关于Oracle数据库迁移(跨版本)以及空表不导出

WBOY
Freigeben: 2016-06-07 17:06:19
Original
895 Leute haben es durchsucht

一、Oracle 11g存在一个特性,如果乃用exp/imp来对数据库进行导入导出时,会出现无数据表无法导出的问题,笔者也遇到了此种问题,

一、Oracle 11g存在一个特性,如果乃用exp/imp来对数据库进行导入导出时,会出现无数据表无法导出的问题,

笔者也遇到了此种问题,经研究觉得遇到此情况,,最好用expdp/impdp方式进行导出导入,可以回避这种问题。(此命令缺点在于必须在服务器上执行)

二、关于Oracle版本数据版本不同时的移植,通常都会提示错误不兼容(这里所说的移植是指由高到低移植,低版本移植高版本)

笔者提供一种解决方案:用expdp进行导出(必须是10G或以上的版本,不然不支持expdp),在导出命令中补充version参数,值为目标数据库的版本号。

比如说:乃想将数据库由oracle版本11.2.0.1.0移植到10.2.0.1.0,只需要在导出时设置version='10.2.0.1.0'即可,导入时不用设置version参数

关于第一个问题:空数据表不能导出,网上也流传着宁外一个解决的方法就是:(这种方法笔者不推荐使用)

11G中有个新特性,当表无数据时,不分配segment,以节省空间

  解决方法:

  1、insert一行,再rollback就产生segment了。

  该方法是在在空表中插入数据,再删除,则产生segment。导出时则可导出空表。

  2、设置deferred_segment_creation 参数


show parameter deferred_segment_creation

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
deferred_segment_creation            boolean     TRUE
SQL> alter system set deferred_segment_creation=false;

系统已更改。

SQL> show parameter deferred_segment_creation

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
deferred_segment_creation            boolean     FALSE

 

  该参数值默认是TRUE,当改为FALSE时,无论是空表还是非空表,都分配segment。

  需注意的是:该值设置后对以前导入的空表不产生作用,仍不能导出,只能对后面新增的表产生作用。如需导出之前的空表,只能用第一种方法。

搞了我好久,最后查到这个方法。

先查询一下当前用户下的所有空表

select table_name from user_tables where NUM_ROWS=0;

用以下这句查找空表

select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0

把查询结果导出,执行导出的语句

'ALTERTABLE'||TABLE_NAME||'ALLOCATEEXTENT;'
-----------------------------------------------------------
alter table AQ$_AQ$_MEM_MC_H allocate extent;
alter table AQ$_AQ$_MEM_MC_G allocate extent;
alter table AQ$_AQ$_MEM_MC_I allocate extent;
alter table AQ$_AQ_PROP_TABLE_T allocate extent;
alter table AQ$_AQ_PROP_TABLE_H allocate extent;
alter table AQ$_AQ_PROP_TABLE_G allocate extent;
alter table AQ$_AQ_PROP_TABLE_I allocate extent;
alter table AQ$_KUPC$DATAPUMP_QUETAB_T allocate extent;
alter table AQ$_KUPC$DATAPUMP_QUETAB_H allocate extent;
alter table AQ$_KUPC$DATAPUMP_QUETAB_G allocate extent;
alter table AQ$_KUPC$DATAPUMP_QUETAB_I allocate extent;

'ALTERTABLE'||TABLE_NAME||'ALLOCATEEXTENT;'
-----------------------------------------------------------
alter table AQ$_SYS$SERVICE_METRICS_TAB_T allocate extent;
alter table AQ$_SYS$SERVICE_METRICS_TAB_H allocate extent;
alter table AQ$_SYS$SERVICE_METRICS_TAB_G allocate extent;
alter table AQ$_SYS$SERVICE_METRICS_TAB_I allocate extent;

然后再执行

exp 用户名/密码@数据库名 file=/home/oracle/exp.dmp log=/home/oracle/exp_smsrun.log 成功!

linux

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!