大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说【ORACLE】自动产生AWR报告,希望您对编程的造诣更进一步.
1. LINUX系统下:
##sh脚本,sh脚本调用sql脚本 #!/bin/bash if [ -f ~/.bash_profile ]; then source ~/.bash_profile fi export AWR_CMD=/home/oracle/awr export AWR_DIR=/home/oracle/awr/report RETENTION=31 # ---------------------------------------------- # Generate awr report # ---------------------------------------------- $ORACLE_HOME/bin/sqlplus / as sysdba<<EOF @${AWR_CMD}/autoawr.sql; exit; EOF exit
##sql脚本
代码100分
SET ECHO OFF;
SET VERI OFF;
SET FEEDBACK OFF;
SET TERMOUT ON;
SET HEADING OFF;
VARIABLE dbid NUMBER;
VARIABLE inst_num NUMBER;
VARIABLE bid NUMBER;
VARIABLE eid NUMBER;
代码100分
BEGIN
SELECT MIN (snap_id) INTO :bid FROM dba_hist_snapshot WHERE TO_CHAR (end_interval_time, ‘yyyymmdd hh24‘) > TO_CHAR (SYSDATE-2/24, ‘yyyymmdd hh24‘);
SELECT MAX (snap_id) INTO :eid FROM dba_hist_snapshot WHERE TO_CHAR (end_interval_time, ‘yyyymmdd hh24‘) > TO_CHAR (SYSDATE-2/24, ‘yyyymmdd hh24‘);
SELECT dbid INTO :dbid FROM v$database;
SELECT instance_number INTO :inst_num FROM v$instance;
END;
/
set pagesize 0;
set linesize 121;
代码100分
COLUMN report_name NEW_VALUE report_name NOPRINT;
SELECT instance_name || ‘_awrrpt_‘ || instance_number || ‘_‘ || c.timestamp ||‘_‘ || b.timestamp || ‘.‘ || ‘html‘
report_name
FROM v$instance a,
(SELECT TO_CHAR (end_interval_time, ‘yyyymmdd_HH24MI‘) timestamp
FROM dba_hist_snapshot
WHERE snap_id = :eid) b,
(SELECT TO_CHAR (end_interval_time, ‘yyyymmdd_HH24MI‘) timestamp
FROM dba_hist_snapshot
WHERE snap_id = :bid) c;
SET TERMOUT OFF;
SPOOL $AWR_DIR/&report_name;
SELECT output
FROM TABLE (DBMS_WORKLOAD_REPOSITORY.awr_report_html(:dbid,
:inst_num,
:bid,
:eid));
SPOOL OFF;
SET TERMOUT ON;
CLEAR COLUMNS SQL;
TTITLE OFF;
BTITLE OFF;
REPFOOTER OFF;
UNDEFINE report_name
2. HP-UX系统下:
##sh脚本,sh脚本调用sql脚本 #!/sbin/sh if [ -f ~/.profile ]; then . ~/.profile fi export AWR_CMD=/home/oracle/awr export AWR_DIR=/home/oracle/awr/report RETENTION=31 # ---------------------------------------------- # Generate awr report # ---------------------------------------------- $ORACLE_HOME/bin/sqlplus / as sysdba<<EOF @${AWR_CMD}/autoawr.sql; exit; EOF exit ##sql脚本 SET ECHO OFF; SET VERI OFF; SET FEEDBACK OFF; SET TERMOUT ON; SET HEADING OFF; VARIABLE dbid NUMBER; VARIABLE inst_num NUMBER; VARIABLE bid NUMBER; VARIABLE eid NUMBER; BEGIN SELECT MIN (snap_id) INTO :bid FROM dba_hist_snapshot WHERE TO_CHAR (end_interval_time, ‘yyyymmdd‘) = TO_CHAR (SYSDATE-7, ‘yyyymmdd‘); SELECT MAX (snap_id) INTO :eid FROM dba_hist_snapshot WHERE TO_CHAR (begin_interval_time,‘yyyymmdd‘) = TO_CHAR (SYSDATE-1, ‘yyyymmdd‘); SELECT dbid INTO :dbid FROM v$database; SELECT instance_number INTO :inst_num FROM v$instance; END; / set pagesize 0; set linesize 121; COLUMN report_name NEW_VALUE report_name NOPRINT; SELECT instance_name || ‘_awrrpt_‘ || instance_number || ‘_‘ || c.timestamp ||‘_‘ || b.timestamp || ‘.‘ || ‘html‘ report_name FROM v$instance a, (SELECT TO_CHAR (end_interval_time, ‘yyyymmdd_HH24MI‘) timestamp FROM dba_hist_snapshot WHERE snap_id = :eid) b, (SELECT TO_CHAR (end_interval_time, ‘yyyymmdd_HH24MI‘) timestamp FROM dba_hist_snapshot WHERE snap_id = :bid) c; SET TERMOUT OFF; SPOOL $AWR_DIR/&report_name; SELECT output FROM TABLE (DBMS_WORKLOAD_REPOSITORY.awr_report_html(:dbid, :inst_num, :bid, :eid)); SPOOL OFF; SET TERMOUT ON; CLEAR COLUMNS SQL; TTITLE OFF; BTITLE OFF; REPFOOTER OFF; UNDEFINE report_name
【ORACLE】自动产生AWR报告
原文:https://www.cnblogs.com/CL-learning/p/12760621.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/8862.html