性能测试常用Oracle语句
显示数据库当前的连接数
select count(*) from v$process;
显示数据库最大连接数:
select value from v$parameter where name =’processes’
修改最大Oracle最大连接数:
alter system set processes = 300 scope = spfile;
显示当前的session连接数;
select count(*) fromv$session
查看当前有哪些用户正在使用数据
SELECT osuser, a.username,cpu_time/executions/1000000||’s’, sql_fulltext,machine from v$session a, v$sqlarea b where a.sql_address =b.address order by cpu_time/executions desc;
查看数据库中SGA:
System global area (SGA),system global area(PGA);
查看连接oracle的所有机器的连接数
selectmachine,count(*) fromv$session groupbymachine;
查看连接oracle的所有机器的连接数和状态
selectmachine,status,count(*) fromv$session groupbymachine,status orderbystatus;
Oracle 11g设置内存自动管理:
ALTERSYSTEM SETMEMORY_TARGET = 1024M SCOPE=SPFILE;
ALTERSYSTEM SETmemory_max_target = 1500M SCOPE=SPFILE;
ALTERSYSTEM SETSGA_TARGET = 0 SCOPE=SPFILE;
ALTERSYSTEM SETSGA_MAX_SIZE=800M SCOPE=SPFILE;
ALTERSYSTEM SETPGA_AGGREGATE_TARGET = 0 SCOPE=SPFILE;
altersystem setpre_page_sga=FALSEscope=spfile;
查看消耗磁盘读取最多的SQL Top 5:
select disk_reads,sql_text,SQL_FULLTEXT
from (select sql_text,disk_reads,SQL_FULLTEXT,
dense_rank() over
(order by disk_reads desc) disk_reads_rank
from v$sql)
where disk_reads_rank <=5;
实例:
通过linux中消耗资源高的进程号获取oracle消耗资源的sql语句:
1、linux中使用top命名查看oracle进程中消耗资源最高的进程号;
2、oracle中使用命令:
select c.spid,a.p1,a.p1raw,a.p2,a.event,b.sql_text,b.SQL_FULLTEXT,b.SQL_ID
from v$session a,v$sql b,v$process c
where a.wait_class<>’Idle’ and a.sql_id=b.sql_id and a.PADDR=c.addr
order by event;
3、查询结果显示出各个sql语句对应的进程号,从中找出top命令中对应消耗资源高的进程号即可找到相应的sql语句。