Oracle生成过去7天峰值时间段AWR报告

#!/bin/bash

Copyright (c) 2024, 2028, Ziheng Zong.

Author Ziheng Zong.

E-mail 321727043@qq.com.

if [ "$DB_USER" = "" ]; then

DB_USER="/ as SYSDBA"

fi

if [ "$1" = "awr7" ]; then

sqlplus -s /NOLOG << ! | egrep -v "Session altered|Connected|rows selected"

connect $DB_USER

CREATE OR REPLACE DIRECTORY tmpdir AS '/tmp/';

DECLARE

back_days NUMBER := 7;

peak_id NUMBER;

my_dbid NUMBER;

today VARCHAR2(30);

awr_dir VARCHAR2(40) := 'TMPDIR';

awr_file UTL_FILE.FILE_TYPE;

awr_file_name VARCHAR2(60);

BEGIN

SELECT snap_id

INTO peak_id

FROM (SELECT snap_id, average, end_time

FROM dba_hist_sysmetric_summary

WHERE average = (SELECT MAX(average)

FROM dba_hist_sysmetric_summary

WHERE metric_name = 'Average Active Sessions'

AND end_time > SYSDATE - back_days))

WHERE ROWNUM = 1;

SELECT dbid INTO my_dbid FROM v\$database;

SELECT TO_CHAR(SYSDATE, 'YYYY_MON_DD_HH24_MI') INTO today FROM dual;

FOR instance_rec IN (SELECT instance_number, instance_name

FROM gv\$instance) LOOP

awr_file_name := 'awr_' || today || '_' || instance_rec.instance_name ||

'.html';

awr_file := UTL_FILE.FOPEN(awr_dir, awr_file_name, 'w');

FOR curr_awr IN (SELECT output

FROM TABLE(dbms_workload_repository.awr_report_html(my_dbid,

instance_rec.instance_number,

peak_id - 1,

peak_id,

0))) LOOP

UTL_FILE.PUT_LINE(awr_file, curr_awr.output);

END LOOP;

UTL_FILE.FCLOSE(awr_file);

END LOOP;

EXCEPTION

WHEN OTHERS THEN

IF UTL_FILE.IS_OPEN(awr_file) THEN

UTL_FILE.FCLOSE(awr_file);

END IF;

RAISE;

END;

/

!

echo "Generate AWR reports save path is /tmp !";

exit 0

fi

相关推荐
一叶飘零_sweeeet几秒前
MongoDB 基础与应用
数据库·mongodb
猿小喵16 分钟前
DBA之路,始于足下
数据库·dba
tyler_download25 分钟前
golang 实现比特币内核:实现基于椭圆曲线的数字签名和验证
开发语言·数据库·golang
weixin_449310841 小时前
高效集成:聚水潭采购数据同步到MySQL
android·数据库·mysql
Cachel wood2 小时前
Github配置ssh key原理及操作步骤
运维·开发语言·数据库·windows·postgresql·ssh·github
standxy2 小时前
如何将钉钉新收款单数据高效集成到MySQL
数据库·mysql·钉钉
汪小敏同学2 小时前
【Django进阶】django-rest-framework中文文档——快速入门
网络·windows·oracle
Narutolxy3 小时前
MySQL 权限困境:从权限丢失到权限重生的完整解决方案20241108
数据库·mysql
Venchill3 小时前
安装和卸载Mysql(压缩版)
数据库·mysql
Humbunklung3 小时前
一种EF(EntityFramework) MySQL修改表名去掉dbo前缀的方法
数据库·mysql·c#