ORACLE查看会话的大小及终止会话
一、出现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查看会话的大小及终止会话的更多相关文章
- Oracle 查看表空间大小及其扩展
在ORACLE数据库中,所有数据从逻辑结构上看都是存放在表空间当中,当然表空间下还有段.区.块等逻辑结构.从物理结构上看是放在数据文件中.一个表空间可由多个数据文件组成.系统中默认创建的几个表空间:S ...
- Oracle查看表空间大小
遇到报错 java.sql.SQLException: ORA-01653: 表 MESHIS.HIS_RET_LOT_FQC 无法通过 8 (在表空间 MESHIS_DATA_TBS 中) 扩展 a ...
- ORACLE 查看分区表分区大小
SELECT * FROM dba_segments t WHERE t.segment_name ='table_name'; pratition_name : 分区名 bytes : 分区大小( ...
- Oracle查看表空间大小和使用率
1. 全部表空间的大小select tablespace_name, sum(bytes)/1024/1024 from dba_data_files group by tablespace_name ...
- oracle 查看用户表数目,表大小,视图数目等
查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * fr ...
- 查看Oracle数据库表空间大小(空闲、已使用),是否要增加表空间的数据文件
查看Oracle数据库表空间大小(空闲.已使用),是否要增加表空间的数据文件 1.查看表空间已经使用的百分比 Sql代码 select a.tablespace_name,a.bytes/1024/1 ...
- oracle 查看用户所在的表空间
查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * fr ...
- ORACLE 查看当前用户信息(用户,表视图,索引,表空间,同义词,存储过程,约束条件)
1.用户 查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select ...
- Oracle查看当前用户所在的表空间
1.用户 查看当前用户的缺省表空间 select username,default_tablespace from user_users; 1 查看当前用户的角色 select * from user ...
- oracle查看编码格式及修改
一.查看编码 1.查看oracle数据库编码 命令:select * from nls_database_parameters where parameter ='NLS_CHARACTERSET'; ...
随机推荐
- 2022-04-29内部群每日三题-清辉PMP
1.在一价值200万美元项目的测试阶段,团队发现了一些缺陷.由于截止期限很紧,团队成员承认他们可能无法修复所有缺陷.若要确定应集中哪些工作,项目经理应该使用什么工具或技术? A.帕累托图 B.矩阵图 ...
- iOS开发之桌面快捷方式Quick Actions
长按桌面APPIcon图标快捷操作添加功能开发 在支持 3D Touch 的设备上,Quick Actions 可以让用户更快,更少的操作步骤去完成他们最常做的事情,其中这么多操作可以通过主屏幕直接完 ...
- JQUERY动态的修改<div>样式
首先需要引入JQUERY <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> & ...
- ubuntu测网速speedometer
下载安装speedometer sudo apt-get install speedometer 查询需要测速的网卡 ifconfig 测速 speedometer -rx enp2s0 执行效果图如 ...
- 组件中的data为什么不是一个对象而是一个函数?
组件中的data为什么不是一个对象而是一个函数? 组件是可复用的vue实例,一个组件被创建好之后,就可能被用在各个地方,而组件不管被复用了多少次,组件中的data数据都应该是相互隔离,互不影响的,基于 ...
- uni-app学习笔记之----getCurrentPages()的使用
1.判断是否是首页 如果得到数组元素只有一个,说明是首页 2.得到页面中的信息 得到数组中的第一个元素代表首页,最后一个元素代表当前页
- 如何让公司内网ip映射到公网?
其实这就是端口映射的技术,而端口映射至外网访问2种方法,今天我们来具体谈一谈. 公司内外网互通是网络技术运维人员经常需要面对的问题和需求场景,不管是疫情严重的当下,还是不在公司而又无法快速回公司却又急 ...
- 关键aspNetCore processPath 这一行,耗费了一天
<?xml version="1.0" encoding="UTF-8"?> <configuration> <locatio ...
- 实验1task4
<实验结论> #include <stdio.h> #include <stdlib.h> int main() { int x, t, m; x = 123; p ...
- ipmitool for windows下载网址
ipmitool for windows版本下载网址 http://ipmiutil.sourceforge.net/