现在的位置: 首页 > 综合 > 正文

14.4 使用EXPDP 和 IMPDP 搬移表空间 案例

2012年11月29日 ⁄ 综合 ⁄ 共 3415字 ⁄ 字号 评论关闭

确定哪些平台之间可以搬移表空间:

SQL> select platform_name from v$transportable_platform;

PLATFORM_NAME
----------------------------------------
Solaris[tm] OE (32-bit)
Solaris[tm] OE (64-bit)
Microsoft Windows IA (32-bit)
Linux IA (32-bit)
AIX-Based Systems (64-bit)
HP-UX (64-bit)
HP Tru64 UNIX
HP-UX IA (64-bit)
Linux IA (64-bit)
HP Open VMS
Microsoft Windows IA (64-bit)
IBM zSeries Based Linux
Linux 64-bit for AMD
Apple Mac OS
Microsoft Windows 64-bit for AMD
Solaris Operating System (x86)
IBM Power Based Linux

已选择17行。

搬移表空间具有以下限制:

  • 要求源数据库和目标数据库必须具有相同的数据库字符集和民族字符集,能过查询数据字典视图 NLS_DATABASE_PATAMETERS, DBA 用户可以取得数据库字符集(NLS_CHARACTERSET) 和民族字符集(NLS_NCHAR_CHARACTERSET)。
  • 不能将表空间搬移到具有相同表空间的目标数据库中。在Oracle Database 10g 之前,如果在目标数据库中存在同名表空间,那么表空间无法搬移。但从Oracle  Database 10g 开始,通过使用 Alter TABLESPACE RENAME 命令可以修改源数据表空间或目标数据库表空间的名称。
  • 不能搬移SYSTEM 表空间和SYS 用户对象所在的表空间。
  • 如果要将表空间搬移到其他 OS 平台,则必须将初始化参数 compatible 设置为 10.0 以上。

将ORCL 数据库中的 TBS01 表空间搬移到 DEMO 数据库中,步骤如下:

(1) 确定自包含表空间集合。自包含表空间集合是指具有关联的表空间集合。当搬移表空间时,如果在两个表空间之间存在关联关系,则必须同时搬移这两个表空间。

例:表空间A 包含了EMP 表,而表空间B 包含了表EMP 的索引IND_EMP,如果要搬移表空间B,则必须同时搬移表空间A,此时表空间A和B为自包含表空间集合。

违反自包含表空间集合规则的常见情况如下:

  • 表空间集合包含有SYS 方案对象。
  • 表空间集合包含了索引所在表空间,但没有包含索引基表所在的表空间。
  • 表空间集合没有包含分区表的所有分区。
  • 表空间集合包含了表所在的表所在的表空间,但没有包含其LOB 列所在的表空间。

SQL> conn system/orcl@orcl
已连接。
SQL> execute sys.dbms_tts.transport_set_check('TBS01',true)

PL/SQL 过程已成功完成。

SQL> select * from sys.transport_set_violations;

VIOLATIONS
--------------------------------------------------------------------------------

Index SCOTT.IND_EMPNO in tablespace TBS01 points to table SCOTT.EMP in tablespac

e USERS

Index SCOTT.IND_DNAME in tablespace TBS01 points to table SCOTT.DEPT in tablespa

ce USERS

SQL> drop index scott.ind_empno;

索引已删除。

SQL> drop index scott.ind_dname;

索引已删除。

SQL> execute sys.dbms_tts.transport_set_check('TBS01',true)

PL/SQL 过程已成功完成。

SQL> select * from sys.transport_set_violations;

未选定行

(2) 生成要搬移的表空间集合。

SQL> alter tablespace tbs01 read only;

表空间已更改。

SQL> host expdp system/orcl@orcl directory=dump_dir dumpfile=transport.dmp trans
port_tablespaces=tbs01

Export: Release 10.2.0.1.0 - Production on 星期一, 05 1月, 2009 14:04:24

Copyright (c) 2003, 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
启动 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/********@orcl directory=dum
p_dir dumpfile=transport.dmp transport_tablespaces=tbs01
处理对象类型 TRANSPORTABLE_EXPORT/PLUGTS_BLK
处理对象类型 TRANSPORTABLE_EXPORT/TABLE
处理对象类型 TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01"
******************************************************************************
SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 的转储文件集为:
  D:\DUMP\TRANSPORT.DMP
作业 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" 已于 14:04:47 成功完成

(3) 传送转储文件和数据文件到目标数据库。

SQL> host copy d:\orcl\tbs01.dbf d:\demo\tbs01.dbf
已复制         1 个文件。

(4) 插入表空间到目标数据库。

SQL> host impdp system/orcl@demo directory=dump_dir dumpfile=transport.dmp trans
port_datafiles=d:\demo\tbs01.dbf remap_schema=scott:hr

Import: Release 10.2.0.1.0 - Production on 星期一, 05 1月, 2009 14:30:55

Copyright (c) 2003, 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
已成功加载/卸载了主表 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01"
启动 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/********@demo directory=dum
p_dir dumpfile=transport.dmp transport_datafiles=d:\demo\tbs01.dbf remap_schema=
scott:hr
处理对象类型 TRANSPORTABLE_EXPORT/PLUGTS_BLK
处理对象类型 TRANSPORTABLE_EXPORT/TABLE
处理对象类型 TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
作业 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" 已于 14:31:05 成功完成

SQL> alter tablespace tbs01 read write;

表空间已更改。

抱歉!评论已关闭.