IMP跨平台遷移資料庫SQL產生SQL方式資料表空間建立指令碼,impsql
我們在利用EXP/IMP進行跨平台遷移的時候,由於資料表空間路徑變更,需要先手工建立在目標端建立與源端一致的資料表空間和資料檔案,以下為建立產生語句的指令碼。
一.在源端資料庫執行以下命令,產生建立指令碼
select 'create tablespace ' || b.NAME || ' DATAFILE ' || chr(39) || a.NAME || chr(39) || ' SIZE ' || a.BYTES / 1024 / 1024 || ' m;' from v$datafile a, v$tablespace bwhere a.ts# = b.TS# And b.INCLUDED_IN_DATABASE_BACKUP='YES'Union Allselect 'Create Temporary Tablespace ' || b.NAME || ' Tempfile ' || chr(39) || a.NAME ||chr(39) || ' SIZE ' || a.BYTES / 1024 / 1024 || ' m;' from v$tempfile a, v$tablespace bwhere a.ts# = b.TS# And b.INCLUDED_IN_DATABASE_BACKUP='NO'Union Allselect 'alter database datafile ' ||chr(39) ||a.NAME ||chr(39)||' autoextend on ;' from v$datafile a, v$tablespace bwhere a.ts# = b.TS# And b.INCLUDED_IN_DATABASE_BACKUP='YES'Union Allselect 'alter database Tempfile ' ||chr(39) ||a.NAME ||chr(39)||' autoextend on ;' from v$tempfile a, v$tablespace bwhere a.ts# = b.TS# And b.INCLUDED_IN_DATABASE_BACKUP='NO'
二.產生結果類似如下:例:
create tablespace system datafile '/oradata/orcl/system01.dbf' size 1000 m;
create tablespace undotbs1 datafile '/oradata/orcl/undotbs01.dbf' size 1630 m;
create tablespace sysaux datafile '/oradata/orcl/sysaux01.dbf' size 1000 m;
create tablespace users datafile '/oradata/orcl/users01.dbf' size 5 m;
......
create tablespace zl9indexdev datafile '/oradata/orcl/zl9indexdev.dbf' size 20 m;
create tablespace zl9humanbase datafile '/oradata/orcl/zl9humanbase.dbf' size 20 m;
create tablespace zl9humaninfo datafile '/oradata/orcl/zl9humaninfo.dbf' size 20 m;
.......
alter database datafile '/oradata/orcl/system01.dbf' autoextend on ;
alter database datafile '/oradata/orcl/undotbs01.dbf' autoextend on ;
alter database datafile '/oradata/orcl/sysaux01.dbf' autoextend on ;
alter database datafile '/oradata/orcl/users01.dbf' autoextend on ;
......
alter database tempfile '/oradata/orcl/zltoolstmp.dbf' autoextend on ;
通過替換方式修改產生語句的資料檔案路徑,在目標端執行該命令,產生資料表空間和資料檔案,最後再進行資料匯入