【轉】不同表空間的導入

很多人在進行數據遷移時,希望把數據導入不同於原系統的表空間,在導入之後卻往往發現,數據被導入了原表空間。
本例舉例說明解決這個問題:
1.如果缺省的用戶具有DBA權限
那麼導入時會按照原來的位置導入數據,即導入到原表空間

$imp bjbbs/passwd file=bj_bbs.dmp fromuser=jive touser=bjbbs grants=n

Import: Release 8.1.7.4.0 - Production on Mon Sep 22 11:49:41 2003

(c) Copyright 2000 Oracle Corporation. All rights reserved.


Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

Export file created by EXPORT:V08.01.07 via conventional path

Warning: the objects were exported by JIVE, not by you

import done in ZHS16GBK character set and ZHS16GBK NCHAR character set
. . importing table "HS_ALBUMINBOX" 12 rows imported
. . importing table "HS_ALBUM_INFO" 47 rows imported
. . importing table "HS_CATALOG" 13 rows imported
. . importing table "HS_CATALOGAUTHORITY" 5 rows imported
. . importing table "HS_CATEGORYAUTHORITY" 0 rows imported
....
. . importing table "JIVEUSERPROP" 4 rows imported
. . importing table "JIVEWATCH" 0 rows imported
. . importing table "PLAN_TABLE" 0 rows imported
. . importing table "TMZOLDUSER" 3 rows imported
. . importing table "TMZOLDUSER2" 3 rows imported
About to enable constraints...
Import terminated successfully without warnings.


查詢發現仍然導入了USER表空間

$sqlplus bjbbs/passwd

SQL*Plus: Release 8.1.7.0.0 - Production on Mon Sep 22 11:50:03 2003

(c) Copyright 2000 Oracle Corporation. All rights reserved.


Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

SQL> select table_name,tablespace_name from user_tables;

TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
HS_ALBUMINBOX USERS
HS_ALBUM_INFO USERS
HS_CATALOG USERS
HS_CATALOGAUTHORITY USERS
HS_CATEGORYAUTHORITY USERS
HS_CATEGORYINFO USERS
HS_DLF_DOWNLOG USERS
...
JIVEWATCH USERS
PLAN_TABLE USERS
TMZOLDUSER USERS

TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
TMZOLDUSER2 USERS

45 rows selected.

2.回收用戶unlimited tablespace權限
這樣就可以導入到用戶缺省表空間
SQL> create user bjbbs identified by passwd
2 default tablespace bjbbs
3 temporary tablespace temp
4 /

User created.


SQL> grant connect,resource to bjbbs;

Grant succeeded.

SQL> grant dba to bjbbs;

Grant succeeded.
如果用戶已經具有sysdba角色的話就只需要執行以下3步就可以啦!
SQL> revoke unlimited tablespace from bjbbs;

Revoke succeeded.

SQL> alter user bjbbs quota 0 on users;

User altered.

SQL> alter user bjbbs quota unlimited on bjbbs;

User altered.

SQL> exit
Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production


3.重新導入數據
$ imp bjbbs/passwd file=bj_bbs.dmp fromuser=jive touser=bjbbs grants=n

Import: Release 8.1.7.4.0 - Production on Mon Sep 22 12:00:51 2003

(c) Copyright 2000 Oracle Corporation. All rights reserved.


Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

Export file created by EXPORT:V08.01.07 via conventional path

Warning: the objects were exported by JIVE, not by you

import done in ZHS16GBK character set and ZHS16GBK NCHAR character set
. . importing table "HS_ALBUMINBOX" 12 rows imported
. . importing table "HS_ALBUM_INFO" 47 rows imported
. . importing table "HS_CATALOG" 13 rows imported
. . importing table "HS_CATALOGAUTHORITY" 5 rows imported
. . importing table "HS_CATEGORYAUTHORITY" 0 rows imported
. . importing table "HS_CATEGORYINFO" 9 rows imported
. . importing table "HS_DLF_DOWNLOG" 0 rows imported
....
. . importing table "JIVEUSER" 102 rows imported
. . importing table "JIVEUSERPERM" 81 rows imported
. . importing table "JIVEUSERPROP" 4 rows imported
. . importing table "JIVEWATCH" 0 rows imported
. . importing table "PLAN_TABLE" 0 rows imported
. . importing table "TMZOLDUSER" 3 rows imported
. . importing table "TMZOLDUSER2" 3 rows imported
About to enable constraints...
Import terminated successfully without warnings.

SQL> select table_name,tablespace_name from user_tables;

TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
HS_ALBUMINBOX BJBBS
HS_ALBUM_INFO BJBBS
HS_CATALOG BJBBS
HS_CATALOGAUTHORITY BJBBS
....
JIVETHREAD BJBBS
JIVETHREADPROP BJBBS
JIVEUSER BJBBS
JIVEUSERPERM BJBBS
JIVEUSERPROP BJBBS
JIVEWATCH BJBBS
PLAN_TABLE BJBBS
TMZOLDUSER BJBBS

TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
TMZOLDUSER2 BJBBS

45 rows selected.
現在數據被導入到正確的用戶表空間中. -----

如何已經導入完畢採用下面方式來更換表空間,同時上面的方法也存在一定對錶空間規劃的問題

另外如果你已經在沒有運行以上命令時就已將數據給導入後還可通過alter方式來對錶以及索引進行表空間規劃.

1:先通過:SELECT 'ALTER INDEX '||INDEX_NAME||' REBUILD TABLESPACE tablespace_name;' FROM USER_INDEXES;語句來得到一個SQL腳本文件.

2:然後在pl/sql developer工具中執行操作即可.

3:當在執行過程中可能會遇到一些不能重新編譯的情況,這時可以將這些暫不能編譯的放在最後面執行即可.

更改表的所屬表空間:alter table a move tablespace tbsname;補充:移動完畢後需重建索引.alte index idx_name rebuild tablespace tablespace_name;

補:在實際應用中遇到了另一種情況就是當按上面第一種方案進行數據導入以後所有的信息全在一個表空間下,這樣對於表空間規劃不太合理,爲了進一步對錶空間的規劃,又在第一種方案下采用方案二對錶空間進行規劃,當執行方案二中得到的SQL語句執行時會報出:ORA-01950 no privileges on tablespace 'workindex'這樣錯誤提示,這隻要是由於方案一中的alter命令所造成的,可能通過:alter user workflow quota unlimited on workinedx;語句來使workflow用戶在workindex表空間上也具有無限制配額即可.然後再執行方案二中得到的alter的SQL腳本!


以下是我工作過程中所使用的導出導入語句

導入語句
導入採用命令行,有利於產生log文件
imp workflow/workflow@WORKFLOW file = /setup/workflow.dmp fromuser=workflow touser=workflow show=n buffer=2048000 ignore=n commit=y grants=y full=n log=/tmp/imp_workflw.log
imp workflow/workflow@WORKFLOW file=/oracle/installfiles/workflow.dmp fromuser=workflow touser=workflow show=n buffer=2048000 ignore=n commit=y grants=y full=n log=/oracle/installfiles/imp_workflw.log
imp workflow/workflow file=/oracle/installfiles/workflow.dmp fromuser=WF9 touser=workflow show=n buffer=2048000 ignore=n commit=y grants=y full=n log=/oracle/installfiles/imp_workflw.log

導入導出Windows下使用以下爲IMP/EXP導入導出命令工具在項目中一些常用的方式如下:

1:導出整個方案庫
EXP username/password@database FILE=D:filename.dmp log=D:filename.log

2:導入整個方案庫 --當源庫中存在表或其它信息內容可加入ROWS=Y IGNORE=Y這兩個參數--
IMP username/password@database file=D:filename.dmp log=D:filename.log fromuser=exp_username touser=imp_username;

3:導出方案中部分表信息
EXP username/password@database tables=(table_name1,table_name2,table_name3,...) file=D:filename.dmp log=D:filename.log

4:導入方案中部分表信息 --同上--
IMP username/password@database tables=(table_name1,table_name2,table_name3,...) ROWS=Y IGNORE=Y file=D:filename.dmp log=D:filenameimp.log fromuser=exp_username touser=imp_username

5:導出方案中表帶子查詢條件的數據--也就是導出某張表中滿足條件的記錄.(用符號將"和'轉義)
EXP username/password@database TABLES=(table_name) QUERY="WHERE column_name IN ('column_value1','column_value2','column_value3',...)" file=D:filename.dmp log=D:filename.log

6:導入方案中表的部分記錄增量導入
IMP username/password@database tables=(table_name) ROWS=Y IGNORE=Y file=D:filename.dmp log=D:filename_imp.log fromuser=exp_username touser=imp_username


原文地址:http://dev.firnow.com/course/7_databases/oracle/oraclejs/2008827/138106.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章