在数据库异常恢复中,经常需要修改数据库的 SCN 值,在 12C 之前,我们常用的方法有如下几个:
1. oradebug poke 直接修改内存中的值;
2. event 10015 来增加 scn 的值;
3. _minimum_giga_scn 来增加 scn 的值;
4. gdb/dbx 来直接修改内存中的值;
5. 修改控制文件来修改 scn 的值;
6. 修改数据文件头来修改 scn 的值;
7. adjust_scn 来增加scn。
在这几种方法中,2、3、7方法在2012年中,Oracle
已经通过补丁更新,导致方法失效,就只有1,4,5,6方法。在这几种方法中,我们常常使用方法1来修改 scn 的值,但是此方法在 12C
中,Oracle 也已经屏蔽,还可以继续使用4,5,6 的方法来实现修改 SCN。在12.2 中,Oracle 多了一个新的 EVENT
21307096 也可以实现增加 SCN 的值。
接下来分别介绍4,5,6以及event等方式推进数据库SCN。
1,查看当前SCN:
SQL> alter system checkpoint;
System altered.
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
3102150
SQL> oradebug setmypid
Statement processed.
SQL> oradebug dumpvar sga kcsgscn_
kcslf kcsgscn_ [0600113B8, 0600113E8) = 002F561D 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 60049740 00000000
当前SCN为3102150,换算为16进制即002F561D,我们将SCN base修改成102F561D, SCN wrp修改为1.
查看进程号
[oracle@devin1 ~]$ ps -ef | grep -i local=yes
oracle 4223 4133 0 09:33 ? 00:00:00 oraclehkora (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 5124 5094 0 09:42 pts/2 00:00:00 grep --color=auto -i local=yes
GDB推进SCN
[oracle@devin1 ~]$ gdb $ORACLE_HOME/bin/oracle 4223
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.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:
<
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/bin/oracle...(no debugging symbols found)...done.
Attaching to program: /u01/app/oracle/product/12.2/dbhome_1/bin/oracle, process 4223
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libodm12.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libodm12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libofs.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libofs.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libcell12.so...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libcell12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libskgxp12.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libskgxp12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libskjcx12.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libskjcx12.so
Reading symbols from /lib64/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/librt.so.1
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libmql1.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libmql1.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libipc1.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libipc1.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libclsra12.so...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libclsra12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libdbcfg12.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libdbcfg12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libhasgen12.so...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libhasgen12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libskgxn2.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libskgxn2.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libocr12.so...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libocr12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libocrb12.so...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libocrb12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libocrutl12.so...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libocrutl12.so
Reading symbols from /lib64/libaio.so.1...Reading symbols from /lib64/libaio.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libaio.so.1
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libons.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libons.so
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /lib64/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnsl.so.1
Reading symbols from /lib64/libresolv.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libresolv.so.2
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /usr/lib64/libnuma.so.1...Reading symbols from /usr/lib64/libnuma.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /usr/lib64/libnuma.so.1
Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnss_files.so.2
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libnque12.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libnque12.so
Reading symbols from /u01/app/oracle/product/12.2/dbhome_1/lib/libshpkavx212.so...(no debugging symbols found)...done.
Loaded symbols for /u01/app/oracle/product/12.2/dbhome_1/lib/libshpkavx212.so
0x00007f9bbcff3740 in __read_nocancel () from /lib64/libpthread.so.0
Missing separate debuginfos, use: debuginfo-install glibc-2.17-317.0.1.el7.x86_64 libaio-0.3.109-13.el7.x86_64 libgcc-4.8.5-36.0.1.el7.x86_64 numactl-libs-2.0.9-7.el7.x86_64
(gdb) set *((int *) 0x0600113B8) = 0x102F561D --scn base,修改为102F561D
(gdb) set *((int *) 0x0600113BC) = 0x0001 --scn wrp,修改为1,因base占用4字节,所以wrp地址在base基础上加4
(gdb) quit
A debugging session is active.
Inferior 1 [process 4223] will be detached.
Quit anyway? (y or n) y
Detaching from program: /u01/app/oracle/product/12.2/dbhome_1/bin/oracle, process 4223
[Inferior 1 (process 4223) detached]
验证
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
4566505132
SQL> select to_char(4566505132,'xxxxxxxxxxxxx') from dual;
TO_CHAR(456650
--------------
1102f56ac --wrp=1 base=102f56ac