SQL常用语句

清空共享内存 :alter system flush shared_pool

下面的SQL查询占用share pool 内存大于10m的sql;

select substr(sql_text,1,100) "stmt",count(*) ,sum(sharable_mem),sum(users_opening),sum(executions) from v$sql group by substr(sql_text,1,100) having sum(sharable_mem)>10000000;

查询share pool的空闲内存;

select a.* ,round(a.bytes/1024/1024,2) M from v$sgastat a where a.name='free memory';

查询version count过高的语句

select address,sql_id,hash_value,version_count,users_opening,users_executing,sql_text from v$sqlarea where version_count>10;

获取PGA,SGA使用情况:

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 vsga) total,(select sum(bytes/1024/1024) from vsgastat 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 vpgastat where name='aggregate PGA target parameter')total,(select value/1024/1024 used from vpgastat where name='total PGA allocated')used from dual);

获取shared pool 使用情况;

select name ,round(total,2) total,round((total-free),2) used,round(free,2) free,round((total-free)/total*100,2) pctused from(select 'Shared pool' name,(select sum(bytes/1024/1024) from vsgastat where pool='shared pool') total, (select bytes/1024/1024 from vsgastat where name='free memory' and pool='shared pool')free from dual)

查询使用频率最高的5个查询sql;

select sql_text,executions from (select sql_text,executions,rank() over (order by executions desc) exec_rank from v$sql) where exec_rank <=5;

查看cpu使用率最高的sql;

select * from (select sql_text,sql_id,cpu_time from v$sql order by cpu_time desc) where rownum<=10 order by rownum asc;

消耗磁盘最多的5个sql;

select disk_reads,sql_text from (select sql_text,disk_reads,dense_rank() over (order by disk_reads desc) disk_reads_rank from v$sql) where disk_reads_rank<=5;

找出需要大量缓冲读取操作的查询:

select buffer_gets,sql_text from (select sql_text,buffer_gets,dense_rank() over (order by buffer_gets desc) buffer_gets_rank from v$sql) where buffer_gets_rank<=5;

查询数据字典缓存的命中率和缺失率;

select round(((1-sum(getmisses)/(sum(gets)+sum(getmisses))))*100,3) "HR" ,round(sum(getmisses)/sum(gets)*100,3) "MR" from v$rowcache where gets+getmisses>0;

相关推荐
TDengine (老段)6 分钟前
TDengine IDMP 十大实用功能(9)
大数据·数据库·人工智能·物联网·时序数据库·tdengine·idmp
starrocks_stella1 小时前
EMR Serverless StarRocks Object Table:用 SQL 连接 OSS 文件与多模态 AI
数据库
这个DBA有点耶1 小时前
以为自增ID只是有空洞?聊聊双主架构下无声的“数据覆盖”
数据库·mysql·dba
钱栈up2 小时前
内网全断,怎么核实高炉和烧结系统的数据库对接信息
数据库
weavecodes2 小时前
双层缓存与权限实时生效:织码在线教育系统的 Caffeine + Redis 设计
数据库
bksczm3 小时前
InnoDB 页结构详解:页类型、页头页尾、数据行与页目录
数据库·mysql
bksczm3 小时前
InnoDB 行格式详解:DYNAMIC / COMPACT / COMPRESSED / REDUNDANT
java·开发语言·数据库
字节跳动开源4 小时前
OpenViking连接业务系统,LLM Wiki一键编译
数据库·开源
进击的荆棘4 小时前
MySQL——数据库基础
数据库·mysql
Decay__5 小时前
22_MySQL 运维自动化平台 —— 部署编排 + 监控 + 巡检 + 告警 + 工单闭环一体化
运维·数据库·sql·mysql·架构