Oracle用分区表分区交换做历史数据迁移(四)

2014-11-24 14:54:14 · 作者: · 浏览: 4
------------------------ TAN_2014_8 TAN_2014_8 TAN_2014_7 TAN_2014_7 TAN_2014_6 TAN_2014_6 TAN_2014_5 TAN_2014_5 TAN_2014_4 TAN_2014_4 TAN_2014_3 TAN_2014_3 TAN_2014_2 TAN_2014_2 TAN_2014_1 TAN_2014_1 TAN_2013_12 TAN_2013_12 TAN_2013_11 TAN_2013_11 TAN_2013_10 TAN_2013_10 IND_TAN_2014_8 TAN_2014_8 IND_TAN_2014_7 TAN_2014_7 IND_TAN_2014_6 TAN_2014_6 IND_TAN_2014_5 TAN_2014_5 IND_TAN_2014_4 TAN_2014_4 IND_TAN_2014_3 TAN_2014_3 IND_TAN_2014_2 TAN_2014_2 IND_TAN_2014_1 TAN_2014_1 IND_TAN_2013_12 TAN_2013_12 IND_TAN_2013_11 TAN_2013_11 IND_TAN_2013_10 TAN_2013_10 22 rows selected.

3. 表空间传输:

更多关于表空间传输的内容:http://blog.csdn.net/bamuta/article/category/1138527

验证表空间的自包含:
SQL> exec dbms_tts.transport_set_check('TAN_2013_9',TRUE);


PL/SQL procedure successfully completed.


SQL> select * from transport_set_violations;

no rows selected

另外表空间传输需要两端库的字符集一致。


导出无数据:

SQL> alter tablespace tan_2013_9 read only;

[oracle@OEL63 ~]$ exp \'sys/oracle as sysdba\' tablespaces=tan_2013_9 transport_tablespace=y file=exp_tan_2013_9.dmp

拷贝文件
[oracle@OEL63 ~]$ scp exp_tan_2013_9.dmp 192.168.114.174:/home/oracle/
[oracle@OEL63 ~]$ scp /data01/qing/QING/datafile/o1_mf_tan_2013_9tht2cgh_.dbf 192.168.114.174:/data01/vm603/VM603/datafile/

在目标库导入元数据
[oracle@vm603 ~]$ imp \'sys/oracle as sysdba\' transport_tablespace=y file=exp_tan_2013_9.dmp log=imp.log tablespaces=tan_2013_9 datafiles='/data01/vm603/VM603/datafile/o1_mf_tan_2013_9tht2cgh_.dbf'


将两端库的该表空间read write
SQL> alter tablespace tan_2013_9 read write;

4.目标库再做分区交换

目标库对就表增加分区:
SQL> alter table tan add partition tan_2013_9 values less than (to_date('2013-10-01','yyyy-mm-dd')) tablespace tan_2013_9;


Table altered.


SQL> select count(*) from tan partition(tan_2013_9);


COUNT(*)
----------0


在目标库做一次分区交换。
SQL> alter table tan exchange partition tan_2013_9 with table tmp_tan_2013_9 including indexes with validation;

Table altered.

检查
SQL>  select count(*) from tan partition(tan_2013_9);


  COUNT(*)
----------
       833


SQL> select table_name,partition_name,tablespace_name from user_tab_partitions;
TABLE_NAME                     PARTITION_NAME                 TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
TAN                            TAN_2013_8                     TAN_2013_8
TAN                            TAN_2013_7                     TAN_2013_7
TAN                            TAN_2013_9                     TAN_2013_9


SQL> select index_name,partition_name,tablespace_name from user_ind_partitions;
INDEX_NAME                     PARTITION_NAME                 TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
IND_TAN                        IND_TAN_2013_8                 TAN_2013_8
IND_TAN                        IND_TAN_2013_7                 TAN_2013_7
IND_TAN                        TAN_2013_9                     TAN_2013_9

5.源库删掉已经迁移走的分区:

SQL> select table_name,partition_name,tablespace_name from user_tab_partitions;


TABLE_NAME                     PARTITION_NAME                 TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
TAN                            TAN_2014_3                     TAN_2014_3
TAN                            TAN_2014_2                     TAN_2014_2
TAN                            TAN_2014_4                     TAN_2014_4
TAN                            TAN_2014_5                     TAN_2014_5
TAN                            TAN_2014_6                     TAN_2014_6
TAN                            TAN_2014_7                     TAN_2014_7
TAN                            TAN_2014_8                     TAN_2014_8
TAN                            TAN_2013_10                    TAN_2013_10
TAN                            TAN_2013_11                    TAN_2013_11
TAN                            TAN_2013_12                    TAN_2013_12
TAN                            TAN_201