oracle如何查看进程状态,6.通过会话查看进程号

通过会话查看进程号

我们在日常Oracle维护中,可能有的遇到一个会话处于假死状态或者通过常规命令无法杀死,这时需要直接通过操作系统kill命令来杀死进程,这节就讲述如何通过SID来获取操作系统的进程号。

注意:该功能只支持同时查一个进程号,无论会话是否ACTIVE

开发环境

操作系统:CentOS 7.3

Python版本 :2.7

Django版本: 1.10.5

操作系统用户:oracle

建立页面的步骤

我们还是通过这张图的步骤来说明如何建立页面

d93c60814fc26712b01f636c75369975.png

urls.py页面

首先是monitor/urls.py,这节不需要修改这个文件

urlpatterns = [

url(r'^$', views.index, name='index'),

url(r'^oracle_command/$',views.oracle_command, name='oracle_command'),

url(r'^commandresult/$',views.commandresult, name='commandresult'),

]

oracle_command为执行Oracle命令的页面

commandresult为执行完Oracle命令显示结果的页面

views.py

下面为commandresult对应的函数在views.py里面的写法

elif command_content=='check_session_process':

try:

db = cx_Oracle.connect(username+'/'+password+'@'+ipaddress+':'+port+'/'+tnsname ,mode=cx_Oracle.SYSDBA)

except Exception , e:

content= (ipaddress+' is Unreachable,The reason is '+ str(e)).strip()

return HttpResponse(content)

else:

sid = str(request.GET['sql'])

cursor = db.cursor()

row=getprocessno(cursor,sid)

cursor.close()

db.close()

title='数据库进程号-'+ipaddress+'-'+tnsname+':'

dic ={'title':title,'row':row}

return render_to_response('oracle_command_result_1.html',dic)

首先获取到表单中的数据,如 ipaddress,tnsname以及执行的命令

然后通过ipaddress,tnsname从oraclelist数据库中查找获得用户名密码用于连接

再判断命令内容,如果是check_session_process

则首先获取SID

在执行函数getprocessno通过SID获取对应的进程号,详情看具体代码

最后把页面的标题以及表格的数据放到dic变量中传到

oracle_command_result_1.html模板文件中

getprocessno函数

这里的getprocessno函数通过SID获取操作系统进程号,详情看具体代码

monitor/command/getoraclecommandresult.py

def getprocessno(cursor,sid):

fp1='select pro.spid from v$session ses,v$process pro where ses.sid='+sid+' and ses.paddr=pro.addr'

s=cursor.execute(fp1)

row=s.fetchone()

if row is None:

return 'None'

else:

return row[0]

template文件

这里我们使用oracle_command_result_1.html文件来显示

oracle_command_result_1.html

{{title}}{{row}}

该模板就是一行文字,通过将传过来的变量显示在前端页面

实际效果

该功能只支持同时查一个进程号

http://10.65.202.218:8081/monitor/oracle_command/

a2221ee96b66d0c32133e39c0c4c3505.png

源码地址

源码请查看我的GitHub主页

下期将介绍如何如何通过Django获取Oracle临时文件的使用率并在前端显示

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值