Oracle

呼叫 DBMS_LOGMNR.START_LOGMNR 時出現“使用者不存在”

  • April 8, 2021

我有一個名為“MYADMIN”的 CDB 使用者,我正在嘗試讓它連接到日誌探勘器。

-- enable calling admin username on CDB 
ALTER SESSION set "_ORACLE_SCRIPT"=true
/
-- create unique table space for admin
CREATE TABLESPACE myadmints DATAFILE '/path/to/admints.dbf' SIZE 20M AUTOEXTEND ON
/
-- create admin user on CDB
CREATE USER myadmin IDENTIFIED BY P@ssw0rd DEFAULT TABLESPACE myadmints QUOTA UNLIMITED ON myadmints ACCOUNT UNLOCK
/
-- allow access to all PDBs to the admin user
ALTER USER myadmin SET CONTAINER_DATA=ALL CONTAINER=CURRENT
/ 
-- grant needed permissions
GRANT DBA to myadmin 
GRANT CREATE SESSION TO myadmin 
GRANT CREATE TABLE TO myadmin 
GRANT EXECUTE_CATALOG_ROLE TO myadmin 
GRANT EXECUTE ON DBMS_LOGMNR TO myadmin 
GRANT SELECT ON V_$DATABASE TO myadmin 
GRANT SELECT ON V_$LOGMNR_CONTENTS TO myadmin 
GRANT SELECT ON V_$ARCHIVED_LOG TO myadmin 
GRANT SELECT ON V_$LOG TO myadmin 
GRANT SELECT ON V_$LOGFILE TO myadmin 
GRANT RESOURCE, CONNECT TO myadmin 

我從“v$archived_log”中選擇了一行並嘗試載入文件。

BEGIN
 DBMS_LOGMNR.ADD_LOGFILE(LogFileName=>'/path/to/archive/ARC000011_1061542581',Options=>DBMS_LOGMNR.new);
 DBMS_LOGMNR.START_LOGMNR(StartScn=>3083464, EndScn=>3388245, Options=>DBMS_LOGMNR.DICT_FROM_ONLINECATALOG+DBMS_LOGMNR.NO_ROW_ID_IN_STMT);
END;

我可以從sys as sysdba使用者執行它,但是當我從“myadmin”使用者執行它時,我得到:

Error report - 
ORA-01435: user does not exist
ORA-06512: at "SYS.DBMS_LOGMNR", line 72
ORA-06512: at line 3
01435. 00000 - "user does not exist"
*Cause:
*Action:

當我刪除它時,錯誤是關於該START_LOGMNR行的,沒有錯誤。

我缺少哪個特權?

當您打破並忽略 CDB 體系結構和普通使用者的基本概念並使用不受支持的“變通方法”( ALTER SESSION set "_ORACLE_SCRIPT"=true) 時,您就會得到這樣的結果。

當您以受支持的方式創建使用者時,上面的程式碼可以完美執行。

-- create admin user on CDB
CREATE USER c##myadmin IDENTIFIED BY myadmin DEFAULT TABLESPACE users QUOTA UNLIMITED ON users ACCOUNT UNLOCK
/
-- allow access to all PDBs to the admin user
ALTER USER c##myadmin SET CONTAINER_DATA=ALL CONTAINER=CURRENT
/ 
-- grant needed permissions
GRANT DBA to c##myadmin                            ;
GRANT CREATE SESSION TO c##myadmin                 ;
GRANT CREATE TABLE TO c##myadmin                   ;
GRANT EXECUTE_CATALOG_ROLE TO c##myadmin           ;
GRANT EXECUTE ON DBMS_LOGMNR TO c##myadmin         ;
GRANT SELECT ON V_$DATABASE TO c##myadmin          ;
GRANT SELECT ON V_$LOGMNR_CONTENTS TO c##myadmin   ;
GRANT SELECT ON V_$ARCHIVED_LOG TO c##myadmin      ;
GRANT SELECT ON V_$LOG TO c##myadmin               ;
GRANT SELECT ON V_$LOGFILE TO c##myadmin           ;
GRANT RESOURCE, CONNECT TO c##myadmin              ;

然後:

sqlplus c##myadmin/myadmin

BEGIN
 DBMS_LOGMNR.ADD_LOGFILE(LogFileName=>'/fra/RYCDB19/archivelog/2021_01_18/o1_mf_1_130_j0bo2onq_.arc',Options=>DBMS_LOGMNR.new);
 DBMS_LOGMNR.START_LOGMNR(Options=>DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG+DBMS_LOGMNR.NO_ROWID_IN_STMT);
END;
/

PL/SQL procedure successfully completed.

SQL> select count(*) from v$logmnr_contents;

 COUNT(*)
----------
   159587

每當您用於ALTER SESSION set "_ORACLE_SCRIPT"=true創建自己的使用者和對象時,它們的ORACLE_MAINTAINED屬性都設置為Y. 這不受支持,並且可能會破壞功能的功能。

引用自:https://dba.stackexchange.com/questions/283417