Oracle数据提交与事务隔离实验
oradebug挂起lgwr进程
原文作者:dbsnake 崔华
实验参考原文链接:http://www.dbsnake.com/unsuccessful-commit-feature.html
Oracle 里未 commit 的数据除了当前 session 之外,其他 session 是看不到的。
Oracle里未成功 commit 的数据我们也可能能看到。
同时启4个 session:
session 1: 创建测试表test,插入一条数据但不提交
SCOTT@PROD>create table test (id number,name varchar2(20));
SCOTT@PROD>insert into test values (1,'lvxinghao');
SCOTT@PROD>select * from test;

session 2:查看test表,由于session 1未commit,session 2查看不到这条数据
SCOTT@PROD>select * from test;
SCOTT@PROD>select count(*) from test;

session 3:sys用户查看并把lgwr进程suspend住(挂起):
操作系统查看LGWR进程号
[oracle@rhel64 ~]$ ps -ef | grep lgwr | grep -v grep

sys用户查看lgwr后台进程对应操作系统pid:
SYS@PROD>select spid from v$process where pname='LGWR';

挂起lgwr进程
SYS@PROD>oradebug setospid 5528
SYS@PROD>oradebug suspend

alert日志中信息显示
[oracle@rhel64 ~]$ tail -f $ORACLE_BASE/diag/rdbms/prod/PROD/trace/alert_PROD.log

session 1:执行commit命令,由于lgwr进程被挂起,commit命令hang住
SCOTT@PROD>commit;

session 2:再次查看test表中数据,能够显示出来
SCOTT@PROD>select * from test;
SCOTT@PROD>select count(*) from test;

从结果来看,之前看不到的那条记录现在已经能看到了,即session 1对于session2而言已经commit了,尽管由于lgwr被挂起,session1的commit操作并没有成功的做完。
Oracle 里 commit 操作时,
1、修改事务所对应的 undo segment header 中 slot 的状态;
2、改完状态后再 flush log buffer;
session 3中把lgwr 挂起了,步骤2 无法完成,但步骤1还可以完成。
只要步骤1做完了,其他的 session 就能看到这个事务所做的改变了(通过ITL中记录的 transaction id 去 check相应的 undo segment header 中 slot 的状态),也就是说对于其他 session 而言,这个事务已经 commit 了,虽然这个事务其实并没有成功commit。
(解除挂起lgwr进程,可以使用oradebug resume)
session 4:shutdown abort之后startup启动实例
SYS@PROD>shutdown abort;
SYS@PROD>startup;

告警日志显示有instance recovery

session 1:再次查看test表,数据不存在。
SCOTT@PROD>conn scott/tiger
SCOTT@PROD>select * from test;

SYS@PROD>oradebug help
HELP [command] Describe one or all commands
SETMYPID Debug current process
SETOSPID <ospid> Set OS pid of process to debug
SETORAPID <orapid> ['force'] Set Oracle pid of process to debug
SETORAPNAME <orapname> Set Oracle process name to debug
SHORT_STACK Get abridged OS stack
CURRENT_SQL Get current SQL
DUMP <dump_name> <lvl> [addr] Invoke named dump
DUMPSGA [bytes] Dump fixed SGA
DUMPLIST Print a list of available dumps
EVENT <text> Set trace event in process
SESSION_EVENT <text> Set trace event in session
DUMPVAR <p|s|uga> <name> [level] Print/dump a fixed PGA/SGA/UGA variable
DUMPTYPE <address> <type> <count> Print/dump an address with type info
SETVAR <p|s|uga> <name> <value> Modify a fixed PGA/SGA/UGA variable
PEEK <addr> <len> [level] Print/Dump memory
POKE <addr> <len> <value> Modify memory
WAKEUP <orapid> Wake up Oracle process
SUSPEND Suspend execution
RESUME Resume execution
FLUSH Flush pending writes to trace file
CLOSE_TRACE Close trace file
TRACEFILE_NAME Get name of trace file
LKDEBUG Invoke global enqueue service debugger
NSDBX Invoke CGS name-service debugger
-G <Inst-List | def | all> Parallel oradebug command prefix
-R <Inst-List | def | all> Parallel oradebug prefix (return output
SETINST <instance# .. | all> Set instance list in double quotes
SGATOFILE <SGA dump dir> Dump SGA to file; dirname in double quotes
DMPCOWSGA <SGA dump dir> Dump & map SGA as COW; dirname in double quotes
MAPCOWSGA <SGA dump dir> Map SGA as COW; dirname in double quotes
HANGANALYZE [level] [syslevel] Analyze system hang
FFBEGIN Flash Freeze the Instance
FFDEREGISTER FF deregister instance from cluster
FFTERMINST Call exit and terminate instance
FFRESUMEINST Resume the flash frozen instance
FFSTATUS Flash freeze status of instance
SKDSTTPCS <ifname> <ofname> Helps translate PCs to names
WATCH <address> <len> <self|exist|all|target> Watch a region of memory
DELETE <local|global|target> watchpoint <id> Delete a watchpoint
SHOW <local|global|target> watchpoints Show watchpoints
DIRECT_ACCESS <set/enable/disable command | select query> Fixed table access
CORE Dump core without crashing process
IPC Dump ipc information
UNLIMIT Unlimit the size of the trace file
PROCSTAT Dump process statistics
CALL [-t count] <func> [arg1]...[argn] Invoke function with arguments
SYS@PROD>
吕星昊
2016.3.27
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29475508/viewspace-2064711/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29475508/viewspace-2064711/