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'; ...
随机推荐
- Spring全家桶(一)之Spring总结
0. Spring常用注解汇总 Spring常用注解汇总 使用注解之前要开启自动扫描功能,其中base-package为需要扫描的包(含子包). <context:component-scan ...
- mysql:数据库加解密查询
解密:SELECT CONVERT (AES_DECRYPT(UNHEX( column_name), '密钥') USING utf8) AS column_name,from table_name ...
- make 编译笔记
make 文件位置 默认的make install指令执行之后,会将程序安装到 /usr/local/bin , /usr/local/lib .也可以通过 参数 --prefix 自定义路径,例如 ...
- 【Linux】常用
查看端口占用 yum install lsof lsof -i:8080:查看8080端口占用 lsof abc.txt:显示开启文件abc.txt的进程 lsof -c abc:显示abc进程现在打 ...
- docker部署opengauss
下载二进制包到/opt/software/ wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.1.0/x86/openGauss-1. ...
- Caused by: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
可能是多数据源使用分页pageHelper导致的: 解决方法:https://blog.csdn.net/qq_35378008/article/details/90024365 https://bl ...
- RocketMQ学习笔记
RocketMQ学习笔记 RocketMQ学习参考官网文档:https://github.com/apache/rocketmq/tree/master/docs/cn . 由于RocketMQ是有国 ...
- ASR6601:国产化lora SOC芯片兼容SX1262/SX1268
ASR6601为目前首颗国产化支持LoRaWAN低功耗广域网无线通信SoC芯片.ASR6601在单芯片上集成了通用微控制器和射频单元(SX1262),包括射频收发器,调制解调器和48 MHz 主频.A ...
- npm查询所有可以安装的包
npm view 包名 versions
- linux 的防火墙 ufw、firwalld、iptables 、
防火墙综述 linux 防火墙,常用的包括三种:ufw . firewalld 和 iptables.学习难度依次递增. ufw 因为原生的 iptable 配置麻烦,学习成本较高. ufw全称 Un ...