oracle 会话 死锁 执行sql 执行job的方法

//根据用户分组会话
select t.USERNAME,count(*) from v$session t group by t.USERNAME
//查找某一用户正在执行的sql_id值
select * from v$session t where t.USERNAME = 'BUDGET' and t.SQL_ID is not null
//查找对应sql_id的对应sql语句
select m.SQL_TEXT from v$session t , v$sqlarea m where t.USERNAME ='BUDGET' and t.sql_id = m.SQL_ID
//
select * from v$sqlarea t where t.SQL_ID = 'g92sy7kwt6mrq'
//查询死锁对象
select * from v$locked_object

1、修改Oracle最大连接数的方法

a、以sysdba身份登陆PL/SQL 或者 Worksheet
b、查询目前连接数
show parameter processes;
c、更改系统连接数
alter system set processes=1000 scope=spfile;
d、创建pfile
create pfile from spfile;
e、重启Oracle服务或重启Oracle服务器
2、查询Oracle游标使用情况的方法
select * from v$open_cursor where user_name = 'TRAFFIC';
3、查询Oracle会话的方法
select * from v$session

杀掉会话:

方法一:SQL> SELECT pid,spid FROM V$PROCESS WHERE ADDR IN (SELECT PADDR FROM V$SESSION where username ='SYS');
PID SPID
---------- ------------
17 13657

ps -ef |grep 13657
kill -9 13657

方法二
SQL> SELECT sid,serial# FROM V$SESSION WHERE sid in (SELECT distinct sid FROM V$MYSTAT);
SID SERIAL#

---------- ----------
1637 13894

alter system disconnect session '1637,13894' immediate;
执行这句会提示:ora-00031:标记要终止的会话。。。但是其实执行成功了。
如果用pl/sql登陆客户端那边会提示:ora-00028:您的会话已经被终止。

查看正在执行sql进度:
SELECT SE.SID,OPNAME,TRUNC(SOFAR / TOTALWORK * 100, 2) || '%' AS PCT_WORK,ELAPSED_SECONDS ELAPSED,ROUND(ELAPSED_SECONDS * (TOTALWORK - SOFAR) / SOFAR) REMAIN_TIME,SQL_TEXT
FROM V$SESSION_LONGOPS SL, V$SQLAREA SA, V$SESSION SE
WHERE SL.SQL_HASH_VALUE = SA.HASH_VALUE AND SL.SID = SE.SID AND SOFAR != TOTALWORK
ORDER BY START_TIME

SELECT a.tablespace_name "表空间名",round(total/1024/1024/1024,4) 表空间大小Gb,round(free/1024/1024/1024,4) 表空间剩余大小Gb,
round((total-free)/1024/1024/1024,4) 表空间使用大小Gb,ROUND((total-free)/total,4)*100 "使用率 %"
FROM (SELECT tablespace_name,SUM(bytes) free FROM DBA_FREE_SPACE
GROUP BY tablespace_name ) a,
(SELECT tablespace_name,SUM(bytes) total FROM DBA_DATA_FILES GROUP BY tablespace_name) b
WHERE a.tablespace_name=b.tablespace_name order by 5 desc
 
强制停止oracle正在执行的job:
 
1、查看所有job;
select * from dba_jobs;
2、查看正在运行的job;
select * from dba_jobs_running;
3、根据sid查出对应的session;
select SID,SERIAL# from V$Session where SID='&SID';
4、kill对应的session;
alter system kill session '&SID,&SERIAL';
5、将job置为broken;
exec dbms_job.broken('&JOB',true);
6、sysdba用户权限删除job;
delete from dba_jobs where JOB='&JOB';
---实在无奈时启动数据库

你可能感兴趣的:(oracle 会话 死锁 执行sql 执行job的方法)