【故障處理】因授權資訊丟失導致IMP時出現IMP-00041錯誤的模擬與分析
問題現象是這樣的,在IMP資料的過程中出現“IMP-00041:
Warning: object created with compilation warnings”錯誤,因這個錯誤導致檢視匯入後無法使用。經分析,發現此問題與“授權資訊丟失”有關。
為避免朋友們走彎路,我模擬再現一下這個問題,同時給出一個分析和解決問題的思路。
1.建立兩個使用者sec1和sec2
sys@ora10g> create user sec1 identified by sec1 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource to sec1;
Grant succeeded.
sys@ora10g> create user sec2 identified by sec2 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource to sec2;
Grant succeeded.
2.在第一個使用者sec1中建立表T_SEC1
sys@ora10g> conn sec1/sec1
Connected.
sec1@ora10g> create table t_sec1 (x int);
Table created.
sec1@ora10g> insert into t_sec1 values (1);
1 row created.
3.在第二個使用者sec2中建立表T_SEC2
sec1@ora10g> conn sec2/sec2
Connected.
sec2@ora10g> create table t_sec2 (x int);
Table created.
sec2@ora10g> insert into t_sec2 values (2);
1 row created.
4.在sec2中建立sec1使用者中t_sec1表的同名
sec2@ora10g> conn / as sysdba
Connected.
sys@ora10g> create synonym sec2.syn_t_sec1 for sec1.t_sec1;
Synonym created.
sys@ora10g> grant insert,delete,update,select on sec1.t_sec1 to sec2;
Grant succeeded.
5.在sec2使用者下建立檢視v_sec2
該檢視同時使用到剛剛在sec2使用者下建立的同名SYN_T_SEC1和表T_SEC2。
sec2@ora10g> conn / as sysdba
Connected.
sys@ora10g>
sys@ora10g> grant create view to sec2;
Grant succeeded.
sys@ora10g> conn sec2/sec2
Connected.
sec2@ora10g> create view v_sec2 as select SYN_T_SEC1.x sec1_x, T_SEC2.x sec2_x from SYN_T_SEC1,T_SEC2;
View created.
6.分別看一下各個使用者下的資料庫物件
sec2@ora10g> conn sec1/sec1
Connected.
sec1@ora10g> select * from cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
T_SEC1 TABLE
sec2@ora10g> select * from cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
T_SEC2 TABLE
SYN_T_SEC1 SYNONYM
V_SEC2 VIEW
7.我們這裡分別生成sec1和sec2使用者的備份
ora10g@secDB1 /exp$ exp sec1/sec1 file=sec1.dmp log=sec1.log
Export: Release 10.2.0.3.0 - Production on Fri Feb 26 03:01:40 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SEC1
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SEC1
About to export SEC1's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SEC1's tables via Conventional Path ...
. . exporting table T_SEC1 1 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
ora10g@secDB1 /exp$ exp sec2/sec2 file=sec2.dmp log=sec2.log
Export: Release 10.2.0.3.0 - Production on Fri Feb 26 03:01:56 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SEC2
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SEC2
About to export SEC2's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SEC2's tables via Conventional Path ...
. . exporting table T_SEC2 1 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
8.將備份檔案傳送到待匯入的伺服器secDB2
ora10g@secDB1 /exp$ scp sec1.dmp sec2.dmp 172.17.193.201:/imp
oracle@172.17.193.201's password:
sec1.dmp 100% 16KB 16.0KB/s 00:00
sec2.dmp 100% 16KB 16.0KB/s 00:00
9.在secDB2伺服器上建立同樣的使用者,並進行匯入測試
1)建立使用者並授權
sys@ora10g> create user sec1 identified by sec1 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource to sec1;
Grant succeeded.
sys@ora10g> create user sec2 identified by sec2 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource,dba to sec2;
Grant succeeded.
2)匯入測試
(1)先匯入sec1使用者
ora10g@secDB2 /imp$ imp sec1/sec1 file=sec1.dmp log=sec1.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 11:58:09 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC1's objects into SEC1
. . importing table "T_SEC1" 1 rows imported
Import terminated successfully without warnings.
(2)匯入sec2使用者
ora10g@secDB2 /imp$ imp sec2/sec2 file=sec2.dmp log=sec2.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:14:59 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC2's objects into SEC2
. . importing table "T_SEC2" 1 rows imported
Import terminated successfully without warnings.
此時是匯入成功的!演示還未結束,請繼續。
(3)假如此時刪除sec2使用者(刪除的目的可能有很多,比如之前授予的許可權不足等),對其進行重新建立後再完成資料匯入
sys@ora10g> drop user sec2 cascade;
User dropped.
sys@ora10g> create user sec2 identified by sec2 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource,dba to sec2;
Grant succeeded.
(4)再重新完成sec2使用者的IMP匯入
ora10g@secDB2 /imp$ imp sec2/sec2 file=sec2.dmp log=sec2.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:20:48 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC2's objects into SEC2
. . importing table "T_SEC2" 1 rows imported
IMP-00041: Warning: object created with compilation warnings
"CREATE FORCE VIEW "SEC2"."V_SEC2" ("SEC1_X","SEC"
"2_X") AS "
"select SYN_T_SEC1.x sec1_x, T_SEC2.x sec2_x from SYN_T_SEC1,T_SEC2"
Import terminated successfully with warnings.
此時,問題出現了,此時的“IMP-00041”錯誤提示內容是建立的檢視存在編譯錯誤(這個錯誤沒有太大的指導意義)。
10.驗證被匯入的內容是否可用
1)匯入了三個物件,沒有問題。
sec2@ora10g> select * from cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
SYN_T_SEC1 SYNONYM
T_SEC2 TABLE
V_SEC2 VIEW
2)T_SEC2表可用
sec2@ora10g> select * from T_SEC2;
X
----------
2
3)SYN_T_SEC1同名可用
sec2@ora10g> select * from SYN_T_SEC1;
X
----------
1
4)此時檢視不可用,提示存在錯誤。原因不詳細。
sec2@ora10g> select * from V_SEC2;
select * from V_SEC2
*
ERROR at line 1:
ORA-04063: view "SEC2.V_SEC2" has errors
5)嘗試重新編譯,無效。
sec2@ora10g> alter view V_SEC2 compile;
Warning: View altered with compilation errors.
6)沒有具體的錯誤提示資訊
sec2@ora10g> show errors;
No errors.
11.問題原因
根本原因在於,當刪除sec2使用者重新建立後,sec2使用者原來具有的sec1使用者下T_SEC1表授權資訊丟失了。
不要著急,我們來分析一下。
在完成sec1使用者匯入後,其實sec1使用者的dmp檔案中包含的授權資訊已經完成對sec2使用者的授權。我們使用“show=y”選項檢視一下sec1使用者的dmp檔案內容。
ora10g@secDB2 /imp$ imp sec1/sec1 file=sec1.dmp log=sec1.log ignore=y full=y show=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:24:50 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC1's objects into SEC1
"BEGIN "
"sys.dbms_logrep_imp.instantiate_schema(schema_name=>SYS_CONTEXT('USERENV','"
"CURRENT_SCHEMA'), export_db_name=>'ORA10G', inst_scn=>'36699433');"
"COMMIT; END;"
"CREATE TABLE "T_SEC1" ("X" NUMBER(*,0)) PCTFREE 10 PCTUSED 40 INITRANS 1 M"
"AXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL"
" DEFAULT) TABLESPACE "TBS_SEC_D" LOGGING NOCOMPRESS"
. . skipping table "T_SEC1"
"GRANT DELETE ON "T_SEC1" TO "SEC2""
"GRANT INSERT ON "T_SEC1" TO "SEC2""
"GRANT SELECT ON "T_SEC1" TO "SEC2""
"GRANT UPDATE ON "T_SEC1" TO "SEC2""
Import terminated successfully without warnings.
注意最後四行的授權資訊。這些授權資訊是在sec1使用者資料匯入過程中同時完成的。
12.問題處理
既然知道了問題的出處,處理就簡單了。以sys使用者顯示的將sec1使用者下t_sec1表的操作許可權授予sec2使用者,然後再重新對問題檢視進行編譯(當然,重新建立這個檢視亦可)。
sec2@ora10g> conn / as sysdba
Connected.
sys@ora10g> grant insert,delete,update,select on sec1.t_sec1 to sec2;
Grant succeeded.
sys@ora10g> conn sec2/sec2
Connected.
sec2@ora10g> alter view V_SEC2 compile;
View altered.
sec2@ora10g> select * from V_SEC2;
SEC1_X SEC2_X
---------- ----------
1 2
1 row selected.
OK,問題到此處理完畢。
13.另外一種導致這個問題的場景演示
還用一種可能出現這種問題的可能性,如果是按照下面的順序在secDB2伺服器上完成使用者的建立和匯入,一樣會報上面的錯誤。
建立sec1使用者,完成對sec1使用者的匯入;
建立sec2使用者,完成對sec2使用者的匯入。
因為在完成sec1使用者匯入後,授權資訊的授予物件sec2還不存在!
為保證資訊的完整性和正確性,贅述在此。
1)刪除sec1和sec2使用者
sys@ora10g> drop user sec1 cascade;
User dropped.
sys@ora10g> drop user sec2 cascade;
User dropped.
2)建立sec1使用者,完成對sec1使用者的匯入
sys@ora10g> create user sec1 identified by sec1 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource to sec1;
Grant succeeded.
sys@ora10g> exit
ora10g@secDB2 /imp$ imp sec1/sec1 file=sec1.dmp log=sec1.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:47:11 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC1's objects into SEC1
. . importing table "T_SEC1" 1 rows imported
IMP-00017: following statement failed with ORACLE error 1917:
"GRANT DELETE ON "T_SEC1" TO "SEC2""
IMP-00003: ORACLE error 1917 encountered
ORA-01917: user or role 'SEC2' does not exist
IMP-00017: following statement failed with ORACLE error 1917:
"GRANT INSERT ON "T_SEC1" TO "SEC2""
IMP-00003: ORACLE error 1917 encountered
ORA-01917: user or role 'SEC2' does not exist
IMP-00017: following statement failed with ORACLE error 1917:
"GRANT SELECT ON "T_SEC1" TO "SEC2""
IMP-00003: ORACLE error 1917 encountered
ORA-01917: user or role 'SEC2' does not exist
IMP-00017: following statement failed with ORACLE error 1917:
"GRANT UPDATE ON "T_SEC1" TO "SEC2""
IMP-00003: ORACLE error 1917 encountered
ORA-01917: user or role 'SEC2' does not exist
Import terminated successfully with warnings.
此處的授權資訊執行失敗的提示資訊已經說明了問題。
3)建立sec2使用者,完成對sec2使用者的匯入
ora10g@secDB2 /imp$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Fri Feb 26 21:47:43 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
sys@ora10g> create user sec2 identified by sec2 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource,dba to sec2;
Grant succeeded.
sys@ora10g> exit
ora10g@secDB2 /imp$ imp sec2/sec2 file=sec2.dmp log=sec2.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:48:17 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC2's objects into SEC2
. . importing table "T_SEC2" 1 rows imported
IMP-00041: Warning: object created with compilation warnings
"CREATE FORCE VIEW "SEC2"."V_SEC2" ("SEC1_X","SEC"
"2_X") AS "
"select SYN_T_SEC1.x sec1_x, T_SEC2.x sec2_x from SYN_T_SEC1,T_SEC2"
Import terminated successfully with warnings.
問題又一次再現,錯誤原因與我們前面分析的結果相同。
14.小結
我們使用EXP/IMP工具在不同使用者間存在較複雜的授權關係的情況下完成資料遷移時,需要特別注意他們的先後順序。
為避免此類錯誤的發生,建議在多使用者資料遷移場景下,使用sys使用者一次性完成(使用OWNER引數)資料遷移工作。
Good luck.
secooler
10.02.26
-- The End --
為避免朋友們走彎路,我模擬再現一下這個問題,同時給出一個分析和解決問題的思路。
1.建立兩個使用者sec1和sec2
sys@ora10g> create user sec1 identified by sec1 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource to sec1;
Grant succeeded.
sys@ora10g> create user sec2 identified by sec2 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource to sec2;
Grant succeeded.
2.在第一個使用者sec1中建立表T_SEC1
sys@ora10g> conn sec1/sec1
Connected.
sec1@ora10g> create table t_sec1 (x int);
Table created.
sec1@ora10g> insert into t_sec1 values (1);
1 row created.
3.在第二個使用者sec2中建立表T_SEC2
sec1@ora10g> conn sec2/sec2
Connected.
sec2@ora10g> create table t_sec2 (x int);
Table created.
sec2@ora10g> insert into t_sec2 values (2);
1 row created.
4.在sec2中建立sec1使用者中t_sec1表的同名
sec2@ora10g> conn / as sysdba
Connected.
sys@ora10g> create synonym sec2.syn_t_sec1 for sec1.t_sec1;
Synonym created.
sys@ora10g> grant insert,delete,update,select on sec1.t_sec1 to sec2;
Grant succeeded.
5.在sec2使用者下建立檢視v_sec2
該檢視同時使用到剛剛在sec2使用者下建立的同名SYN_T_SEC1和表T_SEC2。
sec2@ora10g> conn / as sysdba
Connected.
sys@ora10g>
sys@ora10g> grant create view to sec2;
Grant succeeded.
sys@ora10g> conn sec2/sec2
Connected.
sec2@ora10g> create view v_sec2 as select SYN_T_SEC1.x sec1_x, T_SEC2.x sec2_x from SYN_T_SEC1,T_SEC2;
View created.
6.分別看一下各個使用者下的資料庫物件
sec2@ora10g> conn sec1/sec1
Connected.
sec1@ora10g> select * from cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
T_SEC1 TABLE
sec2@ora10g> select * from cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
T_SEC2 TABLE
SYN_T_SEC1 SYNONYM
V_SEC2 VIEW
7.我們這裡分別生成sec1和sec2使用者的備份
ora10g@secDB1 /exp$ exp sec1/sec1 file=sec1.dmp log=sec1.log
Export: Release 10.2.0.3.0 - Production on Fri Feb 26 03:01:40 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SEC1
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SEC1
About to export SEC1's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SEC1's tables via Conventional Path ...
. . exporting table T_SEC1 1 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
ora10g@secDB1 /exp$ exp sec2/sec2 file=sec2.dmp log=sec2.log
Export: Release 10.2.0.3.0 - Production on Fri Feb 26 03:01:56 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SEC2
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SEC2
About to export SEC2's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SEC2's tables via Conventional Path ...
. . exporting table T_SEC2 1 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
8.將備份檔案傳送到待匯入的伺服器secDB2
ora10g@secDB1 /exp$ scp sec1.dmp sec2.dmp 172.17.193.201:/imp
oracle@172.17.193.201's password:
sec1.dmp 100% 16KB 16.0KB/s 00:00
sec2.dmp 100% 16KB 16.0KB/s 00:00
9.在secDB2伺服器上建立同樣的使用者,並進行匯入測試
1)建立使用者並授權
sys@ora10g> create user sec1 identified by sec1 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource to sec1;
Grant succeeded.
sys@ora10g> create user sec2 identified by sec2 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource,dba to sec2;
Grant succeeded.
2)匯入測試
(1)先匯入sec1使用者
ora10g@secDB2 /imp$ imp sec1/sec1 file=sec1.dmp log=sec1.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 11:58:09 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC1's objects into SEC1
. . importing table "T_SEC1" 1 rows imported
Import terminated successfully without warnings.
(2)匯入sec2使用者
ora10g@secDB2 /imp$ imp sec2/sec2 file=sec2.dmp log=sec2.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:14:59 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC2's objects into SEC2
. . importing table "T_SEC2" 1 rows imported
Import terminated successfully without warnings.
此時是匯入成功的!演示還未結束,請繼續。
(3)假如此時刪除sec2使用者(刪除的目的可能有很多,比如之前授予的許可權不足等),對其進行重新建立後再完成資料匯入
sys@ora10g> drop user sec2 cascade;
User dropped.
sys@ora10g> create user sec2 identified by sec2 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource,dba to sec2;
Grant succeeded.
(4)再重新完成sec2使用者的IMP匯入
ora10g@secDB2 /imp$ imp sec2/sec2 file=sec2.dmp log=sec2.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:20:48 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC2's objects into SEC2
. . importing table "T_SEC2" 1 rows imported
IMP-00041: Warning: object created with compilation warnings
"CREATE FORCE VIEW "SEC2"."V_SEC2" ("SEC1_X","SEC"
"2_X") AS "
"select SYN_T_SEC1.x sec1_x, T_SEC2.x sec2_x from SYN_T_SEC1,T_SEC2"
Import terminated successfully with warnings.
此時,問題出現了,此時的“IMP-00041”錯誤提示內容是建立的檢視存在編譯錯誤(這個錯誤沒有太大的指導意義)。
10.驗證被匯入的內容是否可用
1)匯入了三個物件,沒有問題。
sec2@ora10g> select * from cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
SYN_T_SEC1 SYNONYM
T_SEC2 TABLE
V_SEC2 VIEW
2)T_SEC2表可用
sec2@ora10g> select * from T_SEC2;
X
----------
2
3)SYN_T_SEC1同名可用
sec2@ora10g> select * from SYN_T_SEC1;
X
----------
1
4)此時檢視不可用,提示存在錯誤。原因不詳細。
sec2@ora10g> select * from V_SEC2;
select * from V_SEC2
*
ERROR at line 1:
ORA-04063: view "SEC2.V_SEC2" has errors
5)嘗試重新編譯,無效。
sec2@ora10g> alter view V_SEC2 compile;
Warning: View altered with compilation errors.
6)沒有具體的錯誤提示資訊
sec2@ora10g> show errors;
No errors.
11.問題原因
根本原因在於,當刪除sec2使用者重新建立後,sec2使用者原來具有的sec1使用者下T_SEC1表授權資訊丟失了。
不要著急,我們來分析一下。
在完成sec1使用者匯入後,其實sec1使用者的dmp檔案中包含的授權資訊已經完成對sec2使用者的授權。我們使用“show=y”選項檢視一下sec1使用者的dmp檔案內容。
ora10g@secDB2 /imp$ imp sec1/sec1 file=sec1.dmp log=sec1.log ignore=y full=y show=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:24:50 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC1's objects into SEC1
"BEGIN "
"sys.dbms_logrep_imp.instantiate_schema(schema_name=>SYS_CONTEXT('USERENV','"
"CURRENT_SCHEMA'), export_db_name=>'ORA10G', inst_scn=>'36699433');"
"COMMIT; END;"
"CREATE TABLE "T_SEC1" ("X" NUMBER(*,0)) PCTFREE 10 PCTUSED 40 INITRANS 1 M"
"AXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL"
" DEFAULT) TABLESPACE "TBS_SEC_D" LOGGING NOCOMPRESS"
. . skipping table "T_SEC1"
"GRANT DELETE ON "T_SEC1" TO "SEC2""
"GRANT INSERT ON "T_SEC1" TO "SEC2""
"GRANT SELECT ON "T_SEC1" TO "SEC2""
"GRANT UPDATE ON "T_SEC1" TO "SEC2""
Import terminated successfully without warnings.
注意最後四行的授權資訊。這些授權資訊是在sec1使用者資料匯入過程中同時完成的。
12.問題處理
既然知道了問題的出處,處理就簡單了。以sys使用者顯示的將sec1使用者下t_sec1表的操作許可權授予sec2使用者,然後再重新對問題檢視進行編譯(當然,重新建立這個檢視亦可)。
sec2@ora10g> conn / as sysdba
Connected.
sys@ora10g> grant insert,delete,update,select on sec1.t_sec1 to sec2;
Grant succeeded.
sys@ora10g> conn sec2/sec2
Connected.
sec2@ora10g> alter view V_SEC2 compile;
View altered.
sec2@ora10g> select * from V_SEC2;
SEC1_X SEC2_X
---------- ----------
1 2
1 row selected.
OK,問題到此處理完畢。
13.另外一種導致這個問題的場景演示
還用一種可能出現這種問題的可能性,如果是按照下面的順序在secDB2伺服器上完成使用者的建立和匯入,一樣會報上面的錯誤。
建立sec1使用者,完成對sec1使用者的匯入;
建立sec2使用者,完成對sec2使用者的匯入。
因為在完成sec1使用者匯入後,授權資訊的授予物件sec2還不存在!
為保證資訊的完整性和正確性,贅述在此。
1)刪除sec1和sec2使用者
sys@ora10g> drop user sec1 cascade;
User dropped.
sys@ora10g> drop user sec2 cascade;
User dropped.
2)建立sec1使用者,完成對sec1使用者的匯入
sys@ora10g> create user sec1 identified by sec1 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource to sec1;
Grant succeeded.
sys@ora10g> exit
ora10g@secDB2 /imp$ imp sec1/sec1 file=sec1.dmp log=sec1.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:47:11 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC1's objects into SEC1
. . importing table "T_SEC1" 1 rows imported
IMP-00017: following statement failed with ORACLE error 1917:
"GRANT DELETE ON "T_SEC1" TO "SEC2""
IMP-00003: ORACLE error 1917 encountered
ORA-01917: user or role 'SEC2' does not exist
IMP-00017: following statement failed with ORACLE error 1917:
"GRANT INSERT ON "T_SEC1" TO "SEC2""
IMP-00003: ORACLE error 1917 encountered
ORA-01917: user or role 'SEC2' does not exist
IMP-00017: following statement failed with ORACLE error 1917:
"GRANT SELECT ON "T_SEC1" TO "SEC2""
IMP-00003: ORACLE error 1917 encountered
ORA-01917: user or role 'SEC2' does not exist
IMP-00017: following statement failed with ORACLE error 1917:
"GRANT UPDATE ON "T_SEC1" TO "SEC2""
IMP-00003: ORACLE error 1917 encountered
ORA-01917: user or role 'SEC2' does not exist
Import terminated successfully with warnings.
此處的授權資訊執行失敗的提示資訊已經說明了問題。
3)建立sec2使用者,完成對sec2使用者的匯入
ora10g@secDB2 /imp$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Fri Feb 26 21:47:43 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
sys@ora10g> create user sec2 identified by sec2 default tablespace TBS_SEC_D;
User created.
sys@ora10g> grant connect,resource,dba to sec2;
Grant succeeded.
sys@ora10g> exit
ora10g@secDB2 /imp$ imp sec2/sec2 file=sec2.dmp log=sec2.log ignore=y full=y
Import: Release 10.2.0.3.0 - Production on Fri Feb 26 21:48:17 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in AL32UTF8 character set and UTF8 NCHAR character set
. importing SEC2's objects into SEC2
. . importing table "T_SEC2" 1 rows imported
IMP-00041: Warning: object created with compilation warnings
"CREATE FORCE VIEW "SEC2"."V_SEC2" ("SEC1_X","SEC"
"2_X") AS "
"select SYN_T_SEC1.x sec1_x, T_SEC2.x sec2_x from SYN_T_SEC1,T_SEC2"
Import terminated successfully with warnings.
問題又一次再現,錯誤原因與我們前面分析的結果相同。
14.小結
我們使用EXP/IMP工具在不同使用者間存在較複雜的授權關係的情況下完成資料遷移時,需要特別注意他們的先後順序。
為避免此類錯誤的發生,建議在多使用者資料遷移場景下,使用sys使用者一次性完成(使用OWNER引數)資料遷移工作。
Good luck.
secooler
10.02.26
-- The End --
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-628019/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle GoldenGate導致IMP出現ORACLE 32588錯誤OracleGo
- 【故障處理】因GREP“花哨”功能導致ORA-12157錯誤的排查過程
- imp 匯入遇到 FK (Foreign Key) 導致錯誤處理
- git合併丟失程式碼問題分析與解決(錯誤操作導致)Git
- 雅虎出現程式故障 導致450萬封電子郵件丟失
- 【DataGuard】錯誤的log_file_name_convert引數導致物理Data Guard配置故障分析與處理
- Oracle全部索引丟失導致的效率問題處理Oracle索引
- 儲存崩潰導致資料丟失如何處理
- TSM備份時因歸檔日誌丟失而導致備份失敗
- 故障分析 | MySQL convert 函式導致的字符集報錯處理MySql函式
- 【ARCHIVE】模擬因無法歸檔導致日誌無法切換故障及一般處理方法兩則Hive
- 【Control File】Oracle個別控制檔案丟失故障場景模擬及處理方法Oracle
- 故障分析 | DDL 導致的 Xtrabackup 備份失敗
- lvm資訊丟失處理辦法LVM
- Ora-01555錯誤的模擬及處理
- 找回因錯誤配置丟失的65系列三層模組(轉)
- 【故障處理】imp-00051,imp-00008
- 【故障處理】ORA-12162 錯誤的處理
- impdp時parallel=4導致的錯誤Parallel
- oracle 案例-控制檔案丟失故障處理過程Oracle
- Verdaccio publish 時包含 deprecated 導致歷史版本丟失問題原因分析
- 【故障處理】CRS-1153錯誤處理
- 【故障處理】ORA-19809錯誤處理
- mysql,出現同步停止的錯誤的處理MySql
- 動態建立 @ViewChild 導致執行時錯誤的原因分析View
- 關於Cordova框架對URL攔截導致通訊丟失問題的處理框架
- 異常錯誤資訊處理
- 【故障恢復】因spfile修改錯誤導致資料庫無法啟動的恢復方法資料庫
- 【故障處理】因AIX非同步IO沒有開啟導致SQL*Plus不可用AI非同步SQL
- 小程式沒有授權時的處理方法
- Spring Boot+AngularJS中因為跨域導致Session丟失Spring BootAngularJS跨域Session
- 事務未完成導致關閉物件審計時出現[-6407]:Lock timeout.錯誤的處理記錄物件
- 【問題處理】因ASM磁碟組空間不足導致資料庫例項無法啟動的故障處理ASM資料庫
- 微信小程式授權登入以及使用者資訊相關介面調整導致授權框不彈出微信小程式
- SAN LUN Mapping出錯導致的資料丟失恢復全過程APP
- 【故障處理】手工刪除歸檔日誌導致RMAN備份時報ORA-19625錯誤
- js錯誤處理權威指北JS
- 伺服器不同的故障導致資料丟失都怎麼解決的伺服器