|
本例試驗是使用transport tablespace將表和數(shù)據(jù)從一個用戶下快速遷移到另一個用戶下
C:\Documents and Settings\Administrator.XY>sqlplus "/as sysdba" SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 2月 7 15:46:42 2007
Copyright (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 準備工作:創(chuàng)建表空間、用戶、授權(quán)等。 SQL> create tablespace test1 datafile 'd:\test1.dbf' size 10m; 表空間已創(chuàng)建。
SQL> create tablespace test2 datafile 'd:\test2.dbf' size 10m;
表空間已創(chuàng)建。
SQL> create user test1 identified by test1 default tablespace test1;
用戶已創(chuàng)建。
SQL> create user test2 identified by test2 default tablespace test2;
用戶已創(chuàng)建。
SQL> grant connect,resource to test1;
授權(quán)成功。
SQL> grant connect,resource to test2;
授權(quán)成功。
SQL>
打開另一個窗口
SQL> grant select on dba_objects to test1; 授權(quán)成功。
SQL> grant alter tablespace to test1;
授權(quán)成功。
SQL> grant drop tablespace to test1;
授權(quán)成功。
SQL> select username , default_tablespace from dba_users where username='TEST1'
; USERNAME DEFAULT_TABLESPACE
------------------------------ ------------------------------ TEST1 TEST1 SQL> select username , default_tablespace from dba_users where username='TEST2'
; USERNAME DEFAULT_TABLESPACE
------------------------------ ------------------------------ TEST2 TEST2 SQL>
繼續(xù)... 創(chuàng)建表 SQL> conn test1/test1 已連接。 SQL> create table t as select * from sys.dba_objects;
表已創(chuàng)建。
SQL> alter tablespace test1 read only;
表空間已更改。
使用transport tablespace導(dǎo)出數(shù)據(jù),必須將表空間改成read only。
SQL> host exp 'sys/oracle as sysdba' transport_tablespace=y tablespaces=test1 fi le=d:\test1.dmp Export: Release 10.2.0.1.0 - Production on 星期三 2月 7 16:08:44 2007
Copyright (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 已導(dǎo)出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集 注: 將不導(dǎo)出表數(shù)據(jù) (行) 即將導(dǎo)出可傳輸?shù)谋砜臻g元數(shù)據(jù)... 對于表空間 TEST1... . 正在導(dǎo)出簇定義 . 正在導(dǎo)出表定義 . . 正在導(dǎo)出表 T . 正在導(dǎo)出引用完整性約束條件 . 正在導(dǎo)出觸發(fā)器 . 結(jié)束導(dǎo)出可傳輸?shù)谋砜臻g元數(shù)據(jù) 成功終止導(dǎo)出, 沒有出現(xiàn)警告。 必須執(zhí)行該操作,但是不能刪除datafile。
SQL> drop tablespace test1 including contents; 表空間已刪除。
將數(shù)據(jù)遷移到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 2007
Copyright (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 經(jīng)由常規(guī)路徑由 EXPORT:V10.02.01 創(chuàng)建的導(dǎo)出文件
即將導(dǎo)入可傳輸?shù)谋砜臻g元數(shù)據(jù)... 已經(jīng)完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的導(dǎo)入 . 正在將 TEST1 的對象導(dǎo)入到 TEST2 . . 正在導(dǎo)入表 "T" 成功終止導(dǎo)入, 沒有出現(xiàn)警告。 SQL> conn test2/test2 已連接。 可以看到在用戶2下面已經(jīng)有該表了。 SQL> select count(*) from t; COUNT(*)
---------- 50361 SQL> 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 結(jié)論:使用transport tablespace可以將數(shù)據(jù)很快的從一個用戶遷移到另一個用戶,然而只是表的所有者從test1變成test2,
并沒有將表的其它屬性進行修改。比如:該表所在表空間仍然是test1,數(shù)據(jù)仍然存在test1表空間下。在某些情況下我們想讓 表結(jié)構(gòu)和數(shù)據(jù)一同遷移到test2下,這就需要我們做其它的工作。 例如:
將表所在的表空間(test1)轉(zhuǎn)到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
|
|
|