oracle 推進scn(poke、gdb、event、bbed)方法

wanglinghua0907發表於2024-01-24

1.poke推進scn修復(針對2662)(ORA-600 [2662] [a] [b] [c] [d] [e])(12.2以下可以使用)

1.檢視當前資料庫的Current SCN

SYS@orcl> select current_scn||'' from v$database;

CURRENT_SCN||''

-------------------

4563483988

可以看到當前SCN是4563483988,我現在想推進SCN,在10w級別,也就是4563483988標紅數字修改為指定值。

 

2.重新啟動資料庫到mount階段

SYS@orcl> shutdown abort

ORACLE instance shut down.

SYS@orcl> startup mount

ORACLE instance started.

Total System Global Area 1235959808 bytes

Fixed Size                  2252784 bytes

Variable Size             788529168 bytes

Database Buffers          436207616 bytes

Redo Buffers                8970240 bytes

Database mounted.

 

3.使用oradebug poke推進SCN

我這裡直接把十萬位的"4"改為"9"了,相當於推進了50w左右: 說明:實驗發現oradebug poke 推進的SCN值,既可以指定

十六進位制的0x11008DE74,也可以直接指定十進位制的4563983988。


1.指定程式

SYS@orcl> oradebug setmypid

Statement processed.

 

檢視kcsgscn_

SYS@orcl> oradebug dumpvar sga kcsgscn_

kcslf kcsgscn_ [06001AE70, 06001AEA0) = 00000000 00000000 00000000 00000000 00000000 00000000 00000000

00000000 00000000 00000000 6001AB50 00000000

 

這步沒用

SYS@orcl> select to_char(checkpoint_change#, 'XXXXXXXXXXXXXXXX') from v$database;

TO_CHAR(CHECKPOINT_CHANGE#,'XXXXXX

----------------------------------

        110013C41

 

修改,poke

這裡的0x06001AE70見oradebug dumpvar sga kcsgscn_出來的部分,8是固定的,4563983988是自己想要到的scn位置

SYS@orcl> oradebug poke 0x06001AE70 8 4563983988

BEFORE: [06001AE70, 06001AE78) = 00000000 00000000

AFTER:  [06001AE70, 06001AE78) = 1008DE74 00000001

 

檢視kcsgscn_

SYS@orcl> oradebug dumpvar sga kcsgscn_

kcslf kcsgscn_ [06001AE70, 06001AEA0) = 1008DE74 00000001 00000000 00000000 00000000 00000000 00000000

00000000 00000000 00000000 6001AB50 00000000

 

SYS@orcl> alter database open;

Database altered.

 

SYS@orcl> select current_scn||'' from v$database;

CURRENT_SCN||''

---------------------

4563984271

可以看到已經成功將SCN推進到4563983988,SCN不斷增長,所以這裡查到的值略大一些。


4.補充實際計算推進SCN的方法

ORA-600 [2662] [a] [b] [c] [d] [e]

本文在 2018-12-16 進一步補充說明: 在實際這類工作中,我們實際應該是要認真計算好需要推進SCN的值,

而不應圖省事直接給一個很大的值。後者不但是技術水平不成熟的表現,而且是不負責任的行為。


ora-600 [2662]引數說明:

ORA-00600: internal error code, arguments: [2662], [a], [b], [c], [d], [e], [], []

a–CRUUENT SCN WRAP

b–CURRENT SCN BASE

c–DEPENDENT SCN WRAP

d–DEPENDENT SCN BASE

e–where present this is the dba where the dependent scn came from.


例子1:

--ORA-00600: internal error code, arguments: [2662], [2], [1424107441], [2], [1424142235], [8388617], [], []

select 2*power(2,32)+1424142235 from dual;

10014076827


例子2:

--ORA-00600: internal error code, arguments: [2662], [2], [1424142249], [2], [1424142302], [8388649], [], []

select 2*power(2,32)+1424143000 from dual;

10014077592


總結公式:c * power(2,32) + d {+ 可適當加一點,但不要太大!}


c代表:Arg [c] dependent SCN WRAP

d代表:Arg [d] dependent SCN BASE


SCN組成:

SCN佔6位元組,由SCN_WRAP和SCN_BASE組成

SCN =(SCN_WRAP << 32)+ SCN_BASE

SCN是一個6位元組(6*8=48bit)的數字,其值最大為281,474,976,710,656(2^48),SCN分為2個部分:

SCN_BASE是一個4位元組(4 * 8=32bit)的數字

SCN_WRAP是一個2位元組(2 * 8=16bit)的數字

每當SCN_BASE達到其最大值(2^32 = 4294967296)時,SCN_WRAP增加1,SCN_BASE將被重置為0,一直持續到

SCN_WRAP達到其最大值,即2^16 = 65536


整個流程

oradebug setmypid

oradebug dumpvar sga kcsgscn_

oradebug poke 0x060012658 8 10014077592

oradebug dumpvar sga kcsgscn_

alter database open;


2.12c event 21307096推進scn修復 (12.2之後)

計算方式

Lowest_scn+event  level * 1000000


檢視當前資料庫SCN:

SQL> select to_char(current_scn) from v$database;

 

TO_CHAR(CURRENT_SCN)

----------------------------------------

12796139551520

 

2.新增event以及引數

alter system set "_allow_resetlogs_corruption"=true scope=spfile;

alter system set event='21307096 trace name context forever,level 3' scope=spfile;

 

3.啟動資料庫

SQL> shutdown immediate;

Database dismounted.

ORACLE instance shut down.

 

SQL> startup mount;

ORACLE instance started.

 

Total System Global Area 1660944384 bytes

Fixed Size                  8793448 bytes

Variable Size             889193112 bytes

Database Buffers          754974720 bytes

Redo Buffers                7983104 bytes

Database mounted.

 

SQL> recover database using backup controlfile until cancel;

ORA-00279: change 12796139551734 generated at 04/20/2022 11:13:44 needed for

thread 1

ORA-00289: suggestion :

/app/oracle/product/12.2.0/db_1/dbs/arch1_1_1102504135.dbf

ORA-00280: change 12796139551734 for thread 1 is in sequence #1

 

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

cancel

Media recovery cancelled.

SQL> 

SQL> 

SQL> alter database open resetlogs;

 

Database altered.

 

SQL> select to_char(current_scn) from v$database;

 

TO_CHAR(CURRENT_SCN)

----------------------------------------

12796142552279

 

SCN成功推進300w

 

3.gdb推進scn修復(12.2以下能用)

Session 1:

查詢當前scn:

SQL> select current_scn from v$database;                

CURRENT_SCN

-----------

 2910718245

 

查詢當前SCN轉成16進位制後的值:

SQL> select to_char(2910718245,'xxxxxxxxxxxx') from dual;

TO_CHAR(29107

-------------

     ad7e0925

 

查詢預修改的SCN轉換成16進位制後的值,本次將最高位增加一位數

SQL> select to_char(3910718245,'xxxxxxxxxxxx') from dual; 

TO_CHAR(39107

-------------

     e918d325

 

SQL> oradebug setmypid

Statement processed.

 

SQL> oradebug dumpvar sga kcsgscn_

kscn8 kcsgscn_ [060017E98, 060017EA0) = AD7E093B 00000000

 

需要注意的是,060017E98是SCN BASE值,AD7E093B是當前的SCN值,可以理解為060017E98是一個代號x,

當前的x等於AD7E093B,待會兒我們修改SCN值的時候,就會需要指定060017E98這個值等於多少。

 

Session 2:

[oracle@redhat19c11 ~]$ ps -ef|grep LOCAL=YES

oracle    9824  9730  0 Feb22 ?        00:00:01 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

oracle   18621  8636  0 01:18 pts/1    00:00:00 grep --color=auto LOCAL=YES

oracle   20109 20105  0 Feb15 ?        00:00:13 oracletestdb19c (DESCRIPTION=(LOCAL=YES)(ADDRESS=

(PROTOCOL=beq)))

 

本次測試庫是orcl,因此選9824

[oracle@redhat19c11 ~]$ gdb $ORACLE_HOME/bin/oracle 9824

GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7

Copyright (C) 2013 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

and "show warranty" for details.

This GDB was configured as "x86_64-redhat-linux-gnu".

For bug reporting instructions, please see:

-------------------------------------------

(gdb) set *((int *) 0x060017E98) = 0xe918d32--->將SCN BASE修改為剛才查出來的值

(gdb) quit

A debugging session is active.

        Inferior 1 [process 9824] will be detached.

Quit anyway? (y or n) y

Detaching from program: /oracle/app/product/19.3.0/db_1/bin/oracle, process 9824

 

返回session1查詢,修改成功:

SQL> select current_scn from v$database;

CURRENT_SCN

-----------

 3910718287

 

重啟資料庫,也可正常開啟資料庫

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup;

ORACLE instance started.

 

Total System Global Area 2466250400 bytes

Fixed Size                  9137824 bytes

Variable Size             603979776 bytes

Database Buffers         1845493760 bytes

Redo Buffers                7639040 bytes

Database mounted.

Database opened.

SQL> select current_scn from v$database;

 

CURRENT_SCN

-----------

 3910719415


4.bbed修改

修改offset 484和500資訊即可



部分參考:

Nathan-wang


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

相關文章