感谢花生土豆粉
Script to generate AWR report from remote sql client
通常我们都是通过登录服务器,然后执行$ORACLE_HOME/rdbms/admin/awrrpt.sql脚本来生成awr报告,同时Oracle还提供了DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML存储过程,方便我们在不方便登录服务器的情况下获取AWR报告。
通过如下脚本,可以简单的在dbms_output中获取到AWR报告的内容:
DECLARE
DBID NUMBER;
INST_ID NUMBER;
BID NUMBER;
EID NUMBER;
DB_UNIQUE_NAME VARCHAR2(30);
STARTTIME DATE;
ENDTIME DATE;
BEGIN
STARTTIME := TO_DATE('2014-12-15 18:00', 'YYYY-MM-DD HH24:MI') - 1 / 24;
ENDTIME := TO_DATE('2014-12-15 19:00', 'YYYY-MM-DD HH24:MI');
SELECT MIN(SNAP_ID), MAX(SNAP_ID)
INTO BID, EID
FROM DBA_HIST_SNAPSHOT DHS
WHERE TRUNC(DHS.BEGIN_INTERVAL_TIME, 'HH24') >= TRUNC(STARTTIME, 'HH24')
AND TRUNC(DHS.END_INTERVAL_TIME, 'HH24') <= TRUNC(ENDTIME, 'HH24');
SELECT DBID, INST_ID, DB_UNIQUE_NAME
INTO DBID, INST_ID, DB_UNIQUE_NAME
FROM GV$DATABASE;
FOR C1_REC IN (SELECT OUTPUT
FROM TABLE(DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(DBID,
INST_ID,
BID,
EID))) LOOP
DBMS_OUTPUT.PUT_LINE(C1_REC.OUTPUT);
END LOOP;
END;
/
python实现自动生成oracle awr报告
https://s1.51cto.com/images/20180613/1528857464916528.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
https://www.pianshen.com/article/3658505290/
https://www.pythonf.cn/read/116913
def generate_oracle_awr(database_info,first_id,second_id,output_path)
sql_conn_str='sqlplus {0}/{1}
sql_path_get_db_id='os.path.join(root_path,"congfig")
sql_patch_generate_awr='os.path.join(root_patch,"config\generate_oracle_awr.sql")
try
ret os.popen(sql_conn_str + sql_path_get_bdid)
line_info=ret.readlines()
for line_num line in enumerate(line_info);
if 'DBID INSTAN_NUMBER' in line
dbid,instance_num=line_info
break
Pyhton初学之生成awr报告
https://blog.csdn.net/feng_vs_sunzhilong/article/details/81408170