热衷技术,热爱交流
分类: Oracle
2013-08-20 20:59:23
增量备份与表空间传输
一、增量备份
增量导出只能是全库导出,但是可以在导入时指定模式或者表,从而实现模式和表的增量导入。
1.增量备份方案:
周一:完全导出(1_full.dmp )
周二:增量导出(2_incre.dmp)
周三:增量导出(3_incre.dmp)
周四:增量导出(4_incre.dmp)
周五:累计增量导出(5_cumulative.dmp)
周六:增量导出(6_incre.dmp)
周日:增量导出(7_incre.dmp)
2.建立模式和表:
SYS >create user incre identified by talent;
SYS >grant dba to incre;
SYS >create tablespace incre datafile '/u01/oradata2/hx/incre01.dbf' size 10M autoextend on next 10M maxsize unlimited;
SYS >alter user incre default tablespace incre;
SYS >alter user incre quota 100m on incre;
SYS >conn incre/talent
INCRE >create table a(id number(10));INCRE >insert into a values(1);
3.数据导出:
在周1执行完全增量导出:
oracle[~/imp]$exp incre/talent inctype=complete file=1_full.dmp
. about to export INCRE's tables via Conventional Path ...
. . exporting table A 1 rows exported
在周2执行增量导出:(导出上回增量导出以来更新的表)
INCRE >create table b as select * from a;
INCRE >insert into a values(2);
INCRE >insert into a values(3);
oracle[~/imp]$exp incre/talent inctype=incremental file=2_incre.dmp
. about to export INCRE's tables via Conventional Path ...
. . exporting table A 3 rows exported
. . exporting table B 1 rows exported
周3增量导出:
INCRE >create table c as select * from b;
oracle[~/imp]$exp incre/talent inctype=incremental file=3_incre.dmp
. about to export INCRE's tables via Conventional Path ...
. . exporting table C 1 rows exported
周4增量导出:
INCRE >create table d as select * from b;
INCRE >insert into a values(10);
oracle[~/imp]$exp incre/talent inctype=incremental file=4_incre.dmp
. about to export INCRE's tables via Conventional Path ...
. . exporting table A 3 rows exported
. . exporting table D 1 rows exported
周5累计增量导出(从周1全量导出算起,导出这期间更新的表):
INCRE >create table e as select * from b;
oracle[~/imp]$exp incre/talent inctype=cumulative file=5_cumulative.dmp
. about to export INCRE's tables via Conventional Path ...
. . exporting table A 4 rows exported
. . exporting table B 1 rows exported
. . exporting table C 1 rows exported
. . exporting table D 1 rows exported. . exporting table E 1 rows exported
周6增量导出:
INCRE >create table f as select * from b;
INCRE >insert into a values(20);
oracle[~/imp]$exp incre/talent inctype=incremental file=6_incre.dmp
. . exporting table A 5 rows exported
. . exporting table F 1 rows exported
周日增量导出:
INCRE >create table g as select * from b;
INCRE >insert into a values(20);
oracle[~/imp]$exp incre/talent inctype=incremental file=7_incre.dmp
. about to export INCRE's tables via Conventional Path ...
. . exporting table A 5 rows exported
. . exporting table G 1 rows exported
4.恢复:
假设在周日备份完后,数据库彻底毁坏,可以通过create databae命令或者dbca建立结构一样的新库,然后依次导入1,5,6,7号文件,这样导入不会有重复数据产生:
模拟数据丢失:
INCRE >drop table A cascade constraints purge;
INCRE >drop table b cascade constraints purge;
INCRE >drop table c cascade constraints purge;
INCRE >drop table d cascade constraints purge;
INCRE >drop table e cascade constraints purge;
INCRE >drop table f cascade constraints purge;
INCRE >drop table g cascade constraints purge;
考虑incre模式数据的导入:
oracle[~/imp]$imp incre/talent file=1_full.dmp fromuser=incre touser=incre
oracle[~/imp]$imp incre/talent file=5_cumulative.dmp fromuser=incre touser=incre ignore=y commit=y
oracle[~/imp]$imp incre/talent file=6_incre.dmp fromuser=incre touser=incre ignore=y commit=y
oracle[~/imp]$imp incre/talent file=7_incre.dmp fromuser=incre touser=incre ignore=y commit=y
考虑全库恢复:
oracle[~/imp]$imp incre/talent file=1_full.dmp ignore=y full=y commit=y inctype=restore
oracle[~/imp]$imp incre/talent file=5_cumulative.dmp ignore=y full=y commit=y inctype=restore
oracle[~/imp]$imp incre/talent file=6_incre.dmp ignore=y full=y commit=y inctype=restore
oracle[~/imp]$imp incre/talent file=7_incre.dmp ignore=y full=y commit=y inctype=restore
如果数据库在周4备份后崩溃,可以重新建库,依次导入1,2,3,4号文件,具体操作同上。
imp增量导入以表为单位,所以导入时会卸掉原来的表。在插入更新频繁的OTLP环境中,imp增量导入效率很低,应该避免使用。
二、传输表空间
与普通的全库导出、模式导出相比,表空间传输存在如下弊端:
(1)操作起来更麻烦一些,例如需要手动建立模式对象,需要检查表空间的自包含性;
(2)操作时需要把表空间设置为只读,会影响业务;
(3)新版本跨平台表空间迁移不用考虑文件头文件问题,但是可能会由于平台之间大小端不同而需要进行文件转换;
(4)一般支持低版本到高版本的迁移,而且进行不同平台迁移时需要做更多的操作。
(5)不能传输system和sys用户拥有的对象
表空间传输的优势是它只导出元数据,导出元数据后再复制数据文件,这可以加快数据迁移速度。
Oracle一般支持低版本数据库到高版本数据库的表空间传输。下面讨论同平台、不同数据库版本的数据迁移和跨平台、同字节序、不同数据库版本的数据迁移
1. 同平台不同版本的数据迁移:
现在以分区表的表空间导出为例,说明表空间的导出过程.
源库:windows 10.2.0.4.0
目的库:windows 10.2.0.5.0
需求:分区表hr_event的用户是hr,现在以表空间传输方式导出分区表hr_event以及和它相关的索引,视图等对象。
首先查看这个表的定义:
HR >select dbms_metadata.get_ddl('TABLE','HR_EVENT') FROM DUAL;
DBMS_METADATA.GET_DDL('TABLE','HR_EVENT')
--------------------------------------------------------------------------------
CREATE TABLE "HR"."HR_EVENT"
(
"END_TIME" TIMESTAMP (3) NOT NULL ENABLE,
"UUID" VARCHAR2(128) NOT NULL ENABLE,
"FWRULE" VARCHAR2(256),
"RISK_FACTOR" VARCHAR2(256),
"NAME" VARCHAR2(32),
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(
BUFFER_POOL DEFAULT)
TABLESPACE "HR_SYSTEM_DATA"
PARTITION BY RANGE ("END_TIME")
(PARTITION "P20060323" VALUES LESS THAN (TIMESTAMP' 2006-03-24 00:00:00')
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(INITIAL 1048576 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "HR_EVENT_DATA" NOCOMPRESS ,
PARTITION "P20130819" VALUES LESS THAN (TIMESTAMP' 2013-08-20 00:00:00')
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(INITIAL 8388608 NEXT 8388608 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "HR20130819" NOCOMPRESS ,
PARTITION "P20130820" VALUES LESS THAN (TIMESTAMP' 2013-08-21 00:00:00')
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(INITIAL 8388608 NEXT 8388608 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "HR20130820" NOCOMPRESS ,
PARTITION "P20130821" VALUES LESS THAN (TIMESTAMP' 2013-08-22 00:00:00')
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(INITIAL 8388608 NEXT 8388608 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "HR20130821" NOCOMPRESS ,
PARTITION "P20130822" VALUES LESS THAN (TIMESTAMP' 2013-08-23 00:00:00')
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(INITIAL 8388608 NEXT 8388608 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "HR20130822" NOCOMPRESS ,
PARTITION "P20130823" VALUES LESS THAN (TIMESTAMP' 2013-08-24 00:00:00')
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOLOGGING
STORAGE(INITIAL 8388608 NEXT 8388608 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "HR20130823" NOCOMPRESS )
上面定义表明,分区表hr_event表的默认表空间是HR_SYSTEM_DATA,同时还以end_time为分区键,包含了几个分区。
1.检查表空间的自包含性:
表空间自包含指的是要传输的表空间没有引用指向外部表空间集,这里的引用包括索引,约束等对象。比如下列情况就违反了自包含:
索引在内部表空间,但是依赖的表在外部表空间;
约束在内部表空间,但是相关的表在外部表空间;
表空间在内部表空间,但是lob对象在外部表空间;
一个表包含多个分区,如果分区在不同表空间,则不满足自包含。
自包含分为一般自包含和严格自包含,如果表空间中有个表的索引在外部表空间,那么就不满足严格自包含,严格自包含不影响表空间导出,可以导入后重建索引。
(1)仅仅检查其中一个分区的表空间:
SYS >exec dbms_tts.transport_set_check('HR20130823',true);
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.60
SYS >select * from transport_set_violations;
VIOLATIONS
----------------------------------------------------------------------------------------------------
Default Partition (Table) Tablespace HR_SYSTEM_DATA for HR_EVENT not contained in transportable set
Partitioned table HR.HR_EVENT is partially contained in the transportable set: check table partitions by querying sys.dba_tab_partitions
结果显示,这个表空间是分区表hr_event的一部分,但是这个分区表的默认表空间是HR_SYSTEM_DATA,而且分区表还有其他的分区。
(2)添加其他所有分区的表空间,检查自包含:
SYS > exec dbms_tts.transport_set_check('HR20130819,HR20130820,HR20130821,HR20130822,HR20130823, HR_EVENT_DATA,HR_SYSTEM_DATA',true);
PL/SQL procedure successfully completed.
SYS >select * from transport_set_violations;
no rows selected
(3)检查严格自包含:
SYS >exec dbms_tts.transport_set_check('HR20130819,HR20130820,HR20130821,HR20130822,HR20130823, HR_EVENT_DATA,HR_SYSTEM_DATA',true,true);;
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.48
SYS >select * from transport_set_violations;
VIOLATIONS
-----------------------------------------------------------------------------------------------
Index HR.HR_D_HARDWARE_NAME in tablespace HR_SYSTEM_INDEX points to table HR.HR_D_HARDWARE in ta
blespace HR_SYSTEM_DATA
Index HR.HR_D_SOFTWARE_NAME in tablespace HR_SYSTEM_INDEX points to table HR.HR_D_SOFTWARE in ta
blespace
Index HR.HR_MODULE_IDX in tablespace HR_SYSTEM_INDEX points to table HR.HR_MODULE in tablespace
HR_SYSTEM_DATA
Index HR.ASSOCIATION5_FK in tablespace HR_SYSTEM_INDEX points to table HR.AUTH_RESOURCE in tablesp
ace HR_SYSTEM_DATA
Index HR.INDEX_HR_EVENT_COLNUM in tablespace HR_SYSTEM_INDEX points to table HR.HR_EVENT_COLNUM
in tablespace HR_SYSTEM_DATA
Index HR.INDEX_HR_RELATIONSHIP in tablespace HR_SYSTEM_INDEX points to table HR.HR_RELATIONSHIP
in tablespace HR_SYSTEM_DATA
结果表明,不满足严格自包含,因为有外部表空间(HR_SYSTEM_INDEX)的索引指向内部表空间HR_SYSTEM_DATA中的表,所以需要导出这些索引所在的表空间,当然也可以导出后重新建立索引,这里就一并导出吧。
(4)再次检查严格自包含:
SYS >exec dbms_tts.transport_set_check('HR20130819,HR20130820,HR20130821,HR20130822,HR20130823, HR_EVENT_DATA,HR_SYSTEM_DATA,HR_SYSTEM_INDEX',true,true);;
PL/SQL procedure successfully completed.
SYS >select * from transport_set_violations;
no rows selected
现在确定了,需要导出的表空间包括:HR20130819,HR20130820,HR20130821,HR20130822,HR20130823,HR_EVENT_DATA,HR_SYSTEM_DATA,HR_SYSTEM_INDEX,
(5)检查这些表空间的数据文件:
SYS >select FILE_NAME from dba_data_files where TABLESPACE_NAME in ('HR20130819','HR20130820','HR20130821','HR20130822','HR20130823','HR_EVENT_DATA','HR_SYSTEM_DATA','HR_SYSTEM_INDEX');
FILE_NAME
-------------------------------------------------------------------------------------------------
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_SYSTEM_DATA_000.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_SYSTEM_DATA_001.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_SYSTEM_DATA_002.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_SYSTEM_DATA_003.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_SYSTEM_INDEX_000.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_SYSTEM_INDEX_001.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_SYSTEM_INDEX_002.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_SYSTEM_INDEX_003.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_EVENT_DATA_000.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_EVENT_DATA_001.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_EVENT_DATA_002.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR_EVENT_DATA_003.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR20130819.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR20130820.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR20130821.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR20130822.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCLJJYF2\TA\HR20130823.DBF
2.把表空间设置成只读
导出过程必须要把需要导出的表空间设置成只读
SYS >select 'alter tablespace '||NAME||' read only;' from v$tablespace where NAME in ('HR20130819','HR20130820','HR20130821','HR20130822','HR20130823','HR_EVENT_DATA','HR_SYSTEM_DATA','HR_SYSTEM_INDEX');;
'ALTERTABLESPACE'||NAME||'READONLY;'
----------------------------------------------------------
alter tablespace HR_SYSTEM_DATA read only;
alter tablespace HR_SYSTEM_INDEX read only;
alter tablespace HR_EVENT_DATA read only;
alter tablespace HR20130819 read only;
alter tablespace HR20130820 read only;
alter tablespace HR20130821 read only;
alter tablespace HR20130822 read only;
alter tablespace HR20130823 read only;
3.导出表空间:
表空间自包含检查完毕,并且设置为只读,可以进行导出操作了:
exp "'sys/talent as sysdba'" tablespaces=HR20130819,HR20130820,HR20130821,HR20130822,HR20130823,HR_EVENT_DATA,HR_SYSTEM_DATA,HR_SYSTEM_INDEX transport_tablespace=y file=exp_tablespace.dmp log=exp_tablespace.log
连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
注: 将不导出表数据 (行)
即将导出可传输的表空间元数据...
对于表空间 HR20130819...
. 正在导出簇定义
. 正在导出表定义
对于表空间 HR20130820...
. 正在导出簇定义
. 正在导出表定义
对于表空间 HR20130821...
. 正在导出簇定义
. 正在导出表定义
对于表空间 HR20130822...
. 正在导出簇定义
. 正在导出表定义
对于表空间 HR20130823...
. 正在导出簇定义
. 正在导出表定义
对于表空间 HR_EVENT_DATA...
. 正在导出簇定义
. 正在导出表定义
. . 正在导出表 HR_EVENT
对于表空间 HR_SYSTEM_DATA...
. 正在导出簇定义
. 正在导出表定义
. . 正在导出表 ASS_INTERFACE
. . 正在导出表 GROUP_TSMGROUP
. . 正在导出表 HR_EVENT_CATEGORY
对于表空间 HR_SYSTEM_INDEX...
. 正在导出簇定义
. 正在导出表定义
. 正在导出引用完整性约束条件
. 正在导出触发器
. 结束导出可传输的表空间元数据
成功终止导出, 没有出现警告。
4. 复制元数据和表空间的数据文件到目的库。
5. 到目的库上操作
到目的表空间上进行一些必要操作的目的是为了让目的库和源库结构一致
(1)新建用户hr的撤销表空间和临时表空间:
CREATE UNDO TABLESPACE HR_UNDO
DATAFILE
'D:\oracle_huangxing_data\hx111\hr/HR_SYSTEM_UNDO_000.DBF' SIZE 10 REUSE AUTOEXTEND ON NEXT 128M MAXSIZE UNLIMITED,
'D:\oracle_huangxing_data\hx111\hr/HR_SYSTEM_UNDO_001.DBF' SIZE 10 REUSE AUTOEXTEND ON NEXT 128M MAXSIZE UNLIMITED,
'D:\oracle_huangxing_data\hx111\hr/HR_SYSTEM_UNDO_002.DBF' SIZE 10 REUSE AUTOEXTEND ON NEXT 128M MAXSIZE UNLIMITED,
'D:\oracle_huangxing_data\hx111\hr/HR_SYSTEM_UNDO_003.DBF' SIZE 10 REUSE AUTOEXTEND ON NEXT 128M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
CREATE TEMPORARY TABLESPACE HR_TEMP
TEMPFILE
'D:\oracle_huangxing_data\hx111\hr/HR_TEMP_000.DBF' SIZE 10M REUSE AUTOEXTEND ON NEXT 128M MAXSIZE UNLIMITED,
'D:\oracle_huangxing_data\hx111\hr/HR_TEMP_001.DBF' SIZE 10M REUSE AUTOEXTEND ON NEXT 128M MAXSIZE UNLIMITED,
'D:\oracle_huangxing_data\hx111\hr/HR_TEMP_002.DBF' SIZE 10M REUSE AUTOEXTEND ON NEXT 128M MAXSIZE UNLIMITED,
'D:\oracle_huangxing_data\hx111\hr/HR_TEMP_003.DBF' SIZE 10M REUSE AUTOEXTEND ON NEXT 128M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
UNIFORM SIZE 2M;
ALTER SYSTEM SET UNDO_TABLESPACE=HR_UNDO;
(2)新建用户hr,设置相关属性,包括权限和和临时表空间信息:
drop USER HR CASCADE;
CREATE USER HR IDENTIFIED BY HR;
GRANT SELECT ANY DICTIONARY TO HR;
GRANT ALTER DATABASE TO HR;
GRANT DEBUG CONNECT SESSION TO HR;
GRANT CREATE TABLESPACE TO HR;
GRANT ALTER TABLESPACE TO HR;
GRANT DROP TABLESPACE TO HR;
GRANT CREATE SESSION TO HR;
GRANT ALTER SESSION TO HR;
GRANT CREATE TABLE TO HR;
GRANT CREATE VIEW TO HR;
GRANT CREATE SEQUENCE TO HR;
GRANT CREATE PROCEDURE TO HR;
GRANT CREATE TYPE TO HR;
GRANT QUERY REWRITE TO HR;
ALTER USER HR TEMPORARY TABLESPACE HR_TEMP;
grant unlimited tablespace to HR;
grant create database link to HR;
grant create any trigger to HR;
(3)导入表空间:
参数文件imp.lst:
userid="sys/talent as sysdba"
transport_tablespace=y
tablespaces=HR20130819,HR20130820,HR20130821,HR20130822,HR20130823,HR_EVENT_DATA,HR_SYSTEM_DATA,HR_SYSTEM_INDEX
file=exp_tablespace.dmp
datafiles='D:\oracle_huangxing_data\hx111\hr\HR20130819.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR20130820.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR20130821.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR20130822.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR20130823.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_EVENT_DATA_000.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_EVENT_DATA_001.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_EVENT_DATA_002.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_EVENT_DATA_003.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_SYSTEM_DATA_000.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_SYSTEM_DATA_001.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_SYSTEM_DATA_002.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_SYSTEM_DATA_003.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_SYSTEM_INDEX_000.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_SYSTEM_INDEX_001.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_SYSTEM_INDEX_002.DBF',
'D:\oracle_huangxing_data\hx111\hr\HR_SYSTEM_INDEX_003.DBF'
tts_owners=HR
log=imp.log
执行导入:
imp parfile=imp.lst
(4)导入完成后再设置用户相关属性
ALTER USER HR QUOTA UNLIMITED ON hr_EVENT_DATA;
ALTER USER HR QUOTA UNLIMITED ON hr_SYSTEM_DATA;
ALTER USER HR QUOTA UNLIMITED ON hr_SYSTEM_INDEX;
ALTER USER HR DEFAULT TABLESPACE hr_SYSTEM_DATA;
(5)把表空间设为可读写
表空间导入完成后,不要忘记把他们设置为可读写:
SYS >select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME |STATUS
--------------------|---------
SYSTEM |ONLINE
SYSAUX |ONLINE
UNDOTBS1 |ONLINE
USERS |ONLINE
TEMPGROUP11 |ONLINE
HR_UNDO |ONLINE
HR_TEMP |ONLINE
HR |ONLINE
P20130817 |ONLINE
P20130818 |ONLINE
P20130819 |ONLINE
INCRE |ONLINE
HR20130819 |READ ONLY
HR20130820 |READ ONLY
HR20130821 |READ ONLY
HR20130822 |READ ONLY
HR20130823 |READ ONLY
HR_EVENT_DATA |READ ONLY
HR_SYSTEM_DATA |READ ONLY
HR_SYSTEM_INDEX |READ ONLY
alter tablespace HR_SYSTEM_DATA read write;
alter tablespace HR_SYSTEM_INDEX read write;
alter tablespace HR_EVENT_DATA read write;
alter tablespace HR20130819 read write;
alter tablespace HR20130820 read write;
alter tablespace HR20130821 read write;
alter tablespace HR20130822 read write;
alter tablespace HR20130823 read write;
SYS >select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME |STATUS
--------------------|---------
SYSTEM |ONLINE
SYSAUX |ONLINE
UNDOTBS1 |ONLINE
USERS |ONLINE
TEMPGROUP11 |ONLINE
HR_UNDO |ONLINE
HR_TEMP |ONLINE
HR |ONLINE
P20130817 |ONLINE
P20130818 |ONLINE
P20130819 |ONLINE
INCRE |ONLINE
HR20130819 |ONLINE
HR20130820 |ONLINE
HR20130821 |ONLINE
HR20130822 |ONLINE
HR20130823 |ONLINE
HR_EVENT_DATA |ONLINE
HR_SYSTEM_DATA |ONLINE
HR_SYSTEM_INDEX |ONLINE
2. 同平台不同版本库的表空间传输:
继续上面的内容,但是这回是把数据从window上的表空间导入linux上11.2.0.3.0的数据库。跨平台迁移一般要考虑平台字节序。下面命令可以查看当前数据库支持到哪些操作系统的迁移,以及这些操作系统的字节序。
SYS >select * from v$transportable_platform;
PLATFORM_ID|PLATFORM_NAME |ENDIAN_FORMAT
-----------|----------------------------------------|--------------
1|Solaris[tm] OE (32-bit) |Big
2|Solaris[tm] OE (64-bit) |Big
7|Microsoft Windows IA (32-bit) |Little
10|Linux IA (32-bit) |Little
6|AIX-Based Systems (64-bit) |Big
3|HP-UX (64-bit) |Big
5|HP Tru64 UNIX |Little
4|HP-UX IA (64-bit) |Big
11|Linux IA (64-bit) |Little
15|HP Open VMS |Little
8|Microsoft Windows IA (64-bit) |Little
9|IBM zSeries Based Linux |Big
13|Linux x86 64-bit |Little
16|Apple Mac OS |Big
12|Microsoft Windows x86 64-bit |Little
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.
确认源和目的平台的字节序:
源数据库:windows(10.2.0.4.0)
SYS >col PLATFORM_NAME for a40
SYS >select * from
v$transportable_platform where PLATFORM_NAME=
(select platform_name from v$database);
PLATFORM_ID|PLATFORM_NAME |ENDIAN_FORMAT
-----------|----------------------------------------|--------------
12|Microsoft Windows x86 64-bit |Little
1 row selected.
目的数据库:Linux(11.2.0.3.0):
SYS >col PLATFORM_NAME a20
SYS >select * from
v$transportable_platform where PLATFORM_NAME=
(select platform_name from v$database);
PLATFORM_ID|PLATFORM_NAME |ENDIAN_FORMAT
-----------|----------------------------------------|--------------
13|Linux x86 64-bit |Little
1 row selected.
源操作系统和目的操作系统用的都是小端存储,所以不需要对文件进行转换。所有的操作与windows之间的迁移相同。如果平台的字节序不一致,使用exp/imp迁移时,需要用备份管理工具RMAN对表空间的数据文件进行转换。如果是低版本的数据库,使用exp/imp在不同平台之间传输表空间时,可能还需要修改文件头,否则导入时会出现600错误。不过ORACLE 10g以上可以自动修改,已经不再需要人为去修改了。不同字节序平台的表空间迁移以后再讨论吧。