Oracle9i流環境清除(一)

yangtingkun發表於2007-11-16

Oracle的文件上給出了流環境的配置過程,但是沒有給出如何才能徹底清除流環境。

這篇文章介紹一下流環境中應用站點的清除過程。


首先,將流捕獲站點和流應用站點的所有相關JOB停止,避免JOB對後續的操作進行影響。

在清理過程中,首先清理流應用站點的設定。

使用流管理使用者STRMADMIN登陸,查詢所有除加到流環境中的RULE

SQL> SELECT STREAMS_NAME, RULE_NAME, OBJECT_NAME FROM SYS.STREAMS$_RULES;

STREAMS_NAME RULE_NAME OBJECT_NAME
------------------------------ ------------------------------ ------------------------------
DATA_APPLY_2 CAT_AREA_QUALITY_DEFINE93 CAT_AREA_QUALITY_DEFINE
DATA_APPLY_2 CAT_BUYER95 CAT_BUYER
DATA_APPLY_2 CAT_BUYER_DISTRICT96 CAT_BUYER_DISTRICT
DATA_APPLY_2 CAT_CATEGORY97 CAT_CATEGORY
.
.
.
DATA_APPLY_2 USER_DISTRICT115 USER_DISTRICT

22 rows selected.

將規則清除方法為:

SQL> EXEC DBMS_STREAMS_ADM.REMOVE_RULE('USER_DISTRICT115', 'APPLY', 'DATA_APPLY_2')

PL/SQL procedure successfully completed.

可以透過指令碼批次生成所有需要刪除的規則。

確認所有的規則已經從資料庫的流環境中移去。

下面檢查USER_RULES檢視,檢視還有那些RULE需要刪除。可以採用下面的方法刪除RULE

SQL> EXEC DBMS_RULE_ADM.DROP_RULE('CON_LIST_SHARE_OOS70')

PL/SQL procedure successfully completed.

透過DBMS_APPLY_ADM.DROP_APPLY過程刪除應用就可以了。

SQL> EXEC DBMS_APPLY_ADM.DROP_APPLY('DATA_APPLY_2')

PL/SQL procedure successfully completed.

由於流還保留了源資料,如果這部分需要清除的話,可以透過如下的方法進行清除:

SQL> SELECT OWNER, NAME, SOURCE_DB_NAME FROM SYS.APPLY$_SOURCE_OBJ;

OWNER NAME SOURCE_DB_NAME
------------------------------ ------------------------------ ------------------------------
NDMAIN CAT_AREA_QUALITY_DEFINE DATA01.US.ORACLE.COM
NDMAIN CAT_BUYER DATA01.US.ORACLE.COM
NDMAIN CAT_BUYER_DISTRICT DATA01.US.ORACLE.COM
NDMAIN CAT_CATEGORY DATA01.US.ORACLE.COM
.
.
.
NDMAIN CON_LIST_SHARE_OOS ZJTRADE.US.ORACLE.COM
NDMAIN CAT_STREAM_DATAT DATA01.US.ORACLE.COM

41 rows selected.

使用下面的過程來清除資訊:

SQL> EXEC DBMS_STREAMS_ADM.PURGE_SOURCE_CATALOG('DATA01.US.ORACLE.COM', 'NDMAIN.USER_DISTRICT', 'TABLE')

PL/SQL procedure successfully completed.

對於流環境複製的使用者物件,可以根據實際情況考慮是否進行刪除。

如果是透過OEM進行的流環境的清除,或者在上面的操作中,沒有安裝正確的順序進行操作,很可能導致RULERULESET甚至是APPLY已經被清除掉了,但是RULE仍然存在於流環境配置中。

這種情況將會造成再次配置流環境中出現異常。不過即使是出現了這種情況,也是可以順利刪除的,前提是將所有需要的RULERULESET以及APPLY補充上。

SQL> SELECT STREAMS_NAME, RULE_NAME, OBJECT_NAME FROM SYS.STREAMS$_RULES WHERE OBJECT_NAME = 'CON_LIST';

STREAMS_NAME RULE_NAME OBJECT_NAME
------------------------------ ------------------------------ ------------------------------
ZJTRADE_APPLY CON_LIST30 CON_LIST

SQL> SELECT * FROM ALL_APPLY WHERE APPLY_NAME = 'ZJTRADE_APPLY';

no rows selected

SQL> SELECT * FROM ALL_RULES WHERE RULE_NAME = 'CON_LIST30';

no rows selected

SYS.STREAMS$_RULES檢視中可以看到,流環境中CON_LISTRULE並未清除,但是應用ZJTRADE_APPLY和規則CON_LIST30都已經不存在了。這時候直接清除會報錯:

SQL> EXEC DBMS_STREAMS_ADM.REMOVE_RULE('CON_LIST', 'APPLY', 'ZJTRADE_APPLY')
BEGIN DBMS_STREAMS_ADM.REMOVE_RULE('CON_LIST', 'APPLY', 'ZJTRADE_APPLY'); END;

*
ERROR at line 1:
ORA-23605: invalid value "ZJTRADE_APPLY" for STREAMS parameter STREAMS_NAME
ORA-06512: at "SYS.DBMS_STREAMS_ADM", line 271
ORA-06512: at line 1

需要人工將應用新增上去:

SQL> EXEC DBMS_RULE_ADM.CREATE_RULE_SET('STRMADMIN.RULESET$_29', 'SYS.STREAMS$_EVALUATION_CONTEXT')

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_APPLY_ADM.CREATE_APPLY('STREAMS_QUEUE_T31', 'ZJTRADE_APPLY', 'RULESET$_29', NULL, NULL, 'STRMADMIN')

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_RULE_ADM.CREATE_RULE('CON_LIST30', '(((:dml.get_object_owner() = ''NDMAIN'' and :dml.get_object_name() = ''CON_LIST'')) and :dml.is_null_tag() = ''Y'' and :dml.get_source_database_name() = ''DATA01.US.ORACLE.COM'' )')

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_STREAMS_ADM.REMOVE_RULE('CON_LIST30', 'APPLY', 'ZJTRADE_APPLY')
BEGIN DBMS_STREAMS_ADM.REMOVE_RULE('CON_LIST30', 'APPLY', 'ZJTRADE_APPLY'); END;

*
ERROR at line 1:
ORA-24155: rule STRMADMIN.CON_LIST30 not in rule set STRMADMIN.RULESET$_29
ORA-06512: at "SYS.DBMS_STREAMS_ADM", line 271
ORA-06512: at line 1

光新增RULE還不夠,需要將RULE新增到RULESET中去:

SQL> EXEC DBMS_RULE_ADM.ADD_RULE('CON_LIST30', 'RULESET$_29')

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_STREAMS_ADM.REMOVE_RULE('CON_LIST30', 'APPLY', 'ZJTRADE_APPLY')

PL/SQL procedure successfully completed.

SQL> SELECT STREAMS_NAME, RULE_NAME, OBJECT_NAME FROM SYS.STREAMS$_RULES WHERE OBJECT_NAME = 'CON_LIST';

no rows selected

採用這種方法,可以將確實資訊的流環境徹底清除掉。

最後一步將所有的RULESET清除掉:

SQL> SELECT RULESET_NAME, BASE_TABLE FROM USER_RULESETS;

RULESET_NAME BASE_TABLE
------------------------------ -------------------------------------------
RULESET$_29 SYS.STREAMS$_EVALUATION_CONTEXT
RULESET$_94 SYS.STREAMS$_EVALUATION_CONTEXT
STREAMS_QUEUE_D1_R STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_D1_V
STREAMS_QUEUE_T31_R STRMADMIN.AQ$_STREAMS_QUEUE_TABLE_T31_V

對於RULESET可以透過DBMS_RULE_ADMDROP_RULE_SET過程清除。

SQL> EXEC DBMS_RULE_ADM.DROP_RULE_SET('RULESET$_29', TRUE);

PL/SQL procedure successfully completed.

其中兩個佇列表相關的RULESET無法直接刪除:

SQL> EXEC DBMS_RULE_ADM.DROP_RULE_SET('STREAMS_QUEUE_D1_R');
BEGIN DBMS_RULE_ADM.DROP_RULE_SET('STREAMS_QUEUE_D1_R'); END;

*
ERROR at line 1:
ORA-24170:
ORA-06512: at "SYS.DBMS_RULE_ADM", line 129
ORA-06512: at line 1

可以考慮透過設定EVENTS 25475來清除:

SQL> ALTER SESSION SET EVENTS = '25475 TRACE NAME CONTEXT FOREVER, LEVEL 2';

Session altered.

SQL> EXEC DBMS_RULE_ADM.DROP_RULE_SET('STREAMS_QUEUE_D1_R');

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_RULE_ADM.DROP_RULE_SET('STREAMS_QUEUE_T31_R');

PL/SQL procedure successfully completed.

SQL> ALTER SESSION SET EVENTS = '25475 TRACE NAME CONTEXT OFF';

Session altered.

然後可以清除佇列和相應的佇列表:

SQL> SELECT NAME, QUEUE_TABLE FROM USER_QUEUES;

NAME QUEUE_TABLE
------------------------------ ------------------------------
STREAMS_QUEUE_D1 STREAMS_QUEUE_TABLE_D1
AQ$_STREAMS_QUEUE_TABLE_D1_E STREAMS_QUEUE_TABLE_D1

SQL> EXEC DBMS_AQADM.STOP_QUEUE('STREAMS_QUEUE_D1')

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_AQADM.DROP_QUEUE('STREAMS_QUEUE_D1')

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_AQADM.STOP_QUEUE('AQ$_STREAMS_QUEUE_TABLE_D1_E')

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_AQADM.DROP_QUEUE('AQ$_STREAMS_QUEUE_TABLE_D1_E')

PL/SQL procedure successfully completed.

SQL> EXEC DBMS_AQADM.DROP_QUEUE_TABLE('STREAMS_QUEUE_TABLE_D1')

PL/SQL procedure successfully completed.

如果願意,下面就可以直接清除STRMADMIN使用者,這樣所有的流的配置就清除完畢了,最後可以DBMS_JOB刪除所有流相關的任務即可。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-69505/,如需轉載,請註明出處,否則將追究法律責任。

相關文章