Oracle中常用的语句

1.查询锁表

SELECT a.object_name,b.session_id,c.serial#,c.program,c.username,c.command,c.machine,c.lockwait FROM All_Objects a,
v$locked_object b , v$session c WHERE a.object_id=b.object_id AND c.sid=b.session_id;

 

2.查询运行中的进程(存储过程)

select   b.sid,b.SERIAL#,a.OBJECT, 'alter system kill session   ' || '''' || b.sid || ',' ||b.SERIAL# ||  ''';' kill_command
               from   SYS.V_$ACCESS a, SYS.V_$session b
               where    a.type = 'PROCEDURE'
                  and   (a.OBJECT like upper('%PROCEDURE_NAME%') or
                            a.OBJECT like lower('%PROCEDURE_NAME%'))
                 and a.sid = b.sid
                 and b.status = 'ACTIVE';
备注:其中把要查询的存储过程名替换SQL中的PROCEDURE_NAME,查询后可以复制kill_command新建命令行窗口,在命令行窗口中运行语句,来结束进程。Tips:在plsql中可以点击字段kill_command复制所有语句。

 

3.锁被未决分布式事务处理 x.x.xxxxxx 持有--解决方案(有待验证)

        rollback force '980.3.16843567'; ---执行的可能会有些慢
        --执行完成后,查询DBA_2PC_PENDING,
        select * from DBA_2PC_PENDING s  where s.local_tran_id='980.3.16843567';
        select * from DBA_2PC_PENDING;

 

4.查询数据库中内存使用率

select name,total,round(total-free,2) used, round(free,2) free,round((total-free)/total*100,2) pctused from 
(select 'SGA' name,(select sum(value/1024/1024) from v$sga) total,
(select sum(bytes/1024/1024) from v$sgastat where name='free memory')free from dual)
union
select name,total,round(used,2)used,round(total-used,2)free,round(used/total*100,2)pctused from (
select 'PGA' name,(select value/1024/1024 total from v$pgastat where name='aggregate PGA target parameter')total,
(select value/1024/1024 used from v$pgastat where name='total PGA allocated')used from dual);

 SGA:System Global Area是Oracle Instance的基本组成部分,在实例启动时分配;系统全局域SGA主要由三部分构成:共享池、数据缓冲区、日志缓冲区。
 PGA:Process Global Area是为每个连接到Oracle database的用户进程保留的内存。

posted @ 2019-03-06 20:49  Cloverll  阅读(463)  评论(0编辑  收藏  举报