Translate

Monday, October 22, 2007

Successful DR/BC/BR using RMAN



CASE STUDIES IN RMAN METRICS
Anthony D Noriega, MSCS, MBA, OCP, BSSE, Independent Oracle Consultant, ADN

ABSTRACT

While RMAN is the most commonly used method of Oracle backup, either standalone or in conjunction with other backup and storage technologies, few studies have been made in relation to backup duration, consistency, and reliability. This study focuses on metrics and statistics in an effort to derive some consensus in relation to factors affecting RMAN backup and restore duration, reliability, and consistency, such as database size, channel speed, device type, database infrastructure and architecture, and various others associated with the concurrency of events. The study expands to standard and point-in-time recovery scenarios, with an outlook in RMAN’s positioning in the database Business Continuity (BC) and Disaster Recovery (DR) markets.

INTRODUCTION

RMAN has proven to be a consistent and resilient database backup and recovery management tool, especially, when properly used. Likewise, companies that have used RMAN from previous releases have learned enough to best utilize it, with or without the recovery catalog. The incremental enhancements provided in Oracle versions 9i and 10g. In general, it is expected that when benchmarking comparable Oracle9i and Oracle10g databases, in terms of table contents and overall density, that Oracle10g RMAN backups and related restores will run faster than Oracle9i, in particular, in 10g features have been enabled with a speed-up seeking goal. Although an actual and native Oracle10g performance improvement holds over Oracle9i releases, the customization of Oracle10g features could further enhance backup and recovery performance and reliability over previous releases.

THE RMAN METRICS PROBLEM DEFINITION

The RMAN metric problem consists of the following considerations:
• Determining the window of time and related duration to perform a backup
• Establishing a window of time and related duration to perform the corresponding restore with all the relevant scenario considerations
• Establishing a cost analysis in relation to the appropriate version for any process, namely, backup, recovery, or cloning.
• Creating a policy framework in order to consistently maintain archived redo log files in backup sets, or available accordingly in the file system. This extremely practical for recovery processes independently from whether backup set or image backups are being used. Neglecting this policy accounts for a large percent of causes for restore failures, backup invalidation, and other related inconsistencies.
• Utilizing available features and capabilities such as Block Change Tracking, control file auto-backup, native backup compression, or point-in-time recovery when appropriate.
• Establishing a historic log in connection with the above policy framework to correlate backup/restore metrics with some factorial considerations such as availability of resources, and other IT configuration management concerns.

EXPERIMENTAL PRODUCTION ENVIRONMENTS

The experimental environments discussed in this study are fundamentally Unix-based environments, yet other environments were partly considered both with recorded information and for qualitative observation in relation to the quantitative analysis involved.

ARCHITECTURE AND INFRASTRUCTURE CONSIDERATIONS

The experiments and studies presented are based on dedicated architectures using Oracle9i and 10g instances with projection factors from 9i over 10g versions time improvements. The main most important factor to be considered is block change tracking, since most performance correlations prevail. Obviously, there is a consideration inherit to Oracle10g, based on its improved performance over previous releases. This is particularly true when using incremental backups.

BACKUP AND RESTORE ISSUES

In general, the time to restore an RMAN backup varies due to various factors, including –but not limited to- device and computing resources availability, and network issues, if applicable. However, statistically the restore time is usually commensurate with the backup time, and usually longer if a backup verification policy is in practice. The RMAN restore time increment is usually from a small percent of the backup time without the recovery catalog and up to nearly doubling of that time when both the recovery catalog and verification process is put in place. However, these statements are all relative under the Oracle10g perspective when using Block Change Tracking, which can significantly minimize this overhead.

RMAN METRICS CASE STUDIES

The cases presented here include general backup with and without a recovery catalog, and a database point-in-time recovery without a catalog, with some general observations on restore cases.

GATHERED DATA, METRICS, AND STATISTICS WITHOUT A RECOVERY CATALOG

The following table summarizes a list of data related to RMAN backup sizes and durations for a set of RMAN backup on different databases without using the recovery catalog (Table 1). This information is reorganized and presented once more on Table 2.

RMAN Backup Size and Duration Statistics

Instance Name Host Name RMAN Backup Size Range Duration Range
Prd1 Host1 4.0GB-7.0GB 2 to 7 minutes
Prd2 Host2 3.5GB-4GB 2 to 4 minutes
Dev1 Host3 1.8GB-2.0GB 2 to 3 minutes
Dev2 Host4 5.0GB-6.0GB 5 to 9 minutes
QA1 Host5 23.0GB-24.0GB 28 to 29 minutes

Table 1. RMAN Backup Duration for Oracle Instances Studied (without a Recovery Catalog)

This information is realigned with further details, as presented in the next table. :

Instance Name Host Name Avg DB Size (GB) Rman Backup
Min Size (GB) Rman Backup
Max Size (GB) Min Duration Max Duration
Prod1 Host1 256 4.0 7.0 2 7
Prod2 Host2 198 3.5 4.0 2 4
Dev1 Host3 128 1.8 2.0 2 3
Dev2 Host4 248 5.0 6.0 5 9
Qa1 Host5 300 23.0 24.0 28 29

Table 2. Enhanced Detail for RMAN Backup Duration for Oracle Instances Studies (without a Recovery Catalog)

The RMAN backup restore time without a recovery catalog is about the same as the backup time itself with a slight percent trend to take longer based on the scenario where the restore takes place. Therefore, in consideration to the size of the backup, the restore table is essentially equivalent to the backup table exhibited, since duration discrepancies are as granular as fractions of a second and only up to a few seconds for this case, in particular.

Instance Name Host Name MinSize (GB) MaxSize (GB) MinTime (m) MaxTime (m)
Prod1 Host1 4.0 7.0 2 7
Prod2 Host2 3.5 4 2 4
Dev1 Host3 1.8 2.0 2 3
Dev2 Host4 5.0 6.0 5 9
Qa1 Host5 23.0 24.0 28 29
Table 3. RMAN Restore Fact Data Table (without a Recovery Catalog)


Exhibit 1. RMAN NOCATALOG Instance-Host vs. Duration Line Chart

GATHERED DATA, METRICS, AND STATISTICS USING THE RECOVERY CATALOG

The following table consolidates observations made on several database instances using the recovery catalog.
RMAN Backup Size and Duration Statistics
Instance Name Host Name Average Database Size Rman Backup
Min Size (GB) Rman Backup
Max Size (GB) Min Duration
(Minutes) Max Duration
(Minutes)
Prd1 Host1 512GB 21 81 55 88
Dv1 Host2 512GB 22 99 65 90
Risk1 Host3 256GB 12 31 45 68
Uat1 Host4 300GB 30 105 45 77
Risk2 Host5 628GB 23.0 121 65 116
Table 4. RMAN Backup Data Summary using the Recovery Catalog

RMAN Backup Size and Duration Statistics with Backup Validation
Instance Name Host Name Average Database Size Rman Backup
Min Size (GB) Rman Backup
Max Size (GB) Min Duration
(Minutes) Max Duration
(Minutes)
Prod1 Host1 512GB 21 81 85 128
Prod2 Host2 512GB 22 99 95 135
Dev1 Host3 256GB 12 31 77 102
Dev2 Host4 300GB 30 105 85 105
Qa1 Host5 628GB 23.0 121 97 159

Table 5. RMAN Backup Data Summary using the Recovery Catalog with Backup Validation

The restore table is nearly comparable to that provided by backup with validation, as follows:
RMAN Restore Statistics Using the Recovery Catalog
Instance Name Host Name Average Database Size Rman Backup Min Size (GB) Rman Backup Max Size (GB) (Minutes)
Min Duration (Minutes)
Max Duration
Prod1 Host1 512GB 21 81 81 115
Prod2 Host2 512GB 22 99 90 121
Dev1 Host3 256GB 12 31 72 89
Dev2 Host4 300GB 30 105 77 95
Qa1 Host5 628GB 23.0 121 89 125
Table 6. RMAN Restore Data Summary using the Recovery Catalog


UNIFIED METRICS ANALYSIS

From the entire set, involving both Catalog-based and Catalog-less observations, it is possible derive the following statistical analytic results using Oracle SQL:

Exhibit 2. Some Regression Information Correlating the Average Database Size and the Maximum Backup Duration.

Exhibit 3. Other Regression Metric Analysis

In addition to the observations made by the SQL regression aggregate functions, it is possible to encounter the following correlation among variable with interactions:
• Minimum Duration and RMAN Backup Maximum Size
• Maximum Duration and RMAN Backup Maximum Size
• Maximum and Minimum Duration
• Catalog Option and Minimum Duration
• Catalog Option and Maximum Duration.

Avg DB Size (GB) RMAN Backup Min Size (GB) RMAN Backup Max Size (GB) Min Duration Max Duration Cat Opt
Avg DB Size (GB) 1
RMAN Backup Min Size (GB) 0.672812809 1
RMAN Backup Max Size (GB) 0.850083343 0.856779215 1
Min Duration 0.856536148 0.834302561 0.910370414 1
Max Duration 0.873295324 0.804858853 0.942746843 0.981002475 1
Cat Opt 0.706810637 0.717007196 0.867454307 0.926638071 0.945848466 1
Table 7. Correlation Table Showing Variable Interaction

ORACLE10g ADJUSTMENTS

The following are estimated and adjusted metrics for the Oracle10g versions of this upgraded databases when Block Change Tracking is used, as follows :
• The number of blocks changed as a percent of the total backup, useful with incremental backup policies.
• The global block density in the database being backed up.
• The nature of the block changes in terms of DML transaction types.

The combined effect of these factors should count as a total discount factor in terms of time, in comparison to a conventional backup not using block change tracking.

SESSION LONG OPERATION IMPACT ANALYSES

Although RMAN backup configuration is flexible to accommodate to most scenarios, it is important to understand which parameters apply. In the cases studied, backing up first to disk was the strategy. In all cases, a copy of the database backup was available on disk, while a compressed tape backup was made of the original backup. No compressed backup sets were sent directly to tape. The duration of the overall process varied based on daily database activity and computing resources allocated to a SAN environment and other storage devices involved.
RMAN long session impact is possibly affected by settings of parameters such as FAST_START_MTTR_TARGET or its omission. Similarly, architectural considerations, namely, the usage of an inadequate sizing of the LARGE_POOL parameter or a shared architecture could lead to unconventional results. In the latter case, a dedicate session needs to be set for RMAN to work properly. Other considerations, relate to Oracle10g capabilities to run partial RMAN backup or use explicit options to either run at full speed or running in a controlled fashion within the window of time. On the other hand, in some scenarios, long waits relate to asynchronous RMAN tasks conveying bottlenecks that need to be carefully identified and fixed.

Exhibit 4. A sample RMAN Configuration Without a Recovery Catalog


Exhibit 5. Monitoring RMAN Long Running Jobs for Corrective Action

Exhibit 6. RMAN NOCATALOG Configuration and Database Incarnations

Exhibit 7. Listing RMAN Backup Sets

Exhibit 8. Listing RMAN Archived Logs in Backup Sets

RMAN NO-CATALOG DATABASE POINT-IN-TIME RECOVERY MODEL METRICS

The RMAN Database Point-in-Time Recovery without using a recovery catalog is a special case of an RMAN restore, where determining the point-of-failure is critical to utilizing any type of metrics whether estimated restore time, required resources, such as disk space, and restore strategy based on components to restore. Therefore, it is critical to determine whether the point-in-time to recover is within the backup or outside the backup to restore. If the point of time is after the entire backup set, the solution is trivial and it consists of restoring the entire backup and then applying the required archived redo logs until the desired point in time to recover. The shell provided in the appendix provides both validation and actual point-in-time recovery for the non-trivial case.

Exhibit 9. RMAN DBPITR Duration and Cost Analysis.

Although the study only contemplated the recovery without a catalog, the decision tree provided in the exhibit above does consistently advise about the appropriate way to account for the duration and related costs of the point-in-time recovery. Furthermore, when the point-in-time to recover is found within the backup file, the reduction in time is proportional to the location within the backup. Therefore, point in time locations with older SCNs or timestamps, will have greater reduction than those closer to the last SCN available in the backup. Besides, the DBPITR is not necessarily constrained by the all conditions applying to TSPITR recovery, such as support of snapshot logs, which is simply relative. Also, no auxiliary database is needed for DBPITR However, there are important considerations to properly backing up the archived redo logs within the backup set and maintaining file system copies to attain the desired level of consistency.

MODEL IMPLICATIONS ON VLDB (PRODUCTION DATABASES)

Based on the consistency provided by the current medium and large database models studied, and due to the difficulties in testing these statistics and metrics on Very Large Databases (VLDBs), it is still possible to suggest that the same type of correlation among variables are valid at large scale. Similarly, VLDBs tend to have many business and operational constraints with usually reduced windows of time for backups, for which other high-availability solutions are mostly used. Nonetheless, for some of the experiments designed in these case studies, somewhat presented in this paper, the Database, System, and SAN Administrators utilized a comparable level of HARD-based high availability environment, where the SAN acted as a Maximum Availability Architecture (MAA) providing both Clusters and Data Guard capabilities, such as graceful switchover, failover, and controlled switchback. The database sizes were in the threshold of large databases, but could not compare to a VLDB range.
Consequently, this study can serve as a scalable benchmark for more comprehensive corporate studies on VLDB, as part of a disaster recovery and efficient business continuity practice.

BUSINESS ANALYSIS CONSIDERATIONS

The elicitation of requirements involving Disaster Recovery (DR) or Business Continuity (BC) practices require explicit information on backup and recovery times, in an effort to allocate windows of time to periodic utility tasks. Similarly, these durations of time can be greatly associated with an IT infrastructure’s ability to respond to any DR scenario. Therefore, educing requirements for windows of time, and estimating backup and restore durations becomes foundational to DR/BC.
Another important aspect of any RMAN business analysis focused on DR or BC practices needs to allocate the technical and human resources to perform a large number of quality assurance (QA) and tuning tasks, beyond any required coding or automation. The QA tasks can involve, but are not limited to, backup validation, backup and restore timeliness, shell scripts reliability and robustness through different platform configurations , scheduling, source saving, documentation, and other relevant tasks.

CONCLUDING REMARKS

The RMAN metrics cases discussed here corroborate a relationship between backup and database sizes and backup duration regardless of the catalog-related considerations. While this statement is nearly trivial to assert, there are many environmental factors that could partially change its validity. The most interested aspect of the variability study contemplates the minimum and maximum backup duration, whose variance point the number of a certain number of infrastructure and scenario-based factors involved. The Analysis of Variance (ANOVA) presented in the Appendix attempts to explain this variability. Likewise, a two-way ANOVA table with repetitions is presented.
Disaster Recovery and Business Continuity Teams need to strategically plan on the implementation of a comprehensive set of factors, bottlenecks, and time and resource constraints that could make the derived statistics and analysis useful in those IT administrative areas. By doing so, it is at least evident that technical stakeholders have congruently worked towards the appropriate preparedness in the event of a disaster, and are working on a daily basis with a robust DR/BC infrastructure.
Finally, the most important concluding remarks are summarized in the following table:

Feature/Issue Benefit

9i to 10g Congruent Metrics Allows for post-upgrade and multi-version DR/BC time allocation.
Configuration Bottlenecks Initialization parameter configuration as part of OFA-driven architecture can be further optimized in 10g in relation to 9i releases. The overall benefits translate into faster performance and throughput.
Planning and Risk Analysis Using historic backup/restore historic data can lead to overcoming unplanned process and limiting the risk involved.
Block Change Tracking Extremely useful with incremental backups, reduces CPU cycles, and enables faster backups and shorter recovery time.
DBPITR A parallel strategy to Flashbackup database. It is supported by RMAN with or without a recovery catalog.
Backup Time vs. Restore/Recovery Time Although backup and restore times tend to be comparable, having gather data and statistics on duration can enhance robustness and preparedness in DR/BC processes.
Table 8. Concluding Remarks
APPENDIX

Instance Name Host Name Avg DB Size (GB) Rman Backup Min Size (GB) Rman Backup Max Size (GB) Min Duration Max Duration 0 = nocat
1 = cat
Cat Opt
Prod1 Host1 256 4 7 2 7 0
Prod2 Host2 198 3.5 4 2 4 0
Dev1 Host3 128 1.8 2 2 3 0
Dev2 Host4 248 5 6 5 9 0
Qa1 Host5 300 23 24 28 29 0
Prd1 Host1 512 21 81 55 88 1
Dv1 Host2 512 22 99 65 90 1
Risk1 Host3 256 12 31 45 68 1
Uat1 Host4 300 30 105 45 77 1
Risk2 Host5 628 23 121 65 116 1
Table 9. Source Data Gathered for Statistical Analysis


Statistics Analytics

Two-way Anova with Repetitions for RMAN NOCATALOG Data

SUMMARY 256 4 7 2 7 Total
Host2
Count 2 2 2 2 2 10
Sum 326 5.3 6 4 7 348.3
Average 163 2.65 3 2 3.5 34.83
Variance 2450 1.445 2 0 0.5 4836.133

Host4
Count 2 2 2 2 2 10
Sum 548 28 30 33 38 677
Average 274 14 15 16.5 19 67.7
Variance 1352 162 162 264.5 200 12063.12

Total
Count 4 4 4 4 4
Sum 874 33.3 36 37 45
Average 218.5 8.325 9 9.25 11.25
Variance 5374.333 97.4225 102.6667 158.25 146.9167


ANOVA
Source of Variation SS df MS F P-value F crit
Sample 5402.185 1 5402.185 11.75808 0.006449 4.964591
Columns 139856.7 4 34964.18 76.10099 1.9E-07 3.47805
Interaction 7642.138 4 1910.535 4.158358 0.030764 3.47805
Within 4594.445 10 459.4445

Total 157495.5 19


Table 10. Two-Way ANOVA

Entire Set Multi-Regression Analysis for both With and Without the Recovery Catalog
(Maximum Duration is the Independent Variable (Regressand)

SUMMARY OUTPUT

Regression Statistics
Multiple R 0.9506126
R Square 0.9036643
Adjusted R Square 0.8458629
Standard Error 16.87026
Observations 9

ANOVA
df SS MS F Significance F
Regression 3 13348.53 4449.509062 15.63394 0.005662277
Residual 5 1423.028 284.605674
Total 8 14771.56

Coefficients Standard Error t Stat P-value Lower 95% Upper 95% Lower 95.0% Upper 95.0%
Intercept -4.9598797 17.78092 -0.278943945 0.791457 -50.66711281 40.74735 -50.6671 40.7473533
256 0.077939 0.068482 1.138093711 0.306659 -0.098099465 0.253977 -0.0981 0.25397749
4 0.0677914 1.087778 0.062320971 0.952722 -2.728425992 2.864009 -2.72843 2.86400873
7 0.589539 0.328242 1.796050497 0.132429 -0.254232257 1.43331 -0.25423 1.4333103




RESIDUAL OUTPUT PROBABILITY OUTPUT

Observation Predicted 7 Residuals Standard Residuals Percentile 7
1 13.067471 -9.06747 -0.679867656 5.555555556 3
2 6.3174165 -3.31742 -0.248735753 16.66666667 4
3 18.245187 -9.24519 -0.693192563 27.77777778 9
4 34.129962 -5.12996 -0.384638181 38.88888889 29
5 84.121175 3.878825 0.290829482 50 68
6 94.800669 -4.80067 -0.359948139 61.11111111 77
7 34.081714 33.91829 2.543150806 72.22222222 88
8 82.357163 -5.35716 -0.401673384 83.33333333 90
9 116.87924 -0.87924 -0.065924613 94.44444444 116



















Exhibit 10. Multiple Regression and ANOVA

ORACLE ANALYTIC STATISTICS

Exhibit 11. Oracle Analytic Statistics


Exhibit 12. Oracle Analytic Statistics

BACKUP LISTING
RMAN> list backup;


List of Backup Sets
===================

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
334 Incr 0 1G DISK 00:00:53 19-NOV-05
BP Key: 334 Status: AVAILABLE Tag: WEEKLY_BACKUP
Piece Name:
/dump1/mgnss/rmanbackup/20051119_0105/ful_alh43ia5_MGNSS
SPFILE Included: Modification time: 03-OCT-05
List of Datafiles in backup set 334
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 0 Incr 51691876 19-NOV-05 /data1/oradata/mgnss/system01.dbf
5 0 Incr 51691876 19-NOV-05 /data1/oradata/mgnss/perfstat01.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
335 Incr 0 2G DISK 00:02:00 19-NOV-05
BP Key: 335 Status: AVAILABLE Tag: WEEKLY_BACKUP
Piece Name:
/dump1/mgnss/rmanbackup/20051119_0105/ful_amh43ia5_MGNSS
List of Datafiles in backup set 335
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
2 0 Incr 51691875 19-NOV-05 /data1/oradata/mgnss/undotbs1.dbf
3 0 Incr 51691875 19-NOV-05 /data1/oradata/mgnss/tools01.dbf
4 0 Incr 51691875 19-NOV-05 /data1/oradata/mgnss/users01.dbf
6 0 Incr 51691875 19-NOV-05 /data1/oradata/mgnss/v7data01.dbf

BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
336 588M DISK 00:00:31 19-NOV-05
BP Key: 336 Status: AVAILABLE Tag: TAG20051119T010713
Piece Name:
/dump1/mgnss/rmanbackup/20051119_0105/arc_anh43ie1_MGNSS

List of Archived Logs in backup set 336
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 8945 50427811 18-NOV-05 50429822 18-NOV-05
1 8946 50429822 18-NOV-05 50429825 18-NOV-05
1 8947 50429825 18-NOV-05 50441825 18-NOV-05
...
...
...

1 9244 51974291 21-NOV-05 51976461 21-NOV-05
1 9245 51976461 21-NOV-05 51976464 21-NOV-05

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
350 Full 3M DISK 00:00:01 21-NOV-05
BP Key: 350 Status: AVAILABLE Tag: TAG20051121T010742
Piece Name:
/dump1/mgnss/rmanbackup/20051121_0105/ctl_b5h48r6u_MGNSS
Controlfile Included: Ckp SCN: 51976475 Ckp time: 21-NOV-05

RMAN>


SAMPLE DATABASE POINT-IN-TIME AND VALIDATION SHELL


#!/usr/bin/ksh
# set -x
## ***********************************************************
## rman sample validat script
## prepared by: Anthony D. Noriega, ADN, Oracle Consultant
## Syntax: r_rval_bkp.ksh $ORACLE_SID $R=1_OR_V=0 $TS $DBID
## Example: r_rval_bkp.ksh devtwbg 1 "'01-JAN-2006 01:01:55'"\
## 1885319376
## After recovery temp tbs file(s) must be added manually
## ***********************************************************
ORACLE_SID=$1
export ORACLE_SID
RMAN=rman
SID=$ORACLE_SID
VALOPT=$2
UNTIL_TS=$3
echo $UNTIL_TS
DBID=$4
echo '#*******************************'
echo '# Values Read: *'
echo '# $SID='$SID
echo '# $DBID='$DBID
echo '# $OPT:[1=R,0=V] => '$VALOPT
echo '# $UNTIL_TS='$UNTIL_TS
echo '# *'
echo '#******************************'
RR='R'
VV='V'
sleep 10
export ORATAB=/var/opt/oracle/oratab
i=`cat $ORATAB|grep -v "^#"|grep $ORACLE_SID`
ORACLE_HOME=`echo $i | cut -d: -f2`;
export ORACLE_HOME
DT=`date '+%Y%m%d_%H%M'`
MoDir=`date +%Y%m`
PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/etc;export PATH
export NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS'
DBADMIN=/opt/oracle/admin
OD=/data1/oradata
LOGDIR=/home/dba/admin/rpt/${RMAN}.${MoDir}
LOG=${LOGDIR}/${RMAN}.rv.${DT}.log
INSTCOUNT=`ps -ef|fgrep $SID|fgrep smon|grep -v grep|wc -l`

if [[ ! -d ${LOGDIR} ]]
then
chown oracle:dba ${LOGDIR}
chmod 755 ${LOGDIR}
echo 'Directory already exists'
else
mkdir -p ${LOGDIR}
chown oracle:dba ${LOGDIR}
chmod 755 ${LOGDIR}
echo 'Validated directory '$LOGDIR
fi
if [[ $VALOPT -eq 1 ]] || [[ $INSTCOUNT -eq 0 ]]
then
$ORACLE_HOME/bin/sqlplus -s '/as sysdba' << EOSQL1 >> $LOG
set echo on
set feedback on
startup nomount force
show sga
exit;
EOSQL1
fi
#(
$ORACLE_HOME/bin/sqlplus -s '/as sysdba' << EOSQL >> $LOG
set heading off
set pagesize 0
set linesize 144
set echo off
set feedback off
alter session set nls_date_format = 'dd-mon-yyyy hh24:mi:ss';
spool /tmp/nretrodays.dat
SELECT LTRIM(RTRIM(TRUNC(SYSDATE-TO_DATE(${UNTIL_TS},'DD-MON-YYYY
HH24:MI:SS'))))
FROM dual;
spool off
spool /tmp/hr.dat
SELECT LTRIM(RTRIM(TO_CHAR(TO_DATE(${UNTIL_TS},'DD-MON-YYYY
HH24:MI:SS'),'HH24')))
FROM dual;
spool off
spool /tmp/mn.dat
SELECT LTRIM(RTRIM(TO_CHAR(TO_DATE(${UNTIL_TS},'DD-MON-YYYY
HH24:MI:SS'),'MI')))
FROM dual;
spool off
spool /tmp/sc.dat
SELECT LTRIM(RTRIM(TO_CHAR(TO_DATE($UNTIL_TS,'DD-MON-YYYY
HH24:MI:SS'),'SS')))
FROM dual;
spool off
spool /tmp/dbstatus.dat
SELECT LTRIM(RTRIM(status))
FROM v\$instance;
spool off
exit;
EOSQL
#) | tee -a $LOG
NRETRODAYS=`cat /tmp/nretrodays.dat`
HR=`cat /tmp/hr.dat`
MN=`cat /tmp/mn.dat`
SC=`cat /tmp/sc.dat`
DBST=`cat /tmp/dbstatus.dat`
#
#rm -f /tmp/*.dat
#
if [[ $VALOPT -eq 1 ]]
then
echo '#####'
echo '#############################################' >> $LOG
echo '# Using '${NLS_DATE_FORMAT}' as date format #' >> $LOG
echo '# Validating recovery started at '`date`' #' >> $LOG
echo '#############################################' >> $LOG
echo '#####'
#
#
#(
rman nocatalog << EORMAN >> $LOG
connect target /
allocate channel for maintenance device type disk;
set dbid=$DBID;
restore spfile.ora to '$DBADMIN/$SID/pfile/spfile$SID.ora' from
autobackup;
release channel;
startup force nomount;
run
{
restore controlfile to '/tmp/control01.dbf' from autobackup maxseq 120;
restore controlfile from '/tmp/control01.dbf';
}
run
{
alter database mount;
show all;
}
run
{
set until
time="trunc(sysdate,'dd')-$NRETRODAYS+$HR/24+$MN/1440+$SC/86400";
restore database until
time="trunc(sysdate,'dd')-$NRETRODAYS+$HR/24+$MN/1440+$SC/86400";
set until
time="trunc(sysdate,'dd')-$NRETRODAYS+$HR/24+$MN/1440+$SC/86400";
restore archivelog from time= "trunc(sysdate,'dd')-$NRETRODAYS" until
time= "trunc(sysdate,'dd')-$NRETRODAYS+$HR/24+$MN/1440+$SC/86400";
}
run
{
allocate channel dc1 device type disk;
set until
time="trunc(sysdate,'dd')-$NRETRODAYS+$HR/24+$MN/1440+$SC/86400";
recover database until
time="trunc(sysdate,'dd')-$NRETRODAYS+$HR/24+$MN/1440+$SC/86400";
release channel dc1;
}
run
{
sql "alter database open resetlogs";
}
exit;
EORMAN
#) | tee -a $LOG
else
#(
rman nocatalog << EORMANV >> $LOG
connect target /
allocate channel for maintenance device type disk;
set dbid=$DBID;
restore spfile.ora to '$DBADMIN/$SID/pfile/spfile$SID.ora' from
autobackup;
release channel;
startup force nomount;
run
{
restore controlfile to '/tmp/control01.dbf' from autobackup validate;
restore controlfile from '/tmp/control01.dbf' validate;
}
run
{
alter database mount;
show all;
}
run
{
set until time =
"trunc(sysdate,'dd')-$NRETRODAYS+$HR/24+$MN/1440+$SC/86400";
crosscheck backupset of controlfile;
alter database mount ;
crosscheck backupset of database;
crosscheck backupset of archivelog all;
crosscheck archivelog all;
}
run
{
set until time =
"trunc(sysdate,'dd')-$NRETRODAYS+$HR/24+$MN/1440+$SC/86400";
restore controlfile to 'xx' until time="trunc(sysdate,'dd')-$NRETRODAYS
+ $HR/24 + $MN/1440 + $SC/86400" validate;
restore database until time="trunc(sysdate,'dd')-$NRETRODAYS + $HR/24 +
$MN/1440 + $SC/86400" validate;
restore archivelog time between "trunc(SYSDATE-$NRETRODAYS,'dd')" and
"trunc(SYSDATE-$NRETRODAYS,'dd') + $HR/24+$MN/1440 + $SC/86400"
validate;
}
exit;
EORMANV
#) | tee $LOG
fi
mailx -s 'RMAN restore validated for '$SID anthonydnoriega1@yahoo.com \
anthonydnoriega@msn.com < $LOG
cat $LOG
EOF



*********************************************************************************************************
For the reader interested in obtaining a pdf version of my paper, please send me email at:
anthonydnoriega@gmail.com or retrieve it from the ioug.org Collaborate07 proceedings knowledgebase.
**********************************************************************************************************

Friday, October 19, 2007

Brainstorming Performing Tuning over Life Memories

About Personal Memoirs and Technical Literature

One of the most influential men in my life was an old language professor by the name of Alberto Assa of Turkish origin with a strong European education, mostly German, who had become a cultural celebrity in my city of origin, Barranquilla, and whom I met when he was already a septuagenarian. Having become my first German teacher, he named me his personal Teaching Assistant, just after my first year of commitment to the German class. While we shared the same passion for French literature and for playing the violin, at just 14 years old, I was wondering why he would still thought I would look like an “alemanote with square head”. This means “a big German with a square head” in broken Spanish, a common way to refer to a typical German which fell far from appropriate for a young Latin American man born in a rather dysfunctional family. Significantly enough for me, he frequently related a German proverb to me when translating “Das Geld is nicht immer so wichting”, which literally means “Money is not always so important”. This German proverb probably has as much value for Germans as the American proverb from Franklin’s “wake up early to be healthy, wealthy, and wise.” While most of the people I met during my adolescence consistently built my sentimental education, I learned other important aspects of my way to look at the world myself, without relevance to any of my admirable professors. I learned the lesson of how difficult it is to write for an audience when I published a short story dedicated to him and entitled “Existence”, which lead to my dismissal from his language school. Although I could never understand why, I believe that expressing thoughts clearly through different cultures in a global world is further more difficult that having sound too strong with a child’s story at 14. So every time I write, I tried not to be offensive to anyway in any manner. I had learned my lesson and fourteen, and delayed my learning of German, and went my path to different language schools and lost a valuable relationship at that time.

Before, I graduated from the school of engineering a University of the North, an IBM-driven university, I had attained two diplomas from University of Paris-Sorbonne (Paris IV), including my French Literature diploma, which could have been outstanding one but was rather a passing grade, a critical recall of how public transportation can affect life in a South American country.

One day, while I strolled the beautiful colonial streets of Bogotá and while working for Apple Computer, I remembered my own story and felt very strong about how I was able to handle my dilemma and my career path. Indeed, I had worked hard in the engineering school and had dropped out in my parallel and nightly studies in law and political science. In Bogotá, I had applied to attain a Master’s in Statistics at the University of La Salle, but I never started it, and decided to complete my immigration visa to come to the United States.

Today, once more as I try to write a technical paper, I hit the unromantic fact that one needs a pure thought to get something moving forward in the appropriate direction.

When retrieving statistics and reporting metrics in an aggregate fashion, I was remember my early experience in how to express my thoughts, such that it drives the message without motivating any controversy at all. Reporting performance and analyzing statistics may be as complex as my early literary writing experience, and further interpreting some metrics, which may not be accompanied with a hint or interpretational message could lead to various viewpoints among DBAs.


Regarding technical writing, in the past year, I reviewed a couple of dozen books about Oracle literature, all of which seem to have an exquisite flavor for quality, content, and value derived from the knowledge transmitted. Some of the performance tuning books that have been printed are essentially pretty good, in particular, the Rich Niemic’s book deserves a particular attention for the good content and organizational perspective. Essentially, the Oracle literature, in particular, the pure literature on the Oracle10g product line is quite outstanding both technically speaking and from the literary viewpoint. Some of the books that intended to combine Oracle8i, Oracle9i, and Oracle10g literature have already been removed from the shelf, since for the most part they had unintentionally created a great amount of confusion, and a few had visible inconsistencies. Furthermore, the book diversification to include other Oracle products such as the Application Server, Development tools, and Collaboration Suite, among others is increasingly outstanding.

Incidentally, I stopped playing the violin when I was about 18, yet I still write technical, fiction, and business literature as well. About Personal Memoirs and Technical Literature

One of the most influential men in my life was an old language professor by the name of Alberto Assa of Turkish origin with a strong European education, mostly German, who had become a cultural celebrity in my city of origin, Barranquilla, and whom I met when he was already a septuagenarian. Having become my first German teacher, he named me his personal Teaching Assistant, just after my first year of commitment to the German class. While we shared the same passion for French literature and for playing the violin, at just 14 years old, I was wondering why he would still thought I would look like an “alemanote with square head”. This means “a big German with a square head” in broken Spanish, a common way to refer to a typical German which fell far from appropriate for a young Latin American man born in a rather dysfunctional family. Significantly enough for me, he frequently related a German proverb to me when translating “Das Geld is nicht immer so wichting”, which literally means “Money is not always so important”. This German proverb probably has as much value for Germans as the American proverb from Franklin’s “wake up early to be healthy, wealthy, and wise.” While most of the people I met during my adolescence consistently built my sentimental education, I learned other important aspects of my way to look at the world myself, without relevance to any of my admirable professors. I learned the lesson of how difficult it is to write for an audience when I published a short story dedicated to him and entitled “Existence”, which lead to my dismissal from his language school. Although I could never understand why, I believe that expressing thoughts clearly through different cultures in a global world is further more difficult that having sound too strong with a child’s story at 14. So every time I write, I tried not to be offensive to anyway in any manner. I had learned my lesson and fourteen, and delayed my learning of German, and went my path to different language schools and lost a valuable relationship at that time.

Before, I graduated from the school of engineering a University of the North, an IBM-driven university, I had attained two diplomas from University of Paris-Sorbonne (Paris IV), including my French Literature diploma, which could have been outstanding one but was rather a passing grade, a critical recall of how public transportation can affect life in a South American country.

One day, while I strolled the beautiful colonial streets of Bogotá and while working for Apple Computer, I remembered my own story and felt very strong about how I was able to handle my dilemma and my career path. Indeed, I had worked hard in the engineering school and had dropped out in my parallel and nightly studies in law and political science. In Bogotá, I had applied to attain a Master’s in Statistics at the University of La Salle, but I never started it, and decided to complete my immigration visa to come to the United States.

Today, once more as I try to write a technical paper, I hit the unromantic fact that one needs a pure thought to get something moving forward in the appropriate direction.

When retrieving statistics and reporting metrics in an aggregate fashion, I was remember my early experience in how to express my thoughts, such that it drives the message without motivating any controversy at all. Reporting performance and analyzing statistics may be as complex as my early literary writing experience, and further interpreting some metrics, which may not be accompanied with a hint or interpretational message could lead to various viewpoints among DBAs.


Regarding technical writing, in the past year, I reviewed a couple of dozen books about Oracle literature, all of which seem to have an exquisite flavor for quality, content, and value derived from the knowledge transmitted. Some of the performance tuning books that have been printed are essentially pretty good, in particular, the Rich Niemic’s book deserves a particular attention for the good content and organizational perspective. Essentially, the Oracle literature, in particular, the pure literature on the Oracle10g product line is quite outstanding both technically speaking and from the literary viewpoint. Some of the books that intended to combine Oracle8i, Oracle9i, and Oracle10g literature have already been removed from the shelf, since for the most part they had unintentionally created a great amount of confusion, and a few had visible inconsistencies. Furthermore, the book diversification to include other Oracle products such as the Application Server, Development tools, and Collaboration Suite, among others is increasingly outstanding.

Incidentally, I stopped playing the violin when I was about 18, yet I still write technical, fiction, and business literature as well.

Saturday, October 13, 2007

On Virtualization Technologies

Exhibit 1. Typical ROI Model (Source: Sun Virtualization Seminar)

Exhibit 2. Sun's Virtuozzo Infrastructure Model (Source: Sun's Virtualization Seminar)

Enhancing Virtualization to Consolidate and Reach Performance Optimization

A few months ago, prior to my presentation on grid computing at IOUG, I accepted an invitation from Sun Microsystems to attend their virtualization strategy seminar based on Virtuozzo, which had a dinner setting in the Bergen County. I learned about Virtuozzo, Sun strategic virtual technology, which uses Private Virtual Servers (PVPSs) from the physical server hardware. And I also expanded my knowledge on other software such as VMWare on competing platforms, namely, Linux and Windows. I also got further input about Xen standards. I had previously attending virtualization web seminars with Oracle (VPD and grid computing virtualization concepts) and Microsoft with Microsoft Virtual Server 2003. I had also worked with IBM LPARs with multi-level multi-tier fault-tolerance infrastructure.

Likewise, I had also being a practitioner of Virtual Network Computing using VNC Server/Client while teaching custom personalized Linux classes at Montclair State University, while a GA at the MBA MIS Lab, which I had previously used in several instance to control processes remotely with a higher level of security as a production DBA.

A few days ago, I received an email inviting me to entice others reading a virtual hosting, suggesting that it might be of interest to others. The email follows:



Rich McIver
to me

More options
Oct 8 (5 days ago)

Hi Anthony,

We recently published "25 Tools to Compile an In-Depth Dossier on a Competitors' Site " ( http://www.virtualhosting.com/blog/2007/webmaster-intel-basics-25-tools-to-compile-an-in-depth-dossier-on-a-competitors-site/). I figured I'd bring it to your attention in case you think your readers would find it useful.

Either way, keep up the great blogging!

Cheers,
Rich McIver


Virtual hosting is certainly an important strategy when it comes to achieving compliance and enhancing security and privacy. It is has an enormous impact on website performance and the image projected by a company from the cyberspace point of view, which could be applied as a marketing indicator for company positioning purposes.

Besides, I have also tested virtual servers with the Oracle10g Application Server, through which Oracle provides both IP and port mapping accordingly with full support of their Fusion middleware.

Indeed, in grid computing technology, virtualization generically brings a new layer of security, abstraction, and encapsulation from the database perspective, where resource pooling and automation can bring business and technology integration and consolidation. This virtualization tier is to be controlled optimally with Oracle Enterprise Manager Grid Control.

Since virtualization overall is key to grid computing infrastructure and business strategy it is highly relevant to include in this performance tuning blog. Furthermore, Oracle’s virtualization strategy is based on its grid computing infrastructure and its comprehensive fusion middleware. It is also a cost-effective strategy in larger scale in particular at a time when commodity operating systems (COS) are not meeting today’s data center requirements due to factors such as unplanned application and database growth.

While researching once more about virtualization technologies, I hit some interesting links like the following:

http://fedoranews.org/cms/node/325
http://www.howtoforge.com/perfect_xen_setup_debian_ubuntu
http://www.xensource.com/products/Pages/myproducts.aspx


Optimized for Apple Safari

Wednesday, October 10, 2007

Pro-active Statistics Maintenance using PL/SQL

Customizing DBMS_STATS to Fix Stale Statistics

When a database is indicating a certain level of stale statistics that the DBA might have encountered when running logical backups, it is important to ensure that an operating procedure is put in place to achieve congruency and maintain a pattern of performance tuning, which is reasonably good to support a production environment.

Typically, stale statistics could remain undetected in a production environment when many processes are automated, and this can take place in spite of the usage of pro-active database administration in Oracle10g and in the recently release Oracle11g. Since the policy framework is not necessarily focused on detecting these stale statistics pro-actively, and in most cases no specific policies are established, it is important to customize available tools and PL/SQL API, such as DBMS_STATS to monitor and fix those performance threatening statistics.

Indeed, as an Oracle DBA and Consultant, I have presented several approaches to deal with stale statistics and other related performance issues, which have been resolved with the usage of tools or packages such as STATSPACK and DBMS_STATS. The following sample code can be used to fix stale statistics and in general to gather statistics consistently in general.

If you would like to test my code, you many need to explicitly grant the SELECT_CATALOG_ROLE and specific system object privileges for the SYS objects used in the package to the package owner that you use, e.g., PERFSTAT.

Once the package is compiled, you can be tested through its main entry point, at the bottom of the package body, in many different ways. For instance:

SQL> BEGIN

2 pkg_maintain_stats.std_fix_db_stats();

3 EXCEPTION

4 WHEN OTHERS THEN null;

5 END;

6 /

PL/SQL procedure successfully completed.

This is the PKG_MAINTAIN_STATS package code:

CREATE OR REPLACE PACKAGE PKG_MAINTAIN_STATS IS

-- Written by Anthony D. Noriega, OCP-DBA
-- Date: 12/21/2005
-- Updated 01/04/2006
-- Last Updated 01/11/2006
-- Last Tested: 01/18/2006

FUNCTION funTableExists(
ipTabName IN dba_tables.table_name%TYPE,
ipTabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT'
) RETURN BOOLEAN;

FUNCTION funGetTbs(ipSchema IN dba_users.username%TYPE) RETURN
dba_users.default_tablespace%TYPE;

FUNCTION funColIsIndexed(
ipSchema IN dba_tables.owner%TYPE,
ipTabName IN dba_tables.table_name%TYPE,
ipIndName IN dba_ind_columns.index_name%TYPE,
ipColName IN dba_ind_columns.column_name%TYPE
) RETURN BOOLEAN;

FUNCTION funAvgSchColLength(ipSchema IN dba_tables.owner%TYPE) RETURN NUMBER;

FUNCTION funAvgTabColLength(
ipSchema IN dba_tables.owner%TYPE,
ipTableName IN dba_tables.table_name%TYPE
) RETURN NUMBER;

FUNCTION funAvgIndColLength(
ipSchema IN dba_tables.owner%TYPE,
ipTableName IN dba_tables.table_name%TYPE
) RETURN NUMBER;

FUNCTION funGenSizeOpt(
ipOpt IN VARCHAR2 DEFAULT 'T',
ipChoice IN VARCHAR2 DEFAULT 'C',
ipSize IN INTEGER DEFAULT 100
) RETURN VARCHAR2;

FUNCTION funGetColSize(
ipSchema IN dba_tables.owner%TYPE,
ipTableName IN dba_tables.table_name%TYPE,
ipColumnName IN dba_tab_columns.column_name%TYPE
) RETURN dba_tab_columns.data_length%TYPE;

PROCEDURE grant_obj_priv(
ipGrantPrivs IN VARCHAR2,
ipGrantor IN dba_objects.owner%TYPE,
ipObject IN dba_objects.object_name%TYPE,
ipGrantee IN dba_objects.owner%TYPE
);
PROCEDURE grant_sys_priv(
ipSysPrivs IN VARCHAR2,
ipGrantee IN dba_objects.owner%TYPE
);

PROCEDURE revoke_sys_priv(
ipSysPrivs IN VARCHAR2,
ipGrantee IN dba_objects.owner%TYPE
);

PROCEDURE pop_grant_Revoke_plstabInit(
ipOpt IN VARCHAR2 DEFAULT 'G',
ipStabOwner IN dba_tables.owner%TYPE,
ipSchema IN dba_tables.owner%TYPE,
ipTabObj IN dba_objects.object_name%TYPE,
ipGrantee IN dba_tables.owner%TYPE DEFAULT 'PUBLIC'
);

PROCEDURE popStatTab(
ipSchema IN dba_tables.owner%TYPE,
ipStabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT',
ipTabName IN dba_tables.table_name%TYPE
);

PROCEDURE create_stat_table(
ipSchema IN dba_tables.owner%TYPE,
ipStabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT',
ipTbs IN dba_tables.tablespace_name%TYPE DEFAULT 'PERFSTAT'
) ;

PROCEDURE export_schema_stats(
ipStabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT',
ipSchema IN dba_tables.owner%TYPE
);
PROCEDURE purge_older_stats (
ipStabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT',
ipSchema IN dba_tables.owner%TYPE,
ipRetroDays IN NUMBER DEFAULT 1
);

PROCEDURE fix_schema_stats(
ipSchema IN dba_tables.owner%TYPE,
ipOpt IN VARCHAR2 DEFAULT 'T',
ipChoice IN VARCHAR2 DEFAULT 'C',
ipEstPct IN NUMBER DEFAULT 100
);

PROCEDURE std_fix_db_stats(
ipOpt IN VARCHAR2 DEFAULT 'T',
ipChoice IN VARCHAR2 DEFAULT 'C',
ipEstPct IN NUMBER DEFAULT 100,
ipStatsHistoryFlag IN BOOLEAN DEFAULT TRUE
);
END PKG_MAINTAIN_STATS;
/
CREATE OR REPLACE PACKAGE BODY PKG_MAINTAIN_STATS IS
FUNCTION funTableExists(
ipTabName IN dba_tables.table_name%TYPE,
ipTabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT'
) RETURN BOOLEAN IS
l_tab_name dba_tables.table_name%TYPE;
BEGIN
SELECT table_name
INTO l_tab_name
FROM dba_tables
WHERE table_name = ipTabName
AND owner = ipTabOwner;
RETURN TRUE;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN FALSE;
END;

FUNCTION funGetTbs(ipSchema IN dba_users.username%TYPE) RETURN
dba_users.default_tablespace%TYPE IS
l_tbs dba_users.default_tablespace%TYPE;
BEGIN
SELECT default_tablespace
INTO l_tbs
FROM dba_users
WHERE username = ipSchema;
RETURN l_tbs;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;

FUNCTION funColIsIndexed(
ipSchema IN dba_tables.owner%TYPE,
ipTabName IN dba_tables.table_name%TYPE,
ipIndName IN dba_ind_columns.index_name%TYPE,
ipColName IN dba_ind_columns.column_name%TYPE
) RETURN BOOLEAN IS
lv_ind_col_count INTEGER;
BEGIN
SELECT count(*)
INTO lv_ind_col_count
FROM dba_ind_columns
WHERE index_owner = ipSchema
AND table_name = ipTabName
AND index_name = ipIndName
AND column_name = ipColName;
IF lv_ind_col_count > 0 THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;

FUNCTION funAvgSchColLength(ipSchema IN dba_tables.owner%TYPE) RETURN NUMBER IS
lv_avg_sch_length NUMBER;
BEGIN
SELECT AVG(data_length)
INTO lv_avg_sch_length
FROM dba_tab_columns
WHERE owner = ipSchema;
RETURN lv_avg_sch_length;
EXCEPTION
WHEN OTHERS THEN RETURN 100;
END;

FUNCTION funAvgTabColLength(
ipSchema IN dba_tables.owner%TYPE,
ipTableName IN dba_tables.table_name%TYPE
) RETURN NUMBER IS
lv_avg_tab_length NUMBER;
BEGIN
SELECT AVG(data_length)
INTO lv_avg_tab_length
FROM dba_tab_columns
WHERE owner = ipSchema
AND table_name = ipTableName;
RETURN lv_avg_tab_length;
EXCEPTION
WHEN OTHERS THEN RETURN 65;
END;

FUNCTION funAvgIndColLength(
ipSchema IN dba_tables.owner%TYPE,
ipTableName IN dba_tables.table_name%TYPE
) RETURN NUMBER IS
lv_avg_ind_length NUMBER;
BEGIN
SELECT AVG(column_length)
INTO lv_avg_ind_length
FROM dba_ind_columns
WHERE index_owner = ipSchema
AND table_name = ipTableName;
RETURN lv_avg_ind_length;
EXCEPTION
WHEN OTHERS THEN RETURN 100;
END;

FUNCTION funGenSizeOpt(
ipOpt IN VARCHAR2 DEFAULT 'T',
ipChoice IN VARCHAR2 DEFAULT 'C',
ipSize IN INTEGER DEFAULT 100
) RETURN VARCHAR2 IS
BEGIN
IF ipOpt = 'I' THEN
CASE
WHEN ipChoice = 'C' THEN
RETURN 'FOR ALL INDEXED COLUMNS SIZE '||TO_CHAR(ipSize);
WHEN ipChoice = 'A' THEN
RETURN 'FOR ALL INDEXED COLUMNS SIZE AUTO';
WHEN ipChoice = 'R' THEN
RETURN 'FOR ALL INDEXED COLUMNS SIZE REPEAT';
WHEN ipChoice = 'S' THEN
RETURN 'FOR ALL INDEXED COLUMNS SIZE SKEWONLY';
ELSE RETURN 'FOR ALL INDEXED COLUMNS SIZE 100';
END CASE;
ELSIF ipOpt IN ('S','T') THEN
CASE
WHEN ipChoice = 'C' THEN
RETURN 'FOR ALL COLUMNS SIZE '||TO_CHAR(ipSize);
WHEN ipChoice = 'A' THEN
RETURN 'FOR ALL COLUMNS SIZE AUTO';
WHEN ipChoice = 'R' THEN
RETURN 'FOR ALL COLUMNS SIZE REPEAT';
WHEN ipChoice = 'S' THEN
RETURN 'FOR ALL COLUMNS SIZE SKEWONLY';
ELSE RETURN 'FOR ALL COLUMNS SIZE 100';
END CASE;
ELSE RETURN 'FOR ALL COLUMNS SIZE 100';
END IF;
EXCEPTION WHEN OTHERS THEN
RETURN NULL;
END;


FUNCTION funGetColSize(
ipSchema IN dba_tables.owner%TYPE,
ipTableName IN dba_tables.table_name%TYPE,
ipColumnName IN dba_tab_columns.column_name%TYPE
) RETURN dba_tab_columns.data_length%TYPE IS
lv_csize dba_tab_columns.data_length%TYPE;
BEGIN
SELECT data_length
INTO lv_csize
FROM dba_tab_columns
WHERE owner = ipSchema
AND table_name = ipTableName
AND column_name = ipColumnName;
RETURN lv_csize;
EXCEPTION
WHEN OTHERS THEN
RETURN null;
END;
PROCEDURE grant_obj_priv(
ipGrantPrivs IN VARCHAR2,
ipGrantor IN dba_objects.owner%TYPE,
ipObject IN dba_objects.object_name%TYPE,
ipGrantee IN dba_objects.owner%TYPE
) IS
BEGIN
EXECUTE IMMEDIATE 'GRANT '||ipGrantPrivs||' ON '||ipGrantor||'.'||ipObject||' TO '||ipGrantee;
EXCEPTION
WHEN OTHERS THEN null;
END;

PROCEDURE grant_sys_priv(
ipSysPrivs IN VARCHAR2,
ipGrantee IN dba_objects.owner%TYPE
) IS
BEGIN
EXECUTE IMMEDIATE 'GRANT '||ipSysPrivs||' TO '||ipGrantee;
EXCEPTION
WHEN OTHERS THEN null;
END;

PROCEDURE revoke_sys_priv(
ipSysPrivs IN VARCHAR2,
ipGrantee IN dba_objects.owner%TYPE
) IS
BEGIN
EXECUTE IMMEDIATE 'REVOKE '||ipSysPrivs||' FROM '||ipGrantee;
EXCEPTION
WHEN OTHERS THEN null;
END;

PROCEDURE pop_grant_Revoke_plstabInit(
ipOpt IN VARCHAR2 DEFAULT 'G',
ipStabOwner IN dba_tables.owner%TYPE,
ipSchema IN dba_tables.owner%TYPE,
ipTabObj IN dba_objects.object_name%TYPE,
ipGrantee IN dba_tables.owner%TYPE DEFAULT 'PUBLIC'
) IS

TYPE g_SysPrivs_t IS TABLE OF dba_sys_privs.privilege%TYPE;
TYPE g_ObjPrivs_t IS TABLE OF dba_tab_privs.privilege%TYPE;
gTabSysPrivs g_SysPrivs_t;
gTabObjPrivs g_ObjPrivs_t ;

BEGIN

gtabSysPrivs(1) := 'ANALYZE ANY';
gtabSysPrivs(2) := 'SELECT_CATALOG_ROLE';
gtabSysPrivs(3) := 'SELECT ANY DICTIONARY';
gtabObjPrivs(1) := 'SELECT';
gtabObjPrivs(2) := 'INSERT';
gtabObjPrivs(3) := 'UPDATE';
gtabObjPrivs(4) := 'DELETE';

IF ipOpt = 'G' THEN
FOR i IN gTabObjPrivs.FIRST..gTabObjPrivs.LAST LOOP
grant_obj_priv(
ipGrantPrivs => gtabObjPrivs(i),
ipGrantor => ipStabOwner,
ipObject => ipTabObj,
ipGrantee => ipGrantee
);
grant_obj_priv(
ipGrantPrivs => gtabObjPrivs(i),
ipGrantor => ipSchema,
ipObject => ipTabObj,
ipGrantee => ipGrantee
);
END LOOP;
ELSE
IF ( ipGrantee NOT IN ('SYS','SYSTEM','PERFSTAT') ) THEN
FOR i IN gTabSysPrivs.FIRST..gTabSysPrivs.LAST LOOP
revoke_sys_priv(
ipSysPrivs => gtabSysPrivs(i),
ipGrantee => ipGrantee
);
END LOOP;
END IF;
END IF;

EXCEPTION
WHEN OTHERS THEN
null;
END;

PROCEDURE popStatTab(
ipSchema IN dba_tables.owner%TYPE,
ipStabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT',
ipTabName IN dba_tables.table_name%TYPE
) IS

PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
EXECUTE IMMEDIATE 'TRUNCATE TABLE '||ipStabOwner||'.'||ipTabName||' DROP STORAGE';
EXECUTE IMMEDIATE 'INSERT INTO '||ipStabOwner||'.'||ipTabName||' SELECT * FROM '||ipSchema||'.'||ipTabName;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('Could not replicate statistics to '||ipStabOwner);
END;

PROCEDURE create_stat_table(
ipSchema IN dba_tables.owner%TYPE,
ipStabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT',
ipTbs IN dba_tables.tablespace_name%TYPE DEFAULT 'PERFSTAT'
) IS
l_stat_tab dba_tables.table_name%TYPE;
BEGIN
l_stat_tab := 'STATS$'||SUBSTR(ipSchema,1,17)||'_'||TO_CHAR(SYSDATE,'YYYYMMDD');
DBMS_STATS.create_stat_table(
ownname => ipSchema,
stattab => l_stat_tab,
tblspace => funGetTbs(ipSchema)
);
DBMS_STATS.create_stat_table(
ownname => ipStabOwner,
stattab => l_stat_tab,
tblspace => NVL(ipTbs,funGetTbs(ipStabOwner))
);

pop_grant_Revoke_plstabInit(
ipOpt => 'G',
ipStabOwner => ipStabOwner,
ipSchema => ipSchema,
ipTabObj => l_stat_tab,
ipGrantee => 'PUBLIC'
);

EXCEPTION
WHEN OTHERS THEN
null;
END;

PROCEDURE export_schema_stats(
ipStabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT',
ipSchema IN dba_tables.owner%TYPE
) IS
l_stat_tab dba_tables.table_name%TYPE;
BEGIN
l_stat_tab := 'STATS$'||SUBSTR(ipSchema,1,17)||'_'||TO_CHAR(SYSDATE,'YYYYMMDD');
dbms_stats.export_schema_stats(
ownname => ipSchema,
stattab => l_stat_tab
);
IF (
(ipSchema <> ipStabOwner)
AND
(ipSchema <> 'PERFSTAT')
) THEN
IF funTableExists(l_stat_tab,ipStabOwner) THEN
popStatTab( ipSchema => ipSchema,
ipStabOwner => NVL(ipStabOwner,'PERFSTAT'),
ipTabName => l_stat_tab
);
ELSE
EXECUTE IMMEDIATE 'create table '||ipStabOwner||'.'||l_stat_tab||' as select * from '||ipSchema||'.'||l_stat_tab;
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN null;
DBMS_OUTPUT.put_line('Could not export statistics for schema '||ipSchema);
DBMS_OUTPUT.put_line(SQLERRM);
end;

PROCEDURE purge_older_stats (
ipStabOwner IN dba_tables.owner%TYPE DEFAULT 'PERFSTAT',
ipSchema IN dba_tables.owner%TYPE,
ipRetroDays IN NUMBER DEFAULT 1
) IS

CURSOR purgeCur(
cvStabOwner dba_tables.owner%TYPE,
cvSchema dba_tables.owner%TYPE,
cvRetroDays NUMBER
)
IS
SELECT table_name
FROM dba_tables
WHERE owner = cvStabOwner
AND ( table_name LIKE '%'||
DECODE(
TO_CHAR(SYSDATE,'DD'),'01',
DECODE(TO_CHAR(SYSDATE,'MM'),'01',
TO_CHAR(
TO_NUMBER(
TO_CHAR(SYSDATE,'YYYY')
)-1
)||'12',
TO_CHAR(SYSDATE,'YYYYMMDD')
),
TO_CHAR(SYSDATE,'YYYYMM')
)||'%'
AND
table_name LIKE 'STATS$%'||cvSchema||'%'
)
AND
table_name IN
(
SELECT object_name
FROM dba_objects
WHERE created > trunc(sysdate,'mm')
AND created < sysdate - cvRetroDays
);

l_stat_tab dba_tables.table_name%TYPE;

BEGIN

FOR purgeRec IN purgeCur(ipStabOwner,ipSchema,ipRetroDays) LOOP
BEGIN
DBMS_STATS.DROP_STAT_TABLE(
ownName => ipStabOwner,
statTab => purgeRec.table_name
);
DBMS_STATS.DROP_STAT_TABLE(
ownName => ipSchema,
statTab => purgeRec.table_name
);
EXCEPTION
WHEN OTHERS THEN null;
END;
END LOOP;
END;

PROCEDURE fix_schema_stats(
ipSchema IN dba_tables.owner%TYPE,
ipOpt IN VARCHAR2 DEFAULT 'T',
ipChoice IN VARCHAR2 DEFAULT 'C',
ipEstPct IN NUMBER DEFAULT 100
) IS
cursor psTabCur(
cv_tab_owner dba_tables.owner%TYPE
) IS
SELECT '"'||table_name||'"' table_name
FROM dba_tables
WHERE owner = cv_tab_owner
UNION
SELECT '"'||cluster_name||'"'
FROM dba_clusters
WHERE owner = cv_tab_owner;

cursor tabIndCur(
cv_tab_owner dba_tables.owner%TYPE,
cv_tab_name dba_tables.table_name%TYPE
) IS
SELECT DISTINCT index_owner,
index_name
FROM dba_ind_columns
WHERE table_name = LTRIM(RTRIM(cv_tab_name,'"'),'"')
AND table_owner = cv_tab_owner
ORDER BY 1;

lv_csize NUMBER;

lv_first_pass BOOLEAN := TRUE;

BEGIN

FOR psTabRec IN psTabCur(ipSchema) LOOP

BEGIN

CASE

WHEN ipOpt = 'I' THEN

lv_csize := funAvgIndColLength(ipSchema,psTabRec.table_name);

WHEN ipOpt = 'T' THEN

lv_csize := funAvgTabColLength(ipSchema,psTabRec.table_name);

WHEN ipOpt = 'S' AND lv_first_pass THEN

lv_csize := funAvgSchColLength(ipSchema);

lv_first_pass := FALSE;

ELSE
null;
END CASE;
BEGIN
dbms_stats.delete_table_stats(
ownname => ipSchema,
tabname => psTabRec.table_name
);
EXCEPTION
WHEN OTHERS THEN
null;
END;
BEGIN
dbms_stats.gather_table_stats(
ownname => ipSchema,
tabname => psTabRec.table_name,
estimate_percent => ipEstPct,
method_opt => funGenSizeOpt(ipOpt,ipChoice, lv_csize)
);
EXCEPTION
WHEN OTHERS THEN
null;
END;

FOR tabIndRec IN tabIndCur(ipSchema,psTabRec.table_name)
LOOP
BEGIN
dbms_stats.delete_index_stats(
ownname => tabIndRec.index_owner,
indname => tabIndRec.index_name
);

dbms_stats.gather_index_stats(
ownname => tabIndRec.index_owner,
indname => tabIndRec.index_name,
estimate_percent => ipEstPct
);
EXCEPTION
WHEN OTHERS THEN null;
END;
END LOOP;
EXCEPTION
WHEN OTHERS THEN null;
END;
END LOOP;
END;

PROCEDURE std_fix_db_stats(
ipOpt IN VARCHAR2 DEFAULT 'T',
ipChoice IN VARCHAR2 DEFAULT 'C',
ipEstPct IN NUMBER DEFAULT 100,
ipStatsHistoryFlag IN BOOLEAN DEFAULT TRUE
) IS
CURSOR dbSchemaCur IS
SELECT DISTINCT owner
FROM dba_tables
ORDER BY 1 desc ;

lv_verify_tab boolean;

lv_stat_tab dba_tables.table_name%TYPE;

BEGIN

FOR dbSchemaRec IN dbSchemaCur LOOP

IF ipStatsHistoryFlag THEN

create_stat_table(ipSchema => dbSchemaRec.owner);

export_schema_stats(ipSchema => dbSchemaRec.owner);

purge_older_stats(ipSchema => dbSchemaRec.owner);

END IF;

fix_schema_stats(
ipSchema => dbSchemaRec.owner,
ipOpt => ipOpt,
ipChoice => ipChoice,
ipEstPct => ipEstPct
);
END LOOP;
END;

END PKG_MAINTAIN_STATS;

Saturday, October 6, 2007

Database Technology Synergy

Convergence and Database Operating Procedures

One of my French language teachers frequently used the expression “Qui n’est pas avec nous est contre nous”.  This literarily means “he who is not with us is against us”. While I could never understand whether it was a complement of or an equivalent to the biblical sentence, it always reminded me about his fraternal expectations from pupils and class mates in terms of loyalty and commitment to the French class and the learning of the language and the culture. In spite of being a Vietnam veteran, he had a very fraternal view of life, and a humanitarian one as a friend to everyone. I have always learned about this and recall his words when it comes to commonality and project management, and how this can affect solid careers without any biases.

When tuning databases and leading databases teams, as a Principal Consultant or Vice President, I have had the opportunity to acknowledge many events that can drive commonality for the database team, and entice participation from others, which in many instances lead to either team success or team reorganization to optimize all individual talents.

It takes a three-month study to have an entire corporation to change a simple parameter value such as CURSOR_SHARING from force to exact, which improved performance tuning in at least a few corporation where bind variables had historically caused bind variable related issues, which the knowledge of database administrators or developers for some time. Similarly, it took to bring commonality and team collaboration over individual skills to be able to resolve a SQL bind peaking affecting a clone database, which should have had equivalent performance as the original source database.

When working with grid computing infrastructure, it takes an army of resources to be able to establish a solid enhanced prototype, which can grow into a self-paced enhanced model; while a staging strategy can be achieved to reach database and networking infrastructure milestones, and gradually managing, controlling and tuning, targets, OMS’s, agents, beacons, blackouts, and finally achieving a truthful grid computing infrastructure that thoroughly integrates and optimizes resources, achieves automation, and integrates technology overall. The Oracle Fusion Middleware is there to be together and synergize and place Oracle’s M over any major infrastructure convergence concerns.
Such Oracle’s messaging technology works quite well in partnership with IBM MQ, and so does with MQMS, Tibco, and other middleware messaging technologies. It establishes channels that are open, as much as the people that work in interaction with heterogeneous technologies.

When working in globalization of database and portals, working with the decision-making on the most convenient database and national character sets, Java resource bundling strategies and other relevant, the achievement of a consistent platforms that can also possibly support compression and encryption, and optimize performance on partitioning is more relevant and even more difficult when dealing with regulatory constraints, and not just to human interaction factors. A disaster recovery/business continuance team (DR/BC) can confront similar circumstances if a compliance regulatory procedure leads delaying high-availability architecture and infrastructure enhancements.

In negotiating procedures to establish new architectures, e.g., when using Streams AQ and replication, in order to achieve a safer infrastructure for your RAC database residing in an iSCSI-based IP-SAN, database administrators, SAN administrators, and system administrator may have a variety of concerns that are usually discussed with the information technology manager, CIO and CTO, before finally reaching synergy and commonality over all the relevant infrastructure and making a consistent decision over a final architecture. Then collaboration comes in place…

Pro-active people can reach this type of synergy and being together and collaborate into reaching database operating procedures goals most efficiently. Because a greater amount of dedication, loyalty, inspiration, and a stronger character is needed today to overcome convergence, and achieve business compliance consistently, it is significantly important to state that those that are with us in the working place are certainly with us in heart and being loyal to and consistent with career goals. It brings great inspiration to state that those that are not with us are not necessarily against us.


This blog is optimized to be viewed with Apple Safari.

Monday, October 1, 2007

Targetting the Database Architecture from Design

The following is an excerpt of a paper I am currently writing on Oracle performance tuning and related high availability strategies:

The Best Database Architectures are Designed

During my twenty years in information and database technology, I have encountered that the best database architecture designs were not directly implemented in a production environment, but instead they had been scaled in smaller servers, and systematically brought up to larger servers, in comparison to incremental prototypes and iterative software engineering methodologies. As such, I implemented my first multiple block size in 2G Solaris box, before I used in a 16GB server and later on in a three-level fault tolerant mainframe with four times the number of dual cores and RAM.

Significantly, the results showed that modeling architectures from design is a more effective way to achieve projected performance tuning in large scales, rather than having to deal with a potentially a very large number of events and factors in a production environment. Likewise, when database architectures have to be modified in an intermediate stage or already in production stage, quality assurance methodologies similar to those used in software engineering, as mentioned above, are applied to database technology performance optimization.

Similarly, I have stated in several related papers that about 80% of performance tuning is driving by the original target design, and this is more significant when it is already put into production. As such, no architectural component, application, I/O or SQL statement, and so on, can fully achieve optimal performance when the original design is neglected.