转 OGG add trandata 到底做了什么

有的时候我们做OGG的时候add trandata会出现异常。
 这里就剖析一下add trandata到底做了什么
GGSCI (yjfora81 as ggs_admin@testdb) 2> add trandata ppzhu1.test3
2016-03-08 11:47:36  WARNING OGG-00706  Failed to add supplemental log group on table PPZHU1.TEST3 due to ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired SQL ALTER TABLE “PPZHU1″.”TEST3″ ADD SUPPLEMENTAL LOG GROUP “GGS_87926″ (“USER_ID”) ALWAYS  /* GOLDENGATE_DDL_REPLICATION */.
然后一直hang住

使用OGG用户登陆我的用户GGS_ADMIN

GGSCI (yjfora81) 1> dblogin userid ggs_admin,password test;
 Successfully logged into database.

SQL> select SID , SERIAL# ,PADDR  from v$session where USERNAME=’GGS_ADMIN';
        SID    SERIAL# PADDR
———- ———- —————-
       145         15 00000001BE185360
 SQL> select pid,spid from v$process where addr=’00000001BE185360′;
        PID SPID
———- ————————
        37 40986
         
找到SPID和pid  OS PID是40986数据库的pid是37
我们用37 进行ORADEBUG

SQL> oradebug SETORAPID 37
Oracle pid: 37, Unix process pid: 40986, image: oracle@yjfora81 (TNS V1-V3)
 SQL> oradebug tracefile_name
 /home/oracle/oracle/diag/rdbms/testdb/testdb/trace/testdb_ora_40986.trc

10046事件可以设置以下四个级别:
1 – 启用标准的SQL_TRACE功能,等价于sql_trace
 4 – Level 1 加上绑定值(bind values)
 8 – Level 1 + 等待事件跟踪
12 – Level 1 + Level 4 + Level 8

找到语句使用LEVEL 1即可

SQL> oradebug event 10046 trace name context forever ,level 1;
 Statement processed.

在ggsci中

GGSCI (yjfora81 as ggs_admin@testdb) 3> add trandata ppzhu1.test4

Logging of supplemental redo data enabled for table PPZHU1.TEST4.
 TRANDATA for scheduling columns has been added on table ‘PPZHU1.TEST4′.
 TRANDATA for instantiation CSN has been added on table ‘PPZHU1.TEST4′.

SQL> Oradebug event 10046 trace name context off;
 Statement processed.

然后我们查看trace文件

LOCK TABLE “PPZHU1″.”TEST6″ IN SHARE MODE  NOWAIT 
 LOCK TABLE “PPZHU1″.”TEST6″ IN EXCLUSIVE MODE  NOWAIT 
 ALTER TABLE “PPZHU1″.”TES

可以看到是要加锁的所以add trandata可能造成堵塞
 由于ALTER TABLE 看不全,我做了审计发现如下:
 ALTER TABLE “PPZHU1″.”TEST8″ ADD SUPPLEMENTAL LOG GROUP “GGS_87937″ (“USER_ID”) ALWAYS  /* GOLDENGATE_DDL_REPLICATION */
  ALTER TABLE “PPZHU1″.”TEST8″ ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE, FOREIGN KEY) COLUMNS  /* GOLDENGATE_DDL_REPLICATION */
在结合我们的报错信息

GGSCI (yjfora81 as ggs_admin@testdb) 2> add trandata ppzhu1.test3
 2016-03-08 11:47:36  WARNING OGG-00706  Failed to add supplemental log group on table PPZHU1.TEST3 due to ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired SQL ALTER TABLE “PPZHU1″.”TEST3″ ADD SUPPLEMENTAL LOG GROUP “GGS_87926″ (“USER_ID”) ALWAYS  /* GOLDENGATE_DDL_REPLICATION */.
 2016-03-08 11:53:00  WARNING OGG-00706  Failed to add supplemental log group on table PPZHU1.TEST3 due to ORA-03113: end-of-file on communication channel
 Process ID: 23575
 Session ID: 80 Serial number: 2709 SQL BEGIN DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION(table_name => ‘”PPZHU1″.”TEST3″‘, supplemental_logging => ‘none’); END;.

可以确定 add trandata 至少做了如下操作

1、ALTER TABLE “PPZHU1″.”TEST8″ ADD SUPPLEMENTAL LOG GROUP “GGS_87937″ (“USER_ID”) ALWAYS
 2、ALTER TABLE “PPZHU1″.”TEST8″ ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE, FOREIGN KEY) COLUMNS 
 3、DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION(table_name => ‘”PPZHU1″.”TEST3″‘, supplemental_logging => ‘none’

其中这几部中第三步会加锁并且不是NOWAIT的方式,如果表上有事物正在运行,那么这个语句会等待,因为他需要一个MODE 4的锁在表级S锁
 如下:
SQL> select * from v$lock;
 ADDR             KADDR                   SID TYPE        ID1        ID2      LMODE    REQUEST      CTIME      BLOCK
—————- —————- ———- —- ———- ———- ———- ———- ———- ———-
00000001BD52BC80 00000001BD52BCF8         80 TX       655363       1685          6          0        122          0
 00007F716C65A908 00007F716C65A968         80 TM        87926          0          0          4        122          0

而DML会在表级别上一个SX级别的3级锁,所以不兼容一直卡着,并且它还会影响随后的DML因为DML需要表级别的SX锁,这样对生产系统的影响
 很大。解决方式就是KILL掉OGG登陆的会话。
而1,2两部都是NOWAIT方式,可以及时报错出来及ORA-00054: resource busy,不会堵塞

实际上1,2两部做完后,我们可以再ORACLE数据库中查看视图
dba_log_group_columns
 dba_log_groups
其中的含义不在给出,可以看看官方手册。

 

posted @ 2023-11-16 14:27  雪竹子  阅读(169)  评论(0编辑  收藏  举报