自動生成awr報告指令碼
大家好!
我們知道awr報告每小時自動收集一次,但是不會自動產生awr報告,這裡Aning和大家分享一個自動生成awr報告的指令碼:
1.shell指令碼,report4.sh 這是每4小時生成一次awr報告的指令碼
#!/bin/bash
ORACLE_BASE=/u01/app/oracle
export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_HOME
ORA_CRS_HOME=/u01/app/11.2.0/grid
export ORA_CRS_HOME
ORACLE_SID=rac1
export ORACLE_SID
PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORA_CRS_HOME/bin
export PATH
export ORACLE_UNQNAME=rac
ORACLE_BASE=/u01/app/oracle
export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_HOME
ORA_CRS_HOME=/u01/app/11.2.0/grid
export ORA_CRS_HOME
ORACLE_SID=rac1
export ORACLE_SID
PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORA_CRS_HOME/bin
export PATH
export ORACLE_UNQNAME=rac
datetime=`date +%Y%m%d%H`
cd /home/oracle/hourly_backup
$ORACLE_HOME/bin/sqlplus /nolog<connect / as sysdba;
@/home/oracle/backup/script/awrrpt_rac1_4.sql
exit
!
cd /home/oracle/hourly_backup
$ORACLE_HOME/bin/sqlplus /nolog<connect / as sysdba;
@/home/oracle/backup/script/awrrpt_rac1_4.sql
exit
!
/bin/gzip -9 /home/oracle/hourly_backup/report_$datetime.html
2.shell指令碼呼叫的生成awr報告的sql指令碼,awrrpt_rac1_4.sql
set echo off;
set veri off;
set feedback off;
set termout on;
set heading off;
variable rpt_options number;
define NO_OPTIONS = 0;
set veri off;
set feedback off;
set termout on;
set heading off;
variable rpt_options number;
define NO_OPTIONS = 0;
rem according to your needs, the value can be 'text' or 'html'
define report_type='html';
begin
:rpt_options := &NO_OPTIONS;
end;
/
variable dbid number;
variable inst_num number;
variable bid number;
variable eid number;
define report_type='html';
begin
:rpt_options := &NO_OPTIONS;
end;
/
variable dbid number;
variable inst_num number;
variable bid number;
variable eid number;
variable day number;
begin
select max(snap_id)-5 into :bid from dba_hist_snapshot;
select max(snap_id) into :eid from dba_hist_snapshot;
select dbid into :dbid from v$database;
select instance_number into :inst_num from v$instance;
select to_number(to_char(sysdate,'yyyymmddhh24')) into :day from dual;
select max(snap_id)-5 into :bid from dba_hist_snapshot;
select max(snap_id) into :eid from dba_hist_snapshot;
select dbid into :dbid from v$database;
select instance_number into :inst_num from v$instance;
select to_number(to_char(sysdate,'yyyymmddhh24')) into :day from dual;
end;
/
column ext new_value ext noprint
column fn_name new_value fn_name noprint;
column lnsz new_value lnsz noprint;
select 'txt' ext from dual where lower('&report_type') = 'text';
select 'html' ext from dual where lower('&report_type') = 'html';
select 'awr_report_text' fn_name from dual where lower('&report_type') = 'text';
select 'awr_report_html' fn_name from dual where lower('&report_type') = 'html';
select '80' lnsz from dual where lower('&report_type') = 'text';
select '1500' lnsz from dual where lower('&report_type') = 'html';
set linesize &lnsz;
column report_name new_value report_name noprint;
--select 'sp_'||:bid||'_'||:eid||'.'||'&ext' report_name from dual;
select 'report_'||:day||'.'||'&ext' report_name from dual;
set termout off;
spool &report_name;
select output from table(dbms_workload_repository.&fn_name(:dbid, :inst_num,:bid, :eid,:rpt_options ));
spool off;
set termout on;
clear columns sql;
ttitle off;
btitle off;
repfooter off;
undefine report_name
undefine report_type
undefine fn_name
undefine lnsz
undefine NO_OPTIONS
/
column ext new_value ext noprint
column fn_name new_value fn_name noprint;
column lnsz new_value lnsz noprint;
select 'txt' ext from dual where lower('&report_type') = 'text';
select 'html' ext from dual where lower('&report_type') = 'html';
select 'awr_report_text' fn_name from dual where lower('&report_type') = 'text';
select 'awr_report_html' fn_name from dual where lower('&report_type') = 'html';
select '80' lnsz from dual where lower('&report_type') = 'text';
select '1500' lnsz from dual where lower('&report_type') = 'html';
set linesize &lnsz;
column report_name new_value report_name noprint;
--select 'sp_'||:bid||'_'||:eid||'.'||'&ext' report_name from dual;
select 'report_'||:day||'.'||'&ext' report_name from dual;
set termout off;
spool &report_name;
select output from table(dbms_workload_repository.&fn_name(:dbid, :inst_num,:bid, :eid,:rpt_options ));
spool off;
set termout on;
clear columns sql;
ttitle off;
btitle off;
repfooter off;
undefine report_name
undefine report_type
undefine fn_name
undefine lnsz
undefine NO_OPTIONS
3.在crontab 裡面新增執行時間
crontab -l 10 4,8,12,16,20,0 * * * /home/oracle/backup/script/report4.sh
上述指令碼是沒4小時生成一次awr報告,大家可以根據自己需要修改生成時間
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12457158/viewspace-753875/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- AWR報告自動生成指令碼指令碼
- 【AWR】自動生成AWR報告指令碼以及用法指令碼
- awr報告每天自動生成指令碼指令碼
- shell指令碼實現自動生成awr報告指令碼
- 一個自動生成awr報告的shell指令碼指令碼
- Oracle10g 自動生成AWR報告的指令碼Oracle指令碼
- 【AWR】Oracle批量生成awr報告指令碼Oracle指令碼
- 生成awr報告的指令碼指令碼
- Oracle10g自動生成AWR分析報告的指令碼Oracle指令碼
- 自動生成AWR HTML報告HTML
- 指令碼:定時生成awr報告指令碼
- 自動生成ASH報告指令碼指令碼
- 定時自動生成awr報告
- 轉貼:批量生成awr報告指令碼指令碼
- AWR Report 自動生成指令碼 [final]指令碼
- awr自動收集指令碼指令碼
- 自動生成AWR報告並以郵件附件傳送
- 【效能優化】sqlplus中使用指令碼生成awr報告優化SQL指令碼
- Oracle生成awr報告Oracle
- Oracle 生成awr報告Oracle
- 手工生成AWR分析報告
- 使用shell自動傳送Oracle AWR報告Oracle
- 自動生成Statspack的指令碼指令碼
- ORACLE 11G生成AWR報告Oracle
- 儲存過程批量生成awr指令碼儲存過程指令碼
- SQL Server映象自動生成指令碼方法SQLServer指令碼
- 通過shell指令碼抓取awr報告中的問題sql指令碼SQL
- 透過shell指令碼抓取awr報告中的問題sql指令碼SQL
- Oracle 11g RAC 如何生成AWR報告?Oracle
- Oracle 11g RAC生成 AWR 報告方法Oracle
- AWR不能自動生成快照解決方法?
- oracle報表自動FTP指令碼OracleFTP指令碼
- 使用shell生成orabbix自動化配置指令碼指令碼
- 一個自動生成oracle job的指令碼Oracle指令碼
- 本機生成遠端資料庫AWR報告資料庫
- 手工生成AWR執行期對比報告記錄
- 透過shell指令碼定位效能sql和生成報告指令碼SQL
- 通過shell指令碼定位效能sql和生成報告指令碼SQL