数据库的迁移用TTS也是一种方案,在以下条件满足的条件下进行用TTS:
1.源数据库与目标数据库的wordsize可以不相同,可以将32bit的数据迁移到64bit
2.数据库版本也需要一致,因为各版本的timezone会不一样,可以通过SELECT version FROM v$timezone_file查询当前数据库的timesize.
Oracle 9i 的time zone 文件version是1,10g 是2,10gr2是4,到了11gR2,time zone files 可以从1到14.
默认情况下,11.2.0.1 的time zone 是11.
11.2.0.2的time zone 是14
11.2.0.3的time zone 是14.
3.10g开始,tts支持跨操作系统,通过查v$transportable_platform查看ENDIAN_FORMAT,如果不一致可以通过RMAN来转换,跨平台的前提是DB 的compatibility 参数大于10.0.0。
SQL> select * from v$transportable_platform order by 1;
PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------- ----------------------------------- --------------
1 Solaris[tm] OE (32-bit) Big
2 Solaris[tm] OE (64-bit) Big
3 HP-UX (64-bit) Big
4 HP-UX IA (64-bit) Big
5 HP Tru64 UNIX Little
6 AIX-Based Systems (64-bit) Big
7 Microsoft Windows IA (32-bit) Little
8 Microsoft Windows IA (64-bit) Little
9 IBM zSeries Based Linux Big
10 Linux IA (32-bit) Little
11 Linux IA (64-bit) Little
12 Microsoft Windows x86 64-bit Little
13 Linux x86 64-bit Little
15 HP Open VMS Little
16 Apple Mac OS Big
17 Solaris Operating System (x86) Little
18 IBM Power Based Linux Big
19 HP IA Open VMS Little
20 Solaris Operating System (x86-64) Little
21 Apple Mac OS (x86-64) Little
20 rows selected.
4.两端的字符集以及国际字符集必须要兼容
5.compatibility值的要求如下:
实际操作:
做一个简单的操作,os和oracle版本都是11.2.0.3
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
1.检查两端的endian_format是否一致
SQL> SELECT d.PLATFORM_NAME, 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
2.通过DBMS_TTS.TRANSPORT_SET_CHECK检查一下需要传输的表空间是不是自包含的
SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('L5MSPACE',TRUE);
PL/SQL procedure successfully completed.
SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;
VIOLATIONS
--------------------------------------------------------------------------------
ORA-39907: Index BLUESKY.I_DATA_RANGE in tablespace L5MSPACE points to table BLU
ESKY.DATA_RANGE in tablespace CSPSPACE.
ORA-39907: Index BLUESKY.I_DATA_RANGE_2 in tablespace L5MSPACE points to table B
LUESKY.DATA_RANGE in tablespace CSPSPACE.
如果TRANSPORT_SET_VIOLATIONS有输出的话,需要先解决这些问题。
SQL> alter table bluesky.data_range move tablespace l5mspace;
SQL> alter index BLUESKY.I_DATA_RANGE rebuild tablespace l5mspace;
SQL> alter index BLUESKY.I_DATA_RANGE_2 rebuild tablespace l5mspace;
--再次检查就没有问题了
SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('L5MSPACE',TRUE);
SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;
no rows selected
3.用expdp生成传输表空间的元数据
--先需要设为只读
SQL> alter tablespace l5mspace read only;
--准备一个datapump 目录
SQL> create directory datapump as '/u01/datapump';
SQL> grant read,write on directory sys.datapump to l5m;
[oracle@qht115 u01]$ expdp l5m/l5m dumpfile=l5mspace_full.dmp directory=datapump transport_tablespaces=l5mspace
Export: Release 11.2.0.3.0 - Production on Fri Sep 7 10:53:24 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39006: internal error
ORA-39068: invalid master table data in row with PROCESS_ORDER=-3
ORA-01647: tablespace 'L5MSPACE' is read-only, cannot allocate space in it
在执行expdp时出错了,指示无法分配空间。这个原因是导出的用户L5M的默认表空间就是L5M,所以要用其它的用户做导出操作,换作用system用户导出就正常了
[oracle@qht115 u01]$ expdp system/system dumpfile=l5mspace_full.dmp directory=datapump transport_tablespaces=l5mspace
4.由于不是跨平台的,所以就需要用rman来转换格式。如果需要转换的话,官网的例子如下:
RMAN> CONVERTTABLESPACE sales_1,sales_2
TO PLATFORM'Microsoft Windows IA (32-bit)'
FORMAT '/tmp/%U';
5.将元数据以及datafile都复制到目标库
[oracle@qht115 u01]$ scp /u01/datapump/l5mspace_full.dmp 172.17.61.131:/u01/oradata/orcl
[oracle@qht115 u01]$ scp /u01/oradata/orcl/l5mspace01.dbf 172.17.61.131:/u01/oradata/orcl
6.将源库的表空间恢复为可读写(可选)
SQL> alter tablespace l5mspace read write;
7.目标库准备该表空间对象的用户,在impdp之前需要将l5mspace下所有对象的所属user先建立好,不过默认表空间先临时设为其它表空间,等impdp导入表之后,将用户的默认表空间设为正确的即可。
8.目录库建立directory
SQL> create directory datapump as '/u01/oradata/orcl';
9.导入到目标库
[oracle@qht131 u02]$ impdp system/system dumpfile=l5mspace_full.dmp directory=datapump transport_datafiles=/u01/oradata/orcl/l5mspace01.dbf
dumpfile不需要指定路径,而transport_datafiles需要指定路径
10.正常导入没有问题的话,最后将传输的表空间也设置为可写。
SQL>alter tablespace l5mspace read write;
至此传输表空间完成!
参考:
https://blog.csdn.net/tianlesoftware/article/details/7267582