selectvaluefrom gv$parameter where name ='processes';
查询当前数据库的资源限制
select*from gv$resource_limit;
查询当前数据库的锁表语句
select b.owner, b.object_name, a.session_id, a.locked_mode
from gv$locked_object a, dba_objects b
where b.object_id = a.object_id;
查询当前数据库的锁表程序
select b.owner,
b.object_name,
a.session_id,
c.machine,
c.osuser,
c.process,
c.program,
a.locked_mode,
c.client_info
from gv$locked_object a, dba_objects b, gv$session c
where b.object_id = a.object_id
and a.session_id = c.sid;
生成强制解锁语句
select'alter system kill session '''|| SID ||','||SERIAL# || ''';',
lo.oracle_username,
lo.os_user_name,
ao.object_name,
lo.locked_mode
from gv$locked_object lo, dba_objects ao, gv$session sess
where ao.object_id = lo.object_id
and lo.session_id = sess.sid;
查询单个进程所占的会话数
select s.machine,
s.client_info,
s.process,
s.program,
s.username,count(*) count
from gv$session s
where s.program ='<进程名称>'groupby s.machine, s.client_info, s.process, s.program, s.username
orderby count desc;
查询每台服务器进程占用的总会话数
select s.machine, s.client_info,count(*) count
from gv$session s
where s.program ='<进程名称>'groupby s.machine, s.client_info
orderby count desc;
查询进程服务占的总会话数
selectcount(*) count
from gv$session s
where s.program ='<进程名称>';
查询当前数据库查询次数最多的SQL语句
select*from(select s.sql_text,
s.executions "执行次数",
s.parsing_user_id "用户名",
rank()over(orderby executions desc) exec_rank
from v$sql s
leftjoin all_users u
on u.user_id = s.parsing_user_id) t
where exec_rank <=100;
查询当前数据库执行查询最慢的前50条语句
select*from(select sa.SQL_TEXT,
sa.SQL_FULLTEXT,
sa.EXECUTIONS "执行次数",round(sa.ELAPSED_TIME /1000000,2)"总执行时间",round(sa.ELAPSED_TIME /1000000/ sa.EXECUTIONS,2)"平均执行时间",
sa.COMMAND_TYPE,
sa.PARSING_USER_ID "用户ID",
u.username "用户名",
sa.HASH_VALUE
from v$sqlarea sa
leftjoin all_users u
on sa.PARSING_USER_ID = u.user_id
where sa.EXECUTIONS >0orderby(sa.ELAPSED_TIME / sa.EXECUTIONS)desc)where rownum <=50;
查询表的数据条数、表名、中文表名
select a.num_rows, a.table_name, b.comments
from user_tables a, user_tab_comments b
where a.table_name = b.table_name
orderby table_name;
查询当前数据库中单表数据大约10万条的所有表
select table_name, num_rows
from user_tables
where num_rows >=100000orderby num_rows desc;