一、出现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. JavaSE 日期时间类整理

    一.创建日期对象 1.创建日期对象 //1.直接创建日期 Date date1 = new Date(); //2.创建指定日期 使用Date类 目标 2000-5-10 Date date2 = n ...

  2. C++ 手动创建二叉树,并实现前序、中序、后序、层次遍历

    二叉树的创建是个麻烦事,我的思路是:首先将一个普通的二叉树转化为满二叉树,其中的空节点用一些标识数据来代替,如此一来,就可以用数组索引来描述数据在二叉树的什么位置了. 比如,数组[2,4,3,1,5, ...

  3. 前端下载csv文件

    var str = [ 'ssssssssssssssssssssssssssssssssssssssss' ]; var uri = 'data:text/csv;charset=utf-8,%EF ...

  4. 以EEPROM为例的硬件IIC的使用

    目录 参考调试MPU6050与EEPROM的经验,整合了目标内存/寄存器地址是否为16位的情况,合并了单字节与多字节间的操作,添加了返回值与读写超时功能:硬件IIC的7位从机地址查询方式读写参考代码 ...

  5. redis sentinel 部署

    redis sentinel 部署 服务器说明 192.168.2.200 master redis-server redis-sentinel 192.168.2.201 slave1 redis- ...

  6. Burp学院-信息泄露

    1.Information disclosure in error messages错误消息中的信息泄露 GET /product?productId=1 发送到Repeater. 修改product ...

  7. [记] OpenCV4 源码编译安装 | 记录

    OpenCV4 源码编译安装 | 记录 参考资料 官方文档:https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html 环境 wsl2 ...

  8. Spring入门之使用 spring 的 IOC 解决程序耦合(Spring 基于 XML 的 IOC 细节[掌握])(03-02)

    3.3Spring 基于 XML 的 IOC 细节[掌握] 3.3.1 spring 中工厂的类结构图 3.3.1.1 BeanFactory 和 ApplicationContext 的区别 Bea ...

  9. python_lib_x_1000_file_csv.py

    #!/usr/bin/python # -*- coding: UTF-8 -*- from lib_config import * from lib.lib_x_0002_decorator_log ...

  10. 实验1task1

      <实验结论> #include <stdio.h> #include <stdlib.h> int main() { printf(" O \n&qu ...