[20180604]在内存修改数据(bbed).txt
[20180604]在内存修改数据(bbed).txt
--//以前曾经做过在内存修改数据,通过oradebug poke命令修改内存信息,相关链接:
--//http://blog.itpub.net/267265/viewspace-2124466/=>[20160904]在内存修改数据.txt
--//今天测试看看是否通过bbed修改数据信息的情况.使用asmm,这样/dev/shm可以看到一个一个文件。
1.环境:
SCOTT@book> @ ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
2.建立测试:
create table t1 (id number,name varchar2(20));
insert into t1 values (1,'AAAAAAAAAAB');
commit ;
SCOTT@book> select rowid,t1.* from t1;
ROWID ID NAME
------------------ ---------- --------------------
AAAWQKAAEAAAAJcAAA 1 AAAAAAAAAAB
SCOTT@book> @ &r/rowid AAAWQKAAEAAAAJcAAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
91146 4 604 0 0x100025C 4,604 alter system dump datafile 4 block 604 ;
SYS@book> create pfile='/tmp/@.ora' from spfile;
File created.
--//修改/tmp/book.ora参数,加入
*.memory_target=5120M
*.memory_max_target=5120M
--//注:注意检查use_large_pages参数,我的设置*.use_large_pages='ONLY',无法启动,报
SYS@book> startup pfile=/tmp/book.ora
ORA-27125: unable to create shared memory segment
--//使用参数/tmp/book.ora参数启动数据库,这样采用asmm方式.
SYS@book> startup pfile=/tmp/book.ora
ORACLE instance started.
Total System Global Area 1068994560 bytes
Fixed Size 2259960 bytes
Variable Size 423625736 bytes
Database Buffers 637534208 bytes
Redo Buffers 5574656 bytes
Database mounted.
Database opened.
# ls -l /dev/shm/ora_book_*|wc
--//加载对应数据块到内存:
SCOTT@book> select rowid,t1.* from t1;
ROWID ID NAME
------------------ ---------- --------------------
AAAWQKAAEAAAAJcAAA 1 AAAAAAAAAAB
SYS@book> @ &r/bh 4 604
HLADDR DBARFIL DBABLK CLASS CLASS_TYPE STATE TCH CR_SCN_BAS CR_SCN_WRP CR_UBA_FIL CR_UBA_BLK CR_UBA_SEQ BA OBJECT_NAME
---------------- ---------- ---------- ---------- ------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------- --------------------
000000009DFCB238 4 604 1 data block xcur 1 0 0 0 0 0 0000000081C14000 T1
3.在内存修改数据:
# strings -f -t d /dev/shm/ora_book_* | grep AAAAAAAAAAB
/dev/shm/ora_book_265158658_132: 90097 AAAAAAAAAAB
/dev/shm/ora_book_265158658_132: 3055545 3*AC60AAABAAAAAAAAAAAAAAAAAAAAAAB6UEsFBgAAAAABAAEALwAAABEXAAAAAA==
--//90097/8192 = 10.99816894531250000000
--//确定字符串AAAAAAAAAAB在那个文件.可以确定/dev/shm/ora_book_265158658_132.因为仅仅插入1条,应该在块的底部.
4.使用bbed修改:
BBED> set filename '/dev/shm/ora_book_265158658_132'
FILENAME /dev/shm/ora_book_265158658_132
BBED> set blocksize 8192
BLOCKSIZE 8192
--//注意一定要设置这个参数.不然看到的块大小是512
BBED> show
FILE# 0
BLOCK# 1
OFFSET 0
DBA 0x00000000 (0 0,1)
FILENAME /dev/shm/ora_book_265158658_132
BIFILE bifile.bbd
LISTFILE /home/oracle/bbed/filelist.txt
BLOCKSIZE 512
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 160
COUNT 64
LOGFILE log.bbd
SPOOL Yes
BBED> set block 11
BLOCK# 11
--//因为这个内存文件的第一块非文件头.所以block=11.
BBED> x /rnc *kdbr[0]
rowdata[0] @8170
----------
flag@8170: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8171: 0x01
cols@8172: 2
col 0[2] @8173: 1
col 1[11] @8176: AAAAAAAAAAB
--//确定偏移量:
BBED> dump offset 8176
File: /dev/shm/ora_book_265158658_132 (0)
Block: 11 Offsets: 8176 to 8191 Dba:0x00000000
--------------------------------------------------------------------------------------------------
0b414141 41414141 41414142 0106a09c
<64 bytes per line>
BBED> modify /c 'ABCD' offset 8177
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /dev/shm/ora_book_265158658_132 (0)
Block: 11 Offsets: 8177 to 8191 Dba:0x00000000
--------------------------------------------------------------------------------------------------
41424344 41414141 41414201 06a09c
--//再次查询看看.
SYS@book> select rowid,t1.* from scott.t1;
ROWID ID NAME
------------------ ---------- --------------------
AAAWQKAAEAAAAJcAAA 1 ABCDAAAAAAB
--//注:我并没有做检查和,sum apply.
--//我已经通过内存篡改了信息.
SYS@book> alter system flush BUFFER_CACHE;
System altered.
SYS@book> select rowid,t1.* from scott.t1;
ROWID ID NAME
------------------ ---------- --------------------
AAAWQKAAEAAAAJcAAA 1 AAAAAAAAAAB
--//现在有正常显示回来.