Oracle: How to detect client process termination like it works for sqlplus?

我们两清 提交于 2019-12-23 15:40:18

问题


I have the following problem in my application which connects to an Oracle 10g database:

When my client crashes, or the process is terminated via task manager, or the client loses connection for a while, the appropriate entry in the v$session view remains.

Now when I connect to the database with sqlplus, and i kill sqlplus.exe through the task manager, the session entry gets deleted almost instantly.

Latter behaviour would be preferred for my application for various reasons.

What does sqlplus do differently, and can I do it as well in my own application(s)?


回答1:


SQL*Plus uses OCI - Oracle Call Interface. This is an extensive API (over four hundred function calls. OCI provides a lot of methods for handling connections and sessions. I dont know for sure but I would guess that SQL*Plus uses OCILogon2() to register a dedicated session for the user, and puts something in the session handle which allows it to detect when the session ABENDs.

So, probably your application isn't using OCI to connect the database. If you want to know more about OCI you can read the docs. Be warned it's pretty low level stuff! Find out more.




回答2:


You can set sqlnet.expire_time=minutes_to_check in $ORACLE_HOME/network/admin/sqlnet.ora; it won't be instantaneous like oci, but it will clean up dead connections.




回答3:


Further investigation showed that although sqlplus does behave differently when killing the process, in fact it behaves the same way when the network cable is plugged out for a second => The dangling session will stay on the server.

I have now created a user profile with a limited idle_time which is assigned to the users I need. A background thread sends "keepalive" queries to keep the connection from being SNIPED by PMON.

See my other question Oracle: idle_time appears to be ignored if you are interested in what I did and see the answer on what you have to do to make idle_time work.



来源:https://stackoverflow.com/questions/9632894/oracle-how-to-detect-client-process-termination-like-it-works-for-sqlplus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!