auto_ash
#!/usr/bin/ksh
##############paramter######################
startdate=$1' 00:00:01'
enddate=$2' 23:59:59'
reporttype=$3
reportformat='text'
###################env######################
oraclehome=`echo $ORACLE_HOME`
#############################################
dbname=`sqlplus -s "/ as sysdba" <<EOF
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select distinct name from gv\\$database;
quit;
EOF
`
dbid=`sqlplus -s "/ as sysdba" <<EOF
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select distinct dbid from gv\\$database;
quit;
EOF
`
instid=`sqlplus -s "/ as sysdba" <<EOF
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select instance_number from gv\\$instance;
quit;
EOF
`
instname=`sqlplus -s "/ as sysdba" <<EOF
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select instance_name from gv\\$instance;
quit;
EOF
`
for i in $instid
do
instanceid=`echo $i|tr -d ' '`
echo "from database-->"$dbname" database id--->"$dbid" instance id--->"$instanceid
echo "report type--->"$reporttype"|"$reporttype" snapshot from--->"$startdate" to--->"$enddate
echo $instanceid
if [ $reporttype = 'AWR' ];
then
export NLS_LANG=american_america.AL32UTF8
echo "generate the awr report sql...."
$ORACLE_HOME/bin/sqlplus -s "/ as sysdba" <<EOF >awrreport.sql
set head off
set echo off
set feedback off
set linesize 120 ;
set pagesize 0;
set heading off;
select * from (
select snap_id as snaped,
lag(snap_id, 1) OVER(ORDER BY snap_id) as snapst,
to_char(end_interval_time, 'yyyymmddhh24miss') as snaped1,
lag(to_char(end_interval_time, 'yyyymmddhh24miss'), 1) OVER(ORDER BY to_char(end_interval_time, 'yyyymmddhh24miss')) as snaped2
from dba_hist_snapshot a
where a.begin_interval_time >=to_date('$startdate', 'yyyy-mm-dd hh24:mi:ss')
and a.begin_interval_time <=to_date('$enddate', 'yyyy-mm-dd hh24:mi:ss')
--and rtrim(ltrim(to_char(a.begin_interval_time,'day','NLS_DATE_LANGUAGE=AMERICAN'))) not in ('saturday','sunday')
--and to_char(a.begin_interval_time,'HH24')>=0
--and to_char(a.end_interval_time,'HH24') <=23
and a.DBID='$dbid'
and a.INSTANCE_NUMBER='$instanceid'
) where snapst is not null AND substr(snaped1,1,8)=substr(snaped2,1,8)
order by snapst;
quit;
EOF
export NLS_LANG=american_america.AL32UTF8
cat awrreport.sql | while read line
do
endd=`echo $line | awk ' { print $1 } '`
startd=`echo $line | awk ' { print $2 } '`
endt=`echo $line | awk ' { print $3 } '`
startt=`echo $line | awk ' { print $4 } '`
instid=`echo $instanceid`
awrrp="awrrpt_"$startt"_"$endt"_"$instid".txt"
$ORACLE_HOME/bin/sqlplus -s "/ as sysdba" <<EOF
@?/rdbms/admin/awrrpti.sql;
$reportformat
$dbid
$instanceid
1
$startd
$endd
$awrrp
quit;
EOF
done
echo "generate the node"$instid "report finish,please check..."
else
echo "error!!!please check the input parameters..."
fi
done
tar cvf awr.tar *.txt
2. how to
chmod +x auto-awr-11g.sh nohup sh auto-awr-11g.sh '2016-05-26' '2016-06-02' AWR &
3.FAQ:
ash出现ORA-01843: 无效的月份错误解决
select sysdate from dual;
本帖最后由 drower 于 2013-10-16 15:36 编辑 今天在做优化第十四课作业生成ash时出现错误 select output from table(dbms_workload_repository.ash_report_html( :dbid, * 第 1 行出现错误: ORA-01843: 无效的月份 ORA-06512: 在 "SYS.DBMS_SWRF_REPORT_INTERNAL", line 10999 ORA-06512: 在 "SYS.DBMS_SWRF_REPORT_INTERNAL", line 10421 ORA-06512: 在 "SYS.DBMS_WORKLOAD_REPOSITORY", line 1554 ORA-06512: 在 line 1 通过alter session set nls_date_format='DD-MM-YY';修改当前会话。 select sysdate from dual;查看当前时间格式,发现客户端字符集不对。 exit,退出 set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK 设置客户端字符集 随后进行生成ash就可以了 |
感谢逝鸿
https://blog.csdn.net/qq_21127313/article/details/52471580
ORA-01843 When Generating ASH Report (文档 ID 1147253.1)
Please set nls_language to AMERICAN and re-generate the ASH report:
SQL> alter session set nls_language='AMERICAN';
SQL> @?/rdbms/admin/ashrpt.sql
[appuser@pommodb02 ~]$ env|grep LANG
LANG=en_US.UTF-8
-》正确机器
[appuser@sportalfront01 ~]$ env|grep LANG
LANG=zh_CN.UTF-8