您的位置:首页 > 其它

如何新建索引:高开销的缺失索引

2012-02-13 08:58 211 查看
数据迁移的一种技术;
数据迁移,就是将数据在数据库之间进行的传输;
1.有哪些操作系统平台,支持传输表空间技术
SYS@orcl11g> 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.
SYS@orcl11g> select platform_id,platform_name from v$database;
PLATFORM_ID PLATFORM_NAME
----------- ------------------------------
13 Linux x86 64-bit

2.使用传输表空间技术的限制
a.源库和目标库的数据库字符集必是兼容的;
b.源库和目标库的国家字符集也必须是兼容的;
c.目标库不能存在同名的表空间
d.对于潜在的对象(物化视图,分区表)必须全部存在要传输的表空间集中;
e.不能传输系统表空间,也不能传输包含sys用户对象的表空间

3.传输表空间最小的版本需求

*******************************************************************************
传输表空间样例:
1.创建样传输表空间
SYS@orcl11g> create tablespace tbs_tran
2 datafile '/u01/app/oracle/oradata/orcl11g/tbs_tran01.dbf'
3 size 100m;
Tablespace created.
2.在表空间上创建一些表
SYS@orcl11g> alter table hr.test move tablespace tbs_tran;
SYS@orcl11g> alter table hr.regions move tablespace tbs_tran;
3.查看源库和目标库的平台信息
源库:orcl11g
SYS@orcl11g> SELECT d.name,d.PLATFORM_NAME, ENDIAN_FORMAT
2 FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
3* WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME
SYS@orcl11g> /
NAME PLATFORM_NAME ENDIAN_FORMAT
--------- ------------------------------ --------------
ORCL11G Linux x86 64-bit Little
目标库:catdb
SYS@catdb> col platform_name for a30
SYS@catdb> SELECT d.name,d.PLATFORM_NAME, ENDIAN_FORMAT
2 FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
3* WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME
NAME PLATFORM_NAME ENDIAN_FORMAT
--------- ------------------------------ --------------
CATDB Linux x86 64-bit Little
4.表空间的自包含检查
--自包含检测的包
SYS@orcl11g> exec dbms_tts.transport_set_check('tbs_tran',true);
--查看检测结果
SYS@orcl11g> select * from transport_set_violations;
VIOLATIONS
--------------------------------------------------------------------------------
ORA-39908: Index HR.REG_ID_PK in tablespace EXAMPLE enforces primary constraints
of table HR.REGIONS in tablespace TBS_TRAN.
ORA-39908: Index HR.TEST_PK in tablespace USERS enforces primary constraints of
table HR.TEST in tablespace TBS_TRAN.
--将错误修复
SYS@orcl11g> alter index hr.reg_id_pk rebuild tablespace tbs_tran;
SYS@orcl11g> alter index hr.test_pk rebuild tablespace tbs_tran;
--再次检测
SYS@orcl11g> exec dbms_tts.transport_set_check('tbs_tran',true);
SYS@orcl11g> select * from transport_set_violations;
no rows selected
5.创建传输表空间集
a.源表空间置为read only
SYS@orcl11g> alter tablespace tbs_tran read only;

b.导出传输表空间集的元数据信息
--如果不存在目录对象,还要创建目录对象
[oracle@db253 pumpdir]$ expdp system/oracle directory=pump_dir dumpfile=tbs_tran.dmp transport_tablespaces=tbs_tran
[oracle@db253 pumpdir]$ ll -h tbs_tran.dmp
-rw-r----- 1 oracle oinstall 136K Jun 28 16:15 tbs_tran.dmp
6.把传输表空间集,拷贝到目标数据库所在的服务器
包括传输表空间的元数据信息和表空间的数据文件;
本例中包括:
[oracle@db253 pumpdir]$ ll /home/oracle/pumpdir/tbs_tran.dmp
-rw-r----- 1 oracle oinstall 139264 Jun 28 16:15 /home/oracle/pumpdir/tbs_tran.dmp
[oracle@db253 pumpdir]$ ll /u01/app/oracle/oradata/orcl11g/tbs_tran01.dbf
-rw-r----- 1 oracle oinstall 104865792 Jun 28 16:13 /u01/app/oracle/oradata/orcl11g/tbs_tran01.dbf

--将表空间的数据文件,拷贝至目标数据库所在的路径
[oracle@db253 pumpdir]$ cp /u01/app/oracle/oradata/orcl11g/tbs_tran01.dbf /u01/app/oracle/oradata/catdb/
7.导入传输表空间
a.目标库创建目录对象,读取表空间元数据信息
SYS@catdb> create directory catdb_dir as '/home/oracle/pumpdir';
b.将传输表空间集导入目标数据库
--需要注意的问题
&& 目标库中必须存在和源库中同样的数据库模式
&& 如果不存在,那么,需要使用remap_schema
[oracle@db253 ~]$ impdp system/oracle directory=catdb_dir dumpfile=tbs_tran.dmp transport_datafiles='/u01/app/oracle/oradata/catdb/tbs_tran01.dbf'

或者
[oracle@db253 orcl11g]$ impdp system/oracle directory=catdb_dir dumpfile=tbs_tran.dmp transport_datafiles='/u01/app/oracle/oradata/catdb/tbs_tran01.dbf' remap_schema=hr:new_hr
8.将源库和目标库的表空间都重新设置为read write
--源库的表空间
SYS@orcl11g> alter tablespace tbs_tran read write;

--目标库的表空间
SYS@catdb> alter tablespace tbs_tran read write;
******************************
官方文档样例:
Oracle Database Administrator's Guide
11g Release 2 (11.2)
14 Managing Tablespaces
-->Transporting Tablespaces Between Databases
--> Example
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: