ORACLE objects migration

对象:表空间,数据库
作用:将表空间,数据库通过复制的方法尽快传输的另一台机器,可以跨平台移动
同一台机器system表空间迁移:1. 关闭数据库
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
2. 复制system表空间对应数据文件去新路径
3. 以mount启动数据库
SQL> startup mount
ORACLE 例程已经启动。
Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
4. 修改system表空间对应数据文件去新路径
SQL> alter database rename file  '/u01/app/oracle/oradata/orcl/system01.dbf' to '/u01/app/oracle/oradata/orcl/system/system01.dbf';
数据库已更改。
5. 启动数据库
SQL> alter database open;
数据库已更改。
不同机器
非system表空间迁移:
准备工作:
1. 创建用于传输的表空间:
create tablespace move datafile '/u01/app/oracle/oradata/orcl/move.dbf' size 10M;
2. 在表空间上创建表,以便检查传输结果:
conn hr/hr
create table tbmove tablespace move as select * from hr.employees;
检查:确保表空间的所有对象都在该表空间中,例如表上的Index
命令:exec dbms_tts.transport_set_check('move', true, true);
检查结果:SELECT * FROM TRANSPORT_SET_VIOLATIONS;
确保SELECT * FROM TRANSPORT_SET_VIOLATIONS无返回结果
3. 数据库compatible大于10.0.0:show parameter compatible;
导出:
1. 将表空间设置为只读:alter tablespace move read only;
2. 导出表空间的metadata:
a. 以system用户创建文件夹:
create directory tbmove as '/tmp/tbmove';
b. 以system用户导出表空间的metadata:
服务器端:EXPDP system/password DUMPFILE=expdat.dmp DIRECTORY=TBMOVE TRANSPORT_TABLESPACES =MOVE
客户端:expdp system/password@orcl dumpfile=expdat.dmp directory=tbmove transport_tablespaces=move
导出报错,ORA-39123, ORA-29341;通过exec dbms_tts.transport_set_check('move', true, true)重新检查。
问题是:为检查创建的tbmove用的是sys用户,所以无法导出
c. 检查文件系统,确认文件存在
转换:
转换原因:操作系统的Endian format不同
查看:select * from v$transportable_platform
转换工具:RMAN
转换地点:源服务器,目标服务器均可,源服务器相对简单
脚本:
从Linux转换成windows
RMAN> CONVERT TABLESPACE sales_1,sales_2 
2> TO PLATFORM. 'Microsoft Windows NT'
3> FORMAT '/temp/%U';
从linux转换成HPUX
RMAN> CONVERT DATAFILE 
2> '/hq/finance/work/tru/tbs_31.f',
3> '/hq/finance/work/tru/tbs_32.f',
4> '/hq/finance/work/tru/tbs_41.f'
5> TO PLATFORM="Solaris[tm] OE (32-bit)"
6> FROM PLATFORM="HP TRu64 UNIX"
7> DB_FILE_NAME_CONVERT=
8> "/hq/finance/work/tru/", "/hq/finance/dbs/tru"
9> PARALLELISM=5;
传输:将数据文件,metadata文件(expdat.dmp)复制到目标服务器
(如果针对同一机器,同一服务器,需要先删除表空间 drop tablespace move including contents;)
导入:
IMPDP system/password DUMPFILE=expdat.dmp DIRECTORY=TBMOVE  TRANSPORT_DATAFILES=/tmp/tbmove/move.dbf
设置:
将表空间设置成可读写:alter tablespace move read write;
检查:
conn hr/hr
select * from tbmove;
数据库重建
同一服务器
使用DBCA将现有数据库存为模板(包含结构,数据文件),然后使用模板在新位置创建新库。
非system表空间迁移:
Test environment: Windows Server 2008 + Oracle 11gr2

1. set the tablespace offline;
ALTER TABLESPACE INDEX_1 OFFLINE NORMAL;

2. copy the files to destination

3. Change the path of datafile in database
ALTER TABLESPACE INDEX_1 RENAME DATAFILE 'F:\ORADATA\THOR\INDEX01.DBF' TO 'E:\ORADATA\THOR\INDEX01.DBF';
 
4. set the tablespace online
ALTER TABLESPACE INDEX_1 ONLINE;

表迁移 table migration
method 1. 导入导出,但是会影响DML;

method 2. 在EM管理端中,选择table,在reorganize动作,设置set attribute进行迁移。可以在线做,不影响DML

method 3: Using following command to generate script and run the script
select 'alter table ' ||table_name|| ' move tablespace tbs_name;' table_name from dba_tables where wner='%***%' and table_name like '%***%'

索引迁移 Index migration
method 1.  Generate script and run the script
select 'alter index ' ||index_name|| ' rebuild tablespace tbs_name;' index_name from dba_indexes where wner='%***%' and table_name like '%***%'

method 2. Drop index and recreate index
lob表迁移 table has lob column migration

select 'alter table' ||table_name|| 'move lob('||index_name||') store as (tablespace tbs_name);' from dba_indexes where wner='%***%' and index_name like '%***%'
Description find out the lob column belong to which table
select table_name,segment_name,index_name from DBA_LOBS where SEGMENT_NAME IN ('SYS_LOB0000074320C00036$$','SYS_LOB0000074323C00010$$') AND OWNER='SUMMA'

Comments

Popular posts from this blog

Nginx Proxy & Load Balance & LNMP

Snort+barnyard2+Snorby CentOS 6.5_64 Installation

ORACLE Error