Oracle传输表空间迁移数据库
本文是通过exp/imp方式实现,需要将数据库表空间处于只读模式,对于实时应用的生产数据库,可以采用rman方式进行传输表空间。
执行表空间传输有以下限制条件:
(1)源数据库和目标数据库必须处于相同的平台,10g以后可以用RMAN命令修改数据文件实现跨平台移动表空间。
(2)对于源数据库和目标数据库版本不同时,源数据库的版本必须低于目标数据库。
(3)两边数据库字符集和国家字符集必须一致。
(4)目标数据库不能存在同名的表空间。
1. 查询oracle支持的平台转换
SQL> col PLATFORM_NAME for a40;
SQL> select * from v$transportable_platform order by 3;
PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------- ---------------------------------------- --------------
6 AIX-Based Systems (64-bit) Big
18 IBM Power Based Linux Big
2 Solaris[tm] OE (64-bit) Big
4 HP-UX IA (64-bit) Big
16 Apple Mac OS Big
1 Solaris[tm] OE (32-bit) Big
9 IBM zSeries Based Linux Big
3 HP-UX (64-bit) Big
17 Solaris Operating System (x86) Little
20 Solaris Operating System (x86-64) Little
12 Microsoft Windows x86 64-bit Little
13 Linux x86 64-bit Little
8 Microsoft Windows IA (64-bit) Little
19 HP IA Open VMS Little
11 Linux IA (64-bit) Little
5 HP Tru64 UNIX Little
10 Linux IA (32-bit) Little
7 Microsoft Windows IA (32-bit) Little
15 HP Open VMS Little
2. 创建测试表空间和测试用户、表
SQL> create tablespace tjoa datafile ‘/u01/app/oracle/oradata/orcl/tjoa.dbf‘ size 10m autoextend on next 10m;
SQL> create user abc identified by abc default tablespace TJOA;
SQL> grant connect,resource to abc;
SQL> conn abc/abc
SQL> create table t as select * from all_objects;
3. 检查自包含性
SQL> conn / as sysdba
SQL> execute dbms_tts.transport_set_check(ts_list=>‘TJOA‘,incl_constraints=>TRUE);
SQL> select * from transport_set_violations;
设置表空间只读
SQL> alter tablespace TJOA read only;
SQL> select tablespace_name, status from dba_tablespaces where tablespace_name = ‘TJOA‘;
TABLESPACE_NAME STATUS
------------------------------ ---------
TJOA READ ONLY
SQL>
4. 执行导出
exp \‘/ as sysdba \‘ file=tjoa.dmp transport_tablespace=y tablespaces=TJOA buffer=10240000
通过expdp方式:
expdp \‘/ as sysdba \‘ dumpfile=tjoa.dmp directory=dump_dir transport_tablespaces=TJOA
5. 源库将表空间设置为读写状态
SQL> alter tablespace TJOA read write;
6. 模拟平台转换
windows/linux平台都不需要转换。
使用rman的convert命令转换文件示例如下:
$ rman target /
RMAN> convert tablespace TJOA to platform ‘Linux IA (32-bit)‘ format ‘/u01/%U‘;
7. 复制表空间转换后的数据文件及导出文件到目标平台
scp tjoa.dmp 192.168.233.160:/home/oracle
scp tjoa.dbf 192.168.233.160:/u01/app/oracle/oradata/orcl/
8. 先在目标数据库创建用户abc
SQL> create user abc identified by abc;
SQL> grant connect,resource to abc;
9. 导入表空间
imp \‘/ as sysdba \‘ file=tjoa.dmp transport_tablespace=y tablespaces=TJOA datafiles=/u01/app/oracle/oradata/orcl/tjoa.dbf
通过impdp方式:
impdp \‘/ as sysdba \‘ dumpfile=tjoa.dmp directory=dump_dir transport_datafiles=/u01/app/oracle/oradata/orcl/tjoa.dbf remap_schema=tjoa:tjoa
10. 目标库配置
SQL> alter user abc default tablespace TJOA;
SQL> select tablespace_name, status from dba_tablespaces where tablespace_name = ‘TJOA‘;
SQL> alter tablespace TJOA read write;
SQL> conn / as sysdba;
Connected.
SQL> alter user abc default tablespace TJOA;
User altered.
SQL> select tablespace_name, status from dba_tablespaces where tablespace_name = ‘TJOA‘;
TABLESPACE_NAME STATUS
------------------------------ ---------
TJOA READ ONLY
SQL>
SQL>
SQL> alter tablespace TJOA read write;
Tablespace altered.
SQL>
SQL> select tablespace_name, status from dba_tablespaces where tablespace_name = ‘TJOA‘;
TABLESPACE_NAME STATUS
------------------------------ ---------
TJOA ONLINE
SQL>
本文出自 “koumm的linux技术博客” 博客,请务必保留此出处http://koumm.blog.51cto.com/703525/1574822
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。