跳转至

准备数据库

准备连接

对于有 ASM 的 Oracle 采集代理需要连接 ASM 实例。需开启 ASM 实例的远程监听。若是配置静态监听则需在listener.ora 中有类似如下配置。

listener.ora
SID_LIST_LISTENER_ASM =
    (SID_LIST =
      (SID_DESC =
        (GLOBAL_DBNAME = ASM)
        (ORACLE_HOME = /u01/app/grid)
        (SID_NAME = +ASM1)
    )
)

Oracle 节点 ASM 连接信息配置

ASM 用户名

此处用户为 agentasm 且须持有 SYSDBA 角色。用户名格式为:

agentasm as sysdba

ASM 连接地址

节点 ASM 连接地址格式有两种:官方 Oracle JDBC 连接格式说明

  • 使用 SERVICE: //HOST:PORT/SERVICE 例子://10.0.10.169:1521/+ASM
  • 使用 SID: HOST:PORT:SID 例子: 10.0.10.169:1521:+ASM1

如果是单机 ASM,SID 一般为 +ASM,如果是 RAC,则一般为 +ASM(x),x 为节点数,比如 +ASM1。具体连接地址和 SID 请咨询对应 DBA。

Endian 类型

优先选择大端。如果发现日志不推进,选择小端。POST /export/stop 后,在节点选择小端,并重启任务。

创建 Oracle 实例连接用户

为采集代理创建 Oracle 连接用户。

--******************用户相关******************
-- 创建用户名/密码
create user agent1 identified by agent1;
-- 创建角色
create role agent1_role identified by agent1_role;
-- 赋登陆、查表、查字典权限给该角色
grant connect,select any table,select any dictionary,create session to agent1_role,agent1;
-- 赋予该用户该角色
grant agent1_role to agent1;
-- 选择该用户表空间
alter user agent1 quota 2m on users;

创建 ASM 实例连接用户

如果 Oracle 使用了 ASM 存储。则使用 SYSASM 角色的用户登陆 ASM 数据库后创建采集代理连接 ASM 的用户。

-- 创建用户名/密码
create user agentasm identified by agentasm;
-- ASM 用户须有 SYSDBA 角色
grant sysdba to agentasm;

准备系统视图

create or replace view XKCCLE as select * from sys.x$KCCLE;
create or replace view XKCCCP as select * from sys.x$KCCCP;
create or replace view DP_XKSPPI as select * from X$KSPPI;
create or replace view DP_XKSPPSV as select * from X$KSPPSV;
create or replace view DP_KSPPCV as select * from X$KSPPCV;
如果是 PDB 环境,则须登陆或切换至该 PDB 后执行
create table sys.dp_pdbs as select * from sys.v$pdbs;

赋权用户访问系统视图

grant select on sys.ts$ to agent1;
grant select on sys.tabsubpart$ to agent1;
grant select on sys.obj$ to agent1;
grant select on sys.seg$ to agent1;
grant select on sys.coltype$ to agent1;
grant select on sys.xkccle to agent1;
grant select on sys.xkcccp to agent1;
grant select on sys.DP_XKSPPI to agent1;
grant select on sys.DP_XKSPPSV to agent1;
grant select on sys.DP_KSPPCV to agent1;
grant select on sys.seq$ to agent1;
grant select on sys.user$ to agent1;
grant select on sys.col$ to agent1;
grant select on sys.ind$  to agent1;
grant select on sys.tab$ to agent1;
grant select on sys.lob$ to agent1;
grant select on sys.indpart$ to agent1;
grant select on sys.lobfrag$ to agent1;
grant select on sys.user$ to agent1;
grant select on sys.source$ to agent1;
grant select on sys.view$  to agent1;
grant select on sys.ts$  to agent1;
grant select on sys.profname$ to agent1;
grant select on sys.profile$  to agent1;
grant select on sys.sysauth$ to agent1;
grant select on sys.props$ to agent1;
grant select on sys.idl_ub1$ to agent1;
grant select on sys.user$ to agent1;
grant select on sys.ntab$  to agent1;
grant select on sys.sum$ to agent1;
grant select on sys.com$ to agent1;
grant select on sys.partlob$ to agent1;
grant select on sys.attrcol$ to agent1;
grant select on sys.ccol$ to agent1;
grant select on sys.subpartcol$ to agent1;
grant select on sys.tabpart$ to agent1;
grant select on sys.indpart$ to agent1;
grant select on sys.indcompart$ to agent1;
grant select on sys.defrole$ to agent1;
grant select on sys.v_$instance to agent1;
grant select on SYS.v_$database to agent1;
grant select on sys.v_$datafile to agent1;
grant select on sys.V_$SESSION  to agent1;
grant select on sys.v_$log  to agent1;
grant select on sys.v_$logfile  to agent1;
grant select on sys.gv_$logfile  to agent1;

准备数据库日志

实时数据捕获原理是解析重做日志。 当有激增数据量时,重做日志可能还来不及解析就被切换, 您需要为 Oracle 配置开启归档模式,这样被切换的重做日志会被归档。采集代理仍可以继续解析归档日志而不丢失数据。

确认归档日志模式

  1. 查询是否开启归档日志
    SQL> select log_mode from v$database;
    LOG_MODE
    ------------
    ARCHIVELOG
    
    SQL> archive log list;
    
  2. 如果上述查询结果为否,强烈建议开启归档日志。启用归档模式具体步骤请由 DBA 操作。

确认日志补全

采集代理正常运行需要 Oracle 数据库需要开启最小补全日志。 对于 DataPipeline 数据应用来讲,需要对监听的表开启日志补全,日志补全的方式可以是数据库级别,也可以是表级别。 如果是监听 ADG 备库,则主库需开启补全日志。且主备重做日志大小应当一致。

最小级别补全日志和强制日志记录

  1. 以 SQL*Plus 登陆拥有 ALTER SYSTEM 权限的用户。
  2. 以下命令查询数据库是否开启最小补全及是否处于记录所有日志模式。
    SQL> SELECT supplemental_log_data_min, force_logging FROM v$database;
    
  3. 如果查询结果是 NO,使用以下命令开启数据库日志最小补全、开启强制日志记录。
    SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
    SQL> ALTER DATABASE FORCE LOGGING;
    
  4. 再次执行第一步查询确认结果。
    SQL> SELECT supplemental_log_data_min, force_logging FROM v$database;
    
  5. 切换日志生效。
    SQL> ALTER SYSTEM SWITCH LOGFILE;
    
    为获取 row update 事件所有列的 before 的值, 采集代理时需要为数据库开启 (ALL) 补全日志,或开启表级别 (ALL) 补全日志。

开启数据库级别日志 ALL 补全日志

SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;

开启表级别日志 ALL 补全日志

SQL> ALTER TABLE <schema name>.<table name> ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
如果只开启表级别日志补全,需要在节点中加入 JDBC 连接参数 SUPPLEMENTAL_ALL_CHECK=false,跳过库 ALL 级别日志补全检查。并请为想要监听的表开启 (ALL) 表级别日志补全。否则校验会不通过。