2012年6月21日星期四

exp/imp transport tablespace(传输表空间)

使用exp imp
transport tablespace
与使用expdp/impdp是步骤一样的 语法上有些不一样

限制条件与expdp/impdp一样 (查看expdp/impdp transport tablespace)
将db xh tablespace smallts transport 到db orcl
SQL> conntr/a123@xh
已连接。
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
TEMP
USERS
EXAMPLE
RMAN_TS
XHTEST
XHTR
OUTLINE_TS
SMALLTS
已选择11行。
SQL> select count(*) from t1;
COUNT(*)
----------
0
SQL> insert into t1 values(1);
已创建 1 行。
SQL> select count(*) from t1;
COUNT(*)
----------
1
SQL> commit;
提交完成。
SQL> select tablespace_name from user_tables where table_name='T1';
TABLESPACE_NAME
------------------------------
USERS
SQL> alter table t1 move tablespace smallts;
表已更改。
SQL> select tablespace_name from user_tables where table_name='T1';
TABLESPACE_NAME
------------------------------
SMALLTS

SQL> execute sys.dbms_tts.transport_set_check('smallts',true,true);
PL/SQL 过程已成功完成。
SQL> select * from sys.transport_set_violations;
VIOLATIONS
--------------------------------------------------------------------------------
Index TR.T1_IND in tablespace USERS points to table TR.T1 in tablespace SMALLTS

发现t1_ind 在USER TABLESPACE 与表不在同一个表空间
(expdp的话用TRANSPORT_FULL_CHECK 设置为N 可以导出时候不报告错误 成功导出 不过只导出INDEX 所在表空间 不导出依赖的表所在表空间还是会报错,impdp时也一样)(exp/imp时用 TTS_FULL_CHECK 一样) 在这里 我们还是手动解决下这个问题
SQL> alter index t1_IND REBUilD TABLESPACE smallts
2 ;
索引已更改。
SQL> execute sys.dbms_tts.transport_set_check('smallts',true,true);
PL/SQL 过程已成功完成。
SQL> select * from sys.transport_set_violations;
未选定行~~~~~~~~~~~~~~~~~可以了

C:\>set oracle_sid=orcl
C:\>sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 9月 29 11:43:05 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select name from v$database;
NAME
---------
ORCL
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
TEMP
USERS
EXAMPLE
TEST
RMAN_TS
TESTXH
XHTEST
XHTR
已选择11行。
SQL> host exp'sys/a831115@xhas sysdba' transport_tablespace=y file=d:\exp\tablesp
ace.dmp tablespaces=smallts
Export: Release 10.2.0.1.0 - Production on 星期二 9月 29 11:47:43 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
注: 将不导出表数据 (行)
即将导出可传输的表空间元数据...
EXP-00008: 遇到 ORACLE 错误 29335
ORA-29335: 表空间 'SMALLTS' 不为只读~~~~~~~~必须要 read only
ORA-06512: 在 "SYS.DBMS_PLUGTS", line 507
ORA-06512: 在 line 1
EXP-00000: 导出终止失败

另外必须 sysdba connect(EXP-00044: 必须以 'SYSDBA' 身份连接, 才能进行时间点恢复或可传输的表空间导入)
SQL> alter tablespace smallts read only;
表空间已更改。
SQL> host exp'sys/a831115@xhas sysdba' transport_tablespace=y file=d:\exp\tablesp
ace.dmp tablespaces=smallts
Export: Release 10.2.0.1.0 - Production on 星期二 9月 29 11:48:10 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
注: 将不导出表数据 (行)
即将导出可传输的表空间元数据...
对于表空间 SMALLTS...
. 正在导出簇定义
. 正在导出表定义
. . 正在导出表 T1
. 正在导出引用完整性约束条件
. 正在导出触发器
. 结束导出可传输的表空间元数据
成功终止导出, 没有出现警告。
SQL> host copy d:\xhdatafile\smallfile.dbf E:\orcldatafile\smallfile.dbf
已复制 1 个文件。
SQL> alter tablespace smallts read write
2 ;
表空间已更改。
orcl db
SQL> host imp '/ as sysdba' transport_tablespace=y file=d:\exp\tablespace.dmp data
files=e:\orcldatafile\smallfile.dbf fromuser=tr touser=system
Import: Release 10.2.0.1.0 - Production on 星期二 9月 29 11:54:31 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
经由常规路径由 EXPORT:V10.02.01 创建的导出文件
即将导入可传输的表空间元数据...
已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入
. 正在将 TR 的对象导入到 SYSTEM
. . 正在导入表 "T1"
成功终止导入, 没有出现警告。
SQL> conn system/a831115
已连接。
SQL> select count(*) from t1;
COUNT(*)
----------
1
SQL> select tablespace_name from user_tables where table_name='T1';
TABLESPACE_NAME
------------------------------
SMALLTS
SQL> select file_name from dba_data_files where tablespace_name='SMALLTS';
FILE_NAME
--------------------------------------------------------------------------------
E:\ORCLDATAFILE\SMALLFILE.DBF