前言:
如今你们对“oracle删除表统计值”都比较讲究,小伙伴们都需要剖析一些“oracle删除表统计值”的相关知识。那么小编在网络上汇集了一些有关“oracle删除表统计值””的相关资讯,希望同学们能喜欢,大家快快来学习一下吧!概述
This project meant to provide useful scripts for DB maintance and management, to make work easier and interesting...
今天主要分享一个shell脚本,主要是为了统计最消耗CPU资源的SQL语句等..
一、环境准备
1、配置tnsnames.ora
保证别名和ORACLE_SID一致,后面脚本需要
# vim /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora===================================================================MDMDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =xx.xx.65)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = MDMDB) ) )===================================================================
2、测试连接
二、初始化脚本settdb.sh
use script settdb.sh for DB login details registry
输出:
三、turning.sh
统计最近10分钟,最消耗CPU资源的SQL语句、最近30分钟,最消耗IO资源的会话、根据io消耗前十sql的会话id,查出操作系统号并组合杀进程语句
#!/bin/bashecho "========================================查询最近10分钟,最消耗CPU资源的SQL语句================================================="sqlplus -S $DB_CONN_STR@$SH_DB_SID <<EOF set linesize 1000 pages 500prompt CPU in 10mset line 234col sql_text for a70select sql_id, cnt, pctload, substr(sql_text, 1, 70) sql_text from (select ash.sql_id, count(*) cnt, max(s.sql_text) sql_text, max(s.parsing_schema_name) parsing_schema_name, round(count(*) / sum(count(*)) over(), 2) pctload from v\$active_session_history ash, v\$sqlarea s where ash.sql_id = s.sql_id and sample_time > sysdate - 10 / (24 * 60) and session_type <> 'BACKGROUND' and session_state = 'ON CPU' group by ash.sql_id order by count(*) desc) where rownum <= 20;exitEOFecho "========================================查询最近30分钟,最消耗IO资源的会话================================================="sqlplus -S $DB_CONN_STR@$SH_DB_SID <<EOF prompt IO in 30mset line 234col sql_text for a70select session_id, cnt, substr(sql_text, 1, 70) sql_text from (select ash.session_id, count(*) cnt, max(s.sql_text) sql_text, max(s.parsing_schema_name) parsing_schema_name, round(count(*) / sum(count(*)) over(), 2) pctload from v\$active_session_history ash, v\$sqlarea s where ash.sql_id = s.sql_id(+) and sample_time > sysdate - 30 / (24 * 60) and session_type <> 'BACKGROUND' and session_state = 'WAITING' and wait_class = 'User I/O' group by ash.session_id order by count(*) desc) where rownum <= 20;exitEOFecho "========================================根据io消耗前十sql的会话id,查出操作系统号并组合杀进程语句================================================="sqlplus -S $DB_CONN_STR@$SH_DB_SID <<EOF prompt TOPSQL by IOset line 234col sql_text for a70select session_id, session_serial#, cnt, substr(sql_text, 1, 70) sql_text from (select ash.session_id, ash.session_serial#, count(*) cnt, max(s.sql_text) sql_text, max(s.parsing_schema_name) parsing_schema_name, round(count(*) / sum(count(*)) over(), 2) pctload from v\$active_session_history ash, v\$sqlarea s where ash.sql_id = s.sql_id(+) and sample_time > sysdate - 5 / (24 * 60) and session_type <> 'BACKGROUND' and session_state = 'WAITING' and wait_class = 'User I/O' group by ash.session_id, ash.session_serial# order by count(*) desc) where rownum <= 10;exitEOF
输出结果:
后面会分享更多devops和dba方面内容,感兴趣的朋友可以关注下!
标签: #oracle删除表统计值 #oracle删除一条数据的sql语句 #shell脚本运行oracle语句 #oracle sql语句 #oracle最耗资源的sql