合 【TTS】传输表空间 Linux和AIX 之间传输数据
- 实验部分
- 实验环境介绍
- 实验目标
- 实验过程
- source端环境准备
- 在源库上创建3个用户应用的表空间
- 在相应的表空间创建表和索引
- 判断平台支持并确定字节序
- 在源平台查询
- 在目标平台查询
- 选择自包含的表空间集
- 进行检查
- 查看检查结果
- 产生可传输表空间集
- 使自包含的表空间集中的所有表空间变为只读状态
- 使用数据泵导出工具,导出要传输的各个表空间的元数据
- 确定导出目录
- 开始导出
- 生成数据文件
- 还原源库中的表空间为读/写模式
- 传输数据文件和元数据到target端
- 传输转储元文件到目标库
- 查看目标库数据文件位置和目录
- 拷贝文件到目标库相应位置并修改权限
- target端转换字节序
- 开始导入
- 创建source库的2个用户并赋权限
- 开始导入
- 查看目标平台信息
- 查看导入后结果
【TTS】传输表空间Linux asm -> AIX asm
实验部分
实验环境介绍
项目 | source db | target db |
---|---|---|
db 类型 | 单实例 | 单实例 |
db version | 11.2.0.3 | 11.2.0.4 |
db 存储 | ASM | ASM |
ORACLE_SID | orclasm | ora2lhr |
db_name | orclasm | ora2lhr |
主机IP地址: | 192.168.59.30 | 22.188.194.66 |
OS版本及kernel版本 | RHEL6.5 64位,2.6.32-504.16.2.el6.x86_64 | AIX 64位 7.1.0.0 |
OS hostname | rhel6_lhr | ZFXDESKDB2 |
platform_name | Linux x86 64-bit | AIX-Based Systems (64-bit) |
db time zone | 14 | 14 |
字符集 | ZHS16GBK | ZHS16GBK |
compatible | 11.2.0.0.0 | 11.2.0.4.0 |
归档模式 | Archive Mode | Archive Mode |
实验目标
要实现将自定义的应用程序表空间app1tbs,app2tbs,idxtbs从源平台传递到目标平台,而在实际的工作过程中,需要将AIX上的数据库迁移到Linux,或者将Linux上的数据库迁移到AIX上,除了exp/imp和expdp/impdp外,最常用的就是传输表空间了,若是整个库迁移的话,我们需要做的就是把业务用户和业务表空间的数据迁移过来就行,Undo、temp、system等等的就不用迁移了,整个处理过程和本文档的处理过程大同小异,需要关注的是业务对象的个数、大小、状态等。
实验过程
source端环境准备
在源库上创建3个用户应用的表空间
[oracle@rhel6_lhr ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on 星期日 1月 31 23:34:27 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
23:34:27 SQL> create tablespace app1tbs datafile '+DATA' size 10m;
表空间已创建。
已用时间: 00: 00: 07.60
23:34:42 SQL> create tablespace app2tbs datafile '+DATA' size 10m;
表空间已创建。
已用时间: 00: 00: 27.25
23:35:53 SQL> create tablespace idxtbs datafile '+DATA' size 10m;
表空间已创建。
已用时间: 00: 00: 09.45
23:36:09 SQL> set line 9999 pagesize 9999
23:36:12 SQL> SELECT a.NAME, b.NAME FROM v$tablespace a , v$datafile b WHERE a.TS#=b.TS# ;
NAME NAME
----------------------- -------------------------------------------------------------------------------
SYSTEM +DATA/orclasm/datafile/system.256.850260145
SYSAUX +DATA/orclasm/datafile/sysaux.257.850260145
UNDOTBS1 +DATA/orclasm/datafile/undotbs1.258.851526539
USERS +DATA/orclasm/datafile/users.259.850260147
EXAMPLE +DATA/orclasm/datafile/example.265.850260295
APP1TBS +DATA/orclasm/datafile/app1tbs.268.902619275
APP2TBS +DATA/orclasm/datafile/app2tbs.280.902619327
TS_LHR +DATA/orclasm/datafile/ts_lhr.269.852632495
ENCRYPTED_TS +DATA/orclasm/datafile/encrypted_ts.272.854650889
GOLDENGATE +DATA/orclasm/datafile/goldengate.273.862829891
IDXTBS +DATA/orclasm/datafile/idxtbs.281.902619361
TS_LHR +DATA/orclasm/datafile/ts_lhr.284.869738273
USERS +FRA/orclasm/datafile/users.449.880121199
SYSTEM +FRA/orclasm/datafile/system.349.880121287
已选择14行。
已用时间: 00: 00: 00.80
23:36:21 SQL>
在相应的表空间创建表和索引
23:36:21 SQL> create user user_app1 identified by user_app1 default tablespace app1tbs;
用户已创建。
已用时间: 00: 00: 00.14
23:40:13 SQL> create user user_app2 identified by user_app2 default tablespace app1tbs;
用户已创建。
已用时间: 00: 00: 00.35
23:43:51 SQL> create user user_app2 identified by user_app2 default tablespace app2tbs;
用户已创建。
已用时间: 00: 00: 02.72
23:43:56 SQL> grant connect,resource to user_app1;
授权成功。
已用时间: 00: 00: 00.06
23:44:50 SQL> grant connect,resource to user_app2;
授权成功。
已用时间: 00: 00: 00.00
23:44:52 SQL> create table user_app1.app1_tab tablespace app1tbs as select * from scott.emp;
表已创建。
已用时间: 00: 00: 01.02
23:45:09 SQL> create table user_app2.app2_tab tablespace app2tbs as select * from scott.dept;
表已创建。
已用时间: 00: 00: 00.23
23:45:27 SQL> create index user_app1.idx_emp_ename on user_app1.app1_tab(ename) tablespace idxtbs;
索引已创建。
已用时间: 00: 00: 00.25
23:45:51 SQL> create index user_app2.idx_dept_dname on user_app2.app2_tab(dname) tablespace idxtbs;
索引已创建。
已用时间: 00: 00: 00.01
23:46:13 SQL>
判断平台支持并确定字节序
如果传输表空间集到不同的平台,则要确定对于源和目标平台这种跨平台表空间被支持,也要确定每个平台的字节序,如果平台具有相同的字节序,则不需要进行转化,否则必须做一个表空间集转化,在源端或目标端。
在源平台查询
23:46:13 SQL> col platform_name for a40
23:48:55 SQL> select d.platform_name,tp.endian_format from v$transportable_platform tp,v$database d where tp.platform_name=d.platform_name;
PLATFORM_NAME ENDIAN_FORMAT
---------------------------------------- --------------
Linux x86 64-bit Little
已用时间: 00: 00: 00.19
23:49:13 SQL>
结论:当前的系统平台支持跨平台表空间传输(因为上面的查询有记录返回)
在目标平台查询
ZFXDESKDB2:oracle:/oracle>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 1 13:47:14 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SYS@ora2lhr> col platform_name for a40
SYS@ora2lhr> select d.platform_name,tp.endian_format from v$transportable_platform tp,v$database d where tp.platform_name=d.platform_name;
PLATFORM_NAME ENDIAN_FORMAT
---------------------------------------- ----------------------------
AIX-Based Systems (64-bit) Big
结论: 当前的AIX平台支持跨平台的表空间传输
源平台和目标平台的Endian_format 不同,source端为Little,target端为Big,所以需要进行表空间集转换,前边说过在源端或目标端都可以进行转换,这里我们选择在目标端来进行转换。
选择自包含的表空间集
进行检查
Indicates whether a full or partial dependency check is required. If TRUE, treats all IN and OUT pointers(dependencies) and captures them as violations if they are not self-contained in the transportable set.
先试试要传输app1tbs和idxtbs这2个表空间:
SQL> execute dbms_tts.transport_set_check('app1tbs,idxtbs',true);
PL/SQL procedure successfully completed.
查看检查结果
SQL> col violations for a70
23:50:53 SQL> select * from transport_set_violations;
VIOLATIONS
-------------------------------------------------------------------------------------------------------------------------------------------
ORA-39907: 索引 USER_APP2.IDX_DEPT_DNAME (在表空间 IDXTBS 中) 指向表 USER_APP2.APP2_TAB (在表空间 APP2TBS 中)。
已用时间: 00: 00: 00.18
23:51:14 SQL>
结论: 在idxtbs表空间中IDX_DEPT_DNAME索引指向了表空间集外的USER_APP2.APP2_TAB表,所以这里选择app1tabs,app2tabs,idxtbs作为新的表空间集再次进行检查
23:51:14 SQL> execute dbms_tts.transport_set_check('app1tbs,app2tbs,idxtbs',true);
PL/SQL 过程已成功完成。
已用时间: 00: 00: 07.24
23:52:14 SQL> select * from transport_set_violations;
未选定行
已用时间: 00: 00: 00.00
23:52:54 SQL>
结论: 此时这个表空间集已经不再违背自包含的条件,可以确定为一个可传输表空间集。在实际生产环境中也是如此检查的,若是全库迁移,得把需要迁移的表空间修改为自包含的。
产生可传输表空间集
使自包含的表空间集中的所有表空间变为只读状态
23:52:54 SQL> alter tablespace app1tbs read only;
表空间已更改。
已用时间: 00: 00: 00.36
23:54:31 SQL> alter tablespace app2tbs read only;
表空间已更改。
已用时间: 00: 00: 00.15
23:54:42 SQL> alter tablespace idxtbs read only;
表空间已更改。
已用时间: 00: 00: 00.14
23:54:48 SQL>
使用数据泵导出工具,导出要传输的各个表空间的元数据
确定导出目录
23:55:51 SQL> set line 9999
23:56:07 SQL> col directory_name for a28
23:56:07 SQL> col directory_path for a100
23:56:07 SQL> select directory_name,directory_path from dba_directories;
DIRECTORY_NAME DIRECTORY_PATH
---------------------------- ----------------------------------------------------------------------------------------------------
OSDESC /home/oracle/
ASMSRC +DATA/orclasm/datafile/
DIR_ALERT /u01/app/oracle/diag/rdbms/orclasm/orclasm/trace
SCHEDULER$_WALLET_DIR /u01/app/oracle/product/11.2.0/dbhome_1/scheduler/wallet
TMP_HF_DIR +DATA/orclasm/datafile/
FY_DATA_DIR /tmp
REPDIR /oradata06/repdir
DIR_ALERT_CHECKHELTH_LHR_1 /u01/app/oracle/diag/rdbms/orclasm/orclasm/trace
SUBDIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/order_entry//2002/Sep
SS_OE_XMLDIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/order_entry/
LOG_FILE_DIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/log/
MEDIA_DIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/product_media/
XMLDIR /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/xml
DATA_FILE_DIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/sales_history/
DATA_PUMP_DIR /u01/app/oracle/admin/orclasm/dpdump/
ORACLE_OCM_CONFIG_DIR /u01/app/oracle/product/11.2.0/dbhome_1/ccr/state