1.expdp和impdp
expdp
假設sglaw使用者的預設表空間是users,導出使用者sglaw所有資料:
SQL> conn / as sysdba
SQL> create directory dir as '/home/oracle/';
SQL> grant read,write on directory dir to system;
$expdp system/oracle directory=dir dumpfile=sglaw.dmp schemas=sglaw logfile=sglaw.log
impdp
導入sglaw使用者所有資料到gh,并且轉換表空間users為gh:
SQL> conn / as sysdba
SQL> create directory dir as '/home/oracle/';
SQL> grant read,write on directory dir to system;
$impdp system/oracle directory=dir dumpfile=sglaw.dmp remap_tablespace=users:gh remap_schema=sglaw:gh logfile=sglaw.log
總結:執行impdp時無需建立gh使用者,在導入時會自動建立并改名使用者sglaw為gh(擁有sglaw的所有權限等),自動設定預設表空間為轉換後的表空間gh。如果有多個表空間需要轉換,則使用多個remap_tablespace=源:目标 字段。
此種方法隻限于支援oracle10g以上版本。
2.exp和imp
要實作oracle9i和oracle10g直接不同表空間的資料遷移,就比較麻煩了,而且不一定能夠成功。
首先在原庫上正常導出(假設原使用者資料存放在users表空間)
$exp username/password file=aaa.dmp log=aaa.log
在目标庫上操作如下:
SQL> conn / as sysdba
SQL> create tablespace aaa datafile '/dev/raw/raw30';
SQL> create user username identified by password default tablespace aaa;
SQL> alter user username quota unlimited on aaa;
SQL> grant connect,imp_full_database to username;
然後執行導入
$imp username/password file=aaa.dmp log=aaa.log
由于使用者username沒有對users表空間的操作配額,是以表會自動存放到username的預設表空間。但是有時候發現,有些表通過這種方法是無法轉換過來,本人知識尚淺,不知道是不是很應用寫死表空間有關系。
通過conn username/password
select count(*) from user_tables;
來簡單檢視表的數量是否和原庫相同。
檢視使用者表存放的表空間:
select distinct tablespace_name from user_tables;