一、出现PGA不足时,我们可以查看用户会话大小,结束相应会话

方法一

Select Server, Osuser, Name, Value / 1024 / 1024 Mb, s.Sql_Id, Spid, s.*
From V$session s, V$sesstat St, V$statname Sn, V$process p
Where St.Sid = s.Sid
And St.Statistic# = Sn.Statistic#
And Sn.Name Like 'session pga memory'
And p.Addr = s.Paddr
Order By Value Desc;

方法二

也可以通过下面语句模糊查询

select sid,serial#,username,status,osuser,machine,action from v$session where username like '%TEST%'

二、我们在停机时间停库或者drop用户时经常会遇到如下情况

SQL>drop user test

drop user test

*

ERROR at line 1:

ORA-01940:cannot drop a user that is currently connected

2.终止会话 kill session

alter system kill session 'sid,serial#';

3.终止会话 disconnect session

用法:

alter system disconnect session 'sid,serial#' immediate ;(立即断开用户session,未完成的事务自动会滚。)

alter system disconnect session 'sid,serial#' post_transaction;(事务断开用户session,等待未完成的事务提交后(commit后),断开连接。)

sid(会话ID)和serial#(session序列号)位置填写查询出该用户对应的数值

区别:有的时候我们会遇到会话kill不掉,可以尝试disconnect session

SQL> alter system kill session '137,7818';

alter system kill session '137,7818'

*

ERROR at line 1:

ORA-00031: session marked for kill

SQL> select status,event from v$session where sid = 137;

STATUS   EVENT

-------- ----------------------------------------------------------------

KILLED   SQL*Net more data from dblink

SQL>  select object_id,locked_mode,session_id from v$locked_object;

OBJECT_ID LOCKED_MODE SESSION_ID

---------- ----------- ----------

165           3        137

104489           3        137

212           3        137

SQL> select TYPE,LMODE,REQUEST,BLOCK from v$lock where sid=137;

TY      LMODE    REQUEST      BLOCK

-- ---------- ---------- ----------

JQ          6          0          0

JI          6          0          0

TM          3          0          0

TM          3          0          0

TM          3          0          0

TX          6          0          0

SQL> select t.status, s.status from v$transaction t, v$session s where s.taddr = t.addr and s.sid=137;

STATUS           STATUS

---------------- --------

ACTIVE           KILLED

该session已经被标志为killed,但是其对应的transaction依旧为active,且对应的lock没有被释放;

又因为该instance由其他OS用户启动,当前登录的用户没有权限执行kill -9

ora_10@justin_$ ps -ef | grep 15616

ora_xxx 15616     1  0   Jul 06 ?        0:22 ora_j001_GLIMSP

ora_10  20035 17648  0 08:23:18 pts/7    0:00 grep 15616

ora_10@justin_$ kill -9 15616

kill: 15616: permission denied

不是太清楚到底发生了什么事情,但此时可使用disconnect session,请参考以下解释

The KILL SESSION command doesn’t actually kill the session. It merely asks the session to kill itself. In some situations, like waiting for a reply from a remote database or rolling back transactions, the session will not kill itself immediately and will wait for the current operation to complete. In these cases the session will have a status of “marked for kill”. It will then be killed as soon as possible.

The ALTER SYSTEM DISCONNECT SESSION syntax as an alternative method for killing Oracle sessions. Unlike the KILL SESSION command which asks the session to kill itself, the DISCONNECT SESSION command kills the dedicated server process (or virtual circuit when using Shared Sever), which is equivalent to killing the server process from the operating system. The basic syntax is similar to the KILL SESSION command with the addition of the POST_TRANSACTION clause. The SID and SERIAL# values of the relevant session can be substituted into one of the following statements.

The POST_TRANSACTION clause waits for ongoing transactions to complete before disconnecting the session, while the IMMEDIATE clause disconnects the session and ongoing transactions are recovered immediately.

http://fatihacar.com/blog/show-and-kill-transaction-lock-in-oracle/

SQL> alter system disconnect session '137,7818' immediate;

System altered.

SQL> select serial#,status,event from v$session where sid=137;

SERIAL# STATUS

---------- --------

EVENT

----------------------------------------------------------------

7822 ACTIVE

jobq slave wait

SQL> alter system disconnect session '137,7822' immediate;

System altered.

SQL> select serial#,status,event from v$session where sid=137;

no rows selected

SQL> select object_id,locked_mode,session_id from v$locked_object;

OBJECT_ID LOCKED_MODE SESSION_ID

---------- ----------- ----------

165           3        132

104489           3        132

212           3        132

SQL> select serial#,event,status,sql_id from v$session where sid=132;

SERIAL# EVENT

---------- ----------------------------------------------------------------

STATUS   SQL_ID

-------- -------------

24231 jobq slave wait

ACTIVE

SQL> alter system disconnect session '132,24231' immediate;

System altered.

SQL> select object_id,locked_mode,session_id from v$locked_object;

no rows selected

--此时session被彻底清除,对应的lock

也已释放

ORACLE查看会话的大小及终止会话的更多相关文章

  1. Oracle 查看表空间大小及其扩展

    在ORACLE数据库中,所有数据从逻辑结构上看都是存放在表空间当中,当然表空间下还有段.区.块等逻辑结构.从物理结构上看是放在数据文件中.一个表空间可由多个数据文件组成.系统中默认创建的几个表空间:S ...

  2. Oracle查看表空间大小

    遇到报错 java.sql.SQLException: ORA-01653: 表 MESHIS.HIS_RET_LOT_FQC 无法通过 8 (在表空间 MESHIS_DATA_TBS 中) 扩展 a ...

  3. ORACLE 查看分区表分区大小

    SELECT *  FROM dba_segments t WHERE t.segment_name ='table_name'; pratition_name : 分区名 bytes : 分区大小( ...

  4. Oracle查看表空间大小和使用率

    1. 全部表空间的大小select tablespace_name, sum(bytes)/1024/1024 from dba_data_files group by tablespace_name ...

  5. oracle 查看用户表数目,表大小,视图数目等

    查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * fr ...

  6. 查看Oracle数据库表空间大小(空闲、已使用),是否要增加表空间的数据文件

    查看Oracle数据库表空间大小(空闲.已使用),是否要增加表空间的数据文件 1.查看表空间已经使用的百分比 Sql代码 select a.tablespace_name,a.bytes/1024/1 ...

  7. oracle 查看用户所在的表空间

    查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * fr ...

  8. ORACLE 查看当前用户信息(用户,表视图,索引,表空间,同义词,存储过程,约束条件)

    1.用户 查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select ...

  9. Oracle查看当前用户所在的表空间

    1.用户 查看当前用户的缺省表空间 select username,default_tablespace from user_users; 1 查看当前用户的角色 select * from user ...

  10. oracle查看编码格式及修改

    一.查看编码 1.查看oracle数据库编码 命令:select * from nls_database_parameters where parameter ='NLS_CHARACTERSET'; ...

随机推荐

  1. SpringBoot 自定义启动的logo(即banner)

    1.自定义输出banner样式 推荐生成网站 http://patorjk.com/software/taag/ https://www.bootschool.net/ascii-art 2.配置 A ...

  2. 靶场练习2:cloudantvirus

    靶场链接 https://www.vulnhub.com/entry/boredhackerblog-cloud-av,453/ 信息收集 练习1用了arp-scan,这种工具有可能会被防火墙流量监测 ...

  3. Newtonsoft.Json高级用法--转载至 焰尾迭 随笔

    本人只做搬运工,以这方便自己学习的态度!以下内容均为拷贝! 如有不适请联系本人! 本文原作者:焰尾迭 本文地址:http://www.cnblogs.com/yanweidie/p/4605212.h ...

  4. 【RTOS】RTOS汇编入门 (1)

    引言 为了提高效率,进行更为底层的操作,RTOS常采用汇编语句,因此了解常用的汇编语句,很有必要 汇编指令 1..equ:类似于c中的#define,表声明常量 例如:.equ PSW 0x10000 ...

  5. Selenium私房菜系列9 -- Selenium RC服务器命令行参数列表【VV】

    使用示例: java -jar selenium-server.jar [-interactive] [options] -port <nnnn>: selenium服务器使用的端口号(默 ...

  6. 使用Wireshark完成实验3-IP

    1.使用Wireshark打开ip-ethereal-trace-1,如图 电脑IP地址为192.168.1.102 2.如图,IP包头中上层协议字段的值为1,代表为ICMP 3.如图,IP头中有20 ...

  7. python生成一个WAV文件的正弦波

    import numpy as np import matplotlib.pyplot as plt T = 1.0 / sample_rate #周期 x = np.arange(0, 1.0, T ...

  8. Linux 第五节(特殊权限,隐藏权限,SU,SUDO,FHS文件系统层次化标准)

    特殊权限 SUID  执行者临时获取命令的所有权限(对程序进行设置) SGID  目录内新文件所有组,继承原有目录所有组的名称 SBID  粘滞位,保护位 chmod +权限  文件 chmod   ...

  9. Redis的不同客户端对比

    Redis 官方推荐的 Java 客户端有Jedis.lettuce 和 Redisson 客户端 简介 优点 缺点 Jedis 提供了比较全面的 Redis 操作 Jedis 简单全面, 支持 pi ...

  10. PHP 静态延迟绑定 static

    PHP (self static parent 区别) self调用的方法和属性始终表示当前类的方法和属性 static调用的方法和属性为当前执行的类的方法和属性 parent调用的方法和属性为父类的 ...