关于Oracle Session的几个知识点

来源:互联网 发布:企业对三农的投资数据 编辑:程序博客网 时间:2024/06/05 08:53

 1)强行终止一个session

    在Oracle中,我们可以通过发出 alter system kill session statement.这样的命令来强行停掉一个session.需要清楚的是:alter system操作并不能立即清除该session直到time out或者用户尝试通过该session再次执行其他的statement的时候,服务进程才会发出ORA-03113 EOF on communication channel or "packet write failure". 这也是为什么当我们kill一个session,长时间在v$session还能看到该session[一般status为KILLED]的信息的缘故.

    如果我们设置了DCD检测,那么系统将会在expiry time 到来的时间就清除该session,同时释放该session占用的locks资源.(immediatly meaning: after the session's rollback)

    当然了,大家也可以通过在OS一级发出kill命令来停止一个session.

    比如在aix下,我们通过v$session,v$process两个视图关联得到某个session对应的服务端的process ID,然后在 CMD下,执行 kill -9 processid

    在windows下,可以通过orakill命令在停止一个process

    备注:如果数据库上有logoff trigger之类的系统trigger,it won't be executed for the killed session.

    2)session对应的进程  

If a session belongs to a foreground process, it has v$session.type = 'USER'.If it belongs to a background process, it has v$session.type = 'BACKGROUND'.

    常见的后台进程

    background processes
    SMON
    The System Monitor carries out a crash recovery when a crashed insance is started up again. It also cleans temporary segments.
    PMON
    The Process Monitor checks if a user process fails and if so, does all cleaning up of resources that the user process has aquired.
    DBWR
    The Database Writer writes dirty blocks from the database buffer to the datafiles. How many DBWn Processes are started is determined by the initialization parameter DB_WRITER_PROCESSES. DBWR also writes the actual SCN with the Block.
    LGWR
    The Log Writer writes the redo log buffer from the SGA to the online redo log file.
    MMAN
    The memory manager
    MRP
    Managed recovery process: the process that applies archived redo log to the standby database.
    RFS
    The remote file server process on the standby database receives archived redo logs from the primary database.
    RECO
    The Distributed Transaction Recovery Process finds pending (distributed) transaction and resolves them.
    CKPT
    The Checkpoint Process reqularly initiates a checkpoint which uses DBWR to write all dirty blocks back to the datafiles, thus synchronizing the database. Since a Checkpoint records the current SCN, in a recovery only redo records with a SCN higher than that of the last checkpoint need to be applied.
    ARCH
    The Archiver Process archives redo log files if ARCHIVELOG is enabled.
    Dnnn
    The Dispatcher Process is used in a shared server environment.
    Snnn
    The Shared Server Process is used in a shared server environment.
    LMON
    The lock manager.
    LMD0
    QMNn
    AQ Time Manager
    TRWR
    Trace writer
    WMON
    The wakeup monitor process.
    LCKnnn
    Inter-instance locking process.
    SNPnnn
    The snapshot process.
    MMON
    New background process in Oracle 10g.
    DMON
    The Data Guard Broker process.
    SNP
    The snapshot process.

    3)通过profile来控制session对资源的使用

    在Oracle中,我们通过profile,可以实现对session的部分资源的使用限制。例如:

sessions per usercpu per sessionmaximum connect timemaximum idle timemaximum block reads per sessionmaximum amount of private SGA......

    比如我们要实现:
    对一个学习用户study,当他的空闲时间超过2分钟后,系统自动断开连接. 那么我们就可以通过使用profiles来完成

SQL> conn /as sysdba已连接SQL> show parameter resource_limit;NAME TYPE VALUE------------------------------------ --------resource_limit boolean TRUESQL> create profile study_profile limit2 idle_time 2;配置文件已创建SQL> alter user study profile study_profile;用户已更改。

    下面我们测试一下:

E:>sqlplus /nologSQL*Plus: Release 9.2.0.1.0 - Production on 星期六 6月 24 19:01:43 2006Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.SQL> conn study/study已连接。SQL> select sysdate from dual;SYSDATE----------24-6月 -06SQL>

    过2分钟我们再尝试执行一个SQL 

SQL> select sysdate from dual; * ERROR 位于第 1 行:ORA-02396: 超出最大空闲时间,请重新连接
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 九五出款被黑18w怎么办 很容易感动伤感哭怎么办 为什么安卓版ps打不开怎么办 遇见职业打假人怎么办 打假投诉极限次怎么办 导师无故留学生要怎么办 孩子24了不争气怎么办 退休工资卡遗失怎么办大同市 天津体育惠民卡怎么办 高跟鞋走路太响怎么办 高跟鞋太响怎么办妙招 穿高跟鞋想开车怎么办 脚瘦穿高跟鞋容易掉怎么办 dq11时装卖了怎么办 廉洁教育手抄报怎么办 做美发口才不好怎么办 月嫂怎么办澳大利亚签证 高一学生叛逆怎么办 和异性说话紧张怎么办 幼儿教师模拟讲课紧张怎么办 静不下心来怎么办 失眠焦虑到极点怎么办 老师罚学生买东西怎么办 大学每晚查寝怎么办 教育机构会计账怎么办 车陂扣12分的话怎么办 公选课挂科怎么办 颈椎疼带头疼怎么办 本科出身不好该怎么办 科研经历不丰富怎么办 拍电影需要一些公共场所怎么办 录屏没有声音怎么办 超星课程里阅读怎么办 微信自动冻结怎么办 微信银行卡冻结怎么办 微信封号了怎么办 微信号冻结不了怎么办 微店没收到货怎么办 系统确认收货了怎么办 ppt加载项没有怎么办 手机视频有杂音怎么办