一、 遷移中的阻塞
DBMS_AUDIT_MGMT.set_audit_trail_location 根據網上資料是一種在線遷移方法,但在遷移過程中發現有大量會話等待enq: ZA - add std audit table partition事件,如果時間過長,實際對業務還是會有影響。
SQL> select sid,blocking_session,final_blocking_session,event from v$session where blocking_session is not null;
SID BLOCKING_SESSION FINAL_BLOCKING_SESSION
---------- ---------------- ----------------------
EVENT
----------------------------------------------------------------
5 198 575
enq: ZA - add std audit table partition
6 198 575
enq: ZA - add std audit table partition
8 198 575
enq: ZA - add std audit table partition
...
1346 198 575
enq: ZA - add std audit table partition
1347 198 575
enq: ZA - add std audit table partition
解決方法:
如果審計表很大並且存儲性能不佳,遷移期間大量會話可能會被enq: ZA - add std audit table partition等待事件阻塞。由於遷移速度非常慢,最好可以先導出該表數據、truncate之後再進行遷移,以免影響業務。
導出腳本exp.sh
userid='/ as sysdba'
file=audit.dmp
tables=sys.aud$
compress=y
導出命令
nohup exp parfile=exp.sh &
二、 遷移途中取消操作會怎麼樣
由於遷移過程中出現了大量阻塞,在遷移途中取消(Ctrl+C)掉了set_audit_trail_location操作,可以看到數據庫中的阻塞很快全部消失,但當再次執行set_audit_trail_location操作時就會遇到問題。
SQL> BEGIN
2 DBMS_AUDIT_MGMT.set_audit_trail_location(
3 audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
4 audit_trail_location_value => 'TBAUDIT');
5 END;
6 /
^C
BEGIN
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
ORA-06512: at "SYS.DBMS_AUDIT_MGMT", line 2932
ORA-06512: at "SYS.DBMS_AUDIT_MGMT", line 1586
ORA-06512: at line 2
再次執行
SQL> BEGIN
DBMS_AUDIT_MGMT.set_audit_trail_location(
audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
audit_trail_location_value => 'TABS_DATA');
END;
/ 2 3 4 5 6
BEGIN
*
ERROR at line 1:
ORA-46268: Conflicting operation on audit table(s)
ORA-06512: at "SYS.DBMS_AUDIT_MGMT", line 61
ORA-06512: at "SYS.DBMS_AUDIT_MGMT", line 1530
ORA-06512: at line 2
解決方法:
其實這個並沒有什麼影響,只需要把原來執行該語句的會話關掉,等一段時間再執行即可。
參考 https://nazim-dba.blogspot.com/2018/06/error-sql-begin-dbmsauditmgmt.html
三、 SYSAUX空間不足
在執行init_cleanup時報錯
SQL>BEGIN
DBMS_AUDIT_MGMT.init_cleanup(
audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_FGA_STD,
default_cleanup_interval => 168 );
END;
/ 2 3 4 5 6
BEGIN
*
ERROR at line 1:
ORA-46267: Insufficient space in 'SYSAUX' tablespace, cannot complete operation
ORA-06512: at "SYS.DBMS_AUDIT_MGMT", line 1035
ORA-06512: at line 2
由官方文檔可以知道,如果審計表在SYSTEM表空間中,init_cleanup會將其遷到SYSAUX表空間,但是如果審計表已被遷到特定表空間,init_cleanup則不會將其遷到SYSAUX表空間。
https://docs.oracle.com/database/121/ARPLS/d_audit_mgmt.htm#ARPLS65423
而MOS文檔1508787.1中提到
- INIT_CLEANUP會對SYSAUX剩餘空間進行檢查,這個檢查不看SYSAUX是否能擴展,只看當前剩餘大小
- 即使已經將審計表移動到特定表空間,這個檢查也會進行
解決方法:
除了文檔中提到的修改系統表,如果審計表不大,更簡單的方法是直接給sysaux表空間加個數據文件。
四、 併發收集統計信息報錯
SQL> BEGIN
2 DBMS_AUDIT_MGMT.init_cleanup(
3 audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
4 default_cleanup_interval => 168 );
5 END;
6 /
BEGIN
*
ERROR at line 1:
ORA-20000: Unable to gather statistics concurrently: Resource manager plan is
not active or is not managing CPU usage
ORA-06512: 在 "SYS.DBMS_AUDIT_MGMT", line 2333
ORA-06512: 在 "SYS.DBMS_AUDIT_MGMT", line 617
ORA-06512: 在 line 2
2049013.1文檔中報錯原因如下
查看concurrent設置
查看resource_manager_plan
所以這個問題有兩個解決方法:
要麼Enable Resource Manager(需要重啓DB)
SQL> alter system set resource_manager_plan = 'DEFAULT_PLAN' scope=spfile;
要麼關閉併發統計信息收集(方便)
SQL> exec dbms_stats.set_global_prefs('CONCURRENT', 'FALSE');
五、 PDB中如何重編譯失效對象
如果有PDB,遷移操作需要在pdb中也執行,執行完之後會產生失效對象,但是直接在pdb裏執行alter complile語句會報錯
SQL> alter view sys.DBA_FGA_AUDIT_TRAIL compile;
alter view sys.DBA_COMMON_AUDIT_TRAIL compile;alter view sys.DBA_FGA_AUDIT_TRAIL compile
*
ERROR at line 1:
ORA-65040: operation not allowed from within a pluggable database
解決方法:
在pdb中需要利用dbms_pdb.exec_as_oracle_script來執行編譯語句。
exec dbms_pdb.exec_as_oracle_script ('alter view sys.FGA_LOG$FOR_EXPORT compile');
exec dbms_pdb.exec_as_oracle_script ('alter public synonym DBA_FGA_AUDIT_TRAIL compile');
exec dbms_pdb.exec_as_oracle_script ('alter package MDSYS.SDO_NET compile body');
參考: 文檔 ID 2350934.1
其他:Known Issues When Using: DBMS_AUDIT_MGMT (文檔 ID 804624.1)