-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDBHC_script.V8.4.sh
1632 lines (1380 loc) · 54.4 KB
/
DBHC_script.V8.4.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#/bin/bash
#############################################################
# Author : ##
# Company : xxxxxxxxxxxxxxxxxxx ##
# Description : ##
#############################################################
##
## Set Global Variables
##
OS_TYPE=""
OS_TYPE_STATUS=""
DBNAME=""
DBMODE=""
DBROLE=""
DATE_TIME=`date +%d_%m_%Y`
DDATE_TIME=`date +%d-%m-%Y`
DBSRV_TIME=`date +%a_%H_%M_%S`
#DBHC_DIR=`echo $HOME`"/DBHC/DBHC-"`hostname``echo $DDATE_TIME`
RAC_LOG_FILE=""
#LOG_DEST_DIR=`echo $DBHC_DIR`
OS_LOG_FILE=""
DB_ALERT_LOG=""
SCRIPT_RUN=""
ORA_INSTANCE=""
OS_CHOICE=""
OS_PLATFORM=""
RAC_CHOICE=""
DBHC_BASE=`echo $HOME`"/DBHC"
DBHC_DIR=`echo $HOME`"/DBHC/DBHC-"`hostname`"-"`echo $DDATE_TIME`
LOG_DEST_DIR=`echo $DBHC_DIR`
CLIENT_NAME=""
CLIENT_DBTYPE=""
ADDM_TNAME="DBHC_$DATE_TIME"
ADDM_TDESC="ADDM for DBHC $DATE_TIME"
_banner(){
if [ -z "$1" -a "$1" == " " ]
then
echo "########################################################"
echo "########################################################"
else
echo "########################################################"
echo " $1 "
echo "########################################################"
fi
}
_printNewline(){
echo -e "\n"
}
_dashBanner(){
if [ -z "$1" -a "$1" == " " ]
then
echo "-----------------------------------------------------------"
else
echo "-----------------[ $1 ]------------------"
fi
}
_errorReport(){
echo "########################################################"
echo "Error during Running Scripts"
echo "Error: $1 "
echo "########################################################"
exit 1
}
##
## Function to dispaly Informative message.
##
infoReport(){
echo "########################################################"
echo "INFO : $1"
echo "INFO : $2"
echo "########################################################"
}
##
## Function to dispaly Key Value
##
keyValueReport(){
echo "----------"
echo -e "INFO : $1 :: $2"
echo "----------"
}
##
## Function to check if any specific value exists in array
##
checkSidValid(){
param1=("${!1}")
check=${2}
statusSID=0
for i in ${param1[@]}
do
if [ ${i} == $2 ];
then
statusSID=1
break
esle
echo $i;
fi
done
return $statusSID;
}
##
## Function to verify the correct O/S selection
##
checkValidOS(){
inputOS=${1}
actualOS=`uname`
case "$inputOS" in
'AIX')
if [ "$actualOS" = "AIX" ];
then
OS_TYPE_STATUS=VALID
else
OS_TYPE_STATUS=1
fi
;;
'HP')
if [ "$actualOS" = "HP" ];
then
OS_TYPE_STATUS=VALID
else
OS_TYPE_STATUS=1
fi
;;
'LX')
if [ "$actualOS" = "Linux" ];
then
OS_TYPE_STATUS=VALID
else
OS_TYPE_STATUS=1
fi
;;
'SL')
if [ "$actualOS" = "SunOS" ];
then
OS_TYPE_STATUS=VALID
else
OS_TYPE_STATUS=1
fi
;;
esac
}
##
## Get the cluster name and generate cluster logfilename
##
setClusterLogfile(){
RAC_LOG_FILE=`$1/bin/cemutlo -n`
RAC_LOG_FILE=`echo $RAC_LOG_FILE`_racinfo_$DATE_TIME.log
}
##
## Get the Database name, Open Mode and Database Role
##
getDBname(){
DBNAME=$($1/bin/sqlplus -s /nolog <<END
set pagesize 0 feedback off verify off echo off;
connect / as sysdba
select name from v\$database;
END
)
}
getDBmode(){
DBMODE=$($1/bin/sqlplus -s /nolog <<END
set pagesize 0 feedback off verify off echo off;
connect / as sysdba
select open_mode from v\$database;
END
)
}
getDBrole(){
DBROLE=$($1/bin/sqlplus -s /nolog <<END
set pagesize 0 feedback off verify off echo off;
connect / as sysdba
select database_role from v\$database;
END
)
}
##
## Get the database alert log destination
##
getDBalertLog(){
DB_ALERT_LOG=$($1/bin/sqlplus -s /nolog <<END
set pagesize 0 feedback off verify off echo off;
connect / as sysdba
select value from v\$parameter where name like'background_dump_dest';
END
)
}
##
## For Warning and Text manupulation
##
bold=$(tput bold)
reset=$(tput sgr0)
bell=$(tput bel)
underline=$(tput smul)
##
## Create necessary directories for storing DBHC logs
##
#mkdir -p $DBHC_DIR
#if [ $? -ne 0 ] ; then
# _errorReport "DBHC directory cannot be created. Aborting...."
#fi
##
## Creating Variables and storing Queries
##
##
## Prepare Fomatting cmds
##
read -d '' formatCmd << EOF
set linesize 200
set pages 100
column name format a50
column comp_name format a50
column member format a60
COLUMN FILE_NAME FORMAT A60
COLUMN TABLESPACE_NAME FORMAT A30
column platform_name format a30
EOF
##
## Prepare Document end info
##
read -d '' styleEndCmd << EOF
prompt </body></html>
EOF
##
## Prepare Heading Info for Report
##
read -d '' dbhcHeadingCmd << EOF
prompt <h2>Database Health Checkup Report</h2>
prompt <table border="1" style=" margin: auto; width: 50%;">
prompt <tbody>
prompt <tr><th style="padding: 5px;">Author:</th><th style="background-color: aliceblue; padding: 5px;"> Nepasoft Solutions Pvt. Ltd.</th></tr>
prompt <tr><th style="padding: 5px;">Date Perofrmed:</th><th style="background-color: aliceblue; padding: 5px;">`date +%d-%m-%Y`</th></tr>
prompt </tbody>
prompt </table>
EOF
##
## Prepare Copyright info
##
read -d '' copyRightCmd << EOF
set define off
prompt <h3 style="text-align:center;margin:auto;color: cornflowerblue;text-decoration: underline; margin-top:20px;"> Copyright © `date +%Y` Nepasoft Solutions Pvt. Ltd.</h3>
prompt <p style="width: 53%;margin:auto; margin-bottom:30px; text-align:center;color:black;">
prompt All rights reserved. This report is generated by Nepasoft for Oracle Database health checkup
prompt with proper consent with the Database owner thereof the report may not be
prompt reproduced or used in any manner whatsoever without the
prompt permission of the Nepasoft and Database Owner.
prompt </p>
set define on
EOF
##
## Collect Basic Database info
##
read -d '' basicDBinfoCmd << EOF
----************************************
---- Basic Database Info
----************************************
prompt <h4>Basic Database Info:</h4>
select dbid,name, FLASHBACK_ON, PLATFORM_NAME,DATABASE_ROLE from v\$database;
----************************************
---- List the version of the database
----************************************
prompt <h4>List the version of the database:</h4>
select * from v\$version;
EOF
##
## Collect Online and Standby Redo log info
##
read -d '' onlineRedoCmd << EOF
----********************************************************
---- List the log groups along with their members and size
----********************************************************
prompt <h4>Database Online Redo log groups:</h4>
select a.group#, a.thread#,bytes/(1024*1024) SIZE_MB, b.member from v\$log a, v\$logfile b where a.group#=b.group# order by a.group#;
----********************************************************
---- List the standby log groups with their members and size
----********************************************************
prompt <h4>Database Standby Redo log groups:</h4>
select a.group#, a.thread#,bytes/(1024*1024) SIZE_MB, b.member from v\$standby_log a, v\$logfile b where a.group#=b.group# order by a.group#;
set serveroutput on
DECLARE
rowCnt number(2);
BEGIN
select count(*) into rowCnt from v\$standby_log;
IF rowCnt <= 0 THEN
dbms_output.put_line('<p style="margin-left: 5%; margin-top: 10px;">Information about standby redolog was not found.<p>');
END IF;
END;
/
EOF
##
## Collect Controlfile info
##
read -d '' controlFileCmd << EOF
----********************************************************
---- Control file information
----********************************************************
prompt <h4>Control file information:</h4>
select name, STATUS,IS_RECOVERY_DEST_FILE , BLOCK_SIZE, FILE_SIZE_BLKS from v\$controlfile order by name;
EOF
##
## Collect Wallet Info
##
read -d '' walletInfoCmd << EOF
----********************************************************
---- Wallet Information
----********************************************************
prompt <h4>Wallet Information:</h4>
select * from v\$encryption_wallet;
EOF
##
## Collect archive related info
##
read -d '' archiveInfoCmd << EOF
----********************************************************
---- Archive Information
----********************************************************
prompt <h4>Archive Information:</h4><p style="margin: auto; margin-left: 5%; width: 90%; margin-bottom: 20px;">
archive log list;
prompt </p>
----********************************************************
---- last 1 days archive status
----********************************************************
prompt <h4>Last 1 days archive status:</h4>
col "Archived Date" format a30
select to_char(COMPLETION_TIME,'DD/MM/YYYY HH24:MI:SS') "Archived Date",thread#, sequence#, archived, applied,inst_id, round((BLOCKS * BLOCK_SIZE)/(1024*1024),3) "Archive Size" from gv\$archived_log where COMPLETION_TIME >= sysdate - 1 and thread#=1 and inst_id=1 order by sequence#;
select to_char(COMPLETION_TIME,'DD/MM/YYYY HH24:MI:SS') "Archived Date",thread#, sequence#, archived, applied,inst_id, round((BLOCKS * BLOCK_SIZE)/(1024*1024),3) "Archive Size" from gv\$archived_log where COMPLETION_TIME >= sysdate - 1 and thread#=2 and inst_id=2 order by sequence#;
EOF
##
## Collect Datagurad Information
##
read -d '' dataguardInfoCmd << EOF
----********************************************************
---- Dataguard Information
----********************************************************
prompt <h4>Dataguard Information:</h4>
select name, value,inst_id from gv\$parameter where name in
(
'remote_login',
'db_name',
'memory_target',
'memory_max_target',
'db_unique_name',
'archive_lag_target',
'compatible',
'control_files',
'db_create_file_dest',
'DB_CREATE_ONLINE_LOG_DEST',
'db_recovery_file_dest',
'log_archive_config',
'log_archive_max_processes',
'log_archive_dest_1',
'log_archive_dest_state_1',
'log_archive_dest_2',
'log_archive_dest_state_2',
'fal_server',
'fal_client',
'standby_file_management',
'db_file_name_convert',
'log_file_name_convert',
'log_archive_format');
prompt <h4>Database Force logging Status:</h4>
select force_logging from v\$database;
----********************************************************
---- Check for the redo transport
----********************************************************
prompt <h4>Check for the redo transport:</h4>
select status , error from v\$archive_dest where dest_id=2;
----********************************************************
---- Data guard archive log status
----********************************************************
prompt <h4>DataGuard Sync Status:</h4>
COL DB_NAME FORMAT A8
COL HOSTNAME FORMAT A12
COL LOG_ARCHIVED FORMAT 999999
COL LOG_APPLIED FORMAT 999999
COL LOG_GAP FORMAT 9999
COL APPLIED_TIME FORMAT A12
SELECT DB_NAME, HOSTNAME, LOG_ARCHIVED_TH1,LOG_ARCHIVED_TH2,LOG_APPLIED_TH1,LOG_APPLIED_TH2,LOG_ARCHIVED_TH1-LOG_APPLIED_TH1 LOG_GAP_TH1,LOG_ARCHIVED_TH2-LOG_APPLIED_TH2 LOG_GAP_TH2
FROM
(
SELECT NAME DB_NAME
FROM V\$DATABASE
),
(
SELECT UPPER(SUBSTR(HOST_NAME,1,(DECODE(INSTR(HOST_NAME,'.'),0,LENGTH(HOST_NAME),
(INSTR(HOST_NAME,'.')-1))))) HOSTNAME
FROM V\$INSTANCE
),
(
SELECT MAX(SEQUENCE#) LOG_ARCHIVED_TH1
FROM V\$ARCHIVED_LOG WHERE DEST_ID=1 AND ARCHIVED='YES' and Thread#=1
and
resetlogs_id in
( select max(resetlogs_id) from v\$archived_log where Thread#=1)
),
(
SELECT MAX(SEQUENCE#) LOG_ARCHIVED_TH2
FROM V\$ARCHIVED_LOG WHERE DEST_ID=1 AND ARCHIVED='YES' and Thread#=2
and
resetlogs_id in
( select max(resetlogs_id) from v\$archived_log where Thread#=2)
),
(
SELECT MAX(SEQUENCE#) LOG_APPLIED_TH1
FROM V\$ARCHIVED_LOG WHERE DEST_ID=2 AND APPLIED='YES' and Thread#=1
and
resetlogs_id in
( select max(resetlogs_id) from v\$archived_log where Thread#=1)
),
(
SELECT MAX(SEQUENCE#) LOG_APPLIED_TH2
FROM V\$ARCHIVED_LOG WHERE DEST_ID=2 AND APPLIED='YES' and Thread#=2
and
resetlogs_id in
( select max(resetlogs_id) from v\$archived_log where Thread#=2)
);
EOF
##
## Collect Backup information for database
##
read -d '' backupInfoCmd << EOF
----********************************************************
---- Rman Backup of Information
----********************************************************
set linesize 222
col "Start Time" format a18
col "End Time" format a18
col "BK Input Size: MB" format 999,999,999.99
col "BK Output Size: MB" format 999,999,999.99
col "Backup To" format a12
col "Status" format a35
col "Backup Type" format a20
col "Total Time" format a10
prompt <h4>Rman Backup of Information:</h4>
select to_char(START_TIME,'DD/MM/YYYY HH24:MI') "Start Time", to_char(END_TIME,'DD/MM/YYYY HH24:MI') "End Time",
round(INPUT_BYTES/1024/1024,2) "BK Input Size: MB",round(OUTPUT_BYTES/1024/1024,2) "BK Output Size: MB",
OUTPUT_DEVICE_TYPE "Backup To",STATUS "Status",INPUT_TYPE "Backup Type",TIME_TAKEN_DISPLAY "Total Time"
from V\$RMAN_BACKUP_JOB_DETAILS
where sysdate - START_TIME < 30 order by 1 desc;
set serveroutput on
DECLARE
rowCnt number(2);
BEGIN
select count(*) into rowCnt from V\$RMAN_BACKUP_JOB_DETAILS;
IF rowCnt <= 0 THEN
dbms_output.put_line('<p style="margin-left: 5%; margin-top: 10px;">No Bakcup details about RMAN was found in backup repository.<p>');
END IF;
END;
/
EOF
##
## Collect archive log switch information
##
read -d '' logSwitchCmd << EOF
---- ***************************************************
---- log switch information
----********************************************************
prompt <h4>Log Switch Information for the instance:</h4>
set pages 999;
select to_char(first_time,'DD-MON-RR') "Date",
to_char(sum(decode(to_char(first_time,'HH24'),'00',2,0)),'999') " 00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',2,0)),'999') " 01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',2,0)),'999') " 02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',2,0)),'999') " 03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',2,0)),'999') " 04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',2,0)),'999') " 05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',2,0)),'999') " 06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',2,0)),'999') " 07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',2,0)),'999') " 08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',2,0)),'999') " 09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',2,0)),'999') " 10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',2,0)),'999') " 11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',2,0)),'999') " 12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',2,0)),'999') " 13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',2,0)),'999') " 14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',2,0)),'999') " 15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',2,0)),'999') " 16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',2,0)),'999') " 17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',2,0)),'999') " 18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',2,0)),'999') " 19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',2,0)),'999') " 20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',2,0)),'999') " 21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',2,0)),'999') " 22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',2,0)),'999') " 23"
from v\$log_history
where sysdate - first_time < 30
group by to_char(first_time,'DD-MON-RR')
order by 1;
EOF
##
## Collect Asm Disk information
##
read -d '' asmDiskInfoCmd << EOF
----********************************************************
---- ASM Disk Information
----********************************************************
set linesize 500
column name format a30
column COMPATIBILITY format a20
column DATABASE_COMPATIBILITY format a20
column FREE_MB format a20
column type format a20
prompt <h4>ASM Disk Information:</h4>
select GROUP_NUMBER GROUP_NO ,NAME,STATE, TYPE,(TOTAL_MB/(1024)) total_GB , (FREE_MB/1024) free_GB from v\$asm_diskgroup order by group_number, name;
select GROUP_NUMBER GROUP_NO ,NAME,REQUIRED_MIRROR_FREE_MB ,USABLE_FILE_MB,OFFLINE_DISKS,COMPATIBILITY ,DATABASE_COMPATIBILITY from v\$asm_diskgroup order by group_number, name;
set serveroutput on
DECLARE
rowCnt number(2);
BEGIN
select count(*) into rowCnt from V\$asm_diskgroup;
IF rowCnt <= 0 THEN
dbms_output.put_line('<p style="margin-left: 5%; margin-top: 10px;">ASM Disk group are not configured or No Diskgroup found..<p>');
END IF;
END;
/
EOF
##
## Collect Memory and Memory advisory information for instance
##
read -d '' memoryInfoCmd << EOF
----********************************************************
---- Begin spooling for Memory Advisor
----********************************************************
prompt <h4>Dispaly Memory Parameters:</h4>
show parameter memory;
show parameter sga;
show parameter pga;
prompt <h4>Dispaly Memory Traget Advice:</h4>
select * from v\$memory_target_advice;
prompt <h4>Display SGA target advice:</h4>
select * from v\$sga_target_advice;
-- ************************************************
-- Display pga target advice
-- ************************************************
prompt <h4>Display pga target advice:</h4>
select pga_target_for_estimate, pga_target_factor, ESTD_PGA_CACHE_HIT_PERCENTAGE from v\$pga_target_advice;
prompt <h4>Display pga target advice:</h4>
SELECT
ROUND(pga_target_for_estimate /(1024*1024)) c1,
estd_pga_cache_hit_percentage c2,
estd_overalloc_count c3
FROM
v\$pga_target_advice;
-- ************************************************
-- Display pga target advice histogram
-- ************************************************
prompt <h4>Display pga target advice histogram:</h4>
SELECT
low_optimal_size/1024 "Low(K)",
(high_optimal_size+1)/1024 "High(K)",
estd_optimal_executions "Optimal",
estd_onepass_executions "One Pass",
estd_multipasses_executions "Multi-Pass"
FROM
v\$pga_target_advice_histogram
WHERE
pga_target_factor = 2
AND
estd_total_executions != 0
ORDER BY
1;
EOF
##
## List and collect profile and its properties
##
read -d '' dbProfileInfoCmd << EOF
prompt <h4>List and collect profile and its properties :</h4>
select * from dba_profiles;
EOF
##
## Collect DBA registery info for database
##
read -d '' dbRegistryInfoCmd << EOF
----************************************
---- List the components of dba registry
----************************************
prompt <h4>List the components of dba registry:</h4>
select comp_name, version, status from dba_registry order by comp_name;
EOF
##
## Collect Tablespace and its associated datafile info
##
read -d '' tsDatafileInfoCmd << EOF
----********************************************************
---- List the tablespace info and its usage
----********************************************************
prompt <h4>List the tablespace info and its usage:</h4>
column "Tablespace" format a25
column "Total Size in MB" format 999,999,999.99
column "Total Used in MB" format 999,999,999.99
column "Total free in MB" format 999,999,999.99
column "Used %" format a6
column "Free %" format a6
select tablespace_name "Tablespace",
round("Total in MB",2) "Total Size in MB",
round("Free in MB",2) "Total Free in MB",
round("Total in MB" - "Free in MB", 2) as "Total Used in MB",
round((("Total in MB" - "Free in MB")/"Total in MB")*100,2)||'%' as "Used %",
(round(100-(("Total in MB" - "Free in MB")/"Total in MB")*100,2))||'%' as "Free %"
from (select tablespace_name ,
sum( bytes /(1024*1024)) "Free in MB" from dba_free_space
group by tablespace_name) ts join (select tablespace_name , sum( bytes/(1024*1024)) "Total in MB"
from dba_data_files group by tablespace_name) using ( tablespace_name) order by 4 desc;
----********************************************************
---- List the data files its size and other properties
----********************************************************
prompt <h4>List the data files its size and other properties:</h4>
column TABLESPACE_NAME format a20
column file_name format a50
column "Size: GB" format 999,999.99
column "Extend By" format 999,999.99
column "Max Size: GB" format 999,999.99
column "Free Space: GB" format 999,999.99
select ddf.tablespace_name,file_name,autoextensible,ONLINE_STATUS,"Extend By", "Size: GB", "Max Size: GB", "Free Space: GB" from
(select tablespace_name,file_id , (bytes/1024/1024/1024) "Size: GB",file_name,INCREMENT_BY/1024/1024*1024*8 "Extend By",
ONLINE_STATUS, status,autoextensible, (MAXBYTES/1024/1024/1024) "Max Size: GB"
from dba_data_files) ddf
join
(select file_id, round(sum(BYTES/1024/1024/1024),2) "Free Space: GB" from DBA_FREE_SPACE group by file_id) dfs using (file_id)
order by 1;
EOF
##
## Collect Overall Database size info
##
read -d '' dbSizeInfoCmd << EOF
----************************************
---- View the database size and its usage
----************************************
prompt <h4>Database size and its usage:</h4>
col "Used Percentage" format a15
col "Free Percentage" format a15
select "Size in GB O/S level", ("Size in GB O/S level"- "Total Free in GB") "Size in GB Database Level",("Total Free in GB") "Total Free in GB DB Level",
trunc((("Size in GB O/S level"- "Total Free in GB")/ "Size in GB O/S level")*100,2)||'%' "Used Percentage",trunc(("Total Free in GB"/ "Size in GB O/S level")*100,2)||'%' "Free Percentage"
from
(select
round(( select sum(bytes)/1024/1024/1024 data_size from dba_data_files ) +
( select nvl(sum(bytes),0)/1024/1024/1024 temp_size from dba_temp_files ) +
( select sum(bytes)/1024/1024/1024 redo_size from sys.v_\$log ) +
( select sum(BLOCK_SIZE*FILE_SIZE_BLKS)/1024/1024/1024 controlfile_size from v\$controlfile),2) "Size in GB O/S level",
(select sum(round("Free in MB",2)) from (select tablespace_name ,
sum( bytes /(1024*1024*1024)) "Free in MB" from dba_free_space
group by tablespace_name) ts join (select tablespace_name , sum( bytes/(1024*1024)) "Total in MB"
from dba_data_files group by tablespace_name) using ( tablespace_name)) "Total Free in GB"
from
dual);
EOF
##
## Collect Status of System and Sysaux Tablespaces
##
read -d '' systemTsInfoCmd << EOF
----********************************************************
---- Health of system and sysaux tablespaces
----********************************************************
prompt <h4>Total size of system and sysaux tablespaces used by non System users:</h4>
select sum(bytes/1024/1024) "Size System tablespaces used" from dba_segments
where tablespace_name = 'SYSTEM'
and owner not in ('SYS','SYSTEM');
----********************************************************
---- Select the space of system tablespace consumed by users other then sys and system
----********************************************************
prompt <h4>System tablespace consumed by users other then sys and system:</h4>
select owner, segment_name, segment_type
from dba_segments
where tablespace_name = 'SYSTEM'
and owner not in ('SYS','SYSTEM');
EOF
##
## Collect Tempory Tablespace Info for Database
##
read -d '' tempTsInfoCmd << EOF
----********************************************************
------ Temporary Tablespace in Database
----********************************************************
prompt <h4>Temporary Tablespace in Database:</h4>
select tablespace_name, sum(bytes)/1024/1024 "Size in MB"
from dba_temp_files
group by tablespace_name;
EOF
##
## Collect Database Users Information
##
read -d '' usersInfoCmd << EOF
----********************************************************
---- Users Information
----********************************************************
prompt <h4>Users Information:</h4>
select username, default_tablespace, temporary_tablespace, account_status,EXPIRY_DATE from dba_users order by username;
EOF
##
## Create DBHCGROWTHRATE table to track database growth rate if not exists
##
read -d '' dbGthCreTblCmd << EOF
DECLARE
tableStmt varchar2(4000);
tblOut number(2);
BEGIN
select count(*) into tblOut from dba_tables where table_name='DBHCGROWTHRATE';
IF tblOut <= 0 THEN
tableStmt:='CREATE TABLE DBHCGROWTHRATE (
DBHCDATE DATE DEFAULT SYSDATE,
SIZEINOS_GB varchar2(10),
SIZEINDB_GB varchar2(10),
FREEINDB_GB varchar2(10),
USED_PERCENT VARCHAR2(10),
FREE_PERCENT VARCHAR2(10)
)';
EXECUTE IMMEDIATE tableStmt;
END IF;
END;
/
EOF
##
## Insert Into the TABLE DBHCGROWTHRATE
##
read -d '' dbGthInsrCmd << EOF
BEGIN
FOR DBHCROW IN (select "Size in GB O/S level" OS, ("Size in GB O/S level"- "Total Free in GB") "DB_SIZE",("Total Free in GB") "DB_FREE",
trunc((("Size in GB O/S level"- "Total Free in GB")/ "Size in GB O/S level")*100,2)||'%' "USED_PERCENT",
trunc(("Total Free in GB"/ "Size in GB O/S level")*100,2)||'%' "FREE_PERCENT"
from
(select
round(( select sum(bytes)/1024/1024/1024 data_size from dba_data_files ) +
( select nvl(sum(bytes),0)/1024/1024/1024 temp_size from dba_temp_files ) +
( select sum(bytes)/1024/1024/1024 redo_size from sys.v_\$log ) +
( select sum(BLOCK_SIZE*FILE_SIZE_BLKS)/1024/1024/1024 controlfile_size from v\$controlfile),2) "Size in GB O/S level",
(select sum(round("Free in MB",2)) from (select tablespace_name ,
sum( bytes /(1024*1024*1024)) "Free in MB" from dba_free_space
group by tablespace_name) ts join (select tablespace_name , sum( bytes/(1024*1024)) "Total in MB"
from dba_data_files group by tablespace_name) using ( tablespace_name)) "Total Free in GB"
from
dual))
LOOP
INSERT INTO DBHCGROWTHRATE VALUES (sysdate, DBHCROW.OS, DBHCROW.DB_SIZE, DBHCROW.DB_FREE,DBHCROW.USED_PERCENT, DBHCROW.FREE_PERCENT);
COMMIT;
END LOOP;
END;
/
EOF
##
## Collect Database Growthrate Sofar
##
read -d '' dbGthAllCmd << EOF
prompt <h4>Database Growthrate Sofar:</h4>
select * from DBHCGROWTHRATE;
EOF
##
## Collect Oracle Basic Audit Info.
##
read -d '' dbAuditCmd << EOF
prompt <h4>Database Audit Info:</h4>
show parameter audit;
EOF
##
## Prepare necessary css for whole document
##
read -d '' styleCmd1 << EOF
prompt <html><head><style type="text/css"> p{margin:auto;} h2{color: #336699; text-align: center; margin-bottom: 10px; font-size:40px; text-decoration: underline;} th{color: #000; background: #cccc99; padding:10px;} h4{font-size: 18px; color:#6697ef; text-decoration: underline; margin: auto; margin-left:5%; margin-top:15px; margin-bottom:5px;} th,td{font-family: monospace; font-size:12px;} hr{border-width:4px; border-bottom-color: #000;} br{ display:none; } table{border-spacing: inherit;border-color: #eee;} table tr:nth-child(odd) td{background:#fcf8e3 } table tr:nth-child(even) td{ background:#f5f5f5 }</style></head><body style=" width:90%; margin: auto;">
EOF
##
## Collect Oracle Instance and Database Info for AWR/ADDM.
##
read -d '' dbInstAwAdCmd << EOF
col dbid new_value V_DBID noprint
select dbid from v\$database;
col instance_number new_value V_INST noprint
select instance_number from v\$instance;
EOF
##
## Collect Snapshot Info for AWR/ADDM.
##
read -d '' dbAwrSnapCmd << EOF
-- Begining Snapshot
col snap_id new_value V_BID
select min(snap_id) snap_id
from dba_hist_snapshot
where end_interval_time >= (sysdate-1)
and startup_time <= begin_interval_time
and dbid = &&V_DBID
and instance_number = &&V_INST;
-- END Snapshot
col snap_id new_value V_EID
select max(snap_id) snap_id
from dba_hist_snapshot
where dbid = &&V_DBID
and instance_number = &&V_INST;
EOF
##
## Generate AWR REPORT.
##
read -d '' dbAwrRptCmd << EOF
select 'BEGIN='||trim(to_char(begin_interval_time, 'HH24:MI')) snap_time
from dba_hist_snapshot
where dbid = &&V_DBID
and instance_number = &&V_INST
and snap_id = &&V_BID ;
select 'END='||trim(to_char(end_interval_time, 'HH24:MI')) snap_time
from dba_hist_snapshot
where dbid = &&V_DBID
and instance_number = &&V_INST
and snap_id = &&V_EID ;
EOF
##
## Functions to spool database metrics based on its status
##
spoolDBFULL(){
${1}/bin/sqlplus -s /nolog << __EOF__ > /dev/null 2>&1
connect / as sysdba
set pagesize 0 feedback off verify off echo off;
--SET MARKUP HTML ON SPOOL ON ENTMAP OFF
--SET MARKUP HTML ON SPOOL OFF ENTMAP OFF
SET MARKUP HTML ON SPOOL OFF PREFORMAT OFF ENTMAP OFF
SPOOL ${2}
$formatCmd
$styleCmd1
$dbhcHeadingCmd
$basicDBinfoCmd
$dbRegistryInfoCmd
$dbSizeInfoCmd
$onlineRedoCmd
$tsDatafileInfoCmd
$controlFileCmd
$systemTsInfoCmd
$tempTsInfoCmd
$usersInfoCmd
$walletInfoCmd
$archiveInfoCmd
$dbProfileInfoCmd
$dataguardInfoCmd
$backupInfoCmd
$logSwitchCmd
$asmDiskInfoCmd
$memoryInfoCmd
$dbGthCreTblCmd
$dbGthInsrCmd
$dbAuditCmd
$dbGthAllCmd
$copyRightCmd
$styleEndCmd
spool off;
__EOF__
}
spoolDBPARTIAL(){
echo "-----------> Database found on Mounted mode only partial statistics are accumulated."
${1}/bin/sqlplus -s /nolog << __EOF__ > /dev/null 2>&1
connect / as sysdba
set pagesize 0 feedback off verify off echo off;
SET MARKUP HTML ON SPOOL OFF PREFORMAT OFF ENTMAP OFF
SPOOL ${2}
$formatCmd
$styleCmd1
$dbhcHeadingCmd
$basicDBinfoCmd
$onlineRedoCmd
$controlFileCmd
$walletInfoCmd
$archiveInfoCmd
$dataguardInfoCmd
$logSwitchCmd
$asmDiskInfoCmd
$memoryInfoCmd
$copyRightCmd
$styleEndCmd
spool off;
__EOF__
}
#spoolDBBASIC(){
#
#}
#spoolAWRADDM(){