##sample 0
https://carlos-sierra.net/2013/11/01/a-healthy-way-to-do-an-oracle-database-health-check/
A healthy way to do an Oracle database health-check
with 12 comments
Q: How do I do an Oracle database health-check?
A: It all depends. (hint: we can use this answer for most Oracle related questions in general and Performance related in particular, but don’t try it at home).
This seems like a quite broad question and yes it is. And of course there are many ways to proceed with a database health-check. So at this post I ‘d rather talk about: what I think is a healthy way to approach an Oracle database health-check.
- Start with the basics: Listen to the users of this database. If nobody complains then most probably you would have to define the scope by yourself. In any case, go on.
- Gather environment information. This includes the understanding of the architecture used, the databases on such architecture and the applications on those databases. Also learn who is who: Users, DBAs and Developers.
- Gather metrics. I am referring to OS metrics (CPU, IO and Memory), and also database metrics (AWR) together with alert logs. When gathering these metrics focus on time periods where the pain has been reported, and slice the time as small as possible (i.e. AWR reports for each time slice captured, avoiding the 6-24 hours time frame common mistake).
- Let the combination of complains (concerns) and findings on metrics to guide you to the next step. This is where most get lost. So don’t panic and dive in into what you see as contention on your metrics. Keep in mind that the most important metric of all is “user response time”, so anything affecting it must be in your priority list.
- There are many more things to check, but they are more in the configuration and sound practices arena. For example: redundancy on control files, archive mode, backups, non-default parameters, PX setup, memory setup, etc. For these, creating a check list would help.
- At some point you will have many leads and you will start to lose focus. Do some yoga or go for a walk, then make an A, B, C list with what is really important, what is kind-of and what is mere style.
- You are not an expert on every aspect of the database (nobody is). So, do not pretend you can do everything yourself. Rely on your peers and/or contacts. Reach out for help in those areas where you feel insecure (feeling insecure is a good thing, much better than feeling secure without any solid foundation).
- Once you think you have it nailed, go to your peers, colleagues, boss(es), friends, partner, or strangers if necessarily, and solicit a review of your findings and recommendations. Accept feedback. This is key. Maybe what you thought was sound it makes absolutely no sense to someone with more experience or simply with a different view.
- Reconsider everything. Avoid the pitfall of assuming that what you have learn in your two-digits years of experience can be applied to every case. For example, if you have done mostly SQL Tuning, don’t expect every issue to be SQL Tuning. Health-checks are like fortune cookies, you never know what you will get.
- Last but not least: Learn from your new experience, practice listening to others, use your common sense, exercise your knowledge, and work as a team member. Add the word “collaboration” to your daily work and maybe one day you will learn you are not alone.
#####sample 1
https://www.cnblogs.com/liang545621/p/9410619.html
-- =============================================================================
-- USAGE : sqlplus / as sysdba @healthcheck.sql
--
-- TEST : This script has been successfully tested on these platforms:
--
-- Linux , Windows , AIX , Solaris
-- Oracle Database(Include RAC) 10gR2,11gR2
--
-- NOTE : Please test this script in ur development environment
-- before attempting to run it in production.
-- ==============================================================================
prompt This script must be run as a user with SYSDBA privileges.
prompt This process can take several minutes to complete.
prompt
prompt >> Creating database report...
define reportHeader="<font size=+3 color="blue"><b>Database Health Check Report</b></font><hr>Copyright (c) 2015 Stephen Zhao. All rights reserved.<p--------------------------------------------------------------------------+
-- +----------------------------------------------------------------------------+
-- | Script Settings |
-- +----------------------------------------------------------------------------+
set termout off
set echo off
set feedback off
set heading off
set verify off
set wrap on
set trimspool on
set serveroutput on
set escape on
set linesize 300 pagesize 50000
set long 2000000000
alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS';
alter session set nls_date_language = english;
clear buffer computes columns breaks
define filename=Healthcheck
-- +----------------------------------------------------------------------------+
-- | Gather Database Report Information |
-- +----------------------------------------------------------------------------+
set heading on
clear computes columns breaks
column name new_value _dbname noprint
column spool_time new_value _spool_time noprint
column spooltime new_value _spooltime noprint
select name,to_char(sysdate,'YYYYMMDDHH24MISS') as "spool_time",
to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') as "spooltime"
from v$database;
define _rpt_db_name=&_dbname
define _rpt_spool_time="&_spooltime"
column tablespace_name new_value tablespace_name noprint
column file_name new_value file_name noprint
select max(length_tbs) "tablespace_name",max(length_file) as "file_name"
from (
select case when nvl(max(length(tablespace_name)),0) < 10 then 10 else max(length(tablespace_name)) end length_tbs,
case when nvl(max(length(file_name)),0) < 9 then 9 else max(length(file_name)) end length_file
from dba_data_files
union all
select case when nvl(max(length(tablespace_name)),0) <10 then 10 else max(length(tablespace_name)) end length_tbs,
case when nvl(max(length(file_name)),0) < 9 then 9 else max(length(file_name)) end length_file
from dba_temp_files
);
set markup html on spool on preformat off entmap on -
head '-
<title>Database Health Check Snapshot for DB:&_rpt_db_name,Snap Time:&_rpt_spool_time</title>-
<style type="text/css"> -
body {font:9pt Arial,Helvetica,sans-serif; color:black; background:White;} -
p {font:2pt Arial,Helvetica,sans-serif; color:black; background:White;} -
table {font:9pt Arial,Helvetica,sans-serif; color:Black; padding:0px 0px 0px 0px;padding-left:2px; padding-right:2px; margin:0px 0px 0px 0px;width:300;overflow:auto;} -
table.t_600px {font:9pt Arial,Helvetica,sans-serif; color:Black; background-color:white; padding:0px 0px 0px 0px;padding-left:2px; padding-right:2px; margin:0px 0px 0px 0px;width:600;overflow:auto;} -
table.t_200px {font:9pt Arial,Helvetica,sans-serif; color:Black; padding:0px 0px 0px 0px;padding-left:2px; padding-right:2px; margin:0px 0px 0px 0px;width:200;overflow:auto;} -
tr {font:9pt Arial,Helvetica,sans-serif; color:Black; background-color:white; padding:0px 0px 0px 0px;padding-left:2px; padding-right:2px; margin:0px 0px 0px 0px;white-space:nowrap} -
td {font:9pt Arial,Helvetica,sans-serif; color:Black; padding:0px 0px 0px 0px;padding-left:2px; padding-right:2px; margin:0px 0px 0px 0px;white-space:nowrap} -
tr:nth-child(2n+1) { font-family: Helvetica, "Hiragino Sans GB", 微软雅黑, "Microsoft YaHei UI", SimSun, SimHei, arial, sans-serif; font-size: 16px; font-variant-numeric: normal; font-variant-east-asian: normal; line-height: 27.2px; widows: 1;"> th {font:bold 9pt Arial,Helvetica,sans-serif; color:white; background:#0066cc;padding-left:4px; padding-right:4px;padding-bottom:2px;white-space:nowrap;} -
h1 {font:bold 20pt Arial,Helvetica,Geneva,sans-serif; color:#336699; border-bottom:1px solid gray; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;} -
h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} -
a {font:bold 8pt Arial,Helvetica,sans-serif;color:#663300; vertical-align:top;margin-top:0pt; margin-bottom:0pt;} -
li {font: 8pt Arial,Helvetica,Geneva,sans-serif; color:black; background:White;} -
</style>' -
body 'bgcolor="c0c0c0"'-
table 'border_collapse: collapse;border="0";cellpadding="0";cellspacing="1"'
spool '&filename._&_dbname._&_spool_time..html'
set markup html on entmap off
prompt <h1>Oracle Database Health Check Snapshot</h1>
-- prompt <hr size="2" color="Gray" align="right" noshade/>
-- +----------------------------------------------------------------------------+
-- | Database Summary Information |
-- +----------------------------------------------------------------------------+
-- setup html mark(table) attribute,define table's width to 600px
set markup html table 'class="t_600px"'
-- Display Database Summary Information
clear columns breaks computes
break on name on dbid on version on rac
column name format a10 heading 'Name' print entmap off
column dbid format 9999999999999999 heading 'DBID' print entmap off
column instance_name format a15 heading 'Instance' print entmap off
column instance_number format 999 heading 'Inst Num' print entmap off
column startup_time format a19 heading 'Startup Time' print entmap off
column version format a15 heading 'Release' print entmap off
column rac format a5 heading 'RAC' print entmap off
select d.name,
d.dbid,
i.instance_name,
i.instance_number,
i.startup_time,
i.version,
i.rac
from v$database d,
( select instance_name,
instance_number,
startup_time,
version,
parallel rac
from gv$instance) i
order by i.instance_number;
-- Display Host Summary Information
clear columns breaks computes
column instance_name format a15 heading 'Instance' print entmap off
column host_name format a25 heading 'Host Name' print entmap off
column platform_name format a99 heading 'Platform' print entmap off
column cpus format 9,999 heading 'CPUs' print entmap off
column physical_memory format 999,990.99 heading 'Memory(GB)' print entmap off
select i.instance_name,
i.host_name,
d.platform_name,
o1.cpus,
round(o2.physical_memory/1024/1024/1024,2) physical_memory
from gv$instance i,
(select platform_name from v$database) d,
(select inst_id,value cpus from gv$osstat where osstat_id=0) o1,
(select inst_id,value physical_memory from gv$osstat where osstat_id=1008) o2
where i.inst_id = o1.inst_id and o1.inst_id = o2.inst_id;
-- setup html mark(table) attribute,define table's attribute use style
set markup html table 'border_collapse: collapse;border="0";cellpadding="0";cellspacing="1"'
-- ==============================================================================
-- Main Report Index
-- ==============================================================================
-- Define Main Report Index
prompt <a name="top"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Main Report Index</b></font>
prompt <ul>-
<li><a href='#overview'>Database Information</a></li>-
<li><a href='#storage'>Storage Statistics</a></li>-
<li><a href='#undo'>Undo Segments</a></li>-
<li><a href='#memory'>Memory Statistis</a></li>-
<li><a href='#secutiry'>Security Information</a></li>-
<li><a href='#object'>Object Information</a></li>-
<li><a href='#job'>Schedule/Job</a></li>-
<li><a href='#backup'>Backup Detail</a></li>-
<li><a href='#performance'>Performance Statistics</a></li>-
<li><a href='#parameter'>Init. Parameter</a></li>-
</ul>-
<hr size="1" color="Gray" noshade/>
-- ==============================================================================
-- Overview
-- ==============================================================================
prompt <a name="overview"></a>-
<font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Database Information</b></font>
prompt <ul>-
<li><a href='#11'>Database Overview</a></li>-
<li><a href='#12'>Instance Overview</a></li>-
<li><a href='#13'>Session Overview</a></li>-
<li><a href='#14'>Version</a></li>-
<li><a href='#15'>PSU Registry History</a></li>-
<li><a href='#16'>Database Registry</a></li>-
<li><a href='#17'>Database Options</a></li>-
<li><a href='#18'>Controlfile</a></li>-
<li><a href='#19'>Online Redo Logfiles</a></li>-
<li><a href='#101'>Logfile Switch</a></li>-
<li><a href='#102'>SCN Health Check</a></li>-
<li><a href='#103'>High Water Mark Statistics</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Database Overview |
-- +----------------------------------------------------------------------------+
prompt <a name="11"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Database Overview</b></font>
clear columns breaks computes
column name format a12 heading 'DB Name' print entmap off
column dbid format 999999999999 heading 'DBID' print entmap off
column db_unique_name format a15 heading 'DB Unique Name' print entmap off
column created format a19 heading 'Create Date' print entmap off
column platform_name format a50 heading 'Platform' print entmap off
column current_scn format 9999999999999999 heading 'Current SCN' print entmap off
column log_mode format a25 heading 'Log Mode' print entmap off
column open_mode format a15 heading 'Open Mode' print entmap off
column force_logging format a13 heading 'Force Logging' print entmap off
column flashback_on format a12 heading 'Flashback On' print entmap off
column controlfile_type format a16 heading 'Controlfile Type' print entmap off
column dbtimezone format a11 heading 'DB TimeZone' print entmap off
select name,
dbid,
db_unique_name,
created,
platform_name,
current_scn,
log_mode,
open_mode,
force_logging,
flashback_on,
controlfile_type,
dbtimezone
from v$database;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
-- prompt <br />
-- +----------------------------------------------------------------------------+
-- | Instance Overview |
-- +----------------------------------------------------------------------------+
prompt <a name="12"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Instance Overview</b></font>
clear columns breaks computes
column instance_number format 9999999 heading 'Inst_Num' print entmap off
column instance_name format a15 heading 'Instance Name' print entmap off
column host_name format a30 heading 'Host Name' print entmap off
column version format a10 heading 'Release' print entmap off
column startup_time format a19 heading 'Startup Time' print entmap off
column uptime format 999,990.99 heading 'Up Days' print entmap off
column status format a15 heading 'Status' print entmap off
column archiver format a8 heading 'Archiver' print entmap off
select instance_number,
instance_name,
host_name,
version,
to_char (startup_time, 'YYYY-MM-DD HH24:MI:SS') "startup_time",
round (sysdate - startup_time, 2) "uptime",
status,
archiver
from gv$instance
order by instance_number;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
-- prompt <br />
-- +----------------------------------------------------------------------------+
-- | Session Overview |
-- +----------------------------------------------------------------------------+
prompt <a name="13"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Session Overview</b></font>
clear columns breaks computes
column inst_id format 999 heading 'Inst_ID' print entmap off
column count format 999,999 heading 'Sessions' print entmap off
column status format a10 heading 'Status' print entmap off
break on inst_id on report
--break on report
compute sum label 'Total:' of count on report
select inst_id,count(*) count,status
from gv$session
group by inst_id,status
order by inst_id;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Version |
-- +----------------------------------------------------------------------------+
prompt <a name="14"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Version</b></font>
clear columns breaks computes
column banner format a300 heading 'Banner' print entmap off
select banner
from v$version;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
-- prompt <br />
-- +----------------------------------------------------------------------------+
-- | PSU Registry History |
-- +----------------------------------------------------------------------------+
prompt<a name="15"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>PSU Registry History</b></font>
clear columns breaks computes
column action_time format a19 heading 'Action Time' print entmap off
column action format a8 heading 'Action' print entmap off
column namespace format a9 heading 'Namespace' print entmap off
column version format a10 heading 'Version' print entmap off
column id format 999 heading 'ID' print entmap off
column comments format a25 heading 'Comments' print entmap off
column bundle_series format a13 heading 'Bundle Series' print entmap off
select *
from registry$history;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Database Registry |
-- +----------------------------------------------------------------------------+
prompt <a name="16"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Database Registry</b></font>
clear columns breaks computes
column comp_name format a75 heading 'Comp_Name' print entmap off
column version format a15 heading 'Version' print entmap off
column status format a10 heading 'Status' print entmap off
select comp_name, version, status
from dba_registry;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Database Options |
-- +----------------------------------------------------------------------------+
prompt <a name="17"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Database Options</b></font>
clear columns breaks computes
column parameter format a75 heading 'Options' print entmap off
column value format a15 heading 'Value' print entmap off
select * from v$option;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Controlfile |
-- +----------------------------------------------------------------------------+
prompt <a name="18"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Controlfile</b></font>
clear column breaks computes
column name for a150 heading 'Name' print entmap off
column size for 999,999,999 heading 'Size_Bytes' print entmap off
select name, block_size "size"
from v$controlfile;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Online Redo Logfiles |
-- +----------------------------------------------------------------------------+
prompt <a name="19"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Online Redo Logfiles</b></font>
clear column breaks computes
break on thread# on group#
column thread# format 999 heading 'Thread#' print entmap off
column group# format 999 heading 'Group#' print entmap off
column member format a150 heading 'Member' print entmap off
column status format a8 heading 'Status' print entmap off
column size format 999,999 heading 'Size_MB' print entmap off
column type format a15 heading 'Type' print entmap off
select b.thread#,
b.group#,
a.member,
b.status,
(b.bytes / 1024 / 1024) as "size",
decode(a.type,'ONLINE',a.type,'<div align="left"><font color="red">' || a.type || '</font></div>') type
from v$logfile a, v$log b
where a.group# = b.group#
order by 1, 2;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Redo Logfile Switch |
-- +----------------------------------------------------------------------------+
prompt <a name="101"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Logfile Switch</b></font>
clear columns breaks computes
column day format a10 heading 'Day/Time'
column H00 format 999 heading '00'
column H01 format 999 heading '01'
column H02 format 999 heading '02'
column H03 format 999 heading '03'
column H04 format 999 heading '04'
column H05 format 999 heading '05'
column H06 format 999 heading '06'
column H07 format 999 heading '07'
column H08 format 999 heading '08'
column H09 format 999 heading '09'
column H10 format 999 heading '10'
column H11 format 999 heading '11'
column H12 format 999 heading '12'
column H13 format 999 heading '13'
column H14 format 999 heading '14'
column H15 format 999 heading '15'
column H16 format 999 heading '16'
column H17 format 999 heading '17'
column H18 format 999 heading '18'
column H19 format 999 heading '19'
column H20 format 999 heading '20'
column H21 format 999 heading '21'
column H22 format 999 heading '22'
column H23 format 999 heading '23'
column total format 999,999 heading 'Total'
break on report
compute sum label 'Total:' min label 'Min:' max label 'Max:' avg label 'Average:' of total on report
select to_char (first_time, 'YYYY-MM-DD') day,
sum (decode (to_char (first_time, 'HH24'), '00', 1, 0)) H00,
sum (decode (to_char (first_time, 'HH24'), '01', 1, 0)) H01,
sum (decode (to_char (first_time, 'HH24'), '02', 1, 0)) H02,
sum (decode (to_char (first_time, 'HH24'), '03', 1, 0)) H03,
sum (decode (to_char (first_time, 'HH24'), '04', 1, 0)) H04,
sum (decode (to_char (first_time, 'HH24'), '05', 1, 0)) H05,
sum (decode (to_char (first_time, 'HH24'), '06', 1, 0)) H06,
sum (decode (to_char (first_time, 'HH24'), '07', 1, 0)) H07,
sum (decode (to_char (first_time, 'HH24'), '08', 1, 0)) H08,
sum (decode (to_char (first_time, 'HH24'), '09', 1, 0)) H09,
sum (decode (to_char (first_time, 'HH24'), '10', 1, 0)) H10,
sum (decode (to_char (first_time, 'HH24'), '11', 1, 0)) H11,
sum (decode (to_char (first_time, 'HH24'), '12', 1, 0)) H12,
sum (decode (to_char (first_time, 'HH24'), '13', 1, 0)) H13,
sum (decode (to_char (first_time, 'HH24'), '14', 1, 0)) H14,
sum (decode (to_char (first_time, 'HH24'), '15', 1, 0)) H15,
sum (decode (to_char (first_time, 'HH24'), '16', 1, 0)) H16,
sum (decode (to_char (first_time, 'HH24'), '17', 1, 0)) H17,
sum (decode (to_char (first_time, 'HH24'), '18', 1, 0)) H18,
sum (decode (to_char (first_time, 'HH24'), '19', 1, 0)) H19,
sum (decode (to_char (first_time, 'HH24'), '20', 1, 0)) H20,
sum (decode (to_char (first_time, 'HH24'), '21', 1, 0)) H21,
sum (decode (to_char (first_time, 'HH24'), '22', 1, 0)) H22,
sum (decode (to_char (first_time, 'HH24'), '23', 1, 0)) H23,
count (*) total
from v$log_history a
where first_time >= sysdate - 30
group by to_char (first_time, 'YYYY-MM-DD')
order by to_char (first_time, 'YYYY-MM-DD');
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | SCN Health Check |
-- +----------------------------------------------------------------------------+
prompt <a name="102"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>SCN Health Check</b></font>
clear columns breaks computes
column Date_Time format a19
column scn format 999999999999
column Headroom format 999999999999.0
column Adjust_SCN format 999999999999.0
column ALL_SCN format 999999999999.0
column "SCN Headroom Health" format a21
select tim "Date_Time",
scn,
round((chk16kscn-scn)/24/3600/16/1024,1) "Headroom",
round((chk16kscn-scn)/1024/1024/1024,1) "Adjust_SCN",
round(chk16kscn/1024/1024/1024,1) "ALL_SCN",
case when round((chk16kscn-scn)/24/3600/16/1024,1) > 62 then 'SCN Headroom Is Good.'
when round((chk16kscn-scn)/24/3600/16/1024,1) < 10 then '<div align="left"><font color="red">SCN Headroom Is Bad.</font></div>'
end "SCN Headroom Health"
from (
select tim, scn,
((((to_number(to_char(tim,'YYYY'))-1988)*12*31*24*60*60)
+ ((to_number(to_char(tim,'MM'))-1)*31*24*60*60)
+ (((to_number(to_char(tim,'DD'))-1))*24*60*60)
+ (to_number(to_char(tim,'HH24'))*60*60)
+ (to_number(to_char(tim,'MI'))*60)
+ (to_number(to_char(tim,'SS')))) * (16*1024)) chk16kscn
from (select sysdate tim,dbms_flashback.get_system_change_number scn
from v$instance
where version like '10.%'
or version like '11.1%'
or version like '11.2.0.1%'
)
)
union all
select tim "Date_Time",
scn,
round((chk32kscn-scn)/24/3600/32/1024,1) "Headroom",
round((chk32kscn-scn)/1024/1024/1024,1) "Adjust_SCN",
round(chk32kscn/1024/1024/1024,1) "ALL_SCN",
case when round((chk32kscn-scn)/24/3600/32/1024,1) > 62 then 'SCN Headroom Is Good.'
when round((chk32kscn-scn)/24/3600/32/1024,1) < 10 then '<div align="left"><font color="red">SCN Headroom Is Bad.</font></div>'
end "SCN Headroom Health"
from (
select tim, scn,
((((to_number(to_char(tim,'YYYY'))-1988)*12*31*24*60*60)
+ ((to_number(to_char(tim,'MM'))-1)*31*24*60*60)
+ (((to_number(to_char(tim,'DD'))-1))*24*60*60)
+ (to_number(to_char(tim,'HH24'))*60*60)
+ (to_number(to_char(tim,'MI'))*60)
+ (to_number(to_char(tim,'SS')))) * (32*1024)) chk32kscn
from (select sysdate tim,dbms_flashback.get_system_change_number scn
from v$instance
where version like '11.2.0.2%'
or version like '11.2.0.3%'
or version like '11.2.0.4%'
or version like '12.%'
)
);
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | High Water Mark Statistics |
-- +----------------------------------------------------------------------------+
prompt <a name="103"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>High Water Mark Statistics</b></font>
clear columns breaks computes
column name format a50 heading 'Statistic Name' print entmap off
column version format a10 heading 'Version' print entmap off
column highwater format 9,999,999,999,999,999 heading 'Highwater' print entmap off
column last_value format 9,999,999,999,999,999 heading 'Last Value' print entmap off
column description format a150 heading 'Description' print entmap off
select name, version, highwater, last_value, description
from dba_high_water_mark_statistics;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#overview">Back to Database Information</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- Storage
-- ==============================================================================
prompt <a name="storage"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Storage Statistics</b></font>
prompt <ul>-
<li><a href='#21'>Tablespace Statistics</a></li>-
<li><a href='#22'>Datafiles and Tempfiles Statistics</a></li>-
<li><a href='#23'>Total Segments Size</a></li>-
<li><a href='#24'>Top 10 Tables</a></li>-
<li><a href='#25'>Top 10 Indexes</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Tablespace |
-- +----------------------------------------------------------------------------+
prompt <a name="21"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Tablespace Statistics</b></font>
clear columns breaks computes
column tablespace_name format "a&tablespace_name" heading 'Tablespace' print entmap off
column type format a9 heading 'Type' print entmap off
column status heading 'Status' print entmap off
column bigfile format a7 heading 'Bigfile' print entmap off
column total_mb format 999,999,990.00 heading 'Total_MB' print entmap off
column free_mb format 999,999,990.00 heading 'Free_MB' print entmap off
column used_mb format 999,999,990.00 heading 'Used_MB' print entmap off
column "used%" heading 'Used %' print entmap off
column extent_management format a10 heading 'Extent Management' print entmap off
column segment_space_management format a13 heading 'Segment Space Management' print entmap off
column compute format a7 heading 'Compute' print entmap off
break on report
compute count label 'Count:' of type on report
compute sum label 'Total:' of total_mb used_mb free_mb on report
select a.tablespace_name,
a.type,
space total_mb,
nvl (free_space, 0) free_mb,
space - nvl (free_space, 0) used_mb,
case
when trunc ( (1 - nvl (free_space, 0) / space) * 100) >= 90
then '<div align="right"><font color="red">' || to_char (round ( (1 - nvl (free_space, 0) / space) * 100, 2), '990.99') || '</font></div>'
else '<div align="right">' || to_char (round ( (1 - nvl (free_space, 0) / space) * 100, 2), '990.99') || '</div>'
end "used%",
a.bigfile,
decode(a.status,'ONLINE',a.status,'<div align="left"><font color="red">' || a.status || '</font></div>') status,
a.extent_management,
a.segment_space_management
from ( select d.tablespace_name,
t.contents type,
t.status,
t.bigfile,
t.extent_management,
t.segment_space_management,
round (sum (bytes) / 1024 / 1024, 2) space
from dba_data_files d, dba_tablespaces t
where d.tablespace_name = t.tablespace_name
group by d.tablespace_name,
t.contents,
t.status,
t.bigfile,
t.extent_management,
t.segment_space_management) a,
( select tablespace_name,
round (sum (bytes) / 1024 / 1024, 2) free_space
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
union all
select a.tablespace_name,
a.type,
space total_mb,
nvl (free_space, 0) free_mb,
nvl (used_space, 0) as used_mb,
case
when trunc ( (nvl (used_space, 0) / space) * 100) >= 90
then '<div align="right"><font color="red">' || to_char (round ( (nvl (used_space, 0) / space) * 100, 2), '990.99') || '</font></div>'
else '<div align="right">' || to_char (round ( (nvl (used_space, 0) / space) * 100, 2), '990.99') || '</div>'
end "used%",
a.bigfile,
decode(a.status,'ONLINE',a.status,'<div align="left"><font color="red">' || a.status || '</font></div>') status,
a.extent_management,
a.segment_space_management
from ( select d.tablespace_name,
t.contents type,
t.status,
t.bigfile,
t.extent_management,
t.segment_space_management,
round (sum (bytes) / 1024 / 1024, 2) space
from dba_temp_files d, dba_tablespaces t
where d.tablespace_name = t.tablespace_name
group by d.tablespace_name,
t.contents,
t.status,
t.bigfile,
t.extent_management,
t.segment_space_management) a,
( select tablespace_name,
round (sum (bytes_used) / 1024 / 1024, 2) used_space,
round (sum (bytes_free) / 1024 / 1024, 2) free_space
from v$temp_space_header
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
order by 6 desc;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#storage">Back to Strorage Statistics</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Datafiles And Tempfiles |
-- +----------------------------------------------------------------------------+
prompt <a name="22"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Datafiles And Tempfiles</b></font>
clear columns breaks computes
column tablespace_name format "a&tablespace_name" heading 'Tablespace' print entmap
column file_name format "a&file_name" heading 'File_Name' print entmap
column total_mb format 999,999,990.00 heading 'Total_MB' print entmap
column max_mb format 999,999,990.00 heading 'Max_MB' print entmap
column autoextensible format a15 heading 'Autoextensible' print entmap
column status format a15 heading 'Status' print entmap
break on tablespace_name on report
compute count label 'Count:' of file_name on report
compute sum label 'Total:' of total_mb max_mb on report
select tablespace_name,
file_name,
bytes / 1024 / 1024 total_mb,
maxbytes / 1024 / 1024 max_mb,
autoextensible,
decode(online_status,'ONLINE',online_status,'SYSTEM',online_status,'<div align="left"><font color="red">' || online_status || '</font></div>') status
from dba_data_files
union all
select a.tablespace_name,
a.file_name,
a.bytes / 1024 / 1024 total_mb,
a.maxbytes / 1024 / 1024 max_mb,
a.autoextensible,
decode(b.status,'ONLINE',b.status,'<div align="left"><font color="red">' || b.status || '</font></div>') status
from dba_temp_files a, v$tempfile b
where a.file_id = b.file#;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#storage">Back to Strorage Statistics</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Segment Statistics |
-- +----------------------------------------------------------------------------+
prompt <a name="23"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Total Segments Size</b></font>
set markup html table 'class="t_200px"'
clear columns breaks computes
column total_segments_mb format 999,999,990.99 heading 'Total Segments Size(MB)' print entmap off
select '<div align="center">' || round (sum (bytes) / 1024 / 1024, 2) || '</div>' total_segments_mb
from dba_segments;
set markup html table 'border_collapse: collapse;border="0";cellpadding="0";cellspacing="1"'
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#storage">Back to Strorage Statistics</a>
prompt <a href="#top">Back to Top</a>
prompt <a name="24"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Top 10 Tables</b></font>
clear columns breaks computes
column owner format a50 heading 'Owner' print entmap off
column table_name format a50 heading 'Table_Name' print entmap off
column partitioned format a15 heading 'Partition' print entmap off
column size_mb format 999,999,990.99 heading 'Size_MB' print entmap off
select *
from ( select t.owner,
t.table_name,
t.partitioned,
round (sum (s.bytes) / 1024 / 1024, 2) size_mb
from dba_tables t, dba_segments s
where t.owner = s.owner
and s.segment_name = t.table_name
and s.segment_type like 'TABLE%'
group by t.owner, t.table_name, t.partitioned
order by size_mb desc)
where rownum <= 10;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#storage">Back to Strorage Statistics</a>
prompt <a href="#top">Back to Top</a>
prompt <a name="25"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Top 10 Indexes</b></font>
column owner format a50 heading 'Owner' print entmap off
column table_name format a50 heading 'Table_Name' print entmap off
column index_name format a50 heading 'Index_Name' print entmap off
select *
from ( select i.owner,
i.table_name,
i.index_name,
i.partitioned,
sum (s.bytes) / 1024 / 1024 size_mb
from dba_indexes i, dba_segments s
where s.owner = i.owner
and s.segment_name = i.index_name
and s.segment_type like 'INDEX%'
group by i.owner,
i.table_name,
i.index_name,
i.partitioned
order by size_mb desc)
where rownum <= 10;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#storage">Back to Strorage Statistics</a>
prompt <a href="#top">Back to Top</a>
-- ==============================================================================
-- Undo Segments
-- ==============================================================================
prompt <a name="undo"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Undo Segments Information</b></font>
prompt <ul>-
<li><a href='#31'>Undo Parameters</a></li>-
<li><a href='#32'>Undo Segments Statistics</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Undo Parameters |
-- +----------------------------------------------------------------------------+
prompt <a name="31"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Undo Parameters</b></font>
clear columns breaks computes
column instance format a15 heading 'Instance' print entmap off
column name format a15 heading 'Name' print entmap off
column value format a10 heading 'Value' print entmap off
break on instance
select i.instance_name instance, p.name, p.value
from gv$parameter p, gv$instance i
where name like '%undo%'
and p.inst_id = i.inst_id
order by 1;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#undo">Back to Undo Segments Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Undo Segments |
-- +----------------------------------------------------------------------------+
prompt <a name="32"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Undo Segments Statistics</b></font>
clear columns breaks computes
column instance_name format a10 heading 'Instance' entmap off
column tablespace_name format a9 heading 'Tablspace' entmap off
column roll_name format a20 heading 'Roll Name' entmap off
column initial_extent format 999,999,999 heading 'Init Extent' entmap off
column next_extent format 999,999,999 heading 'Next Extent' entmap off
column min_extents format 999,999,999 heading 'Min Extents' entmap off
column max_extents format 999,999,999 heading 'Max Extents' entmap off
column status format a8 heading 'Status' entmap off
column wraps format 999,999,999 heading 'Wraps' entmap off
column shrinks format 999,999,999 heading 'Shrinks' entmap off
column optsize format 999,999,999,999 heading 'Optsize' entmap off
column bytes format 999,999,999,999 heading 'Bytes' entmap off
column extents format 999,999,999 heading 'Extents' entmap off
clear computes breaks
break on report on instance_name on tablespace
compute sum label 'Total:' of bytes extents shrinks wraps on report
select instance_name,
a.tablespace_name,
a.owner || '.' || a.segment_name roll_name,
a.initial_extent,
a.next_extent,
a.min_extents,
a.max_extents,
a.status,
b.bytes,
b.extents,
d.shrinks,
d.wraps,
d.optsize
from dba_rollback_segs a,
dba_segments b,
v$rollname c,
v$rollstat d,
gv$parameter p,
gv$instance i
where a.segment_name = b.segment_name
and a.segment_name = c.name(+)
and c.usn = d.usn(+)
and p.name(+) = 'undo_tablespace'
and p.value(+) = a.tablespace_name
and p.inst_id = i.inst_id(+)
order by a.tablespace_name, a.segment_name;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#undo">Back to Undo Segments Information</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- Memory Statistics
-- ==============================================================================
prompt <a name="memory"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Memory Statistics</b></font>
prompt <ul>-
<li><a href='#41'>Memory Allocate Size</a></li>-
<li><a href='#42'>Show SGA</a></li>-
<li><a href='#43'>SGA Info</a></li>-
<li><a href='#44'>PGA Info</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Memory Allocate Size |
-- +----------------------------------------------------------------------------+
prompt <a name="41"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Memory Allocate Size</b></font>
clear columns breaks computes
break on instance_name
column instance_name format 9999999 heading 'Instance' print entmap off
column name format a20 heading 'Memory Stats' print entmap off
column value format 999,990.99 heading 'Size_MB' print entmap off
select i.instance_name, name, round (value / 1024 / 1024, 2) value
from gv$parameter p, gv$instance i
where p.inst_id = i.inst_id
and name in ('memory_max_target',
'memory_target',
'sga_max_size',
'sga_target',
'pga_aggregate_target')
order by 1;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#memory">Back to Memory Statistics</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | SGA Show |
-- +----------------------------------------------------------------------------+
prompt <a name="42"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Show SGA</b></font>
clear columns breaks computes
column instance_name format a13 heading 'Instance' print entmap off
column name format a30 heading 'Name' print entmap off
column value format 999,990.99 heading 'Size_MB' print entmap off
break on report on instance_name
compute sum label 'Total SGA:' of value on instance_name
select i.instance_name,
s.name,
round(s.value/1024/1024,2) value
from gv$sga s, gv$instance i
where s.inst_id = i.inst_id
order by i.instance_name, s.value desc;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#memory">Back to Memory Statistics</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | SGA Info |
-- +----------------------------------------------------------------------------+
prompt <a name="43"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>SGA Info</b></font>
clear columns breaks computes
break on report on instance_name
column instance_name format a13 heading 'Instance' print entmap off
column name format a50 heading 'Pool Name' print entmap off
column bytes format 999,990.99 heading 'Size_MB' print entmap off
column resizeable format a10 heading 'Resizeable' print entmap off
select instance_name,
name,
round (bytes / 1024 / 1024, 2) bytes,
resizeable
from gv$sgainfo s, gv$instance i
where s.inst_id = i.inst_id
order by 1, 3 desc;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#memory">Back to Memory Statistics</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | PGA Info |
-- +----------------------------------------------------------------------------+
prompt <a name="44"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>PGA Info</b></font>
clear columns breaks computes
column instance_name format a13 heading 'Instance' print entmap off
column name format a50 heading 'Name' print entmap off
column total_mb format 999,999,990.99 heading 'Total_MB' print entmap off
column unit format a7 heading 'Unit' print entmap off
break on report on instance_name
select i.instance_name,
p.name,
round (p.value / 1024 / 1024, 2) total_mb,
p.unit
from gv$pgastat p, gv$instance i
where p.inst_id = i.inst_id
order by 1, 3 desc,4;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#memory">Back to Memory Statistics</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- Security
-- ==============================================================================
prompt <a name="secutiry"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Security Information</b></font>
prompt <ul>-
<li><a href='#51'>User Summary</a></li>-
<li><a href='#52'>User Profiles</a></li>-
<li><a href='#53'>Role</a></li>-
<li><a href='#54'>Database Links</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | User Info |
-- +----------------------------------------------------------------------------+
prompt <a name="51"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>User Summary</b></font>-
<br>
-- User Information
prompt <font size="2pt"><b>User Information</b></font>
clear columns breaks computes
column username format a30 heading 'Username' print entmap off
column default_tablespace format a18 heading 'Default Tablespace' print entmap off
column temporary_tablespace format a15 heading 'Temp Tablespace' print entmap off
column created format a19 heading 'Created' print entmap off
column expiry_date format a19 heading 'Expire Date' print entmap off
column lock_date format a19 heading 'Lock Date' print entmap off
column profile format a20 heading 'Profile' print entmap off
column sysdba format a6 heading 'SYSDBA' print entmap off
column sysoper format a7 heading 'SYSOPER' print entmap off
column sysasm format a6 heading 'SYSASM' print entmap off
column account_status format a16 heading 'Account Status' print entmap off
select distinct a.username,
a.default_tablespace,
a.temporary_tablespace,
a.profile,
a.account_status,
to_char (a.created, 'YYYY-MM-DD HH24:MI:SS') created,
to_char (a.expiry_date, 'YYYY-MM-DD HH24:MI:SS') expiry_date,
to_char (a.lock_date, 'YYYY-MM-DD HH24:MI:SS') lock_date
from dba_users a
order by a.account_status desc;
-- User With SYSDBA Privilege
prompt <font size="2pt"><b>User With SYSDBA Privilege</b></font>
select * from v$pwfile_users;
-- User With DBA Privilege
prompt <font size="2pt"><b>User With DBA Privilege</b></font>
clear columns breaks computes
column grantee for a50 heading 'User' print entmap off
column granted_role for a4 heading 'Role' print entmap off
column admin_option for a12 heading 'Admin Option' print entmap off
column default_role for a12 heading 'Default Role' print entmap off
select grantee,
granted_role,
admin_option,
default_role
from dba_role_privs
where granted_role = 'DBA';
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#secutiry">Back to Security Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | User Profiles |
-- +----------------------------------------------------------------------------+
prompt <a name="52"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>User Profiles</b></font>
clear columns breaks computes
column profile format a20 heading 'Profile' print entmap off
column resource_name format a50 heading 'Resource Name' print entmap off
column resource_type format a30 heading 'Resource Type' print entmap off
column limit format a30 heading 'Limit' print entmap off
break on profile
select profile,
resource_name,
resource_type,
limit
from dba_profiles
order by profile;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#secutiry">Back to Security Information</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Role |
-- +----------------------------------------------------------------------------+
prompt <a name="53"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Roles</b></font>
clear columns breaks computes
column role for a50 heading 'Role name' print entmap off
column grantee for a50 heading 'Grantee' print entmap off
column admin_option for a15 heading 'Admin Option' print entmap off
column default_role for a15 heading 'Default Role' print entmap off
break on role
select b.role,
a.grantee,
a.admin_option,
a.default_role
from dba_role_privs a, dba_roles b
where granted_role(+) = b.role
order by b.role, a.grantee;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#secutiry">Back to Security Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | DB Links |
-- +----------------------------------------------------------------------------+
prompt <a name="54"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Database Links</b></font>
clear columns breaks computes
column owner for a30 heading 'Owner' print entmap off
column db_link for a30 heading 'DB Link' print entmap off
column username for a30 heading 'Username' print entmap off
column host for a30 heading 'Host' print entmap off
column created for a19 heading 'Created' print entmap off
break on owner
select owner,
db_link,
username,
host,
to_char (created, 'YYYY-MM-DD HH24:MI:SS') created
from dba_db_links
order by owner, db_link;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#secutiry">Back to Security Information</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- Objects
-- ==============================================================================
prompt <a name="object"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Objects Information</b></font>
prompt <ul>-
<li><a href='#61'>Invalid Objects</a></li>-
<li><a href='#62'>Disabled Constraints</a></li>-
<li><a href='#63'>Disabled Triggers</a></li>-
<li><a href='#64'>Objects In System Tablespace</a></li>-
<li><a href='#65'>Directory Information</a></li>-
<li><a href='#66'>Recyclebin</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Invalid Objects |
-- +----------------------------------------------------------------------------+
prompt <a name="61"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Invalid Objects</b></font>-
<br>
-- Invalid Objects Count
prompt <font size="2pt"><b>Invalid Objects Count</b></font>
clear columns breaks computes
column owner for a30 heading 'Owner' print entmap off
column object_name for a50 heading 'Name' print entmap off
column object_type for a50 heading 'Type' print entmap off
column count for 999,999 heading 'Count' print entmap off
column status for a7 heading 'Status' print entmap off
select owner,
object_type,
status,
count (object_name) as "count"
from dba_objects
where status = 'INVALID'
group by owner, object_type, status
order by count (object_name) desc;
-- Invalid Objects Detail
prompt <font size="2pt"><b>Invalid Objects Detail</b></font>
break on owner on object_type
select owner,
object_type,
object_name,
status
from dba_objects
where status = 'INVALID'
order by 1,2,3;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#object">Back to Objects Information</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Disabled Constraints |
-- +----------------------------------------------------------------------------+
prompt <a name="62"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Disabled Constraints</b></font>
clear columns breaks computes
column owner format a20 heading 'Owner' print entmap off;
column constraint_name format a30 heading 'Constraint Name' print entmap off;
column constraint_type format a15 heading 'Constraint Type' print entmap off;
column table_name format a30 heading 'Table Name' print entmap off;
break on owner on table_name
select owner,
table_name,
constraint_name,
decode (constraint_type,
'C', 'check constraint on a table',
'P', 'primary key',
'U', 'unique key',
'R', 'referential integrity',
'V', 'with check option, on a view',
'O', 'with read only, on a view',
null)
constraint_type
from dba_constraints
where status = 'DISABLED'
order by 1,2;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#object">Back to Objects Information</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Disabled Triggers |
-- +----------------------------------------------------------------------------+
-- Check if there have disabled triggers
---- Recompile the disabled triggers
prompt <a name="63"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Disabled Triggers</b></font>
clear columns breaks computes
column owner format a20 heading 'Owner' print entmap off
column trigger_name format a30 heading 'Trigger Name' print entmap off
column trigger_type format a20 heading 'Trigger Type' print entmap off
break on owner
select owner, trigger_name, trigger_type
from dba_triggers
where status = 'DISABLED';
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#object">Back to Objects Information</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Object In System Tablespace |
-- +----------------------------------------------------------------------------+
prompt <a name="64"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Objects In System Tablespace</b></font>
-- Check tables and indexes in system tablespace that not belong to sys or system
clear columns breaks computes
column object_type format a15 heading 'Object Type' print entmap off
column owner format a20 heading 'Owner' print entmap off
column tablespace format a30 heading 'Tablespace' print entmap off
column object_name format a30 heading 'Object Name' print entmap off
break on object_type on owner on tablespace
select object_type,
owner,
tablespace_name tablespace,
object_name
from (select 'Table' object_type,
owner,
tablespace_name,
table_name object_name
from dba_tables
union
select 'Index' object_type,
owner,
tablespace_name,
index_name object_name
from dba_indexes)
where tablespace_name = 'SYSTEM'
and owner not in
('ANONYMOUS',
'BI',
'CTXSYS',
'DBSNMP',
'DIP',
'DMSYS',
'EXFSYS',
'HR',
'IX',
'LBACSYS',
'MDDATA',
'MDSYS',
'MGMT_VIEW',
'OE',
'OLAPSYS',
'ORDPLUGINS',
'ORDSYS',
'OUTLN',
'PM',
'SCOTT',
'SH',
'SI_INFORMTN_SCHEMA',
'SYS',
'SYSMAN',
'SYSTEM',
'WMSYS',
'WKPROXY',
'WK_TEST',
'WKSYS',
'XDB',
'APEX_030200',
'APEX_PUBLIC_USER',
'APPQOSSYS',
'DVSYS',
'FLOWS_FILES',
'IX',
'LBACSYS',
'ORACLE_OCM',
'OWBSYS',
'OWBSYS_AUDIT',
'SPATIAL_CSW_ADMIN_USR',
'SPATIAL_WFS_ADMIN_USR');
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#object">Back to Objects Information</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Directory |
-- +----------------------------------------------------------------------------+
prompt <a name="65"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Directory Information</b></font>-
<br>
-- Directory List
prompt <font size="2pt"><b>Directory List</b></font>
clear columns breaks computes
column owner format a30 heading 'Owner' print entmap off
column directory_name format a30 heading 'Directory Name' print entmap off
column directory_path format a100 heading 'Directory Path' print entmap off
break on report on owner
select owner,
directory_name,
directory_path
from dba_directories
order by owner,directory_name;
-- Directory Privilege
prompt <font size="2pt"><b>Directory Privilege</b></font>
clear columns breaks computes
column table_name format a30 heading 'Directory Name' print entmap off
column grantee format a30 heading 'Grantee' print entmap off
column privilege format a9 heading 'Privilege' print entmap off
column grantable format a9 heading 'Grantable' print entmap off
break on report on table_name on grantee
select table_name,
grantee,
privilege,
grantable
from dba_tab_privs
where privilege in ('READ', 'WRITE')
order by table_name, grantee, privilege;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#object">Back to Objects Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Recyclebin |
-- +----------------------------------------------------------------------------+
prompt <a name="66"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Recyclebin</b></font>
clear columns breaks computes
column owner heading 'Owner' print entmap off
column type format a50 heading 'Object Type' print entmap off
column count format 999999 heading 'Count' print entmap off
break on report on owner
compute sum label 'Total:' of count on report
select owner,type,count(*) count
from dba_recyclebin
group by owner,type;
/*
column owner heading 'Owner' print entmap off
column original_name heading 'Original Name' print entmap off
column type format a50 heading 'Object Type' print entmap off
column object_name format a50 heading 'Object Name' print entmap off
column ts_name format a50 heading 'Tablespace' print entmap off
column operation format a9 heading 'Operation' print entmap off
column createtime format a19 heading 'Create Time' print entmap off
column droptime format a19 heading 'Drop Time' print entmap off
column can_undrop format a10 heading 'Can Undrop' print entmap off
column can_purge format a9 heading 'Can Purge' print entmap off
column size_mb format 999,990.99 heading 'Size_MB' print entmap off
break on report on owner
compute count label 'Count:' of original_name on report
select owner,
original_name,
type,
object_name,
ts_name,
operation,
createtime,
droptime,
can_undrop,
can_purge,
round((space * p.blocksize) / 1024 / 1024,2) as "size_mb"
from dba_recyclebin r,
(select value blocksize
from v$parameter
where name = 'db_block_size') p
order by owner, object_name;
*/
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#object">Back to Objects Information</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- Jobs
-- ==============================================================================
prompt <a name="job"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Jobs</b></font>
clear columns breaks computes
column job format 999999 heading 'Job ID'
column log_user format a30 heading 'Log User'
column what format a150 heading 'What'
column next_date format a19 heading 'Next Date'
column interval format a10 heading 'Interval'
column last_date format a19 heading 'Last Date'
column failures format 999999 heading 'Failures'
column broken format a6 heading 'Broken'
select job,
log_user,
what,
next_date,
interval,
last_date,
failures,
broken
from dba_jobs
order by job;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#job">Back to Jobs Information</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- Backup
-- ==============================================================================
prompt <a name="backup"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Backup Information</b></font>
prompt <ul>-
<li><a href='#71'>RMAN Backup Job</a></li>-
<li><a href='#72'>RMAN Configure</a></li>-
<li><a href='#73'>RMAN Backupset</a></li>-
<li><a href='#74'>RMAN Backup Piece</a></li>-
<li><a href='#75'>RMAN Backup Controlfile</a></li>-
<li><a href='#76'>RMAN Backup Spfile</a></li>-
<li><a href='#77'>Archive Log List</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | RMAN Backup Job |
-- +----------------------------------------------------------------------------+
prompt <a name="71"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>RMAN Backup Job</b></font>
clear columns breaks computes
column backup_name format a19 heading 'Backup Name' print entmap off
column start_time format a19 heading 'Start Time' print entmap off
column elapsed_time format a12 heading 'Elapsed Time' print entmap off
column status format a30 heading 'Status' print entmap off
column input_type format a30 heading 'Input Type' print entmap off
column output_device_type format a11 heading 'Output Type' print entmap off
column input_size format a10 heading 'Input Size' print entmap off
column output_size format a11 heading 'Output Size' print entmap off
column output_rate_per_sec format a13 heading 'Output Rate/s' print entmap off
select r.command_id backup_name,
to_char(r.start_time, 'YYYY-MM-DD HH24:MI:SS') start_time,
r.time_taken_display elapsed_time,
decode(r.status,'COMPLETED',r.status,'<div align="left"><font color="red">' || r.status || '</font></div>') status,
r.input_type input_type,
r.output_device_type output_device_type,
r.input_bytes_display input_size,
r.output_bytes_display output_size,
r.output_bytes_per_sec_display output_rate_per_sec
from
( select command_id,start_time,time_taken_display,status,input_type,output_device_type,input_bytes_display,output_bytes_display,output_bytes_per_sec_display
from v$rman_backup_job_details
order by start_time desc
) r;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#backup">Back to Backup Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | RMAN Configure |
-- +----------------------------------------------------------------------------+
prompt <a name="72"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>RMAN Configure</b></font>
clear columns breaks computes
column name format a150 heading 'name' print entmap off
column value format a150 heading 'value' print entmap off
select name,value
from v$rman_configuration;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#backup">Back to Backup Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | RMAN Backupset |
-- +----------------------------------------------------------------------------+
prompt <a name="73"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>RMAN Backupset</b></font>
clear columns breaks computes
column bs_key format 999,999 heading 'BS Key'
column backup_type format a20 heading 'Backup Type'
column device_type format a11 heading 'Device Type'
column controlfile_included format a20 heading 'Controlfile Included'
column spfile_included format a15 heading 'SPFILE Included'
column incremental_level format 999 heading 'Incremental Level'
column pieces format 999,999 heading 'Pieces#'
column start_time format a19 heading 'Start Time'
column completion_time format a19 heading 'End Time'
column elapsed_seconds format 999,999,999,999 heading 'Elapsed Seconds'
column tag format a18 heading 'Tag'
column block_size format 999,999,999 heading 'Block Size'
column keep format a4 heading 'Keep'
column keep_until format a19 heading 'Keep Until'
column keep_options format a12 heading 'Keep Options'
break on report
compute sum label 'Total:' of pieces elapsed_seconds on report
select bs.recid bs_key,
decode (backup_type,'L', 'Archived Redo Logs','D', 'Datafile Full Backup','I', 'Incremental Backup') backup_type,
device_type,
decode (bs.controlfile_included, 'NO', '-', bs.controlfile_included) controlfile_included,
nvl (sp.spfile_included, '-') spfile_included,
bs.incremental_level,
bs.pieces,
to_char (bs.start_time, 'YYYY-MM-DD HH24:MI:SS') start_time,
to_char (bs.completion_time, 'YYYY-MM-DD HH24:MI:SS') completion_time,
bs.elapsed_seconds,
bp.tag,
bs.block_size,
bs.keep,
to_char (bs.keep_until, 'YYYY-MM-DD HH24:MI:SS') keep_until,
bs.keep_options
from v$backup_set bs,
(select distinct set_stamp,
set_count,
tag,
device_type
from v$backup_piece
where status in ('A', 'X')) bp,
(select distinct set_stamp, set_count, 'YES' spfile_included
from v$backup_spfile) sp
where bs.set_stamp = bp.set_stamp
and bs.set_count = bp.set_count
and bs.set_stamp = sp.set_stamp(+)
and bs.set_count = sp.set_count(+)
order by bs.recid;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#backup">Back to Backup Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | RMAN Backup Piece |
-- +----------------------------------------------------------------------------+
prompt <a name="74"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>RMAN Backup Piece</b></font>
clear columns breaks computes
column bs_key format 999,999 heading 'BS Key' print entmap off
column piece# format 999,999 heading 'Piece#' print entmap off
column copy# format 999,999 heading 'Copy#' print entmap off
column bp_key format 999,999 heading 'BP Key' print entmap off
column status format a30 heading 'Status' print entmap off
column handle format a150 heading 'Handle' print entmap off
column start_time format a19 heading 'Start Time' print entmap off
column completion_time format a19 heading 'End Time' print entmap off
column elapsed_seconds format 999,999,999,999 heading 'Elapsed Seconds' print entmap off
break on bs_key
select bs.recid bs_key,
bp.piece#,
bp.copy#,
bp.recid bp_key,
decode (bp.status, 'A', 'Available',
'D', '<div align="left"><font color="red">' || 'Deleted' || '</font></div>',
'X', '<div align="left"><font color="red">' || 'Expired' || '</font></div>') status,
bp.handle,
to_char (bp.start_time, 'YYYY-MM-DD HH24:MI:SS') start_time,
to_char (bp.completion_time, 'YYYY-MM-DD HH24:MI:SS') completion_time,
bp.elapsed_seconds
from v$backup_set bs, v$backup_piece bp
where bs.set_stamp = bp.set_stamp
and bs.set_count = bp.set_count
and bp.status in ('A', 'X')
order by bs.recid, piece#;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#backup">Back to Backup Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | RMAN Backup Controlfile |
-- +----------------------------------------------------------------------------+
prompt <a name="75"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>RMAN Backup Controlfile</b></font>
clear columns breaks computes
column bs_key format 999,999 heading 'BS Key' print entmap off
column piece# format 999,999 heading 'Piece#' print entmap off
column copy# format 999,999 heading 'Copy#' print entmap off
column bp_key format 999,999 heading 'BP Key' print entmap off
column controlfile_included format a20 heading 'Controlfile Included' print entmap off
column status format a30 heading 'Status' print entmap off
column handle format a150 heading 'Handle' print entmap off
column start_time for a19 heading 'Start Time' print entmap off
column completion_time for a19 heading 'End Time' print entmap off
column elapsed_seconds for 999,999,999,999 heading 'Elapsed Seconds' print entmap off
break on bs_key
select bs.recid bs_key,
bp.piece#,
bp.copy#,
bp.recid bp_key,
decode (bs.controlfile_included, 'NO', '-', bs.controlfile_included) controlfile_included,
decode (bp.status, 'A', 'Available',
'D', '<div align="left"><font color="red">' || 'Deleted' || '</font></div>',
'X', '<div align="left"><font color="red">' || 'Expired' || '</font></div>') status,
handle
from v$backup_set bs, v$backup_piece bp
where bs.set_stamp = bp.set_stamp
and bs.set_count = bp.set_count
and bp.status in ('A', 'X')
and bs.controlfile_included != 'NO'
order by bs.recid, piece#;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#backup">Back to Backup Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | RMAN Backup Spfile |
-- +----------------------------------------------------------------------------+
prompt <a name="76"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>RMAN Backup Spfile</b></font>
clear columns breaks computes
column bs_key format 999,999 heading 'BS Key' print entmap off
column piece# format 999,999 heading 'Piece#' print entmap off
column copy# format 999,999 heading 'Copy#' print entmap off
column bp_key format 999,999 heading 'BP Key' print entmap off
column spfile_included format a15 heading 'SPFILE Included' print entmap off
column status format a30 heading 'Status' print entmap off
column handle format a150 heading 'Handle' print entmap off
column start_time format a19 heading 'Start Time' print entmap off
column completion_time format a19 heading 'End Time' print entmap off
column elapsed_seconds format 999,999,999,999 heading 'Elapsed Seconds' print entmap off
break on bs_key
select bs.recid bs_key,
bp.piece#,
bp.copy#,
bp.recid bp_key,
nvl (sp.spfile_included, '-') spfile_included,
decode (bp.status, 'A', 'Available',
'D', '<div align="left"><font color="red">' || 'Deleted' || '</font></div>',
'X', '<div align="left"><font color="red">' || 'Expired' || '</font></div>') status,
handle
from v$backup_set bs,
v$backup_piece bp,
(select distinct set_stamp, set_count, 'YES' spfile_included
from v$backup_spfile) sp
where bs.set_stamp = bp.set_stamp
and bs.set_count = bp.set_count
and bp.status in ('A', 'X')
and bs.set_stamp = sp.set_stamp
and bs.set_count = sp.set_count
order by bs.recid, piece#;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#backup">Back to Backup Information</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | Archive Mode |
-- +----------------------------------------------------------------------------+
prompt <a name="77"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Archive Log List</b></font>
clear columns breaks computes
column inst_id format 999 heading 'Inst_ID' entmap off
column log_mode format a15 heading 'Database Log Mode' entmap off
column log_archive_start format a20 heading 'Automatic Archival' entmap off
column oldest_online_log_sequence format 999999999999999 heading 'Oldest Online Log Sequence' entmap off
column current_log_sequence format 999999999999999 heading 'Current Log Sequence' entmap off
column destination format a80 heading 'Archive Destination' entmap off
select a.inst_id,
d.log_mode,
p.log_archive_start,
a.destination,
o.oldest_online_log_sequence,
c.current_log_sequence
from (select decode (log_mode,'ARCHIVELOG', 'Archive Mode','NOARCHIVELOG', 'No Archive Mode',log_mode) log_mode
from v$database) d,
(select decode (log_mode,'ARCHIVELOG', 'Enabled','NOARCHIVELOG', 'Disabled') log_archive_start
from v$database) p,
(select inst_id,destination
from gv$archive_dest
where status='VALID' and inst_id = 1) a,
(select sequence# current_log_sequence
from v$log
where status = 'CURRENT' and thread# = 1) c,
(select min (sequence#) oldest_online_log_sequence
from v$log where thread# = 1 ) o
union all
select a.inst_id,
d.log_mode,
p.log_archive_start,
a.destination,
o.oldest_online_log_sequence,
c.current_log_sequence
from (select decode (log_mode,'ARCHIVELOG', 'Archive Mode','NOARCHIVELOG', 'No Archive Mode',log_mode) log_mode
from v$database) d,
(select decode (log_mode,'ARCHIVELOG', 'Enabled','NOARCHIVELOG', 'Disabled') log_archive_start
from v$database) p,
(select inst_id,destination
from gv$archive_dest
where status='VALID' and inst_id = 2) a,
(select sequence# current_log_sequence
from v$log
where status = 'CURRENT' and thread# = 2) c,
(select min (sequence#) oldest_online_log_sequence
from v$log where thread# = 2 ) o
union all
select a.inst_id,
d.log_mode,
p.log_archive_start,
a.destination,
o.oldest_online_log_sequence,
c.current_log_sequence
from (select decode (log_mode,'ARCHIVELOG', 'Archive Mode','NOARCHIVELOG', 'No Archive Mode',log_mode) log_mode
from v$database) d,
(select decode (log_mode,'ARCHIVELOG', 'Enabled','NOARCHIVELOG', 'Disabled') log_archive_start
from v$database) p,
(select inst_id,destination
from gv$archive_dest
where status='VALID' and inst_id = 3) a,
(select sequence# current_log_sequence
from v$log
where status = 'CURRENT' and thread# = 3) c,
(select min (sequence#) oldest_online_log_sequence
from v$log where thread# = 3 ) o
union all
select a.inst_id,
d.log_mode,
p.log_archive_start,
a.destination,
o.oldest_online_log_sequence,
c.current_log_sequence
from (select decode (log_mode,'ARCHIVELOG', 'Archive Mode','NOARCHIVELOG', 'No Archive Mode',log_mode) log_mode
from v$database) d,
(select decode (log_mode,'ARCHIVELOG', 'Enabled','NOARCHIVELOG', 'Disabled') log_archive_start
from v$database) p,
(select inst_id,destination
from gv$archive_dest
where status='VALID' and inst_id = 4) a,
(select sequence# current_log_sequence
from v$log
where status = 'CURRENT' and thread# = 4) c,
(select min (sequence#) oldest_online_log_sequence
from v$log where thread# = 4 ) o;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#backup">Back to Backup Information</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- Performance Statistics
-- ==============================================================================
prompt <a name="performance"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Performance Statistics</b></font>
prompt <ul>-
<li><a href='#81'>Statistics Level</a></li>-
<li><a href='#82'>10g Gather Stats Job Information</a></li>-
<li><a href='#83'>11g Gather Stats Job Information</a></li>-
<li><a href='#84'>Objects Without Statistics Within 30 Days</a></li>-
<li><a href='#85'>Resource Limit</a></li>-
<li><a href='#86'>AWR Setting</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | STATISTICS LEVEL |
-- +----------------------------------------------------------------------------+
prompt <a name="81"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Statistics Level</b></font>
clear columns breaks computes
column instance_name format a95 heading 'Instance' entmap off
column statistics_name format a95 heading 'Statistics Name' entmap off
column session_status format a95 heading 'Session Status' entmap off
column system_status format a95 heading 'System Status' entmap off
column activation_level format a95 heading 'Activation Level' entmap off
column statistics_view_name format a95 heading 'Statistics View Name' entmap off
column session_settable format a95 heading 'Session Settable' entmap off
break on report on instance_name
select i.instance_name,
s.statistics_name,
s.session_status,
s.system_status,
s.activation_level,
s.statistics_view_name,
s.session_settable
from gv$statistics_level s, gv$instance i
where s.inst_id = i.inst_id
order by i.instance_name, s.statistics_name;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#performance">Back to Performance Statistics</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Optimizer Job(10g) |
-- +----------------------------------------------------------------------------+
-- 10g,gather statistics job
prompt <a name="82"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>10g Gather Stats Job Information</b></font>
clear columns breaks computes
column owner format a30 heading 'Owner' print entmap off
column job_name format a30 heading 'Job Name' print entmap off
column job_action format a30 heading 'Job Action' print entmap off
column enabled format a15 heading 'Enable' print entmap off
column state format a15 heading 'State' print entmap off
select owner,
job_name,
job_action,
enabled,
state
from dba_scheduler_jobs
where job_name = 'GATHER_STATS_JOB';
---- For 10g gather_stats_job runing details
clear columns breaks computes
column owner format a6 heading 'Owner' print entmap off
column job_name format a20 heading 'Job Name' print entmap off
column status format a15 heading 'Status' print entmap off
column additional_info format a20 heading 'Additional Info' print entmap off
column run_duration format a10 heading 'Run Duration' print entmap off
column instance_id format 99 heading 'Inst ID' print entmap off
column session_id format a10 heading 'Session ID' print entmap off
column start_date format a25 heading 'Start Time' print entmap off
column end_date format a25 heading 'End Time' print entmap off
column error# format 999 heading 'Error#' print entmap off
select instance_id,
session_id,
owner,
job_name,
status,
error#,
additional_info,
to_char (actual_start_date, 'YYYY-MM-DD HH24:MI:SS') start_date,
to_char (log_date, 'YYYY-MM-DD HH24:MI:SS') end_date,
run_duration
--( extract (day from run_duration)*24*60 + extract (hour from run_duration)*60 + extract (minute from run_duration)) + extract (second from run_duration)/60 "Run_Duration(Min)"
from dba_scheduler_job_run_details
where job_name = 'GATHER_STATS_JOB'
order by log_id;
---- For 10g,Check gather stats windows
clear columns breaks computes
column window_group_name heading 'Window Group Name' print entmap off
column window_name heading 'Window Name' print entmap off
break on window_group_name on window_name;
select window_group_name,
window_name
from dba_scheduler_wingroup_members
where window_group_name = 'MAINTENANCE_WINDOW_GROUP'
having (select substr(version,1,2) from v$instance) = '10';
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#performance">Back to Performance Statistics</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Optimizer Job(11g) |
-- +----------------------------------------------------------------------------+
prompt <a name="83"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>11g Gather Stats Job Information</b></font>-
<br>
-- On Oracle 10g,not exists table dba_autotask_client and dba_autotask_client_history
-- Below 2 query will raise error:table or view does not exist
-- Please ignore this error.
prompt <font size="1pt"><b> On Oracle 10g,not exists table dba_autotask_client and dba_autotask_client_history.</b></font>
prompt <font size="1pt"><b> This query only for 11g, please ignore the query errors on oracle 10g.</b></font>
-- 11g,gather statistics job
clear columns breaks computes
column client_name heading 'Client Name' print entmap off
column status heading 'Status' print entmap off
select client_name,
status
from dba_autotask_client;
-- 11g gather_stats_job runing details
clear columns breaks computes
break on client_name
column client_name format a60 heading 'Client Name' print entmap off
column window_name format a60 heading 'Window Nmae' print entmap off
column jobs_created heading 'Jobs Created' print entmap off
column jobs_started heading 'Jobs Started' print entmap off
column jobs_completed heading 'Jobs Completed' print entmap off
column start_time format a20 heading 'Start Time' print entmap off
column end_time format a20 heading 'End Time' print entmap off
column window_duration heading 'Run Duration' print entmap off
select client_name,
window_name,
jobs_created,
jobs_started,
jobs_completed,
to_char(window_start_time,'YYYY-MM-DD HH24:MI:SS') start_time,
to_char(window_end_time,'YYYY-MM-DD HH24:MI:SS') end_time,
window_duration
from dba_autotask_client_history
where client_name = 'auto optimizer stats collection';
/*
-- PL/SQL display the table (dba_autotask_client and dba_autotask_client_history) information that not exists in 10g without raise any errors
-- Use PL/SQL Intead of 2 query above.
declare
v_version varchar2 (5);
type c_type is ref cursor;
v_c1 c_type;
v_c2 c_type;
sql_a varchar2 (100);
sql_b varchar2 (4000);
v_client_name varchar2 (100);
v_status varchar2 (100);
v_client varchar2 (100);
v_window_name varchar2 (100);
v_jobs_created number;
v_jobs_started number;
v_jobs_completed number;
v_start_time char (19);
v_end_time char (19);
v_window_duration interval day (9) to second (6);
begin
sql_a := 'select client_name, status from dba_autotask_client';
sql_b :=
'select client_name client,
window_name,
jobs_created,
jobs_started,
jobs_completed,
to_char(window_start_time,''YYYY-MM-DD HH24:MI:SS'') start_time,
to_char(window_end_time,''YYYY-MM-DD HH24:MI:SS'') end_time,
window_duration
from dba_autotask_client_history
where client_name = ''auto optimizer stats collection''';
select substr (version, 1, 2) into v_version from v$instance;
if v_version = '11'
then
--dbms_output.put_line (v_version);
-- table sql_a
dbms_output.put ('<table>');
dbms_output.put (
'<tr>'
|| '<th>'
|| 'Client Name'
|| '</th>'
|| '<th>'
|| 'Status'
|| '</th>'
|| '</tr>');
open v_c1 for sql_a;
loop
fetch v_c1
into v_client_name, v_status;
exit when v_c1%notfound;
dbms_output.put (
'<tr>'
|| '<td>'
|| v_client_name
|| '</td>'
|| '<td>'
|| v_status
|| '</td>'
|| '</tr>');
end loop;
dbms_output.put_line ('</table>');
-- table sql_b
dbms_output.put ('<table>');
dbms_output.put_line (
'<tr>'
|| '<th>'
|| 'Client Name'
|| '</th>'
|| '<th>'
|| 'Window Name'
|| '</th>'
|| '<th>'
|| 'Jobs Created'
|| '</th>'
|| '<th>'
|| 'Jobs Started'
|| '</th>'
|| '<th>'
|| 'Jobs Completed'
|| '</th>'
|| '<th>'
|| 'Start Time'
|| '</th>'
|| '<th>'
|| 'End Time'
|| '</th>'
|| '<th>'
|| 'Window Duration'
|| '</th>'
|| '</tr>');
open v_c2 for sql_b;
loop
fetch v_c2
into v_client,
v_window_name,
v_jobs_created,
v_jobs_started,
v_jobs_completed,
v_start_time,
v_end_time,
v_window_duration;
exit when v_c2%notfound;
dbms_output.put_line (
'<tr>'
|| '<td>'
|| v_client
|| '</td>'
|| '<td>'
|| v_window_name
|| '</td>'
|| '<td>'
|| v_jobs_created
|| '</td>'
|| '<td>'
|| v_jobs_started
|| '</td>'
|| '<td>'
|| v_jobs_completed
|| '</td>'
|| '<td>'
|| v_start_time
|| '</td>'
|| '<td>'
|| v_end_time
|| '</td>'
|| '<td>'
|| v_window_duration
|| '</td>');
end loop;
dbms_output.put_line ('</table>');
end if;
end;
/
*/
clear columns breaks computes
column window_group_name heading 'Window Group Name' print entmap off
column window_name heading 'Window Name' print entmap off
break on window_group_name on window_name
select window_group_name,
window_name
from dba_scheduler_wingroup_members
where window_group_name = 'ORA$AT_WGRP_OS';
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#performance">Back to Performance Statistics</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Statistics Collect |
-- +----------------------------------------------------------------------------+
prompt <a name="84"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Objects Whitout Statistics Within 60 Days</b></font>
-- Stats the objects those not collect statistics within 60 days
clear columns breaks computes
column object_type heading 'Object Type' print entmap off
column owner heading 'Owner' print entmap off
column object_name heading 'Object Name' print entmap off
break on object_type skip 1 on owner on report
compute count label 'Count By Object Type:' of object_name on object_type
compute count label 'Count All:' of object_name on report
select object_type, owner, object_name
from (select 'Table' object_type, owner, table_name object_name
from dba_tables
where last_analyzed < sysdate - 60 and partitioned = 'NO'
union all
select 'Index' object_type, owner, index_name object_name
from dba_indexes
where last_analyzed < sysdate - 60 and partitioned = 'NO'
union all
select 'Partition Table' object_type, owner, table_name object_name
from dba_tables
where last_analyzed < sysdate - 60 and partitioned = 'YES'
union all
select 'Partition Index' object_type, owner, index_name object_name
from dba_indexes
where last_analyzed < sysdate - 60 and partitioned = 'YES')
where owner not in
('ANONYMOUS',
'BI',
'CTXSYS',
'DBSNMP',
'DIP',
'DMSYS',
'EXFSYS',
'HR',
'IX',
'LBACSYS',
'MDDATA',
'MDSYS',
'MGMT_VIEW',
'OE',
'OLAPSYS',
'ORDPLUGINS',
'ORDSYS',
'OUTLN',
'PM',
'SCOTT',
'SH',
'SI_INFORMTN_SCHEMA',
'SYS',
'SYSMAN',
'SYSTEM',
'WMSYS',
'WKPROXY',
'WK_TEST',
'WKSYS',
'XDB',
'APEX_030200',
'APEX_PUBLIC_USER',
'APPQOSSYS',
'DVSYS',
'FLOWS_FILES',
'IX',
'LBACSYS',
'ORACLE_OCM',
'OWBSYS',
'OWBSYS_AUDIT',
'SPATIAL_CSW_ADMIN_USR',
'SPATIAL_WFS_ADMIN_USR');
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#performance">Back to Performance Statistics</a>
prompt <a href="#top">Back to Top</a>
prompt <a name="85"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Resource Limit</b></font>
-- Resource limit
clear columns breaks computes
column resource_name format a50 heading 'Resource Name' print entmap off
column current_utilization format 999,999,999 heading 'Current Utilization' print entmap off
column max_utilization format 999,999,999 heading 'Max Utilization' print entmap off
column initial_allocation format a20 heading 'Initial Allocation' print entmap off
column limit_value format a20 heading 'Limit Value' print entmap off
select resource_name,
current_utilization,
max_utilization,
initial_allocation,
limit_value
from v$resource_limit;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#performance">Back to Performance Statistics</a>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | AWR Setting |
-- +----------------------------------------------------------------------------+
prompt <a name="86"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>AWR Setting</b></font>
clear columns breaks computes
column dbid heading 'DBID' print entmap off
column snap_interval heading 'Interval' print entmap off
column retention heading 'Retention' print entmap off
column topnsql heading 'TopN SQL' print entmap off
select dbid, snap_interval, retention, topnsql
from dba_hist_wr_control;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#performance">Back to Performance Statistics</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- Initialization Parameters
-- ==============================================================================
prompt <a name="parameter"></a>
prompt <font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Initialization Parameters</b></font>
prompt <ul>-
<li><a href='#91'>Not Default Init Parameters</a></li>-
<li><a href='#92'>All Database Initialization Parameters</a></li>-
</ul>
prompt <a href="#top">Back to Top</a>
-- +----------------------------------------------------------------------------+
-- | Not Default Initialization Parameters |
-- +----------------------------------------------------------------------------+
-- Not default init parameters
prompt <a name="91"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>Not Default Initialization Parameters</b></font>
clear columns breaks computes
column instance format a20 heading 'Instance' print entmap off
column name format a50 heading 'Name' print entmap off
column value format a300 heading 'Value' print entmap off
column isdefault format a10 heading 'Isdefault' print entmap off
break on instance
select i.instance_name instance,
p.name,
p.value,
p.isdefault
from gv$parameter p,
gv$instance i
where p.inst_id = i.inst_id
and isdefault = 'FALSE';
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#parameter">Back to Initialization Parameters</a>
prompt <a href="#top">Back to Top</a>
--prompt <br />
-- +----------------------------------------------------------------------------+
-- | All Database Initialization Parameters |
-- +----------------------------------------------------------------------------+
prompt <a name="92"></a>
prompt <font size="+1" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>All Database Initialization Parameters</b></font>
select ksppinm name,ksppstvl value
from x$ksppi a,x$ksppcv b
where a.indx = b.indx
order by name;
prompt <hr align="left" size="1" color="Gray" width="20%" />-
<a href="#parameter">Back to Initialization Parameters</a>
prompt <a href="#top">Back to Top</a>
prompt <br />
-- ==============================================================================
-- End Of Report
-- ==============================================================================
prompt <div align="right">-
<font size="-1" face="Arial,Helvetica,Geneva,sans-serif" color="gray">-
<hr size="2" color="Gray" align="right" noshade/>-
<b>Database Health Check Snapshot</b><br><b>Copyright (c) 2015 Stephen Zhao. All Rights Reserved</b>-
</font>-
</div>
spool off
set markup html off
set termout on
prompt
prompt Output written to: &filename._&_dbname._&_spool_time..html
prompt
exit;
###sample 3 perl
https://exchange.nagios.org/directory/Plugins/Databases/Oracle/Check-Oracle-status-&-health-without-install-Oracle-client/details
This perl nagios plugin allow you to check oracle service (ability to connect to database ) and health of oracle databse (Dictionary Cache Hit Ratio,Library Cache Hit Ratio,DB Block Buffer Cache Hit Ratio,Latch Hit Ratio,Disk Sort Ratio,Rollback Segment Waits,Dispatcher Workload) is possible define own parameters.Big advantage is that it does not need to install ORACLE client or compile other perl modules.
Instalation steps:
1/ download oracle instant client from http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html Instant Client Package - Basic and Instant Client Package - SQL*Plus unzip it and make sqlplus runnable from anywhere ( set new PATH or copy to defined PATH) and test SQLPLUS sqlplus user/passwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=IP or hostname)(Port=port))(CONNECT_DATA=(SID=sid)))
2/ copy check_oracle_instant script to libexec directory (on linux /usr/local/nagios/libexec)
and set correct rights and owner
3/ set /usr/local/nagios/objects/etc/commands.cfg add define own values
# ### CHECK ORACLE ###
define command{
command_name check_oracle_instant
command_line $USER1$/check_oracle_instant $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$ $ARG4$
}
4/ define service add and set own values
define service{
use profile name
host_name hostname
service_description ORACLE: check_login_health
check_command check_oracle_instant!port!sid!login!passwd
}
5/ restart nagios and that is all :-)
Reviews (12)
I am able to get proper output of the command when I am using it from the shell of Nagios server.
But when I am trying get it executed through service in Nagios, it is saying 'Unable to connect to ORACLE orcl, error !!!'
Is there I am missing something to configure in Nagios?
This plugin is very good in the way that you don't need the Oracle client. I did change the script to suit my needs: split the checks, add perfdata and variable thresholds.
$host = $ARGV[0];
$port = $ARGV[1];
$sid = $ARGV[2];
$user = $ARGV[3];
$pass = $ARGV[4];
$check = $ARGV[5];
$thresholdw = $ARGV[6];
$thresholdc = $ARGV[7];
$ENV{LD_LIBRARY_PATH} = "/etc/oracle";
$sqlplus = '/etc/oracle/sqlplus';
sub trim($);
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3);
my %checks = (
'dictionary' => 0,
'library' => 1,
'blockbuffer' => 2,
'latch' => 3,
'disk' => 4,
'rollback' => 5,
'dispatcher' => 6,
);
my @param_array = (
[">","Dictionary Cache Hit Ratio",'SELECT (1 - (Sum(getmisses)/(Sum(gets) + Sum(getmisses)))) * 100 FROM v\$rowcache;'],
[">","Library Cache Hit Ratio",'SELECT (1 -(Sum(reloads)/(Sum(pins) + Sum(reloads)))) * 100 FROM v\$librarycache;'],
[">","DB Block Buffer Cache Hit Ratio",'SELECT (1 - (phys.value / (db.value + cons.value))) * 100 FROM v\$sysstat phys,v\$sysstat db,v\$sysstat cons WHERE phys.name = \'physical reads\' AND db.name = \'db block gets\' AND cons.name = \'consistent gets\';'],
[">","Latch Hit Ratio",'SELECT (1 - (Sum(misses) / Sum(gets))) * 100 FROM v\$latch;'],
[" "unless (".$results.$param_array[$checks{$check}][0].$thresholdw.") {print\"".$param_array[$checks{$check}][1]." on ".$sid." is WARNING ($results !$param_array[$checks{$check}][0] $thresholdw)\\n| $perfcounter\"; exit ".$ERRORS{"WARNING"}.";}";
print "$param_array[$checks{$check}][1] on $sid is OK ($results $param_array[$checks{$check}][0] $thresholdw)|$perfcounter";
exit $ERRORS{"OK"};
} else {print "Bad check - values are: dictionary,library,blockbuffer,latch,disk,rollback,dispatcher\n "; exit $ERRORS{"UNKNOWN"};}
This is an excellent script. I had to made few changes for making it to work with Oracle 12c PDBs.
First, my sqlplus binary is 64 bits, so I edited the script changing it for 'sqlplus64'.
In Oracle 12c you can use a "Container" and put many datbases in there, as PDB. But in this case, they don't use the variable SID, instead, you must use SERVICE_NAME.
So, I changed this:
==> sub logon {
==> open (SQL,"sqlplus -s aloha/teste@\\(DESCRIPTION=\\(ADDRESS=\\(PROTOCOL=TCP\\)\\(Host=$host\\)\\(Port=$port\\)\\)\\(CONNECT_DATA=\\(SID=$sid\\)\\)\\) sub logon {
==> open (SQL,"sqlplus64 -s aloha/teste@\\(DESCRIPTION=\\(ADDRESS=\\(PROTOCOL=TCP\\)\\(Host=$host\\)\\(Port=$port\\)\\)\\(CONNECT_DATA=\\(SERVICE_NAME=$sid\\)\\)\\)racle 12c
Therefore i rewrote this script, so that the usability will be higher, i will post this one soon.
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 and SQL*Plus: Release 11.2.0.2.0 Production and it wont work, SQL plus will connect using something like
sqlplus username/passowrd@ip_address:port/SSID
rather than
sqlplus user/passwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=IP or hostname)(Port=port))(CONNECT_DATA=(SID=sid)))
ANy ideas on how to make this work? I cant figure it out ...
To make it work with a RAC cluster I had to do the following little changes in the code of the script.
replace $SID by $SERVICE_NAME (it happens 2 times)
It is compatible from my experience (using 10.1 and 10.2)
Thank you
1 of 1 people found this review helpful
#!/usr/bin/perl -w
my $host = $ARGV[0];
my $port = $ARGV[1];
my $sid = $ARGV[2];
my $user = $ARGV[3];
my $pass = $ARGV[4];
### point this to your sqlplus binary
my $sqlplus = "/usr/local/src/instantclient_11_2/sqlplus";
### point this to your sqlplus directory
$ENV{"LD_LIBRARY_PATH"} = "/usr/local/src/instantclient_11_2/";
sub trim($);
my @result;
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2);
my @param_array = (
[90,">","Dictionary Cache Hit Ratio",'SELECT (1 - (Sum(getmisses)/(Sum(gets) + Sum(getmisses)))) * 100 FROM v\$rowcache;'],
[99,">","Library Cache Hit Ratio",'SELECT (1 -(Sum(reloads)/(Sum(pins) + Sum(reloads)))) * 100 FROM v\$librarycache;'],
[89,">","DB Block Buffer Cache Hit Ratio",'SELECT (1 - (phys.value / (db.value + cons.value))) * 100 FROM v\$sysstat phys,v\$sysstat db,v\$sysstat cons WHERE phys.name = \'physical reads\' AND db.name = \'db block gets\' AND cons.name = \'consistent gets\';'],
[98,">","Latch Hit Ratio",'SELECT (1 - (Sum(misses) / Sum(gets))) * 100 FROM v\$latch;'],
[5,"\)\)\)\" |");
while ( my $res = ) {
if ($res =~ /^(ORA-\d{5})/) {
return $1;
}
}
}
if (logon() eq "ORA-01017" ){
for (my $i=0; $iumformat 999.999
$param_array[$i][3]
exit
EOF |") or die;
while ( my $res = ) {
#print trim($res)."\n";
if ( $res =~/^\s*\S+/ ) {
push(@results,trim($res));
}
}
}
for (my $i=0; $is OK";
exit $ERRORS{"OK"};
} else {
print "Unable to connect to $sid database!";
exit $ERRORS{"CRITICAL"};
}
1 of 1 people found this review helpful
Had to change the script to get the right environment variables
BEGIN {
unless (($ENV{BEGIN_BLOCK}) or $^C) {
$ENV{"LD_LIBRARY_PATH"} = '/usr/lib/oracle/11.2/client/lib/';
$ENV{BEGIN_BLOCK} = 1;
exec 'env',$0,@ARGV;
}
}
My system is Red Hat Linux. I installed
oracle-instantclient11.2-basic-11.2.0.2.0.i386.rpm
oracle-instantclient11.2-sqlplus-11.2.0.2.0.i386.rpm
I think the lack of environment is due some changes in last versions of oracle instant client for linux.
Thanks for the plugin!
Good morning, i can't run this script in my ubuntu distro with nagios or icinga. I get an error: need explicit attach before authenticating a user (DBD ERROR: OCISessionBegin). I va installed DBD::Oracle and DBI OK, but it not run.
What hapends??
0 of 1 people found this review helpful
This script has a serious flaw, since it tries to login as "system" with an incorrect password. The result is that the "system" account is locked after a couple of attempts. Needs to be modified.
0 of 2 people found this review helpful
I think I am messing this up because i can´t seen to get this plugin working.Before I put plugins in Nagios3 I test then via command line like this ./check_oracle_instant replacing the words between with the appropriate data to fit my needs.Can anyone tell me if this is the correct syntax?
1050468@isep.ipp.pt
0 of 1 people found this review helpful
Very good because you dont need to add anythig to the oracle server. Works fine , tested. With DB up it was green , with oracle stopped it became critical , and while DB was starting up it sent a warning message.
## ##sample 4
https://labs.consol.de/nagios/check_oracle_health/#example-with---runas-and-an-external-user
源码 在 位置上 : check_oracle_health-3.2.1\plugins-scripts\Nagios\DBD\Oracle
Description
check_oracle_health is a plugin to check various parameters of an Oracle database.
Documentation
Warning
There seems to be a bug in DBD::Oracle 1.76 which hits at least with mode tablespace-usage/free. Stay away from this version and use 1.74
Command line parameters
- –connect
The database name
- –user
The database user
- –password
Password of the database user.
- –connect
Alternativ to the parameters above.
- –connect=sysdba@ Login with / as sysdba (if the user that executes the plugin is privileged to do this)
- –connect=/@token Login with help of the Password Store (assumes –method=sqlplus)
- –mode
With the mode-parameter you tell the plugin what it should do. See the list of possible values further down.
- –tablespace
With this you can limit the check of a single tablespace. If this parameter is omitted all tablespaces are checked.
- –datafile
With this you can limit the check of a single datafile. If this parameter is omitted all datafiles are checked.
- –name
Here the check can be limited to a single object (Latch, Enqueue, Tablespace, Datafile). If this parameter is omitted all objects are checked. (Instead of –tablespace or –datafile this parameter can and should be used. It servers the purpose to standardize the CLI interface.)
- –name2
If you use –mode=sql, then the SQL-Statement appears in the output and performance values. With the parameter name2 you’re able to specify a custom string for this.
- –regexp Through this switch the value of the –name Parameters will be interpreted as regular expression.
- –warning
Determined values outside of this range trigger a WARNING.
- –critical
Determined values outside of this range trigger a CRITICAL.
- –absolute Without –absolute values that increase in the course of time will show the increase per second or with –absolute show the difference between the current and last run.
- –runas
With this parameter it is possible to run the script under a different user. (Calls sudo internally: sudo -u .
- –environment
With this you can pass environment variables to the script. For example: –environment ORACLE_HOME=/u01/oracle. Multiple declarations are possible.
- –method
With this parameter you tell the plugin how it should connect to the database. (dbi for using DBD::Oracle (default), sqlplus for using the sqlplus-Tool).
- –units=<%|KB|MB|GB> The declaration from units servers the “beautification” of the output from mode=sql and simplification from threshold values when using mode=tablespace-free
- –dbthresholds With this parameter thresholds are read from the database table check_oracle_health_thresholds
- –statefilesdir This parameter tells the plugin not do use the default directory for temporary files, but a user-specified one. It can be important in a clustered environment with shared filesystems.
Use the option –mode with various keywords to tell the Plugin which values it should determine and check.
Keyword |
Description |
Range |
tnsping |
Listener |
|
connection-time |
Determines how long connection establishment and login take |
0..n Seconds (1, 5) |
connected-users |
The sum of logged in users at the database |
0..n (50, 100) |
session-usage |
Percentage of max possible sessions |
0%..100% (80, 100) |
process-usage |
Percentage of max possible processes |
0%..100% (80, 100) |
rman-backup-problems |
Number of RMAN-errors during the last three days |
0..n (1, 2) |
sga-data-buffer-hit-ratio |
Hitrate in the Data Buffer Cache |
0%..100% (98:, 95:) |
sga-library-cache-gethit-ratio |
Hitrate in the Library Cache (Gets) |
0%..100% (98:, 95:) |
sga-library-cache-pinhit-ratio |
Hitrate in the Library Cache (Pins) |
0%..100% (98:, 95:) |
sga-library-cache-reloads |
Reload-Rate in the Library Cache |
n/sec (10,10) |
sga-dictionary-cache-hit-ratio |
Hitrate in the Dictionary Cache |
0%..100% (95:, 90:) |
sga-latches-hit-ratio |
Hitrate of the Latches |
0%..100% (98:, 95:) |
sga-shared-pool-reloads |
Reload-Rate in the Shared Pool |
0%..100% (1, 10) |
sga-shared-pool-free |
Free Memory in the Shared Pool |
0%..100% (10:, 5:) |
pga-in-memory-sort-ratio |
Percentage of sorts in the memory. |
0%..100% (99:, 90:) |
invalid-objects |
Sum of faulty Objects, Indices, Partitions |
|
stale-statistics |
Sum of objects with obsolete optimizer statistics |
n (10, 100) |
tablespace-usage |
Used diskspace in the tablespace |
0%..100% (90, 98) |
tablespace-free |
Free diskspace in the tablespace |
0%..100% (5:, 2:) |
tablespace-fragmentation |
Free Space Fragmentation Index |
100..1 (30:, 20:) |
tablespace-io-balanc |
IO-Distribution under the datafiles of a tablespace |
n (1.0, 2.0) |
tablespace-remaining-time |
Sum of remaining days until a tablespace is used by 100%. The rate of increase will be calculated with the values from the last 30 days. (With the parameter –lookback different periods can be specified) |
Days (90:, 30:) |
tablespace-can-allocate-next |
Checks if there is enough free tablespace for the next Extent. |
|
flash-recovery-area-usage |
Used diskspace in the flash recovery area |
0%..100% (90, 98) |
flash-recovery-area-free |
Free diskspace in the flash recovery area |
0%..100% (5:, 2:) |
datafile-io-traffic |
Sum of IO-Operationes from Datafiles per second |
n/sec (1000, 5000) |
datafiles-existing |
Percentage of max possible datafiles |
0%..100% (80, 90) |
soft-parse-ratio |
Percentage of soft-parse-ratio |
0%..100% |
switch-interval |
Interval between RedoLog File Switches |
0..n Seconds (600:, 60:) |
retry-ratio |
Retry-Rate in the RedoLog Buffer |
0%..100% (1, 10) |
redo-io-traffic |
Redolog IO in MB/sec |
n/sec (199,200) |
roll-header-contention |
Rollback Segment Header Contention |
0%..100% (1, 2) |
roll-block-contention |
Rollback Segment Block Contention |
0%..100% (1, 2) |
roll-hit-ratio |
Rollback Segment gets/waits Ratio |
0%..100% (99:, 98:) |
roll-extends |
Rollback Segment Extends |
n, n/sec (1, 100) |
roll-wraps |
Rollback Segment Wraps |
n, n/sec (1, 100) |
seg-top10-logical-reads |
Sum of the userprocesses under the top 10 logical reads |
n (1, 9) |
seg-top10-physical-reads |
Sum of the userprocesses under the top 10 physical reads |
n (1, 9) |
seg-top10-buffer-busy-waits |
Sum of the userprocesses under the top 10 buffer busy waits |
n (1, 9) |
seg-top10-row-lock-waits |
Sum of the userprocesses under the top 10 row lock waits |
n (1, 9) |
event-waits |
Waits/sec from system events |
n/sec (10,100) |
event-waiting |
How many percent of the elapsed time has an event spend with waiting |
0%..100% (0.1,0.5) |
enqueue-contention |
Enqueue wait/request-Ratio |
0%..100% (1, 10) |
enqueue-waiting |
How many percent of the elapsed time since the last run has an Enqueue spend with waiting |
0%..100% (0.00033,0.0033) |
latch-contention |
Latch misses/gets-ratio. With –name a Latchname or Latchnumber can be passed over. (See list-latches) |
0%..100% (1,2) |
latch-waiting |
How many percent of the elapsed time since the last run has a Latch spend with waiting |
0%..100% (0.1,1) |
sysstat |
Changes/sec for any value from v$sysstat |
n/sec (10,10) |
sql |
Result of any SQL-Statement that returns a number. The statement itself is passed over with the parameter –name. A Label for the performance data output can be passed over with the parameter –name2. |
n (1,5) |
sql-runtime |
The time an sql command needs to run |
Seconds (1, 5) |
list-tablespaces |
Prints a list of tablespaces |
|
list-datafiles |
Prints a list of datafiles |
|
list-latches |
Prints a list with latchnames and latchnumbers |
|
list-enqueues |
Prints a list with the Enqueue-Names |
|
list-events |
Prints a list with the events from (v$system_event). Besides event_number/event_id a shortened form of the eventname is printed out. This could be use as Nagios service descriptions. Example: lo_fi_sw_co = log file switch completion |
|
list-background-events |
Prints a list with the Background-Events |
|
list-sysstats |
Prints a list with system-wide statistics |
|
Measurements that are dependent on a time interval can be execute differently. To calculate the end result the following is needed: start value, end value and the passed time between this two values. Without further options the inital value will be the value from the last plugin run. The passed time is normally the time of normal_check_interval of the according service.
If the increase per second shouldn’t be decisive for the check result, but the difference between two measured values, than use the option –absolute. This is useful for Rollback Segment Wraps which happen very rare so that their rate is nearly 0/sec. Nevertheless you want to be alarmed if the number od this events grows.
The threshold values should be choosen in a way that they can be reached during a retry_check_interval. If not the service will change into the OK-State after each SOFT;1.
Please note, that the thresholds must be specified according to the Nagios plug-in development Guidelines.
- “10” means “Alarm, if > 10” and
- “90:” means “Alarm, if < 90”
Preparation of the database
In order to be able to collect the needed information from the database a database user with specific privileges is required:
create user nagios identified by oradbmon;
grant create session to nagios;
grant select any dictionary to nagios;
grant select on V_$SYSSTAT to nagios;
grant select on V_$INSTANCE to nagios;
grant select on V_$LOG to nagios;
grant select on SYS.DBA_DATA_FILES to nagios;
grant select on SYS.DBA_FREE_SPACE to nagios;
--
-- if somebody still uses Oracle 8.1.7...
grant select on sys.dba_tablespaces to nagios;
grant select on dba_temp_files to nagios;
grant select on sys.v_$Temp_extent_pool to nagios;
grant select on sys.v_$TEMP_SPACE_HEADER to nagios;
grant select on sys.v_$session to nagios;
Examples
nagios$ check_oracle_health --connect bba --mode tnsping
OK - connection established to bba.
nagios$ check_oracle_health --mode connection-time
OK - 0.17 seconds to connect |
connection_time=0.1740;1;5
nagios$ check_oracle_health --mode sga-data-buffer-hit-ratio
CRITICAL - SGA data buffer hit ratio 0.99% |
sga_data_buffer_hit_ratio=0.99%;98:;95:
nagios$ check_oracle_health --mode sga-library-cache-hit-ratio
OK - SGA library cache hit ratio 98.75% |
sga_library_cache_hit_ratio=98.75%;98:;95:
nagios$ check_oracle_health --mode sga-latches-hit-ratio
OK - SGA latches hit ratio 100.00% |
sga_latches_hit_ratio=100.00%;98:;95:
nagios$ check_oracle_health --mode sga-shared-pool-reloads
OK - SGA shared pool reloads 0.28% |
sga_shared_pool_reloads=0.28%;1;10
nagios$ check_oracle_health --mode sga-shared-pool-free
WARNING - SGA shared pool free 8.91% |
sga_shared_pool_free=8.91%;10:;5:
nagios$ check_oracle_health --mode pga-in-memory-sort-ratio
OK - PGA in-memory sort ratio 100.00% |
pga_in_memory_sort_ratio=100.00;99:;90:
nagios$ check_oracle_health --mode invalid-objects
OK - no invalid objects found |
invalid_ind_partitions=0 invalid_indexes=0
invalid_objects=0 unrecoverable_datafiles=0
nagios$ check_oracle_health --mode switch-interval
OK - Last redo log file switch interval was 18 minutes |
redo_log_file_switch_interval=1090s;600:;60:
nagios$ check_oracle_health --mode switch-interval --connect rac1
OK - Last redo log file switch interval was 32 minutes (thread 1)|
redo_log_file_switch_interval=1938s;600:;60:
nagios$ check_oracle_health --mode tablespace-usage
CRITICAL - tbs SYSTEM usage is 99.33%
tbs SYSAUX usage is 93.73%
tbs USERS usage is 8.75%
tbs UNDOTBS1 usage is 6.65% | 'tbs_users_usage_pct'=8%;90;98
'tbs_users_usage'=0MB;4;4;0;5
'tbs_undotbs1_usage_pct'=6%;90;98
'tbs_undotbs1_usage'=11MB;153;166;0;170
'tbs_system_usage_pct'=99%;90;98
'tbs_system_usage'=695MB;630;686;0;700
'tbs_sysaux_usage_pct'=93%;90;98
'tbs_sysaux_usage'=802MB;770;839;0;856
nagios$ check_oracle_health --mode tablespace-usage
--tablespace USERS
OK - tbs USERS usage is 8.75% |
'tbs_users_usage_pct'=8%;90;98
'tbs_users_usage'=0MB;4;4;0;5
nagios$ check_oracle_health --mode tablespace-usage
--name USERS
OK - tbs USERS usage is 8.75% |
'tbs_users_usage_pct'=8%;90;98
'tbs_users_usage'=0MB;4;4;0;5
nagios$ check_oracle_health --mode tablespace-free
--name TEST
OK - tbs TEST has 97.91% free space left |
'tbs_test_free_pct'=97.91%;5:;2:
'tbs_test_free'=32083MB;1638.40:;655.36:;0.00;32767.98
nagios$ check_oracle_health --mode tablespace-free
--name TEST --units MB --warning 100: --critical 50:
OK - tbs TEST has 32083.61MB free space left |
'tbs_test_free_pct'=97.91%;0.31:;0.15:
'tbs_test_free'=32083.61MB;100.00:;50.00:;0;32767.98
nagios$ check_oracle_health --mode tablespace-free
--name TEST --warning 10: --critical 5:
OK - tbs TEST has 97.91% free space left |
'tbs_test_free_pct'=97.91%;10:;5:
'tbs_test_free'=32083MB;3276.80:;1638.40:;0.00;32767.98
nagios$ check_oracle_health --mode tablespace-remaining-time
--tablespace ARUSERS --lookback 7
WARNING - tablespace ARUSERS will be full in 78 days |
'tbs_arusers_days_until_full'=78;90:;30:
nagios$ check_oracle_health --mode flash-recovery-area-free
OK - flra /u00/app/oracle/flash_recovery_area has 100.00% free space left |
'flra_free_pct'=100.00%;5:;2:
'flra_free'=2048MB;102.40:;40.96:;0;2048.00
nagios$ check_oracle_health --mode flash-recovery-area-free
--units KB --warning 1000: --critical 500:
OK - flra /u00/app/oracle/flash_recovery_area has 2097152.00KB free space left | 'flra_free_pct'=100.00%;0.05:;0.02:
'flra_free'=2097152.00KB;1000.00:;500.00:;0;2097152.00
nagios$ check_oracle_health --mode datafile-io-traffic
--datafile users01.dbf
WARNING - users01.dbf: 1049.83 IO Operations per Second |
'dbf_users01.dbf_io_total_per_sec'=1049.83;1000;5000
nagios$ check_oracle_health --mode latch-contention
--name 214
OK - SGA latch library cache (214) contention 0.08% |
'latch_214_contention'=0.08%;1;2
'latch_214_sleep_share'=0.00% 'latch_214_gets'=49995
nagios$ check_oracle_health --mode latch-contention
--name 'library cache'
OK - SGA latch library cache (214) contention 0.08% |
'latch_214_contention'=0.08%;1;2
'latch_214_sleep_share'=0.00% 'latch_214_gets'=49937
nagios$ check_oracle_health --mode enqueue-contention --name TC
CRITICAL - enqueue TC: 19.90% of the requests must wait |
'TC_contention'=19.90%;1;10
'TC_requests'=2015 'TC_waits'=401
nagios$ check_oracle_health --mode latch-contention
--name 'messages'
OK - SGA latch messages (17) contention 0.02% |
'latch_17_contention'=0.02%;1;2 'latch_17_gets'=4867
nagios$ check_oracle_health --mode latch-waiting
--name 'user lock'
OK - SGA latch user lock (205) sleeping 0.000841% of the time |
'latch_205_sleep_share'=0.000841%
nagios$ check_oracle_health --mode event-waits
--name 'log file sync'
OK - log file sync : 1.839511 waits/sec |
'log file sync_waits_per_sec'=1.839511;10;100
nagios$ check_oracle_health --mode event-waiting
--name 'Log file parallel write'
OK - log file parallel write waits 0.045843% of the time |
rarr 'log file parallel write_percent_waited'=0.045843%;0.1;0.5
nagios$ check_oracle_health --mode sysstat
--name 'transaction rollbacks'
OK - 0.000003 transaction rollbacks/sec |
'transaction rollbacks_per_sec'=0.000003;10;100
'transaction rollbacks'=4
nagios$ check_oracle_health --mode sql
--name 'select count(*) from v$session' --name2 sessions
CRITICAL - sessions: 21 | 'sessions'=21;1;5
nagios$ check_oracle_health --mode sql
--name 'select 12 from dual' --name2 twelve --units MB
CRITICAL - twelfe: 12MB | 'twelfe'=12MB;1;5
nagios$ check_oracle_health --mode sql
--name 'select 200,300,1000 from dual'
--name2 'kaspar melchior balthasar'
--warning 180 --critical 500
WARNING - kaspar melchior balthasar: 200 300 1000 |
'kaspar'=200;180;500 'melchior'=300;; 'balthasar'=1000;;
nagios$ check_oracle_health --mode sql
--name "select 'abc123' from dual" --name2 \\d
--regexp
OK - output abc123 matches pattern \d
###
###
###
###
Oracle Database Health Check Script
|
# ############################################################################################## |
|
# DAILY HEALTH CHECK MONITORING SCRIPT |
|
# |
|
# ========================================================= |
|
# BECAUSE OF THE PERFORMANCE IMPACT THIS SCRIPT CAN CAUSE, |
|
# I STRONGLY RECOMMEND TO SCHEDULE IT TO RUN IN NON PEAK HOURS |
|
# E.G. SCHEDULE IT TO RUN ONE TIME BETWEEN 12:00AM to 5:00AM |
|
# ========================================================= |
|
# |
|
# FEATURES: |
|
# CHECKING ALL DATABASES ALERTLOGS FOR ERRORS. |
|
# CHECKING ALL LISTENERS ALERTLOGS FOR ERRORS. |
|
# CHECKING CPU UTILIZATION. |
|
# CHECKING FILESYSTEM UTILIZATION. |
|
# CHECKING TABLESPACES UTILIZATION. |
|
# CHECKING BLOCKING SESSIONS ON THE DATABASE. |
|
# CHECKING UNUSABLE INDEXES ON THE DATABASE. |
|
# CHECKING INVALID OBJECTS ON THE DATABASE. |
|
# CHECKING FAILED LOGIN ATTEMPTS ON THE DATABASE. |
|
# CHEKCING AUDIT RECORDS ON THE DATABASE. |
|
# CHECKING CORRUPTED BLOCKS ON THE DATABASE. |
|
# CHECKING FAILED JOBS IN THE DATABASE. |
|
# |
|
# # # # |
|
# Author: Mahmmoud ADEL # # # # ### |
|
# # # # # # |
|
# |
|
# Created: 22-12-13 Created with name dbalarm |
|
# Modified: 23-12-13 Handled non exist logs 1run |
|
# 14-05-14 Handled non existance of |
|
# LOG_DIR directory. |
|
# 18-05-14 Added Filsystem monitoring. |
|
# 19-05-14 Added CPU monitoring. |
|
# 09-12-14 Converted the script to "dbdailychk" |
|
# Added Tablespaces monitoring |
|
# Added BLOCKING SESSIONS monitoring |
|
# Added UNUSABLE INDEXES monitoring |
|
# Added INVALID OBJECTS monitoring |
|
# Added FAILED LOGINS monitoring |
|
# Added AUDIT RECORDS monitoring |
|
# Added CORRUPTED BLOCKS monitoring |
|
# [It will NOT run a SCAN just checkng V$DATABASE_BLOCK_CORRUPTION view.] |
|
# Added FAILED JOBS monitorings |
|
# 06-10-15 Replaced mpstat with iostat for CPU Utilization Check |
|
# |
|
# TO BE ADDED LATER: >LOGIN ATTEMPTS DURING NON BUSINESS HOURS |
|
# >LOGIN ATTEMPTS USING NON REGULAR APPLICATIONS |
|
# ############################################################################################## |
|
SCRIPT_NAME="dbdailychk.sh" |
|
SRV_NAME=`uname -n` |
|
MAIL_LIST="youremail@yourcompany.com" |
|
|
|
case ${MAIL_LIST} in "youremail@yourcompany.com") |
|
echo |
|
echo "#######################################################" |
|
echo "Please EDIT line# 51 in dbdailychk.sh script and change" |
|
echo "youremail@yourcompany.com to your E-mail address." |
|
echo "#######################################################" |
|
echo |
|
echo "Script Terminated !" |
|
echo |
|
exit;; |
|
esac |
|
|
|
# ######################### |
|
# THRESHOLDS: |
|
# ######################### |
|
# Send an E-mail for each THRESHOLD if been reached: |
|
# ADJUST the following THRESHOLD VALUES as per your requirements: |
|
|
|
FSTHRESHOLD=98 # THRESHOLD FOR FILESYSTEM %USED [OS] |
|
CPUTHRESHOLD=95 # THRESHOLD FOR CPU %UTILIZATION [OS] |
|
TBSTHRESHOLD=98 # THRESHOLD FOR TABLESPACE %USED [DB] |
|
UNUSEINDXTHRESHOLD=1 # THRESHOLD FOR NUMBER OF UNUSABLE INDEXES [DB] |
|
INVOBJECTTHRESHOLD=1 # THRESHOLD FOR NUMBER OF INVALID OBJECTS [DB] |
|
FAILLOGINTHRESHOLD=1 # THRESHOLD FOR NUMBER OF FAILED LOGINS [DB] |
|
AUDITRECOTHRESHOLD=1 # THRESHOLD FOR NUMBER OF AUDIT RECORDS [DB] |
|
CORUPTBLKTHRESHOLD=1 # THRESHOLD FOR NUMBER OF CORRUPTED BLOCKS [DB] |
|
FAILDJOBSTHRESHOLD=1 # THRESHOLD FOR NUMBER OF FAILED JOBS [DB] |
|
|
|
# ######################### |
|
# Checking The FILESYSTEM: |
|
# ######################### |
|
|
|
# Report Partitions that have 2% or less of FREE space: |
|
|
|
FSLOG=/tmp/filesystem_DBA_BUNDLE.log |
|
echo "Reported By Script: ${SCRIPT_NAME}" > ${FSLOG} |
|
echo "" >> ${FSLOG} |
|
df -h >> ${FSLOG} |
|
df -h | grep -v "^Filesystem" | awk '{print $(NF-1)" "$NF}'| while read OUTPUT |
|
do |
|
PRCUSED=`echo ${OUTPUT}|awk '{print $1}'|cut -d'%' -f1` |
|
FILESYS=`echo ${OUTPUT}|awk '{print $2}'` |
|
if [ ${PRCUSED} -ge ${FSTHRESHOLD} ] |
|
then |
|
mail -s "ALARM: Filesystem [${FILESYS}] on Server [${SRV_NAME}] has reached ${PRCUSED}% of USED space" $MAIL_LIST < ${FSLOG} |
|
fi |
|
done |
|
|
|
rm -f /tmp/filesystem_DBA_BUNDLE.log |
|
|
|
# ############################# |
|
# Checking The CPU Utilization: |
|
# ############################# |
|
|
|
# Report CPU Utilization if reach >= 95%: |
|
OS_TYPE=`uname -s` |
|
CPUUTLLOG=/tmp/CPULOG_DBA_BUNDLE.log |
|
|
|
# Getting CPU utilization in last 5 seconds: |
|
case `uname` in |
|
Linux ) CPU_REPORT_SECTIONS=`iostat -c 1 5 | sed -e 's/,/./g' | tr -s ' ' ';' | sed '/^$/d' | tail -1 | grep ';' -o | wc -l` |
|
if [ ${CPU_REPORT_SECTIONS} -ge 6 ]; then |
|
CPU_IDLE=`iostat -c 1 5 | sed -e 's/,/./g' | tr -s ' ' ';' | sed '/^$/d' | tail -1| cut -d ";" -f 7` |
|
else |
|
CPU_IDLE=`iostat -c 1 5 | sed -e 's/,/./g' | tr -s ' ' ';' | sed '/^$/d' | tail -1| cut -d ";" -f 6` |
|
fi |
|
;; |
|
AIX ) CPU_IDLE=`iostat -t $INTERVAL_SEC $NUM_REPORT | sed -e 's/,/./g'|tr -s ' ' ';' | tail -1 | cut -d ";" -f 6` |
|
;; |
|
SunOS ) CPU_IDLE=`iostat -c $INTERVAL_SEC $NUM_REPORT | tail -1 | awk '{ print $4 }'` |
|
;; |
|
HP-UX) SAR="/usr/bin/sar" |
|
if [ ! -x $SAR ]; then |
|
echo "sar command is not supported on your environment | CPU Check ignored"; CPU_IDLE=99 |
|
else |
|
CPU_IDLE=`/usr/bin/sar 1 5 | grep Average | awk '{ print $5 }'` |
|
fi |
|
;; |
|
*) echo "uname command is not supported on your environment | CPU Check ignored"; CPU_IDLE=99 |
|
;; |
|
esac |
|
|
|
# Getting Utilized CPU (100-%IDLE): |
|
CPU_UTL_FLOAT=`echo "scale=2; 100-($CPU_IDLE)"|bc` |
|
|
|
# Convert the average from float number to integer: |
|
CPU_UTL=${CPU_UTL_FLOAT%.*} |
|
|
|
if [ -z ${CPU_UTL} ] |
|
then |
|
CPU_UTL=1 |
|
fi |
|
|
|
if [ ${CPU_UTL} -ge ${CPUTHRESHOLD} ] |
|
then |
|
echo "Top 10 Processes:" > /tmp/top_processes_DBA_BUNDLE.log |
|
echo "================" >> /tmp/top_processes_DBA_BUNDLE.log |
|
echo "" >> /tmp/top_processes_DBA_BUNDLE.log |
|
ps -eo pcpu,pid,user,args | sort -k 1 -r | head -11 >> /tmp/top_processes_DBA_BUNDLE.log |
|
mail -s "ALERT: CPU Utilization on Server [${SRV_NAME}] has reached [${CPU_UTL}%]" $MAIL_LIST < /tmp/top_processes_DBA_BUNDLE.log |
|
fi |
|
|
|
rm -f ${CPUUTLLOG} |
|
rm -f /tmp/top_processes_DBA_BUNDLE.log |
|
|
|
|
|
# ######################### |
|
# Getting ORACLE_SID: |
|
# ######################### |
|
# Exit with sending Alert mail if No DBs are running: |
|
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|grep -v ASM|wc -l ) |
|
if [ $INS_COUNT -eq 0 ] |
|
then |
|
echo "Reported By Script: ${SCRIPT_NAME}:" > /tmp/oracle_processes_DBA_BUNDLE.log |
|
echo " " >> /tmp/oracle_processes_DBA_BUNDLE.log |
|
echo "The following are the processes running by oracle user on server ${SRV_NAME}:" >> /tmp/oracle_processes_DBA_BUNDLE.log |
|
echo " " >> /tmp/oracle_processes_DBA_BUNDLE.log |
|
ps -ef|grep ora >> /tmp/oracle_processes_DBA_BUNDLE.log |
|
mail -s "ALARM: No Databases Are Running on Server: $SRV_NAME !!!" $MAIL_LIST < /tmp/oracle_processes_DBA_BUNDLE.log |
|
rm -f /tmp/oracle_processes_DBA_BUNDLE.log |
|
exit |
|
fi |
|
|
|
# ######################### |
|
# Setting ORACLE_SID: |
|
# ######################### |
|
for ORACLE_SID in $( ps -ef|grep pmon|grep -v grep|grep -v ASM|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" ) |
|
do |
|
export ORACLE_SID |
|
|
|
# ######################### |
|
# Getting ORACLE_HOME |
|
# ######################### |
|
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|grep -v ASM|awk '{print $1}'|tail -1` |
|
USR_ORA_HOME=`grep ${ORA_USER} /etc/passwd| cut -f6 -d ':'|tail -1` |
|
|
|
## If OS is Linux: |
|
if [ -f /etc/oratab ] |
|
then |
|
ORATAB=/etc/oratab |
|
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'` |
|
export ORACLE_HOME |
|
|
|
## If OS is Solaris: |
|
elif [ -f /var/opt/oracle/oratab ] |
|
then |
|
ORATAB=/var/opt/oracle/oratab |
|
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'` |
|
export ORACLE_HOME |
|
fi |
|
|
|
## If oratab is not exist, or ORACLE_SID not added to oratab, find ORACLE_HOME in user's profile: |
|
if [ -z "${ORACLE_HOME}" ] |
|
then |
|
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' $USR_ORA_HOME/.bash* $USR_ORA_HOME/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1` |
|
export ORACLE_HOME |
|
fi |
|
|
|
# ######################### |
|
# Variables: |
|
# ######################### |
|
export PATH=$PATH:${ORACLE_HOME}/bin |
|
export LOG_DIR=${USR_ORA_HOME}/BUNDLE_Logs |
|
mkdir -p ${LOG_DIR} |
|
chown -R ${ORA_USER} ${LOG_DIR} |
|
chmod -R go-rwx ${LOG_DIR} |
|
|
|
if [ ! -d ${LOG_DIR} ] |
|
then |
|
mkdir -p /tmp/BUNDLE_Logs |
|
export LOG_DIR=/tmp/BUNDLE_Logs |
|
chown -R ${ORA_USER} ${LOG_DIR} |
|
chmod -R go-rwx ${LOG_DIR} |
|
fi |
|
|
|
# ######################## |
|
# Getting ORACLE_BASE: |
|
# ######################## |
|
|
|
# Get ORACLE_BASE from user's profile if it EMPTY: |
|
|
|
if [ -z "${ORACLE_BASE}" ] |
|
then |
|
ORACLE_BASE=`grep -h 'ORACLE_BASE=\/' $USR_ORA_HOME/.bash* $USR_ORA_HOME/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1` |
|
fi |
|
|
|
# ######################### |
|
# Getting DB_NAME: |
|
# ######################### |
|
VAL1=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" <<EOF |
|
set pages 0 feedback off; |
|
prompt |
|
SELECT name from v\$database |
|
exit; |
|
EOF |
|
) |
|
# Getting DB_NAME in Uppercase & Lowercase: |
|
DB_NAME_UPPER=`echo $VAL1| perl -lpe'$_ = reverse' |awk '{print $1}'|perl -lpe'$_ = reverse'` |
|
DB_NAME_LOWER=$( echo "$DB_NAME_UPPER" | tr -s '[:upper:]' '[:lower:]' ) |
|
export DB_NAME_UPPER |
|
export DB_NAME_LOWER |
|
|
|
# DB_NAME is Uppercase or Lowercase?: |
|
|
|
if [ -d $ORACLE_HOME/diagnostics/${DB_NAME_LOWER} ] |
|
then |
|
DB_NAME=$DB_NAME_LOWER |
|
else |
|
DB_NAME=$DB_NAME_UPPER |
|
fi |
|
|
|
|
|
# ######################### |
|
# Tablespaces Size Check: |
|
# ######################### |
|
# Check if AUTOEXTEND OFF (MAXSIZE=0) is set for any of the datafiles divide by ALLOCATED size else divide by MAXSIZE: |
|
VAL33=$(${ORACLE_HOME}/bin/sqlplus -S '/ as sysdba' << EOF |
|
SELECT COUNT(*) FROM DBA_DATA_FILES WHERE MAXBYTES=0; |
|
exit; |
|
EOF |
|
) |
|
VAL44=`echo $VAL33| awk '{print $NF}'` |
|
case ${VAL44} in |
|
"0") CALCPERCENTAGE1="((sbytes - fbytes)*100 / MAXSIZE) bused " ;; |
|
*) CALCPERCENTAGE1="round(((sbytes - fbytes) / sbytes) * 100,2) bused " ;; |
|
esac |
|
|
|
VAL55=$(${ORACLE_HOME}/bin/sqlplus -S '/ as sysdba' << EOF |
|
SELECT COUNT(*) FROM DBA_TEMP_FILES WHERE MAXBYTES=0; |
|
exit; |
|
EOF |
|
) |
|
VAL66=`echo $VAL55| awk '{print $NF}'` |
|
case ${VAL66} in |
|
"0") CALCPERCENTAGE2="((sbytes - fbytes)*100 / MAXSIZE) bused " ;; |
|
*) CALCPERCENTAGE2="round(((sbytes - fbytes) / sbytes) * 100,2) bused " ;; |
|
esac |
|
|
|
TBSCHK=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set pages 0 termout off echo off feedback off |
|
col tablespace for A25 |
|
col "MAXSIZE MB" format 999999 |
|
col x for 999999999 heading 'Allocated MB' |
|
col y for 999999999 heading 'Free MB' |
|
col z for 999999999 heading 'Used MB' |
|
col bused for 999.99 heading '%Used' |
|
--bre on report |
|
spool ${LOG_DIR}/tablespaces_DBA_BUNDLE.log |
|
select a.tablespace_name tablespace,bb.MAXSIZE/1024/1024 "MAXSIZE MB",sbytes/1024/1024 x,fbytes/1024/1024 y, |
|
(sbytes - fbytes)/1024/1024 z, |
|
$CALCPERCENTAGE1 |
|
--round(((sbytes - fbytes) / sbytes) * 100,2) bused |
|
--((sbytes - fbytes)*100 / MAXSIZE) bused |
|
from (select tablespace_name,sum(bytes) sbytes from dba_data_files group by tablespace_name ) a, |
|
(select tablespace_name,sum(bytes) fbytes,count(*) ext from dba_free_space group by tablespace_name) b, |
|
(select tablespace_name,sum(MAXBYTES) MAXSIZE from dba_data_files group by tablespace_name) bb |
|
--where a.tablespace_name in (select tablespace_name from dba_tablespaces) |
|
where a.tablespace_name = b.tablespace_name (+) |
|
and a.tablespace_name = bb.tablespace_name |
|
and round(((sbytes - fbytes) / sbytes) * 100,2) > 0 |
|
UNION ALL |
|
select c.tablespace_name tablespace,dd.MAXSIZE/1024/1024 MAXSIZE_GB,sbytes/1024/1024 x,fbytes/1024/1024 y, |
|
(sbytes - fbytes)/1024/1024 obytes, |
|
$CALCPERCENTAGE2 |
|
from (select tablespace_name,sum(bytes) sbytes |
|
from dba_temp_files group by tablespace_name having tablespace_name in (select tablespace_name from dba_tablespaces)) c, |
|
(select tablespace_name,sum(bytes_free) fbytes,count(*) ext from v\$temp_space_header group by tablespace_name) d, |
|
(select tablespace_name,sum(MAXBYTES) MAXSIZE from dba_temp_files group by tablespace_name) dd |
|
--where c.tablespace_name in (select tablespace_name from dba_tablespaces) |
|
where c.tablespace_name = d.tablespace_name (+) |
|
and c.tablespace_name = dd.tablespace_name |
|
order by tablespace; |
|
select tablespace_name,null,null,null,null,null||'100.00' from dba_data_files minus select tablespace_name,null,null,null,null,null||'100.00' from dba_free_space; |
|
spool off |
|
exit; |
|
EOF |
|
|
|
TBSLOG=${LOG_DIR}/tablespaces_DBA_BUNDLE.log |
|
TBSFULL=${LOG_DIR}/full_tbs.log |
|
cat ${TBSLOG}|awk '{ print $1" "$NF }'| while read OUTPUT2 |
|
do |
|
PRCUSED=`echo ${OUTPUT2}|awk '{print $NF}'` |
|
TBSNAME=`echo ${OUTPUT2}|awk '{print $1}'` |
|
echo "Reported By Script: ${SCRIPT_NAME}:" > ${TBSFULL} |
|
echo " " >> ${TBSFULL} |
|
echo "Tablespace_name %USED" >> ${TBSFULL} |
|
echo "---------------------- -----------" >> ${TBSFULL} |
|
echo ${OUTPUT2}|awk '{print $1" "$NF}' >> ${TBSFULL} |
|
# Convert PRCUSED from float number to integer: |
|
PRCUSED=${PRCUSED%.*} |
|
if [ -z ${PRCUSED} ] |
|
then |
|
PRCUSED=1 |
|
fi |
|
# If the tablespace %USED >= the defined threshold send an email for each tablespace: |
|
if [ ${PRCUSED} -ge ${TBSTHRESHOLD} ] |
|
then |
|
mail -s "ALERT: TABLESPACE [${TBSNAME}] reached ${PRCUSED}% on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" $MAIL_LIST < ${TBSFULL} |
|
fi |
|
done |
|
|
|
rm -f ${LOG_DIR}/tablespaces_DBA_BUNDLE.log |
|
rm -f ${LOG_DIR}/full_tbs.log |
|
) |
|
|
|
# ############################################ |
|
# Checking BLOCKING SESSIONS ON THE DATABASE: |
|
# ############################################ |
|
VAL77=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
select count(*) from gv\$LOCK l1, gv\$SESSION s1, gv\$LOCK l2, gv\$SESSION s2 |
|
where s1.sid=l1.sid and s2.sid=l2.sid and l1.BLOCK=1 and l2.request > 0 and l1.id1=l2.id1 and l2.id2=l2.id2; |
|
exit; |
|
EOF |
|
) |
|
VAL88=`echo $VAL77| awk '{print $NF}'` |
|
case ${VAL88} in |
|
"0") ;; |
|
*) |
|
VAL99=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set linesize 160 pages 0 echo off feedback off |
|
col BLOCKING_STATUS for a90 |
|
spool ${LOG_DIR}/blocking_sessions.log |
|
select 'User: '||s1.username || '@' || s1.machine || '(SID=' || s1.sid ||' ) running SQL_ID:'||s1.sql_id||' is blocking |
|
User: '|| s2.username || '@' || s2.machine || '(SID=' || s2.sid || ') running SQL_ID:'||s2.sql_id||' For '||s2.SECONDS_IN_WAIT||' sec |
|
------------------------------------------------------------------------------ |
|
Warn user '||s1.username||' Or use the following statement to kill his session: |
|
------------------------------------------------------------------------------ |
|
ALTER SYSTEM KILL SESSION '''||s1.sid||','||s1.serial#||''' immediate;' AS blocking_status |
|
from gv\$LOCK l1, gv\$SESSION s1, gv\$LOCK l2, gv\$SESSION s2 |
|
where s1.sid=l1.sid and s2.sid=l2.sid |
|
and l1.BLOCK=1 and l2.request > 0 |
|
and l1.id1 = l2.id1 |
|
and l2.id2 = l2.id2 ; |
|
spool off |
|
exit; |
|
EOF |
|
) |
|
mail -s "ALERT: BLOCKING SESSIONS detected on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" $MAIL_LIST < ${LOG_DIR}/blocking_sessions.log |
|
rm -f ${LOG_DIR}/blocking_sessions.log |
|
;; |
|
esac |
|
|
|
# ############################################ |
|
# Checking UNUSABLE INDEXES ON THE DATABASE: |
|
# ############################################ |
|
VAL111=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set pages 0 feedback off echo off; |
|
select count(*) from DBA_INDEXES where status='UNUSABLE'; |
|
exit; |
|
EOF |
|
) |
|
VAL222=`echo $VAL111 | awk '{print $NF}'` |
|
if [ ${VAL222} -ge ${UNUSEINDXTHRESHOLD} ] |
|
then |
|
VAL333=$(${ORACLE_HOME}/bin/sqlplus -s "/ as sysdba" << EOF |
|
set linesize 160 pages 0 echo off feedback off |
|
spool ${LOG_DIR}/unusable_indexes.log |
|
PROMPT FIX UN-USABLE INDEXES USING THE FOLLOWING STATEMENTS: |
|
PROMPT ------------------------------------------------------------------------------ |
|
|
|
PROMPT |
|
select 'ALTER INDEX '||OWNER||'.'||INDEX_NAME||' REBUILD ONLINE;' from dba_indexes where status='UNUSABLE'; |
|
spool off |
|
exit; |
|
EOF |
|
) |
|
mail -s "INFO: UNUSABLE INDEXES detected on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" $MAIL_LIST < ${LOG_DIR}/unusable_indexes.log |
|
rm -f ${LOG_DIR}/unusable_indexes.log |
|
fi |
|
|
|
# ############################################ |
|
# Checking INVALID OBJECTS ON THE DATABASE: |
|
# ############################################ |
|
VAL444=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set pages 0 feedback off echo off; |
|
select count(*) from dba_objects where status <> 'VALID'; |
|
exit; |
|
EOF |
|
) |
|
VAL555=`echo $VAL444 | awk '{print $NF}'` |
|
if [ ${VAL555} -ge ${INVOBJECTTHRESHOLD} ] |
|
then |
|
VAL666=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set linesize 160 pages 0 echo off feedback off |
|
spool ${LOG_DIR}/invalid_objects.log |
|
PROMPT FIX INVALID OBJECTS USING THE FOLLOWING STATEMENTS: |
|
PROMPT --------------------------------------------------------------------------- |
|
|
|
PROMPT |
|
select 'alter package '||owner||'.'||object_name||' compile;' from dba_objects where status <> 'VALID' and object_type like '%PACKAGE%' union |
|
select 'alter type '||owner||'.'||object_name||' compile specification;' from dba_objects where status <> 'VALID' and object_type like '%TYPE%'union |
|
select 'alter '||object_type||' '||owner||'.'||object_name||' compile;' from dba_objects where status <> 'VALID' and object_type not in ('PACKAGE','PACKAGE BODY','SYNONYM','TYPE','TYPE BODY') union |
|
select 'alter public synonym '||object_name||' compile;' from dba_objects where status <> 'VALID' and object_type ='SYNONYM'; |
|
spool off |
|
exit; |
|
EOF |
|
) |
|
mail -s "WARNING: INVALID OBJECTS # reached the THRESHOLD on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" $MAIL_LIST < ${LOG_DIR}/invalid_objects.log |
|
rm -f ${LOG_DIR}/invalid_objects.log |
|
fi |
|
|
|
|
|
# ############################################### |
|
# Checking FAILED LOGIN ATTEMPTS ON THE DATABASE: |
|
# ############################################### |
|
VAL777=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set pages 0 feedback off echo off; |
|
select /*+ parallel 2 */ COUNT(*) from DBA_AUDIT_SESSION where returncode = 1017 and timestamp > (sysdate-1); |
|
exit; |
|
EOF |
|
) |
|
VAL888=`echo $VAL777 | awk '{print $NF}'` |
|
if [ ${VAL888} -ge ${FAILLOGINTHRESHOLD} ] |
|
then |
|
VAL999=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set linesize 160 pages 100 |
|
spool ${LOG_DIR}/failed_logins.log |
|
PROMPT FAILED LOGIN ATTEMPT [SESSION DETAILS]: |
|
PROMPT -------------------------------------------------------------------- |
|
|
|
PROMPT |
|
col OS_USERNAME for a20 |
|
col USERNAME for a25 |
|
col TERMINAL for a30 |
|
col ACTION_NAME for a20 |
|
col TIMESTAMP for a21 |
|
col USERHOST for a40 |
|
select /*+ parallel 2 */ to_char (EXTENDED_TIMESTAMP,'DD-MON-YYYY HH24:MI:SS') TIMESTAMP,OS_USERNAME,USERNAME,TERMINAL,USERHOST,ACTION_NAME |
|
from DBA_AUDIT_SESSION |
|
where returncode = 1017 |
|
and timestamp > (sysdate -1) |
|
order by 1; |
|
spool off |
|
exit; |
|
EOF |
|
) |
|
mail -s "INFO: FAILED LOGIN ATTEMPT detected on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" $MAIL_LIST < ${LOG_DIR}/failed_logins.log |
|
rm -f ${LOG_DIR}/failed_logins.log |
|
fi |
|
|
|
# ############################################### |
|
# Checking AUDIT RECORDS ON THE DATABASE: |
|
# ############################################### |
|
VAL70=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set pages 0 feedback off echo off; |
|
SELECT (SELECT COUNT(*) FROM dba_audit_trail |
|
where ACTION_NAME not like 'LOGO%' and ACTION_NAME not in ('SELECT','SET ROLE') and timestamp > SYSDATE-1) |
|
+ |
|
(SELECT COUNT(*) FROM dba_fga_audit_trail WHERE timestamp > SYSDATE-1) AUD_REC_COUNT FROM dual; |
|
exit; |
|
EOF |
|
) |
|
VAL80=`echo $VAL70 | awk '{print $NF}'` |
|
if [ ${VAL80} -ge ${AUDITRECOTHRESHOLD} ] |
|
then |
|
VAL90=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set linesize 160 pages 100 |
|
spool ${LOG_DIR}/audit_records.log |
|
col EXTENDED_TIMESTAMP for a36 |
|
col OWNER for a25 |
|
col OBJ_NAME for a25 |
|
col OS_USERNAME for a20 |
|
col USERNAME for a25 |
|
col USERHOST for a21 |
|
col ACTION_NAME for a25 |
|
col ACTION_OWNER_OBJECT for a55 |
|
prompt |
|
prompt |
|
prompt ---------------------------------------------------------- |
|
|
|
prompt Audit records in the last 24Hours AUD$... |
|
prompt ---------------------------------------------------------- |
|
|
|
prompt |
|
select extended_timestamp,OS_USERNAME,USERNAME,USERHOST,ACTION_NAME||' '||OWNER||' . '||OBJ_NAME ACTION_OWNER_OBJECT |
|
from dba_audit_trail |
|
where |
|
ACTION_NAME not like 'LOGO%' |
|
and ACTION_NAME not in ('SELECT','SET ROLE') |
|
-- and USERNAME not in ('CRS_ADMIN','DBSNMP') |
|
-- and OS_USERNAME not in ('workflow') |
|
-- and OBJ_NAME not like '%TMP_%' |
|
-- and OBJ_NAME not like 'WRKDETA%' |
|
-- and OBJ_NAME not in ('PBCATTBL','SETUP','WRKIB','REMWORK') |
|
and timestamp > SYSDATE-1 order by EXTENDED_TIMESTAMP; |
|
prompt |
|
prompt ---------------------------------------------------------- |
|
|
|
prompt Fine Grained Auditing Data ... |
|
prompt ---------------------------------------------------------- |
|
|
|
prompt |
|
col sql_text for a70 |
|
col time for a36 |
|
col USERHOST for a21 |
|
col db_user for a15 |
|
select to_char(timestamp,'DD-MM-YYYY HH24:MI:SS') as time,db_user,userhost,sql_text,SQL_BIND |
|
from dba_fga_audit_trail |
|
where |
|
timestamp > SYSDATE-1 |
|
-- and policy_name='PAYROLL_TABLE' |
|
order by EXTENDED_TIMESTAMP; |
|
spool off |
|
exit; |
|
EOF |
|
) |
|
mail -s "INFO: AUDIT RECORDS on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" $MAIL_LIST < ${LOG_DIR}/audit_records.log |
|
rm -f ${LOG_DIR}/audit_records.log |
|
fi |
|
|
|
# ############################################ |
|
# Checking CORRUPTED BLOCKS ON THE DATABASE: |
|
# ############################################ |
|
# It won't validate the datafiles nor scan for corrupted blocks, it will just check V$DATABASE_BLOCK_CORRUPTION view if populated. |
|
VAL10=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set pages 0 feedback off echo off; |
|
select count(*) from V\$DATABASE_BLOCK_CORRUPTION; |
|
exit; |
|
EOF |
|
) |
|
VAL20=`echo $VAL10 | awk '{print $NF}'` |
|
if [ ${VAL20} -ge ${CORUPTBLKTHRESHOLD} ] |
|
then |
|
VAL30=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set linesize 160 pages 100 |
|
spool ${LOG_DIR}/corrupted_blocks.log |
|
PROMPT CORRUPTED BLOCKS DETAILS: |
|
PROMPT -------------------------------------- |
|
|
|
PROMPT |
|
select * from V\$DATABASE_BLOCK_CORRUPTION; |
|
spool off |
|
exit; |
|
EOF |
|
) |
|
mail -s "ALARM: CORRUPTED BLOCKS detected on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" $MAIL_LIST < ${LOG_DIR}/corrupted_blocks.log |
|
rm -f ${LOG_DIR}/corrupted_blocks.log |
|
fi |
|
|
|
# ############################################ |
|
# Checking FAILED JOBS ON THE DATABASE: |
|
# ############################################ |
|
VAL40=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set pages 0 feedback off echo off; |
|
SELECT (SELECT COUNT(*) FROM dba_jobs where failures <> '0') + (SELECT COUNT(*) FROM dba_scheduler_jobs where FAILURE_COUNT <> '0') FAIL_COUNT FROM dual; |
|
exit; |
|
EOF |
|
) |
|
VAL50=`echo $VAL40 | awk '{print $NF}'` |
|
if [ ${VAL50} -ge ${FAILDJOBSTHRESHOLD} ] |
|
then |
|
VAL60=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF |
|
set linesize 160 pages 100 |
|
spool ${LOG_DIR}/failed_jobs.log |
|
PROMPT DBMS_JOBS: |
|
PROMPT ----------- |
|
|
|
col LAST_RUN for a25 |
|
col NEXT_RUN for a25 |
|
select job,schema_user,failures,to_char(LAST_DATE,'DD-Mon-YYYY hh24:mi:ss')LAST_RUN,to_char(NEXT_DATE,'DD-Mon-YYYY hh24:mi:ss')NEXT_RUN from dba_jobs where failures <> '0'; |
|
|
|
PROMPT |
|
PROMPT DBMS_SCHEDULER: |
|
PROMPT ---------------- |
|
|
|
col OWNER for a25 |
|
col JOB_NAME for a40 |
|
col STATE for a11 |
|
col FAILURE_COUNT for 999 heading 'Fail' |
|
--col LAST_START_DATE for a40 |
|
select JOB_NAME,OWNER,ENABLED,STATE,FAILURE_COUNT,to_char(LAST_START_DATE,'DD-Mon-YYYY hh24:mi:ss')LAST_RUN,to_char(NEXT_RUN_DATE,'DD-Mon-YYYY hh24:mi:ss')NEXT_RUN from dba_scheduler_jobs where FAILURE_COUNT <> '0' order by ENABLED,STATE; |
|
|
|
spool off |
|
exit; |
|
EOF |
|
) |
|
mail -s "WARNING: FAILED JOBS detected on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" $MAIL_LIST < ${LOG_DIR}/failed_jobs.log |
|
rm -f ${LOG_DIR}/failed_jobs.log |
|
fi |
|
|
|
|
|
# ######################### |
|
# Getting ALERTLOG path: |
|
# ######################### |
|
VAL2=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" <<EOF |
|
set pages 0 feedback off; |
|
prompt |
|
SELECT value from v\$parameter where NAME='background_dump_dest'; |
|
exit; |
|
EOF |
|
) |
|
ALERTZ=`echo $VAL2 | perl -lpe'$_ = reverse' |awk '{print $1}'|perl -lpe'$_ = reverse'` |
|
ALERTDB=${ALERTZ}/alert_${ORACLE_SID}.log |
|
|
|
|
|
# ########################### |
|
# Checking Database Errors: |
|
# ########################### |
|
|
|
# Determine the ALERTLOG path: |
|
if [ -f ${ALERTDB} ] |
|
then |
|
ALERTLOG=${ALERTDB} |
|
elif [ -f $ORACLE_BASE/admin/${ORACLE_SID}/bdump/alert_${ORACLE_SID}.log ] |
|
then |
|
ALERTLOG=$ORACLE_BASE/admin/${ORACLE_SID}/bdump/alert_${ORACLE_SID}.log |
|
elif [ -f $ORACLE_HOME/diagnostics/${DB_NAME}/diag/rdbms/${DB_NAME}/${ORACLE_SID}/trace/alert_${ORACLE_SID}.log ] |
|
then |
|
ALERTLOG=$ORACLE_HOME/diagnostics/${DB_NAME}/diag/rdbms/${DB_NAME}/${ORACLE_SID}/trace/alert_${ORACLE_SID}.log |
|
else |
|
ALERTLOG=`/usr/bin/find ${ORACLE_BASE} -iname alert_${ORACLE_SID}.log -print 2>/dev/null` |
|
fi |
|
|
|
# Rename the old log generated by the script (if exists): |
|
if [ -f ${LOG_DIR}/alert_${ORACLE_SID}_new.log ] |
|
then |
|
mv ${LOG_DIR}/alert_${ORACLE_SID}_new.log ${LOG_DIR}/alert_${ORACLE_SID}_old.log |
|
# Create new log: |
|
tail -1000 ${ALERTLOG} > ${LOG_DIR}/alert_${ORACLE_SID}_new.log |
|
# Extract new entries by comparing old & new logs: |
|
echo "Reported By Script: ${SCRIPT_NAME}" > ${LOG_DIR}/diff_${ORACLE_SID}.log |
|
echo " " >> ${LOG_DIR}/diff_${ORACLE_SID}.log |
|
diff ${LOG_DIR}/alert_${ORACLE_SID}_old.log ${LOG_DIR}/alert_${ORACLE_SID}_new.log |grep ">" | cut -f2 -d'>' >> ${LOG_DIR}/diff_${ORACLE_SID}.log |
|
|
|
# Search for errors: |
|
ERRORS=`cat ${LOG_DIR}/diff_${ORACLE_SID}.log | grep 'ORA-\|TNS-' | grep -v 'ORA-2396' | tail -1` |
|
FILE_ATTACH=${LOG_DIR}/diff_${ORACLE_SID}.log |
|
|
|
else |
|
# Create new log: |
|
echo "Reported By Script: ${SCRIPT_NAME}" > ${LOG_DIR}/alert_${ORACLE_SID}_new.log |
|
echo " " >> ${LOG_DIR}/alert_${ORACLE_SID}_new.log |
|
tail -1000 ${ALERTLOG} >> ${LOG_DIR}/alert_${ORACLE_SID}_new.log |
|
|
|
# Search for errors: |
|
ERRORS=`cat ${LOG_DIR}/alert_${ORACLE_SID}_new.log | grep 'ORA-\|TNS-' | grep -v "ORA-2396" | tail -1` |
|
FILE_ATTACH=${LOG_DIR}/alert_${ORACLE_SID}_new.log |
|
fi |
|
|
|
# Send mail in case error exist: |
|
case "$ERRORS" in |
|
*ORA-*|*TNS-*) |
|
mail -s "ALERT: Instance [${ORACLE_SID}] on Server [${SRV_NAME}] reporting errors: ${ERRORS}" ${MAIL_LIST} < ${FILE_ATTACH} |
|
esac |
|
|
|
# ##################### |
|
# Reporting Offline DBs: |
|
# ##################### |
|
# Populate ${LOG_DIR}/alldb_DBA_BUNDLE.log from ORATAB: |
|
grep -v '^\#' $ORATAB | grep -v "ASM" |grep -v "${DB_NAME}:"| grep -v '^$' | grep "^" | cut -f1 -d':' > ${LOG_DIR}/alldb_DBA_BUNDLE.log |
|
# Populate ${LOG_DIR}/updb_DBA_BUNDLE.log: |
|
echo $ORACLE_SID >> ${LOG_DIR}/updb_DBA_BUNDLE.log |
|
echo $DB_NAME >> ${LOG_DIR}/updb_DBA_BUNDLE.log |
|
|
|
# End looping for databases: |
|
done |
|
|
|
# Continue Reporting Offline DBs... |
|
# Sort the lines alphabetically with removing duplicates: |
|
sort ${LOG_DIR}/updb_DBA_BUNDLE.log | uniq -d > ${LOG_DIR}/updb_DBA_BUNDLE.log.sort |
|
sort ${LOG_DIR}/alldb_DBA_BUNDLE.log > ${LOG_DIR}/alldb_DBA_BUNDLE.log.sort |
|
diff ${LOG_DIR}/alldb_DBA_BUNDLE.log.sort ${LOG_DIR}/updb_DBA_BUNDLE.log.sort > ${LOG_DIR}/diff_DBA_BUNDLE.sort |
|
echo "The Following Instances are Down on $SRV_NAME :" > ${LOG_DIR}/offdb_DBA_BUNDLE.log |
|
grep "^< " ${LOG_DIR}/diff_DBA_BUNDLE.sort | cut -f2 -d'<' >> ${LOG_DIR}/offdb_DBA_BUNDLE.log |
|
echo " " >> ${LOG_DIR}/offdb_DBA_BUNDLE.log |
|
echo "If those instances are permanently offline, please hash their entries in $ORATAB to let the script ignore them in the next run." >> ${LOG_DIR}/offdb_DBA_BUNDLE.log |
|
OFFLINE_DBS_NUM=`cat ${LOG_DIR}/offdb_DBA_BUNDLE.log| wc -l` |
|
|
|
# If OFFLINE_DBS is not null: |
|
if [ ${OFFLINE_DBS_NUM} -gt 3 ] |
|
then |
|
mail -s "ALARM: Database Down on Server: [$SRV_NAME]" $MAIL_LIST < ${LOG_DIR}/offdb_DBA_BUNDLE.log |
|
fi |
|
|
|
# Wiping Logs: |
|
#cat /dev/null > ${LOG_DIR}/updb_DBA_BUNDLE.log |
|
#cat /dev/null > ${LOG_DIR}/alldb_DBA_BUNDLE.log |
|
#cat /dev/null > ${LOG_DIR}/updb_DBA_BUNDLE.log.sort |
|
#cat /dev/null > ${LOG_DIR}/alldb_DBA_BUNDLE.log.sort |
|
#cat /dev/null > ${LOG_DIR}/diff_DBA_BUNDLE.sort |
|
|
|
rm -f ${LOG_DIR}/updb_DBA_BUNDLE.log |
|
rm -f ${LOG_DIR}/alldb_DBA_BUNDLE.log |
|
rm -f ${LOG_DIR}/updb_DBA_BUNDLE.log.sort |
|
rm -f ${LOG_DIR}/alldb_DBA_BUNDLE.log.sort |
|
rm -f ${LOG_DIR}/diff_DBA_BUNDLE.sort |
|
|
|
|
|
# ########################### |
|
# Checking Listeners log: |
|
# ########################### |
|
|
|
# In case there is NO Listeners are running send an (Alarm): |
|
LSN_COUNT=$( ps -ef|grep -v grep|grep tnslsnr|wc -l ) |
|
|
|
if [ $LSN_COUNT -eq 0 ] |
|
then |
|
echo "Reported By Script: ${SCRIPT_NAME}" > ${LOG_DIR}/listener_processes.log |
|
echo " " >> ${LOG_DIR}/listener_processes.log |
|
echo "The following are the processes running by user ${ORA_USER} on server ${SRV_NAME}:" >> ${LOG_DIR}/listener_processes.log |
|
echo " " >> ${LOG_DIR}/listener_processes.log |
|
ps -ef|grep -v grep|grep oracle >> ${LOG_DIR}/listener_processes.log |
|
mail -s "ALARM: No Listeners Are Running on Server: $SRV_NAME !!!" $MAIL_LIST < ${LOG_DIR}/listener_processes.log |
|
|
|
# In case there is a listener running analyze it's log: |
|
else |
|
for LISTENER_NAME in $( ps -ef|grep -v grep|grep tnslsnr|awk '{print $(NF-1)}' ) |
|
do |
|
LISTENER_HOME=`ps -ef|grep -v grep|grep tnslsnr|grep "${LISTENER_NAME} "|awk '{print $(NF-2)}' |sed -e 's/\/bin\/tnslsnr//g'|grep -v sed|grep -v "s///g"` |
|
TNS_ADMIN=${LISTENER_HOME}/network/admin; export TNS_ADMIN |
|
LISTENER_LOGDIR=`${LISTENER_HOME}/bin/lsnrctl status ${LISTENER_NAME} |grep "Listener Log File"| awk '{print $NF}'| sed -e 's/\/alert\/log.xml//g'` |
|
LISTENER_LOG=${LISTENER_LOGDIR}/trace/${LISTENER_NAME}.log |
|
|
|
# Determine if the listener name is in Upper/Lower case: |
|
if [ -f ${LISTENER_LOG} ] |
|
then |
|
# Listner_name is Uppercase: |
|
LISTENER_NAME=$( echo ${LISTENER_NAME} | perl -lpe'$_ = reverse' |perl -lpe'$_ = reverse' ) |
|
LISTENER_LOG=${LISTENER_LOGDIR}/trace/${LISTENER_NAME}.log |
|
else |
|
# Listener_name is Lowercase: |
|
LISTENER_NAME=$( echo "${LISTENER_NAME}" | tr -s '[:upper:]' '[:lower:]' ) |
|
LISTENER_LOG=${LISTENER_LOGDIR}/trace/${LISTENER_NAME}.log |
|
fi |
|
|
|
# Rename the old log (If exists): |
|
if [ -f ${LOG_DIR}/alert_${LISTENER_NAME}_new.log ] |
|
then |
|
mv ${LOG_DIR}/alert_${LISTENER_NAME}_new.log ${LOG_DIR}/alert_${LISTENER_NAME}_old.log |
|
# Create a new log: |
|
tail -1000 ${LISTENER_LOG} > ${LOG_DIR}/alert_${LISTENER_NAME}_new.log |
|
# Get the new entries: |
|
echo "Reported By Script: ${SCRIPT_NAME}" > ${LOG_DIR}/diff_${LISTENER_NAME}.log |
|
echo " " >> ${LOG_DIR}/diff_${LISTENER_NAME}.log |
|
diff ${LOG_DIR}/alert_${LISTENER_NAME}_old.log ${LOG_DIR}/alert_${LISTENER_NAME}_new.log | grep ">" | cut -f2 -d'>' >> ${LOG_DIR}/diff_${LISTENER_NAME}.log |
|
# Search for errors: |
|
ERRORS=`cat ${LOG_DIR}/diff_${LISTENER_NAME}.log| grep "TNS-" |tail -1` |
|
SRVC_REG=`cat ${LOG_DIR}/diff_${LISTENER_NAME}.log| grep "service_register" ` |
|
FILE_ATTACH=${LOG_DIR}/diff_${LISTENER_NAME}.log |
|
|
|
# If no old logs exist: |
|
else |
|
# Just create a new log without doing any comparison: |
|
echo "Reported By Script: ${SCRIPT_NAME}" > ${LOG_DIR}/alert_${LISTENER_NAME}_new.log |
|
echo " " >> ${LOG_DIR}/alert_${LISTENER_NAME}_new.log |
|
tail -1000 ${LISTENER_LOG} >> ${LOG_DIR}/alert_${LISTENER_NAME}_new.log |
|
|
|
# Search for errors: |
|
ERRORS=`cat ${LOG_DIR}/alert_${LISTENER_NAME}_new.log | grep "TNS-" | tail -1` |
|
SRVC_REG=`cat ${LOG_DIR}/alert_${LISTENER_NAME}_new.log | grep "service_register" ` |
|
FILE_ATTACH=${LOG_DIR}/alert_${LISTENER_NAME}_new.log |
|
fi |
|
|
|
# Report TNS Errors (Alert) |
|
case "$ERRORS" in |
|
*TNS-*) |
|
mail -s "ALERT: Listener [${LISTENER_NAME}] on Server [${SRV_NAME}] reporting errors: ${ERRORS}" $MAIL_LIST < ${FILE_ATTACH} |
|
esac |
|
|
|
# Report Registered Services to the listener (Info) |
|
case "$SRVC_REG" in |
|
*service_register*) |
|
mail -s "INFO: Service Registered on Listener [${LISTENER_NAME}] on Server [${SRV_NAME}] | TNS poisoning posibility" $MAIL_LIST < ${FILE_ATTACH} |
|
esac |
|
|
|
done |
|
fi |
|
|
|
# ############# |
|
# END OF SCRIPT |
|
# ############# |
|
# REPORT BUGS to: mahmmoudadel@hotmail.com |
|
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM: |
|
# http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html |
|
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS". |
|
- Oracle SQL 调优之 sqlhc
SQL 执行慢,如何 快速准确的优化. sqlhc 就是其中最好工具之一 通过获得sql所有的执行计划,列出实际的性能的瓶颈点,列出 sql 所在的表上的行数,每一列的数据和分布,现有的索引,sql ...
- Oracle SQL 调优健康检查脚本
Oracle SQL 调优健康检查脚本 我们关注数据库系统的性能,进行数据库调优的主要工作就是进行SQL的优化.良好的数据架构设计.配合应用系统中间件和写一手漂亮的SQL,是未来系统上线后不出现致命性 ...
- SQL Tuning Health-Check Script (SQLHC)
1. 纯手工打造 工具:程序员的双手 特点:手写客户端与服务器端验证代码 2. 半手工半自动 工具:jquery.validate(客户端) + DataAnnotations & DataA ...
- Oracle Applications DBA 基础(一)
1.引子 2014年9月13日 20:33 <oracle Applications DBA 基础>介绍Oracle Applications R12的系统架构, 数据库后台及应用系统的基 ...
- healthcheck
-- ============================================================================= -- USAGE : sqlplus ...
- Oracle分析函数入门
一.Oracle分析函数入门 分析函数是什么?分析函数是Oracle专门用于解决复杂报表统计需求的功能强大的函数,它可以在数据中进行分组然后计算基于组的某种统计值,并且每一组的每一行都可以返回一个统计 ...
- Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级
Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part3:db安装和升级 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 5.安装Database软件 5. ...
- Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part1:准备工作
Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part1:准备工作 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 1.实施前准备工作 1.1 服务器安装操 ...
- Oracle 的基本操作符
!= 不等于 select empno,ename,job from scott.emp where job!='manager' ^= 不等于 select empno,ename,job from ...
随机推荐
- cookies localStorage和sessionStorage的区别
sessionStorage用于本地存储一个会话(session)中的数据,这些数据只有在同一个会话中的页面才能访问并且当会话结束后数据也随之销毁.因此sessionStorage不是一种持久化的本地 ...
- final修饰的变量引用不能变还是对象不可变
两种情况:如果是基本数据类型,被final修饰的变量一旦初始化就不能改变:如果是引用数据类型的变量,初始化之后不能指向另外一个对象. 基本数据类型: package cn.yqg.day2; publ ...
- linux 中截取字符串
shell中截取字符串的方法有很多中,${expression}一共有9种使用方法.${parameter:-word}${parameter:=word}${parameter:?word}${pa ...
- 012——matlab判断变量是否存在
(一)参考文献:https://www.ilovematlab.cn/thread-48319-1-1.html (二) clc clear a = exist('a') ans =1 clc cle ...
- learning java ATW ScrollPane
import java.awt.*; public class ScrollPaneTest { public static void main(String[] args) { var f = ne ...
- ES单机版安装
1.安装JDK(1.8)2.上传解压Elasticsearch-5.4.33.创建一个普通用户,然后将对于的目录修改为普通用户的所属用户和所属组4.修改配置文件config/elasticsearch ...
- ELK教程2:Kibana的安装
kibana作为ElastciSearch的数据查询展示界面,集成了很多的功能,本文主要讲述如下部署kibana. 安装 安装命令如下: # 下载kibana的npm wget https://art ...
- P2502 [HAOI2006]旅行——暴力和并查集的完美结合
P2502 [HAOI2006]旅行 一定要看清题目数据范围再决定用什么算法,我只看着是一个蓝题就想到了记录最短路径+最小生成树,但是我被绕进去了: 看到只有5000的边,我们完全可以枚举最小边和最大 ...
- Jmeter5.1 Plugins Manager配置dummy使用jp@gc - Dummy Sampler
背景和目的 最近想使用dummy进行mockserver服务器的模拟来实现正则表达式测试,但是发现在选项中没有Plugins Manager可供选择 如果本文对你有帮助,请关注我哦,一起进步.接下来看 ...
- 2、Apache(httpd)之一 三种工作模式
httpd的特性: 高度模块化:core + modules 模块化设计DSO:Dynamic Shared Object MPM:Multipath Processing Modules 多路处理模 ...