转 oracle healthcheck
Posted feiyun8616
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转 oracle healthcheck相关的知识,希望对你有一定的参考价值。
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;
以上是关于转 oracle healthcheck的主要内容,如果未能解决你的问题,请参考以下文章