`
venceinfo
  • 浏览: 38213 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

转载一篇

阅读更多

sure you are all familiar with this situation:

SQL> alter system kill session '152,33';
alter system kill session '152,33'
*
ERROR at line 1:
ORA-00031: session marked for kill

The session trying to issue the kill will hang for 60 seconds and then return this “session marked for kill” message. And the target session does not get killed at all.

So why is that?

The issue is in what this alter system kill command is doing. It’s not actually killing the target session (like kill -9 would do for OS processes). It just sets a bit in the target sessions state object, which marks that the target session should end. But its entirely up the target session to check this bit and act on it!

So, intead of ALTER SYSTEM KILL SESSION, the command should look something like ALTER SYSTEM ASK SESSION TO COMMIT SUICIDE.

All the kill session command is doing is ASK the target session to clean up and exit – via setting that bit.

Now, normally the target sessions are nice and check that bit often enough in their code, act on it and die.

But sometimes when the target session happens to be busy looping in some tight loop (due a bug perhaps) or is hung, then it never gets to check that “please die” bit and never exits.

 

This is why DBAs often need to kill the OS process or thread via OS tools to get rid of that session (and its locks, transactions) as when you kill the OS process, PMON will detect it (if not fast enough then it can be woken up via ORADEBUG WAKEUP call few times) and clean up after that session.

So, the “ORA-00031: session marked for kill” message you see after 60 seconds just means that:

1) Your session sets the “please die” bit in target sessions state object

2) Your session waits the target session to die for 60 seconds and times out after it doesn’t happen

3) Your session returns “session marked for kill” error – which means exactly what I wrote in step 1 above (“please die” bit is set)

By the way, if your session waits for the target session to die – what is the wait event you are waiting on then? Every wait, except few bugs, should be instrumented in Oracle.

This is easy to test, run this for example:

SQL> exec dbms_lock.sleep(100)

And immediately after try to kill that sleeping session from your session (in my case my session which issued the alter system kill command was 146). Lets see what it waits for:

SQL> @sw 146

 SID STATE   EVENT                                          SEQ# SEC_IN_WAIT                 P1
------- ------- ---------------------------------------- ---------- ----------- ------------------
 146 WAITING inactive session                                140           3                152

See, the killer waits for inactive session event. The parameter 1 (P1) is 152. What does that mean?

V$EVENT_NAME (or V$SESSION_WAIT itself) gives you the answer. I will run my show event descriptions script to display that events parameter meaning:

SQL> @sed "inactive session"

EVENT# EVENT_NAME                                              PARAMETER1           PARAMETER2
------ ------------------------------------------------------- -------------------- ---------------
296 inactive session                                        session# waited

SQL>

So, the killer waits for inactive session wait for 60 seconds and then times out. If the target session to be killed ever checks that “please die” bit, it will clean up and exit, otherwise it could be stuck forever!

This is the case when you need to log on to the server and kill the target process from OS level. If you can’t log on to target OS for whatever reason (but still have SYSDBA access) then you could try attaching to target process with oradebug and running ORADEBUG EVENT IMMEDIATE CRASH as I’ve explained here.

My preferred approach for killing sessions usually is:

1) of course – verify whether you’re killing the right session first

2) ALTER SYSTEM KILL SESSION

3) If that doesn’t work immediately then check whether the target session has acknowledged the kill and is rolling back its (large) transaction. You can do this by checking V$TRANSACTION.USED_UREC for that session’s transaction (if it has any) and see if its decreasing. If yes, the transaction is rolling back and we just need to wait it to finish. There’s also a bit in V$TRANSACTION which states whether the transaction is rolling back, but I don’t have my notes available right now (I’m on vacation actually :)

4) If there’s no rollback happening and session just seems to be stuck, then its time to kill that session’s process from OS level.

5) If couple of minutes after killing the process from OS level that sessions and its locks & resources are still not released (remember, we have verified that there was no long transaction rollback happening) then I would attach to my own process with oradebug and run “ORADEBUG WAKEUP 2″ couple of times (and checking if the session has gone + waiting few seconds between each invocation). The “2″ here means Oracle PID of PMON process which is usually 2, but you should check it from your V$PROCESS view.

If the session is still not gone, it’s time to open a support request.

Note that I didn’t post all the little details here – for example, before killing a problem process which is stuck it makes sense to gather some diagnostic data first (like run pstack on the problem process few times to get its current stack trace).

分享到:
评论

相关推荐

    dvb teletext标准&参考代码

    文件"转载一篇PSI-SI 分析的好文 — Windows Live.mht"可能提供了有关节目和系统信息(PSI-SI)的深入分析,这对于理解如何在DVB系统中定位和解析Teletext数据至关重要。而"Teletext简介(一) -- defish's Blog.mht...

    手把手教你在CSND中怎么样去转载别人的文章(2020最新版)

    这篇教程将带你了解如何在CSDN(China Software Developer Network)这个知名的中文IT技术社区中,优雅地转载一篇文章。 首先,理解转载的道德规范至关重要。在互联网上,尊重原创是基本的原则。当你发现一篇有价值...

    回归测试概念和策略

    转载一篇关于回归测试的概述,这篇文章从回归测试的基本概念定义、回归测试的测试策略包  回归测试做为测试中最重要,同时也是最复杂的一种测试类型。一直都是大家关注的焦点。转载一篇关于回归测试的概述,这篇...

    IOS 开发中画扇形图实例详解

    我们知道了这个方法,就可以在自定义UIView的子类的- (void)drawRect:(CGRect)rect里面绘图了,关于drawrect的调用周期,网上也是一找一大堆,等下我会整理一下,转载一篇供你们参考。 废话少说,下面直接开始代码...

    jquery validate.js表单验证的基本用法入门

    这里转载一篇前辈写的文章,在我自己的理解上修改了一下,仅作记录。 先贴一个国内某大公司的代码: 代码如下: [removed] function lang(key) { mylang = { ‘ls_input_myb’: ‘请输入您的账户’, ‘ls_myb_email’...

    .net,c#,c++,vc.net ,vc 诸多名词的区别与联系

    许多初学者对.net,c#,c++,vc.net ,vc 还不够了解,常常有人问我它们之间有什么区别,那个最好,那个最……等等,现在我转载一篇文章,希望对初学者有所帮助。pdf文件 .net,c#,c++,vc.net ,vc 区别与联系 QQ223857666...

    双系统资料(linux和windows)

    这里拥有你要双系统资料,建议您先安装WINDOWS...转载一篇文章供您参考(因条件有限,不能进行认证,请您自行探索修改LINUX选项的方法): boot.ini 文件是个启动引导程序文件,装多系统或者重装系统的时候会用到它

    转载协议实用.pdf

    在IT行业中,转载协议是指当一篇作品被转载或者分发到其他媒体平台时,原作者和转载方之间所约定的规则和条件。这些规则可能包括但不限于以下内容: 1. 转载授权:这是转载协议的核心部分,涉及原作者是否授权他人...

    javascript定时保存表单数据的代码

    (忘记是不是两家邮箱都有这...,我将在文章最后转载一篇介绍它的文章。 现在,我直接上例子,所谓无代码,无真相嘛: 代码如下: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.

    博客积分获取(转载)

    2、每发布一篇转载文章:可获得2分; 3、博主的文章每被评论一次:可获得1分; 4、每发表一次评论:可获得1分(自己给自己评论、博主回复评论不获得积分); 5、博文阅读次数每超过100次:可获得1分,阅读...

    桥式转载机转弯装置研究与应用

    综上所述,这篇文章是关于煤矿中桥式转载机转弯装置的研究与应用,涵盖了煤矿生产效率的提升、设备设计优化、工业应用推广等多方面的知识点,同时展示了工程技术分析和仿真工具在现代煤矿设备中的重要作用。

    RAR旧一篇: WINCE 注册表编辑器

    WINCE打印完美解决方案 以Photosmart 385 照片打印机为例收藏 ... | 旧一篇: WINCE 注册表编辑器 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/tayosoft/archive/2007/07/12/1686160.aspx

    Struts2 Tiles 配置篇 转载

    这篇文章将深入探讨Struts2与Tiles的集成配置及其相关知识点。 首先,理解Tiles的核心概念至关重要。Tiles允许开发者定义模板(template),这些模板可以被视为页面布局的组成部分。通过将内容插入到这些模板中,...

    网络转载传播实证分析与DSCCA模型研究.pdf

    本文通过对新浪名人博客、人民网新闻等五个网站343篇文章一个月内的84674条转载记录进行深入研究,揭示了网络转载的一些关键特性。研究表明,小众化网站的转载速度最快,博客类网站的平均转载周期最长。同时,转载...

    如何一键转载好文章到QQ空间.docx

    当我们遇到一篇有价值的文章时,常常希望能够将其分享到自己的社交平台上,以便让更多人受益。QQ空间作为国内非常流行的社交平台之一,提供了一键转载的功能,帮助用户轻松实现文章的分享。 #### 二、一键转载到QQ...

    浅析如何编辑出一篇成功的软文.pdf

    软文不仅有助于推广网站,还可以通过被广泛转载获得高质量的外部链接,这对于SEO优化至关重要。因此,无论是网站编辑还是SEO专家,都需要掌握撰写成功软文的技巧。 首先,准备是关键。在动笔之前,必须深入理解你...

    转载牛人文章学习

    iteye.com是一个知名的IT技术交流平台,博主Jason Gang在这里发布了一篇博客,编号为971134。通常,这样的博客会涵盖软件开发、编程技巧、问题解决等方面,尤其是Android平台的相关技术。遗憾的是,由于这是一个虚构...

    输送系统转载溜槽工艺设计

    综上所述,转载溜槽工艺设计是一项复杂的工程任务,需要综合考虑多个技术因素,并利用现代工程技术和管理方法来确保设计的合理性和经济性。同时,对于不同行业和场景的特定要求,设计者还需要进行针对性的分析和优化...

Global site tag (gtag.js) - Google Analytics