Oracle DBA Best Practices
Oracle DBA Best Practices
Field
Arup Nanda
Starwood Hotels
Who am I
• Oracle DBA for 13
years and counting
• Speak at
conferences, write
articles, 4 books
• Brought up the Global
Database Group at
Starwood Hotels, in
White Plains, NY
Why this Session
• I have seen too many Rules of Thumb and
“Best” Practices.
• Some of them could be questionable or
even downright wrong!
• Warning: I am questioning everything,
leaving nothing to “expert opinions”.
• proligence.com/downloads.html
“
Advice is seldom welcome.
And those who want it most
always like it the least.
”
Earl of Chesterfield
1694-1773
Guidelines
• Best practices must be justified
“Use Oracle Flexible Architecture”
“Ummm … why?”
“Because, it’s the best practice, stupid!”
No Justification → Not Acceptable
• It must aply to all cases or show clearly
where it’s applicable
Best practice is to hot-backup the database
Unless, there is a performance gain by running in
NOARCHIVELOG mode
Different Oracle Homes
• Traditional Approach:
– /u01/app/oracle/10.2
– Patches are applied to the same OH
• Suggestion:
– Use a different Oracle Home for each upgrade and
patching
/u01/app/oracle/10.2/db1
– In next patch, create a different OH
/u01/app/oracle/10.2/db2
– Apply the patch here, not on db1
New Approach
Step Traditional Proposed
1 Shutdown DB
4 Change OH
5 Startup DB Startup DB
New OH Each Time
Current OH: /u01/app/oracle/10.2/db4
New OH: /u01/app/oracle/10.2/db5
• Reduction in risk of new code.
– Patch fails -> reset the OH to the old one – db4 and
restart the db
• Diff is possible, what changed by the patch
• Catalog scripts (c*,u*,catalog, catproc)
preserved
• Some binaries are available in older OH
• OPatch "bugs" are also mitigated
ASM Home ≠ DB Home
• ASM is embedded in the Database code;
so no need to have a different Ora Home
• Suggestion:
– Create a different OH for ASM, even though it
will be initially identical to DB Ora Home
/u01/app/oracle/10.2/db1
/u01/app/oracle/10.2/asm1
– Apply patches specific to product to OH
Set Audit Trail
• Set audit_trail = db
Even if you do not need to audit
• True or False: Setting audit_trail to DB
will start auditing and increase IO?
• Answer: FALSE! You need to issue
AUDIT statements as well.
• This parameter needs a recycle; so set it
even if you don’t plan on using it.
• 11g already has it by default!
Set some parameters
• Set some parameters (These are not modifiable
by ALTER SYSTEM).
• _trace_files_public = TRUE
– Sooner or later you need to give access to
some trace files to developers
• utl_file_dir = '/tmp'
– Don’t need that because of directory objects
– Reqd for creating Log Miner Dictionary on Flat
File
Dump "OFA"
• Oracle Flexible Architecture (OFA)
/u01/app/oracle
admin/SID/bdump
admin/SID/udump
oradata/SID/datafiles
• Does not allow separation of filesystems
for security, performance, physical
location, etc.
• Does not allow for passive failovers
Non-OFA Layout
• Suggested Layout
/oracle
admin/SID/* - not allowed to users
/u01/udump – allowed for users
/prddata/SID/mount1/datafiles – high performance
/prddata/SID/mount2/datafiles – low performance
Output
• Service Name
(CONNECT_DATA = (SERVICE_NAME = PRODB1)))
Enable Service Names
• In the instance, check service names present
already:
SQL> show parameter service_names
• Create additional service names:
SQL> alter system set service_names =
'SVC1', 'SVC3', 'SVC3';
• Check is listener is listening for these:
$ lsnrctl services
• In RAC, you should use SRVCTL:
$ srvctl add service –d MYDB –s SVC1 ...
Why Service Names?
• No change in functionality
• Separates use from user, e.g. SCOTT logging
from laptop uses service SVC1; but from app
server SVC2.
• Enhances resource manager use
• Allows load balancing and failover in RAC or
Data Guard databases
• Allows fine grained failover capabilities
– Service SVC1 fails from node1 to node2; but SVC2
fails to node3
OS Specific Tweaks
• On HP/UX, use sched_noage
– Necessary for setting right priorities for
processes
– Make "dba" group pat of MLOCK
• On Solaris use Intimate Shared Memory
– Optimizes the memory management
Raw Devices
• Use one size for devices and add them to tablespaces.
• Common Use:
– Create a raw device of 100GB in name /dev/../users01.dbf
– Create tablespace USERS with the raw device
– When USERS need more room, expand the raw device.
• Recommended Use:
– Create raw devices of 30GB named /dev/…/d1, d2, etc.
– Create tablespace with the devices d1, d2 and d3.
– When USERS need more room, add a new device
• Advantages
– No outage
– Reuse devices
Using ORADEBUG
• Problem:
– Database Issue; you want to use oradebug;
but SQL*Plus hangs!
• When SQL*Plus does not work, use
$ sqlplus -prelim
It does not establish a connection
You can run ORADEBUG now
Dumping
• Data block
alter system dump datafile d block b;
• The rest:
alter session set events 'immediate trace
name <Key> level 10';
• Controlfile CONTROLF
• File Headers FILE_HDRS
• Redo Headers REDOHDR
• System State SYSTEMSTATE
• Process State PROCESSSTATE
• Library Cache LIBRARY_CACHE
alter session set events 'immediate trace
name LIBRARY_CACHE level 10';
Scripts
• Deletion of trace files older than some days.
DAYS=2
find /u02/app/oracle/admin -name "*.log" -ctime
${DAYS} -exec rm {} \;
find /u02/app/oracle/admin -name "*.trc" -ctime
${DAYS} -exec rm {} \;
find /u02/app/oracle/admin -name "*.trw" -ctime
${DAYS} -exec rm {} \;
find /u02/app/oracle/admin/*/cdump -ctime ${DAYS}
-exec rm -r {} \;
alias bdump='cd
$ORACLE_BASE/admin/$ORACLE_SID/bdump'
alias pfile='cd
$ORACLE_BASE/admin/$ORACLE_SID/pfile'
alias obase='cd $ORACLE_BASE'
alias tns='cd $ORACLE_HOME/network/admin'
alias oh='cd $ORACLE_HOME'
alias os='echo $ORACLE_SID'
Remember
• It’s not a best practice, if it is not justified
• You have to understand why; not just what
• Best practice needs to be situation-aware
– Which goes back to “you have to understand”
• Always question whenever someone tells
you it’s a best practice
Thank You!
Q&A
proligence.com/downloads.html