电子科技大学 黑名单:使用transport tablespace将表和数据从一个用户下快速迁移到另一个用户

来源:百度文库 编辑:中财网 时间:2024/05/03 09:23:35
本例试验是使用transport tablespace将表和数据从一个用户下快速迁移到另一个用户下
C:\Documents and Settings\Administrator.XY>sqlplus "/as sysdba"SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 2月 7 15:46:42 2007Copyright (c) 1982, 2005, Oracle.  All rights reserved.
连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
准备工作:创建表空间、用户、授权等。
SQL> create tablespace test1 datafile 'd:\test1.dbf' size 10m;表空间已创建。SQL> create tablespace test2 datafile 'd:\test2.dbf' size 10m;表空间已创建。SQL> create user test1 identified by test1 default tablespace test1;用户已创建。SQL> create user test2 identified by test2 default tablespace test2;用户已创建。SQL> grant connect,resource to test1;授权成功。SQL> grant connect,resource to test2;授权成功。SQL>打开另一个窗口
SQL> grant select on dba_objects to test1;授权成功。SQL> grant alter tablespace to test1;授权成功。SQL> grant drop tablespace to test1;授权成功。SQL>  select username , default_tablespace from dba_users where username='TEST1'
;USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
TEST1                          TEST1SQL>  select username , default_tablespace from dba_users where username='TEST2'
;USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
TEST2                          TEST2SQL>
继续...
创建表
SQL> conn test1/test1
已连接。SQL> create table t as select * from sys.dba_objects;表已创建。SQL> alter tablespace test1 read only;表空间已更改。使用transport tablespace导出数据,必须将表空间改成read only。
SQL> host exp 'sys/oracle as sysdba' transport_tablespace=y tablespaces=test1 fi
le=d:\test1.dmpExport: Release 10.2.0.1.0 - Production on 星期三 2月 7 16:08:44 2007Copyright (c) 1982, 2005, Oracle.  All rights reserved.
连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
注: 将不导出表数据 (行)
即将导出可传输的表空间元数据...
对于表空间 TEST1...
. 正在导出簇定义
. 正在导出表定义
. . 正在导出表                               T
. 正在导出引用完整性约束条件
. 正在导出触发器
. 结束导出可传输的表空间元数据
成功终止导出, 没有出现警告。必须执行该操作,但是不能删除datafile。
SQL> drop tablespace test1 including contents;表空间已删除。将数据迁移到test2用户。
SQL> host imp 'sys/oracle as sysdba' transport_tablespace=y file=d:\test1.dmp fr
omuser=test1 touser=test2 datafiles='d:\test1.dbf';Import: Release 10.2.0.1.0 - Production on 星期三 2月 7 16:12:08 2007Copyright (c) 1982, 2005, Oracle.  All rights reserved.
连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options经由常规路径由 EXPORT:V10.02.01 创建的导出文件
即将导入可传输的表空间元数据...
已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入
. 正在将 TEST1 的对象导入到 TEST2
. . 正在导入表                             "T"
成功终止导入, 没有出现警告。
SQL> conn test2/test2
已连接。
可以看到在用户2下面已经有该表了。
SQL> select count(*) from t;  COUNT(*)
----------
     50361SQL> select t.segment_name,t.segment_type,t.tablespace_name from user_segments t
;SEGMENT_NAME SEGMENT_TYPE       TABLESPACE_NAME
------------------------------------------------
T       TABLE              TEST1
提示:要注意将test改为read write结论:使用transport tablespace可以将数据很快的从一个用户迁移到另一个用户,然而只是表的所有者从test1变成test2,
并没有将表的其它属性进行修改。比如:该表所在表空间仍然是test1,数据仍然存在test1表空间下。在某些情况下我们想让
表结构和数据一同迁移到test2下,这就需要我们做其它的工作。例如:
将表所在的表空间(test1)转到test2
SQL> alter table t move tablespace test2;表已更改。SQL> select t.segment_name,t.segment_type,t.tablespace_name from user_segments t
;SEGMENT_NAME SEGMENT_TYPE       TABLESPACE_NAME
------------------------------------------------
T       TABLE              TEST2参考:blog.itpub.net/warehouse