oracle dba best practices
DESCRIPTION
Best practices for Oracle DBA. From 2004TRANSCRIPT
UTOUG Training Days 2004
Advanced DBA Best Practices
Michael S. Abbey
The Pythian Group
2Michael S. Abbey – Advanced DBA Best Practices
• Preamble / raison d'être
• Monitoring
• INIT.ora
• Do not wait for waits
• Integrity of your backups
Agenda
DBA Best
Practices
WOW!!UTOUG
March
2004
3Michael S. Abbey – Advanced DBA Best Practices
Agenda
• Infrastructure setup• Schema environments• Cost-based optimizer• Distributed computing• Application tuning
DBA Best
Practices
WOW!!UTOUG
March
2004
4Michael S. Abbey – Advanced DBA Best Practices
Agenda
DBA Best
Practices
WOW!!
• Working with Oracle Support Services
• Hodge podgeUTOUG
March
2004
5Michael S. Abbey – Advanced DBA Best Practices
• It's so hard to tune– Cryptic?
– Too many areas?
– Too complex?
• It’s so easy to tune– Separate components
– Version compatibility
– Concept carry-over
Memory
I/O
Apps
Preamble / raison d'êtreCryptic Too many areas
6Michael S. Abbey – Advanced DBA Best Practices
• Terminology is portable across version
• Same background processes
• Method rather than guesswork– Ripple affect
– Fix this / break that
• Instance parameters– v$parameter
– v$instance
• SQL statement– v$sqlarea
– v$sqltext
• Memory structures– v$librarycache
Preamble / raison d'êtreFacts about the Oracle Server
7Michael S. Abbey – Advanced DBA Best Practices
• Tune Apps
• Tune Memory
• Tune I/O
Turn this
Preamble / raison d'êtreToo complex??
8Michael S. Abbey – Advanced DBA Best Practices
Into this!!!!!
Preamble / raison d'êtreFacts about the Oracle Server
9Michael S. Abbey – Advanced DBA Best Practices
Monitoring
Best practices NOW will payoff down the road
10Michael S. Abbey – Advanced DBA Best Practices
You would not believe what the guy at Training Days told me. He said that his approach to
monitoring was to ignore situations that he did not deem to be necessary!
One person's approach to monitoring may not be the other person's style. Suggestions? Be my guest.
Caveat
11Michael S. Abbey – Advanced DBA Best Practices
Ensure your space monitoring traps ALL space
deficiency situations
12Michael S. Abbey – Advanced DBA Best Practices
MonitoringThe dba_free_space poltergeist
select distinct a.tablespace_name
from dba_tablespaces a,
dba_free_space b
where a.tablespace_name =
b.tablespace_name;
TABLESPACE_NAME------------------------------AD_DATAAD_INDEXRBSSYSTEMTEMP
select distinct a.tablespace_name
from dba_tablespaces a,
dba_free_space b
where a.tablespace_name =
b.tablespace_name (+);
TABLESPACE_NAME------------------------------AD_DATAAD_INDEXBLINKYRBSSYSTEMTEMP
13Michael S. Abbey – Advanced DBA Best Practices
set pages 100
col ts_name form a20 head 'Tablespace'
col pieces form 9990 head 'Pcs'
col ts_size form 999,990 head 'SizeMb'
col largestpc form 999,990 head 'LrgMB'
col totalfree form 999,990 head 'FreeMb'
col pct_free form 990 head '%Free'
col whatsused form 999,990 head 'Used'
col pct_used form 990 head '%Used'
col problem head 'Prob??'
spool umcdbp1
. . .
spool off
Da code goes hereDa code goes here
Environment
MonitoringI'm too full
14Michael S. Abbey – Advanced DBA Best Practices
select q2.other_tname ts_name, pieces, ts_size ts_size,
nvl(largest_chunk,0) largestpc, nvl(total_free,0) totalfree,
nvl(round((total_free/ts_size)*100,2),0) pct_free,
ts_size-total_free whatsused,
nvl(100-round((total_free/ts_size)*100,2),100) pct_used,
decode(nvl(100-round((total_free/ts_size)*100,0),100),
85,'+',86,'+',87,'+',88,'+',89,'++',90,'++',91,'++',
92,'++',93,'++',94,'+++',95,'+++',96,'+++',97,'++++',
98,'+++++',99,'+++++',100,'+++++','') problem
from (select dfs.tablespace_name,count(*) pieces,
round(max(dfs.bytes)/1024/1024,2) largest_chunk,
round(sum(dfs.bytes)/1024/1024,2) total_free
from dba_free_space dfs group by tablespace_name) q1,
(select tablespace_name other_tname,
round(sum(ddf2.bytes)/1024/1024,2) ts_size
from dba_data_files ddf2 group by tablespace_name) q2
where q2.other_tname = q1.tablespace_name(+) order by nvl(100-round((total_free/ts_size)*100,0),100) desc;
Code
MonitoringI'm too full
15Michael S. Abbey – Advanced DBA Best Practices
• Percentage based on– Growth patterns
– Past experiences
– Archival habits
• Ignore or not ignore– Rollback segments
– Temp
– Non-app related
• LM tablespaces with extent management local …uniform size …
• The dba_free_space poltergeist
Infrastructure issues
More of a than anything else
MonitoringThresholds
16Michael S. Abbey – Advanced DBA Best Practices
Ensure you trap potential object extension problems before your applications
17Michael S. Abbey – Advanced DBA Best Practices
• Less free space available than potential object extension • Objects within 5 extents of their maximum
MonitoringUnable to extend
col owner form a5 head Ownercol segment_type form a5 head Typecol segment_name form a24 head Namecol next_extent form 999,999,990 head NextEXTcol max_extents form 9,999 head MaxEXTcol extents form 9,999 head CurrEXT
break on owner on segment_type
18Michael S. Abbey – Advanced DBA Best Practices
MonitoringUnable to extend – available extents
promptprompt Objects that cannot extend ...prompt
select owner,segment_type,segment_name,next_extent from sys.dba_segments ds where segment_type in ('TABLE','INDEX') and next_extent > (select max(bytes) from sys.dba_free_space dfs where dfs.tablespace_name = ds.tablespace_name) order by 1,2,3;
19Michael S. Abbey – Advanced DBA Best Practices
MonitoringUnable to extend – within 5
promptprompt Objects within 5 of max extents ...prompt
select owner,segment_type,segment_name,max_extents,extents from sys.dba_segments ds where segment_type in ('TABLE','INDEX') and max_extents - extents <= 5;
• Avoid maxextents unlimited – will never detect objects with too many extents
• Number arbitrary -- based on DBA experiences
20Michael S. Abbey – Advanced DBA Best Practices
Ensure you are fluent with monitoring locally managed
tablespaces
21Michael S. Abbey – Advanced DBA Best Practices
• Locally managed [permanent] – Extent management LOCAL in DBA_TABLESPACES– Free space tracked in data files by DBA_FREE_SPACE
as well– What’s the deal then with locally managed??
• Locally managed temporary– TEMP segment cleanup not one of Oracle’s “strengths”– Easy way to track space released by segments– Easy way to see progress of TEMP-related operations
MonitoringLocally managed is what!!
22Michael S. Abbey – Advanced DBA Best Practices
MonitoringLocally managed temp
• Use V$TEMP_FILE and V$TEMP_SPACE_HEADER
• Useful to assess cleanup of temporary segments
col trname form a23 head Filecol tablespace_name form a7 head TSNamecol bytes form 9,999,999,990col bytes_free like bytes
23Michael S. Abbey – Advanced DBA Best Practices
select tsh.tablespace_name, '..'||substr(tf.name,length(name)-23) trname, tf.bytes,tsh.bytes_freefrom v$tempfile tf, v$temp_space_header tshwhere tf.file# = tsh.file_id;
TS Name File BYTES BYTES_FREE-------- ----------------------- -------------- --------------LOC_TEMP ../od01/loc_temp01.dbf 2,098,200,576 1,887,436,800LOC_TEMP ../od02/loc_temp02.dbf 2,098,200,576 1,258,291,200LOC_TEMP ../od04/loc_temp03.dbf 2,098,200,576 1,887,436,800LOC_TEMP ../od02/loc_temp04.dbf 2,098,200,576 1,887,436,800
MonitoringLocally managed temp
24Michael S. Abbey – Advanced DBA Best Practices
Ensure you protect what precious space exists in the
SYSTEM tablespace
25Michael S. Abbey – Advanced DBA Best Practices
select username from dba_users where temporary_tablespace = 'SYSTEM';
select username from dba_users where default_tablespace = 'SYSTEM';
MonitoringOuta SYSTEM buddy!!
• SYSTEM is the last place you can afford object extension
• SOURCE$ and OBJ$ love space
What did your DBA tell you??
I would never use SYSTEM!!
I hope no-one noticed I used SYSTEM – it can't happen here
26Michael S. Abbey – Advanced DBA Best Practices
Ensure you are in synch with the status of your
rollback segments
27Michael S. Abbey – Advanced DBA Best Practices
• ORA-01552: cannot use system rollback segment for non-system tablespace GRID
• ONLINE is the only acceptable status• needs recovery or full are a problem• Assumes your utility segment is in SYSTEM
tablespace
MonitoringRollback segments
select segment_name from dba_rollback_segs where status <> 'ONLINE' and tablespace_name <> 'SYSTEM';
RBS01
28Michael S. Abbey – Advanced DBA Best Practices
Detect problems with your job stream before it plagues your application operations
29Michael S. Abbey – Advanced DBA Best Practices
• Of interest to the monitoring exercise– What the job does– How often it runs – When it last ran – When it will run next
• Is the job broken– By Oracle or deliberately
dba_jobs
dba_jobs_running
MonitoringThe job stream
30Michael S. Abbey – Advanced DBA Best Practices
select schema_user||','||job||','|| to_char(last_date,'mmdd hh24:mi:ss') from dba_jobs where broken='Y' or (last_date < sysdate - 20/(24*60)20/(24*60)
INTERVAL
Exclusions– and what <> 'abcdefghi';– and job not in (210,222,388);– and instr (replace (lower(interval, ' ',null)) <> 'sysdate+1';
MonitoringJob run details
31Michael S. Abbey – Advanced DBA Best Practices
• Broken jobs seem to magically fix themselves
• Broken job auto fix (next run)create or replace procedure fj (inter in number) is cursor jobstofix is select job,what from user_jobs where last_date > sysdate-inter/1440 and broken = 'Y'; begin for jobrec in jobstofix loop dbms_job.run(jobrec.job); end loop; end;/
Smarts to ensure you do not un-break what is supposed to be broken
MonitoringUnbreakable
32Michael S. Abbey – Advanced DBA Best Practices
Ensure unusable index partitions are caught by
you, not your apps
33Michael S. Abbey – Advanced DBA Best Practices
select 'alter index '||owner||'.'||index_name|| ' rebuild partition '||partition_name||';' from dba_ind_partitions where status= 'UNUSABLE';
MonitoringUnusable index partitions
Automagically, index partitions are marked unusable
• Aborted direct path Loader sessions• Some partition maintenance operations local• Partition maintenance operations global
34Michael S. Abbey – Advanced DBA Best Practices
3 "L" words – locks & latches turn into lousy
performance if not detected early
35Michael S. Abbey – Advanced DBA Best Practices
• Two sessions vying for the same resource
• catblock.sql – rdbms/admin• Assortment of cryptic lock
views• Narrow down sessions and
convert to OS pid using v$session and v$process
paddr
spid
addr
v$sessionv$session
v$processv$process
MonitoringLocks
36Michael S. Abbey – Advanced DBA Best Practices
• The DBA's nightmare
• Low level serializable mechanisms designed to protect global data structures in the SGA
• Life expectancy sub-second
• Latches are to memory as locks are to disk
MonitoringLatches
37Michael S. Abbey – Advanced DBA Best Practices
col Requests form 999,999,999,990 head 'Requests'
col PctMiss form 99.90 head 'PCTMiss'
select name,gets+misses Requests,
round(misses/decode(gets+misses,0,-1,
gets+misses)*100,2) PctMiss
from v$latch
where misses/decode(gets+misses,0,-1,gets+misses)*100 > 10
order by gets desc;
MonitoringLatches
38Michael S. Abbey – Advanced DBA Best Practices
select count(*) from x$kglpn;
X:Y
Absolute over a certain amount (static)
Relative compared to the norm
MonitoringLatches
39Michael S. Abbey – Advanced DBA Best Practices
• A healthy environment returns counts well under 200
• Spinning for latches to gain access to precious resources
• Tempting to increase latch counts
• Low level supervisory mechanism would not allow
MonitoringLatches
40Michael S. Abbey – Advanced DBA Best Practices
Detect spikes in system load that affect performance
41Michael S. Abbey – Advanced DBA Best Practices
#!/bin/kshtypeset -i THRESHOLDtypeset -i LOADHOUR=$(date +%H)if (( $HOUR > 7 && $HOUR < 17 )); then THRESHOLD=$1else THRESHOLD=$2fitmpuptime=`uptime`tmploads=${tmpuptime##*average:}LOAD=${tmploads%%.*}if (( $LOAD > $THRESHOLD )); then echo "Load of $LOAD exceeded threshold of $THRESHOLD" exit 1fiexit 0
MonitoringSystem load
42Michael S. Abbey – Advanced DBA Best Practices
Detect devices with low free space
43Michael S. Abbey – Advanced DBA Best Practices
#!/bin/ksh
# $1 - the filesystem to check
# $2 - the byte count threshold
typeset -i bytesused
typeset -i pctused
pctused=$(df -k |grep $1 | awk '{print $5}' | sed 's/%//')
bytesused=$(df -k |grep $1 | awk '{print $4}')
if (( $bytesused < $2 ))
then print $1 is $pctused% full, PROBLEM.
fi
MonitoringDisk usage
Some locations are crucial to
backups exports archived redo logs
44Michael S. Abbey – Advanced DBA Best Practices
SQL statement contention is a sibling of latch
contention
45Michael S. Abbey – Advanced DBA Best Practices
• Concurrent executions
• Location of data
• Clustering
• Default RS locking mode
MonitoringSQL statement contention
46Michael S. Abbey – Advanced DBA Best Practices
select 'Too many sessions ( '||to_char(count(*))||' running '
substr(sql_text,1,80) query
from v$session s, v$sqlarea sa
where s.sql_address = sa.address
and s.sql_hash_value = sa.hash_value
and s.status = 'ACTIVE'
and s.audsid != 0
and sql_text not like 'select sql_text%'
group by substr(sql_text,1,80)
having count(*) > 100;
MonitoringSQL statement contention
47Michael S. Abbey – Advanced DBA Best Practices
Why do you think Oracle writes that alert log
anyways?
48Michael S. Abbey – Advanced DBA Best Practices
• Per instance• Significant errors• Lots of meaningless
gobbledygook• Establish a marker
– Read on
– Set new marker
• Ignore list
00600 00604 0651203113 07445 0165901142 0114601598 01545
Err on the side of the client—if the pages are not necessary, add to the exclude list.
MonitoringAlert log
49Michael S. Abbey – Advanced DBA Best Practices
Who discards the state of those packages anyways?
50Michael S. Abbey – Advanced DBA Best Practices
• SYS and SYSTEM– Expect DBMS_ invalid
packages
– Run dbmsxxxx,sql & prvtxxxx.plb
– Interdependencies cause one to invalidate other
• DBA_DEPENDENCIES
oracle> grep –il dbms_job *sqla0800150.sqlcatjobq.sqldbmsjob.sqle0800150.sqlstatsauto.sqlstatscusr.sqlstatspack.sqloracle> sqlplus /nolog
SQL> connect / as sysdba. . .SQL> @dbmsjob. . .. . .SQL> @prvtjob.plb
MonitoringInvalid objects
51Michael S. Abbey – Advanced DBA Best Practices
Ensure you standby your standby
52Michael S. Abbey – Advanced DBA Best Practices
MonitoringStandby database – is it up?typeset -i LINESexport log_history=\$log_historyecho "connect / as sysdba desc v$log_history exit"| sqlplus -s /nolog > recid.logLINES=`grep RECID recid.log|wc -l`if (( $LINES = 0 ))then echo Standby down exit 1else echo Standby OK exit 0fi
But I'm still on 8, what should I do??
Replace line 1 with internal, and get rid of the /nolog!
53Michael S. Abbey – Advanced DBA Best Practices
MonitoringStandby database – is it up-to-date?
typeset -i CHECKER
export log_history=\$log_history
CHECKER=`echo "connect / as sysdba
set echo off feed off pages 0
select (sysdate-(max(first_time)))*24 from v$log_history;" | sqlplus –s /nolog`if (( $CHECKER > 1 ))
then
echo Recovery older than 1 hour
exit 1
else
echo OK
exit 0
fi
54Michael S. Abbey – Advanced DBA Best Practices
MonitoringIs standby useable?
• Do an a regular basis• Weekly, bi-weekly,
every 48 hours?• Script and inspect
output• Significant output
(dual??)
echo "/ as sysdbaalter database open read only;describe dual;shutdown immediatestartup nomount;alter database mount standby database;" | sqlplus -s > roc.logLINES=`grep DUMMY roc.log|wc -l`if [ $LINES = 1 ]then echo OK exit 0else echo Problem @standby ... exit 1fi
Only required for 8i
*
*
55Michael S. Abbey – Advanced DBA Best Practices
MonitoringDirect inserts on master
All transactions propagated from master to standby via archived
redo logs.
Direct inserts not logged!
This is a problem on the standby, so ya'd better
watch out!
alter session enable parallel dml;
alter table mailer nologging;
insert into mailer
select /*+ parallel (mailer,2) */
* from mailer@hasek;
commit;
On master, there is no undo or redo for these inserts!
Beware or else
56Michael S. Abbey – Advanced DBA Best Practices
MonitoringDirect inserts on master
• mailer table on master row count = 12,345,781 on July 12
• 77,999,201 rows created in mailer on master on July 12
• Standby database activated due to disaster on July 13
select num_rows
from user_tables
where table_name = 'MAILER';
NUM_ROWS
------------
13889778
Over-simplified, but the gist of the problem.
57Michael S. Abbey – Advanced DBA Best Practices
MonitoringDetection of nologging activities
Resolution Babette
col tablespace_name form a20 head 'Tablespace'
col file_name form a30 head 'File'
col tablespace_name form a20 head 'Tablespace'
col unrecoverable_time form a20 head 'Change Time'
select ddf.file_name,ddf.tablespace_name,
vd.unrecoverable_time
from sys.dba_data_files ddf,v$datafile vd
where ddf.file_name = vd.name
and nvl(vd.unrecoverable_time,trunc(sysdate+10)) >
to_date('&1','DD-MON-YYYY');
58Michael S. Abbey – Advanced DBA Best Practices
Ensure statistics exist for CBO and they are current
59Michael S. Abbey – Advanced DBA Best Practices
MonitoringTable statistics
-- Not analyzedselect owner,table_name from sys.dba_tables where owner not in ('SYS','SYSTEM') and nvl(num_rows,0) = 0 or last_analyzed is null;
-- Not analyzed for pre-determined number of daysselect owner,table_name from sys.dba_tables where owner not in ('SYS','SYSTEM') and last_analyzed is not null and trunc(last_analyzed) < trunc(sysdate)-5;
60Michael S. Abbey – Advanced DBA Best Practices
Make sure YOU are not the bottleneck
61Michael S. Abbey – Advanced DBA Best Practices
MonitoringThe real story
• dba_ and user_ views are expensive• Learn your way around the x$ tables• With credit to Steve Adams (ixora)
– Build x_$ views to match their corresponding x$ views
– Grant select to public– Reference these views using sys.
{view_name}
62Michael S. Abbey – Advanced DBA Best Practices
set pages 0 lines 999 trimsp on echo off ver off feed off
spool xdollars
select 'create view x_$'||substr(table_name,3)||
' as select * from '||table_name||';'
from user_tables
where table_name like 'X$%';
spool off
set echo on feed on
spool xdollars.log
@xdollars.lst
spool off
Monitoring The real story
63Michael S. Abbey – Advanced DBA Best Practices
Monitoring Dollar signs
• Familiarize yourself with the v$ views• Available when database mounted and not
open• Column names inconsistent with dba_
counterpartsselect table_name
from dict
where table_name like 'V$%'
order by 1;
64Michael S. Abbey – Advanced DBA Best Practices
Monitoring Roadmap to $#
select ds.owner, ds.segment_name, ds.partition_name, ds.segment_type,. . . from sys.uet$ e, sys.sys_dba_segs ds, sys.file$ f. . .select /*+ ordered use_nl(e) use_nl(f) */. . . from sys.sys_dba_segs ds, sys.x$ktfbue e, sys.file$ f
DONE
65Michael S. Abbey – Advanced DBA Best Practices
select u.name, o.name, o.subname,. . . from sys.user$ u, sys.obj$ o, sys.ts$ ts, sys.sys_objects so, sys.seg$ s, sys.file$ f. . .select u.name, un.name, NULL,. . . from sys.user$ u, sys.ts$ ts, sys.undo$ un, sys.seg$ s, sys.file$ f. . .select u.name, to_char(f.file#)||'.'||to_char(s.block#),. . . from sys.user$ u, sys.ts$ ts, sys.seg$ s, sys.file$ f
Monitoring sys_dba_segs
66Michael S. Abbey – Advanced DBA Best Practices
select . . . from sys.tab$ tselect . . . from sys.tabpart$ tpselect . . . from sys.clu$ cselect . . . from sys.ind$ iselect . . . from sys.indpart$ ipselect . . . from sys.lob$ lselect . . . from sys.tabsubpart$ tspselect . . . from sys.indsubpart$ ispselect . . . from sys.lobfrag$ lf
Monitoring This is the end
67Michael S. Abbey – Advanced DBA Best Practices
MonitoringCaveat at upgrade time
It's changed in the next release
68Michael S. Abbey – Advanced DBA Best Practices
MonitoringSo many alerts!!
69Michael S. Abbey – Advanced DBA Best Practices
The autoextensible black hole revealed
70Michael S. Abbey – Advanced DBA Best Practices
• Default for many installations
• 2 serious issues when requested extension– over 2Gb limit– cannot be physically accommodated one device
• Oracle is known to not do a very good job of recovering from aborted autoextension
• Cleanup after abend not handled well
MonitoringAutoextension
71Michael S. Abbey – Advanced DBA Best Practices
MonitoringAutoextension
create table aemon ( file_name varchar2(30), sdate date bytes number);
insert into aemon select file_name,sysdate,bytes from dba_data_files where autoextensible = 'YES';
72Michael S. Abbey – Advanced DBA Best Practices
MonitoringAutoextension
select fst.file_name, fst.bytes, fsy.bytes,
round((fst.bytes-fsy.bytes)/fsy.bytes *100,2)
from aem fsy, aem fst
where fst.file_name = fsy.file_name
and trunc(fst.sdate) = trunc(sysdate)
and trunc(fsy.sdate) = trunc(sysdate-1)
and fst.bytes > fsy.bytes;
73Michael S. Abbey – Advanced DBA Best Practices
• Connection testing• Anticipate common
problematic areas• Be thorough and pro-
active• Email gateway• Share the load
• Page and/or email• Document via some
form of tracking system
• MetaLink MetaLink MetaLink MetaLink MetaLink MetaLink
MonitoringBest practices
74Michael S. Abbey – Advanced DBA Best Practices
INIT.ora
Best practices NOW will payoff down the road
75Michael S. Abbey – Advanced DBA Best Practices
INIT.ora
• Organization• Compatibility• Shared pool• Ramifications• Undocumented
parameters
76Michael S. Abbey – Advanced DBA Best Practices
INIT.ora must be clean and readable
77Michael S. Abbey – Advanced DBA Best Practices
• Not a fan of ifile
• Alphabetical ordersort < initumc.ora > sio
cp sio initumc.ora
rm sio
• Toggles stay in place
• Comment changes
• Clean up dbs directory– What is soxx??
Significant defaults– Hard-code– Movements between
versions
• Show parameters
INIT.oraOrganization
78Michael S. Abbey – Advanced DBA Best Practices
• Hard-code– Surprises during
upgrades
– Are you going far enough
• New features– Can I use them?
– Can I go back?
• Access to new features• Changed behaviour of
old features
INIT.oraCompatibility
79Michael S. Abbey – Advanced DBA Best Practices
Wading through the shared pool
80Michael S. Abbey – Advanced DBA Best Practices
• Increasing demands as version increases
• CURSOR_SHARING in 8.1.6 is a big deal– Default is EXACT
– Preferred is FORCE
– Linux 8.1.7
– Alpha 8.1.6
• Bigger is not always better• 4031 errors centre around
4096– _shared_pool_reserved_min_alloc
at 4000• Flushing the pool
– Manual or transparently– A double-edged sword
• Get yourself in a bind
INIT.oraShared pool
81Michael S. Abbey – Advanced DBA Best Practices
INIT.ora
HAR
82Michael S. Abbey – Advanced DBA Best Practices
Aware of ramifications when changing values
83Michael S. Abbey – Advanced DBA Best Practices
INIT.oraRamifications of higher values
set shmsys:shminfo_shmmax=4294967295set shmsys:shminfo_shmmin=1set shmsys:shminfo_shmmni=100set shmsys:shminfo_shmseg=10set semsys:seminfo_semmni=100set semsys:seminfo_semmsl=500set semsys:seminfo_semmns=500set semsys:seminfo_semopm=1000set semsys:seminfo_semvmx=32767
DB_CACHE_SIZE
LARGE_POOL_SIZE
SHARED_POOL_SIZE
OPEN_CURSORS
PROCESSES
• Semaphores are advisory locking mechanisms that ensure a server completes certain tasks before beginning another.
• Some parameter values drain semaphores and others look for larger portions of shared memory
84Michael S. Abbey – Advanced DBA Best Practices
More than meets the eye
85Michael S. Abbey – Advanced DBA Best Practices
INIT.oraUndocumented parameters
x$ksppi Name Type
--------- ----------------
ADDR RAW(4)
INDX NUMBER
INST_ID NUMBER
KSPPINM VARCHAR2(64)
KSPPITY NUMBER
KSPPDESC VARCHAR2(64)
KSPPIFLG NUMBER
x$ksppcv Name Type
----------- --------------
ADDR RAW(4)
INDX NUMBER
INST_ID NUMBER
KSPPSTVL VARCHAR2(512)
KSPPSTDF VARCHAR2(9)
KSPPSTVF NUMBER
KSPPSTCMNT VARCHAR2(255)
86Michael S. Abbey – Advanced DBA Best Practices
INIT.oraUndocumented parameters
select ksppinm,ksppstvl,ksppdesc
from x$ksppi x,x$ksppcv y
where x.indx = y.indx
and translate(ksppinm,'_','#') like '#%' order by 1
KSPPINSM KSPPSTVL KSPPDESC
-------------------------------- --------- ---------------------------------
_allow_resetlogs_corruption FALSE allow resetlogs even if it
will cause corruption
_corrupted_rollback_segments corrupted undo segment list
_db_handles_cached 5 Buffer handles cached each process
_shared_pool_reserved_min_alloc 4400 minimum allocation size in bytes
for reserved area of shared pool
87Michael S. Abbey – Advanced DBA Best Practices
• Readable is crucial• Comment changes• Cleanup the dbs
directory• Be familiar with
memory consumers• Semaphore limitations
• Familiarize yourself with dynamic memory structures in 9i
• Block size caches 9i• Watch out for
shared_pool_size > 90000000
INIT.oraBest practices
Issues Rich
88Michael S. Abbey – Advanced DBA Best Practices
Do not wait for WAITs
Best practices NOW will payoff down the road
89Michael S. Abbey – Advanced DBA Best Practices
Are wait situations detracting from overall
performance?
90Michael S. Abbey – Advanced DBA Best Practices
Do not wait for WAITs
• Wait situations are the biggest performance detractor
• Latches—protect the integrity of shared memory structures.
• Locks—protect the integrity of your data.
• V$ dynamic performance views:– v$waitstat– v$session_wait
• DBA_ views– dba_blockers
(catblock.sql)
91Michael S. Abbey – Advanced DBA Best Practices
select event,count(*),sum(seconds_in_wait) siw from v$session_wait group by event;
EVENT COUNT(*) SIW--------------------------- -------- ---------
SQL*Net message from client 1192 747,039SQL*Net message to client 2 0db file sequential read 5 0log file parallel write 1 0pmon timer 1 9,062rdbms ipc message 24 128smon timer 1 908
Do not wait for WAITsv$session_wait
92Michael S. Abbey – Advanced DBA Best Practices
Where has all the CPU gone?
93Michael S. Abbey – Advanced DBA Best Practices
• Map running SQL to user sessions
• Zero in on CPU consumers
select sql_text, sid, serial#
from v$session s, v$sqlarea sa
where s.sql_address = sa.address
and s.sql_hash_value = sa.hash_value
and s.status = 'ACTIVE'
and s.audsid != 0
and sql_text not like 'select sql_text%';
Do not wait for WAITsWho's doing what
94Michael S. Abbey – Advanced DBA Best Practices
Do not wait for WAITsRelationship to system load
• Get a handle on "normal" system load using uptime command
• Spool to log file in the crontab, running every 5 minutes
*/5 /oracle/bin/uptime.sh >> /oracle/logs/uptime.sh.log 2>&1
• High load averages almost always map to wait situations SQL*Net message from client
db_file sequential readdb file scattered read
95Michael S. Abbey – Advanced DBA Best Practices
set charwidth 17
select lpad(' ',3*(level-1))||waiting_session,
waiting_session,lock_type,mode_requested,
mode_held,lock_id1,lock_id2
from lock_holders
connect by prior waiting_session = holding_session
start with holding_session is null;
WAITING_SESSION TYPE MODE REQUESTED MODE HELD LOCK ID1 LOCK ID2
----------------- ---- ----------------- ----------------- -------- --------
553 NONE None None 0 0
213 TX Share (S) Exclusive (X) 34888 39
378 RW Exclusive (X) S/Row-X (SSX) 33255666 2
3928 RW Exclusive (X) S/Row-X (SSX) 3255666 2
Do not wait for WAITsutllockt.sql
96Michael S. Abbey – Advanced DBA Best Practices
• Waiting drains system resources
• Wait events cause destructive spinning
• Minimizing potential waits foremost in your minds
• Commit often
• SQL statement contention
• Concurrent user requests for the same data in the cache
• DO not exploit multi-tasking
Do not wait for waitsBest practices
Issues Rich
97Michael S. Abbey – Advanced DBA Best Practices
Integrity of your backups
Best practices NOW will payoff down the road
98Michael S. Abbey – Advanced DBA Best Practices
Integrity of your backups
Media recovery enabled (archivelog mode)
1. Image backups
2. Export– No indexes / No
constraints
– No rows
3. Control file
5. INIT.ora
6. listener.ora
7. tnsnames.ora
Assume these are run nightly
99Michael S. Abbey – Advanced DBA Best Practices
Backup is nada without integrity and recovery
testing
100Michael S. Abbey – Advanced DBA Best Practices
Best case scenario• Separate server to restore image• Deliberate complete media recovery
– recover database . . .– recover datafile . . .– recover tablespace . . .
• Deliberate incomplete recovery at the database level
Integrity of your backupsImage backups
101Michael S. Abbey – Advanced DBA Best Practices
• Mock disaster recovery• Ideally on the same machine
– With no downtime, involves an ORACLE_SID change
• using backup controlfile is not the Real McCoy
– Plan during a window of opportunity
• Make sure you have performed the recovery portion of your image is NOT tested
Integrity of your backupsImage backups
102Michael S. Abbey – Advanced DBA Best Practices
• NFS device is no substitute for offline storage but …– Mount points all over the corporate server
environment– Target of all images and exports
• Run the NFS out to secondary storage
• root user buy-in
Integrity of your backupsImage backups
103Michael S. Abbey – Advanced DBA Best Practices
Tested rebuild from full database exports
104Michael S. Abbey – Advanced DBA Best Practices
• Create the database (see in Infrastructure section)
• Run 3 or 4 full database imports
Integrity of your backupsTest rebuild from full database export
inctype=systemonline rollback
segments just builtinctype=restore
rows=n ignore=y
rows=n ignore=y
1 2
34
Just definitions NOT data
105Michael S. Abbey – Advanced DBA Best Practices
Standby assisting checkup of recovery process
106Michael S. Abbey – Advanced DBA Best Practices
• Shutdown your standby• Re-instantiate (hot /u02/hot)
Integrity of your backupsTesting using standby technology
set pages 0 trimsp on lines 999 echo off feed off
select 'scp /u02/hot'||file_name||
' [email protected]:'||file_name
from dba_data_files;
set pages 0 trimsp on lines 999 echo off feed off
select 'gzip –d '||file_name||'.gz'
from dba_data_files;
107Michael S. Abbey – Advanced DBA Best Practices
• Re-get standby control file
• Copy to appropriate control_files = locations
alter database create standby
controlfile as 'standby.ctl';
set pages 0 trimsp on lines 999 echo off feed off
select 'cp standby.ctl '||name
from v$controlfile;
Integrity of your backupsTesting using standby technology
108Michael S. Abbey – Advanced DBA Best Practices
Data integrity of your exports
109Michael S. Abbey – Advanced DBA Best Practices
Integrity of your backupsHow's export written
Export: Release 9.2.0.5 - Production on Sat Sep 31 16:47:52 2004
(c) Copyright 2001 Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.5 - Production
With the Partitioning option
JServer Release 9.2.0.5 - Production
Export done in WE8DEC character set and AL16UTF16 NCHAR character set
server uses US7ASCII character set (possible charset conversion)
• Mismatch between UNIX environment and Server character set
• Determined by NLS_LANG
Wake-upWake-up
110Michael S. Abbey – Advanced DBA Best Practices
Collège Brébeuf
Frhre Norman:
Mrs. Jelinski and I were very pleased with our visit to Collhge Bribeuf, and are pleased with what we saw. We are especially happy that we see eye to eye on the preservation of the native Francophone culture with something as simple as accent retention in our Oracle9i database!
Integrity of your backupsCharacter set conversion
Oracle9i: A Beginner's
Guide
111Michael S. Abbey – Advanced DBA Best Practices
Compression checking your export/import engine
112Michael S. Abbey – Advanced DBA Best Practices
Integrity of your backupsGee, zip?
rm export.pipe > /dev/null 2>&1mkfifo export.pipegzip < export.pipe > fulldb.dmp.gz &sleep 2exp parfile=fulldb.parfile
userid=/ full=y log=fulldb
indexes=n constraints=n
buffer=5000000 triggers=n
file=export.pipe
8i
9i
triggers=n
Usable in its compressed state?
113Michael S. Abbey – Advanced DBA Best Practices
Integrity of your backupsGee, unzip?
rm import.pipe > /dev/null 2>&1mkfifo import.pipegunzip < fulldb.dmp.gz > import.pipe &sleep 2imp userid=/ file=import.pipe full=y log=fulldb_in buffer=50000000
Better find out sooner than during a disaster recovery!!
IMP-00037: Character set marker unknownIMP-00000: Import terminated unsuccessfully
IMP-00009: abnormal end of export fileIMP-00000: Import terminated unsuccessfully
114Michael S. Abbey – Advanced DBA Best Practices
Bottom-line … can I read that export file?
115Michael S. Abbey – Advanced DBA Best Practices
Integrity of your backupsRead this, import!
imp userid=/ full=y indexfile=fulldb.sql log=fulldb_if
Import: Release 9.2.0.5 - Production on Sat Jun 30 22:13:49 2004(c) Copyright 2001 Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.5 - ProductionWith the Partitioning optionJServer Release 9.2.0.5 - Production
Export file created by EXPORT:V09.20.00.05 via conventional pathimport done in US7ASCII character set and AL16UTF16 NCHAR character setImport terminated successfully without warnings.
116Michael S. Abbey – Advanced DBA Best Practices
• Only 10% of the way there without testing recovery
• Full and partial components of database
• Missing archived redo logs
• Missing control file(s)• Test rebuild from
export• Test clone on another
server• Role played by your
standby
Integrity of your backupsBest practices
117Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setup
Best practices NOW will payoff down the road
Oracle
The
9i
118Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupA word on creating a database
I've been an Oracle DBA for 2,000 years (US) and
have never created a database; why start
now?? I always upgrade
No thanks, sonny, I went to a user group meeting. As soon as I got back to the office I started creating databases. I
learned SO MUCH!! You ever tried it?? You need the support
more than me!!
Please sit
No
119Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupCreating the database
• 9i Oracle Managed files by specifying– db_create_file_dest
– db_create_online_log_destn
– undo_management = auto
– undo_tablespace = rollback
– undo_retention = 2000
• Do it yourself– Create database
• controlfile• character set• maxlogfiles• maxloghistory• maxlogmembers• maxdatafiles
– Datafile
– Log file(s)create database umcundo tablespace rollbackdefault temporary tablespace temp;
120Michael S. Abbey – Advanced DBA Best Practices
Step-by-step database creation; the players
121Michael S. Abbey – Advanced DBA Best Practices
• The SYSTEM tablespace– systemnn.dbf ~ 250m– Set pctincrease 1
(later)
• Redo log groups– At least dual two-
membered groups– logmn_gn.ora (member
number / group number)
• Construct first non-SYSTEM rollback segment– Acquire 20 extents of ~
100k each
• Run admin scripts• Test creation
Infrastructure setupCreating the database yourself
122Michael S. Abbey – Advanced DBA Best Practices
startup nomountcreate database umc controlfile reuse maxlogfiles 16 maxlogmembers 2 maxdatafiles 2048 maxloghistory 1000 character set we8iso8859p1datafile '/data01/oracle/umc/dbs1_umc.dbf' size 250mlogfile group 1 ('/redo01/umc/log1_g1.dbf', '/redo02/umc/log2_g1.dbf') size 200m, group 2 ('/redo02/umc/log1_g2.dbf', '/redo01/umc/log2_g2.dbf') size 200m;
Infrastructure setupCreate database – phase 1
123Michael S. Abbey – Advanced DBA Best Practices
startup nomount
create database umc
controlfile reuse
maxlogfiles 16
maxlogmembers 2
maxdatafiles 30
maxloghistory 1000
character set
datafile '/data01/…' size 250m
logfile group 1 ('…1_g1.dbf',
'…2_g1.dbf') size 200m,
group 2 ('…1_g2.dbf',
'…2_g2.dbf') size 200m;
1
2
3
4
5
6
1. For this or create controlfile
2. Will not error out if files already exist
3. Make an artificially large #4. Do not allow to default – WE
good place to start 5. No smaller6. 2 dual membered groups
Infrastructure setupCreate database (1) – important points
124Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupA word on sizing online redo logs
Two choices:
1. Small online redo logs to minimize time to push to standby
2. Customary large redo logs with forced log switches
125Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupCreate database – phase 2
shutdown
startup
alter tablespace system default
storage (pctincrease 1);
create rollback segment rb_temp
tablespace system storage (initial
50k next 50k minextents 20 maxextents 20);
alter rollback segment rb_temp online;
126Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupCreate database (2) – important points
shutdown
startup
alter tablespace system default
storage (pctincrease 1);
create rollback segment rb_temp
tablespace system storage (initial 50k
next 50k minextents 20 maxextents 20);
alter rollback segment rb_temp online;
1
23
4
1. No more to be done nomount – rest of work requires instance to be open.
2. Permit pmon to automatically coalesce free space in SYSTEM
3. First non-SYSTEM rollback segment (~1Mb)
4. Rollback segments created OFFLINE by default; edit INIT.ora at the same time so you do not forget
127Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupCreate database – phase 3
@?/rdbms/admin/catalog
@?/rdbms/admin/catproc
@?/rdbms/admin/catrep
@?/rdbms/admin/catsnap
@?/rdbms/admin/dbmsutil
@?/rdbms/admin/prvtutil.plb
@?/rdbms/admin/dbmssql
@?/rdbms/admin/prvtsql.plb
Build the data dictionary
Install PL/SQL
Replication
Snapshot specifics
Popular utility packages
""
SQL utilities
""
128Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupCreate database – phase 4
Right option(s)
Version numbering EE/Standard
Expected feedback
129Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setup
Database is created
Data dictionary has been populated
First non-system rollback segment exists and is online
130Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setuppupbld.sql
131Michael S. Abbey – Advanced DBA Best Practices
Fluency in rollback segment setup
132Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupRollback segments
• 4 to 6 equally-sized segments
• minextents and maxextents the same at creation time
• 500k to 2Mb extents• Not in locally managed
tablespaces• Mentioned in INIT.ora
• Large segment for large transactions– 2 to 4Gb– Larger extent size– Cap at creation time
• No guarantee unless the only one online
133Michael S. Abbey – Advanced DBA Best Practices
• Dedicated tablespace
• Appropriately named
Infrastructure setupRollback segment tablespace(s)
create tablespace rollback datafile
'/u3/oradata/umc/rollback01.dbf' size 1024m,
'/u5/oradata/umc/rollback02.dbf' size 1024m,
'/u5/oradata/umc/rollback03.dbf' size 1024m,
'/u5/oradata/umc/rollback04.dbf' size 1024m;
File names contain tablespace name.
134Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupRollback segment creation
create rollback segment rbs01 tablespace rollback storage (initial 2m next 2m minextents 499 maxextents 499);create rollback segment rbs02 tablespace rollback storage (initial 2m next 2m minextents 499 maxextents 499);create rollback segment rbs03 tablespace rollback storage (initial 2m next 2m minextents 499 maxextents 499);create rollback segment rbs04 tablespace rollback storage (initial 2m next 2m minextents 499 maxextents 499);
ROLLBACK_SEGMENTS = (rbs01,rbs02,rbs03,rbs04)
135Michael S. Abbey – Advanced DBA Best Practices
Empowering the techies with do-it-yourself
136Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupv$dba
• v$ dynamic performance views• Over 200 with 9i
– most accessible when database mounted• DBA_ dictionary views similar to their
USER_ counterparts with ownership column
• There's nothing to hide• Grant access but no public synonyms
Mother may I ??
137Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupv$dba
connect / as sysdbaset echo off pages 0 lines 999 trimsp on feed offspool veedbaselect 'grant select on '||view_name||' to public;' from user_views where view_name like 'DBA%' or view_name like 'V_$%';
• Often used here and there by applications• V$ public synonyms probably exist• Granting must be done on view, not public synonym
for V$ to avoidORA-02030: can only select from fixed tables/views
138Michael S. Abbey – Advanced DBA Best Practices
Fluency in locally managed
139Michael S. Abbey – Advanced DBA Best Practices
• Different syntax than DM counterparts
• Temporary files end up in DBA_TEMP_FILES
• Free space bitmap in datafile headers
• Reduced recursive I/O
• Extent management local– autoallocate turns
Oracle loose with extent sizing
• Objects of differing sizes
• Lots of different sized extents
– uniform size {} defaults to 1Mb
Infrastructure setupLocally managed tablespaces
140Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupLocally managed tablespaces
create tablespace loc_geo_index datafile '/u01/oradata/loc_geo_index01.dbf' size 2000m, '/u04/oradata/loc_geo_index01.dbf' size 2000mextent management local autoallocate ;
create tablespace loc_geo_index datafile '/u01/oradata/loc_geo_index01.dbf' size 2000m, '/u04/oradata/loc_geo_index01.dbf' size 2000mextent management local uniform size 20m;
141Michael S. Abbey – Advanced DBA Best Practices
Infrastructure setupLM temp tablespace
create temporary tablespace loc_temp datafile '/u01/oradata/loc_temp01.dbf' size 2000m, '/u04/oradata/loc_temp02.dbf' size 2000mextent management local uniform size 20m;
• Keep extents in TEMP below 1000• Space allocated then controls uniform size• Great deal of the work done at startup involves
reconciliation and transfer of block ids from free to unallocated (fet$ to uet$)
142Michael S. Abbey – Advanced DBA Best Practices
• Make a point of starting from the beginning (create database)
• Pay attention to each piece in the puzzle
• Completeness checking at the end
• Practice practice practice
• Do temp and rollback right
• Know your friendly neighbourhood admin scripts
Infrastructure setupBest practices
143Michael S. Abbey – Advanced DBA Best Practices
Schema Environments
Best practices NOW will payoff down the road
144Michael S. Abbey – Advanced DBA Best Practices
Establish and follow guidelines
145Michael S. Abbey – Advanced DBA Best Practices
Schema environments Guidelines
• Thou shalt not give user an over-rich environment
• Thou shalt not sort or default to SYSTEM
• Thou shalt occupy space in appropriately-named tablespaces
• Thou shalt not have DBA, CONNECT, or RESOURCE
146Michael S. Abbey – Advanced DBA Best Practices
Smart when setting up your user environments
147Michael S. Abbey – Advanced DBA Best Practices
• Creating a user• Temporary tablespace• Use O/S authorization
for all host-based users
• Connection and privileges depend on function
create user sample identified by sx_p0 temporary tablespace loc_temp;
alter user sample identified externally;
-- Jack and Jill users
grant create session to jj_user;
Schema environments User creation
148Michael S. Abbey – Advanced DBA Best Practices
• Give necessary privileges and no moregrant create table, create view, create procedure, create trigger, create synonym, create snapshot, create database link to sample;
• Who has more than they need??
• Who has been given DBA
• Are the any privileges given out correctly?
Schema environments Application data users
149Michael S. Abbey – Advanced DBA Best Practices
select grantee, privilege -- SAMPLE is a schema from sys.dba_sys_privs -- deliberately set up to where privilege not in -- set the standard (select privilege from sys.dba_sys_privs where grantee = 'SAMPLE')UNIONselect grantee, granted_role from sys.dba_role_privs where granted_role in ('DBA','CONNECT', 'RESOURCE','EXP_FULL_DATABASE', 'IMP_FULL_DATABASE')order by 1;
Schema environments Who has more than they need??
150Michael S. Abbey – Advanced DBA Best Practices
GRANTEE PRIVILEGE------------------ -----------------------ABRAMSON DBAABRAMSOM DROP PUBLIC SYNONYMJACKSON CONNECTJACKSON RESOURCE JONES DBAREDMOND SELECT ANY TABLETHOMSON DBATHOMSON INSERT ANY TABLETHOMSON UPDATE ANY TABLEUQUART DBAUQUART UNLIMITED TABLESPACES
Schema environments Who has more than they need??
151Michael S. Abbey – Advanced DBA Best Practices
Adopt conventions that make sense
152Michael S. Abbey – Advanced DBA Best Practices
• Plan for the future
• Picture yourself at 4:15 am weeding through cryptic names
• Bind tablespace names to owner USERNAME
• Marry data and index tablespace names
Schema environments Naming conventions
153Michael S. Abbey – Advanced DBA Best Practices
• Based on USERNAME
Schema environments Naming tablespaces
• Based on function (data or index)
create tablespace DELIVERY datafile -- Data segments '/u01/oracle/oradata/delivery01.dbf' size 1024m, '/u05/oracle/oradata/delivery02.dbf' size 1024mdefault storage (initial 100m next 100, pctincrease 0);
create tablespace DELIVERYX datafile -- Index segments '/u02/oracle/oradata/deliveryx01.dbf' size 1024m, '/u03/oracle/oradata/deliveryx02.dbf' size 1024mdefault storage (initial 100m next 100, pctincrease 0);
154Michael S. Abbey – Advanced DBA Best Practices
Schema environments Naming tablespaces - violators
select distinct tablespace_name from sys.dba_segments where tablespace_name not in (owner,owner||'X') or (tablespace_name not in ('%'||owner||'%X%'||'%PTS%') or tablespace_name not in ('%'||owner||'%PTS%'));
Define rules first, implement, and track– Data segment names = USERNAME– Index segment names = USERNAME with X– Partitioned objects = USERNAME followed by
underscore ~ X for index partitions ~ PTS for partitioned tablespace
155Michael S. Abbey – Advanced DBA Best Practices
• Object name• Index non-unique or
unique indicator + sequential number
• Underscore separators• Pnnnn forcing fixed-
length names for sorts• Abbreviate carefully
• Imbed hp for hash-partitioned objects– Affects syntax for
maintenance
– Affects how operations are carried out
• Fix names after merges and splits
Schema environments Naming partitions
156Michael S. Abbey – Advanced DBA Best Practices
create table mail (originator varchar2(40), created date, . . . . . . read varchar2(1)) storage (initial 200m next 200m pctincrease 0)partition by range (created)(partition post_mail_p0001 values less than (to_date('01-JAN-2001','DD-MON-YYYY')) tablespace post_mail_pts_0001, partition post_mail_p0002 values less than (to_date('01-JUL-2001','DD-MON-YYYY')) tablespace post_mail_pts_0002, partition post_mail_p0003 values less than (to_date('01-JAN-2002','DD-MON-YYYY')) tablespace post_mail_pts_0003, . . . . . . partition post_mailing_pmax values less than (maxvalue) tablespace post_mail_pts_max);
Schema environments Data partitions
157Michael S. Abbey – Advanced DBA Best Practices
create index mail_n1 on mail (originator) (partition post_mail_n1_p0001 values less than tablespace post_mailx_pts_0001, partition post_mail_n1_p0002 values less than tablespace post_mailx_pts_0002, partition post_mail_n1_p0003 values less than tablespace post_mailx_pts_0003, . . . . . . partition post_mail_n1_pmax values less than (maxvalue) tablespace post_mailx_pts_max);
Schema environments Index partitions
158Michael S. Abbey – Advanced DBA Best Practices
Schema environments Naming indexes
2 schools of thought
Table name
N for non-unique indexesU for unique indexes
Separate series for each type
Table name
Abbreviation(s) for column(s) in index
159Michael S. Abbey – Advanced DBA Best Practices
Key index decisions
160Michael S. Abbey – Advanced DBA Best Practices
• Primary key constraints – Always name with _PK suffix– With using index are the same as unique
indexes– Allow foreign key references
Schema environments Unique index vs. constraint
alter table mailer add constraint mailer_pk
primary key (id) using index
storage (initial 300m next 300m pctincrease 0)
tablespace loc_mail_indx;
161Michael S. Abbey – Advanced DBA Best Practices
• Users allowed to do what they need and nothing more
• Segregate users by function
• Adopt and follow naming conventions
Schema environmentsBest practices
• Trap and report on violators
• 30 character limit– Abbreviate smartly– Abbreviate
consistently– Ensure all players are
aware
162Michael S. Abbey – Advanced DBA Best Practices
Distributed computing
Best practices NOW will payoff down the road
163Michael S. Abbey – Advanced DBA Best Practices
Manage (not mis-manage) your replication
environment
164Michael S. Abbey – Advanced DBA Best Practices
Distributed computing Snapshots are a snap
• Use same name as master table• Give them storage parameters just like tables• Negotiate refresh interval• Ensure there are no premature refreshes• Existing refresh intervals . . .select job,what,interval from user_jobs where lower(what) like 'dbms_refresh%';
165Michael S. Abbey – Advanced DBA Best Practices
Distributed computing Indexes on snapshots
• Primary key snapshots preferred
• ROWID (à la Oracle7) still supported in 9i
• PK constraint created with create snapshot
• Check for secondary indexes on snapshots by referring back to master
• Do not check and forget—do so on a regular basis
166Michael S. Abbey – Advanced DBA Best Practices
Distributed computing Indexes on snapshots
create snapshot log on vendor_prod storage (initial 2m next 2m pctincrease 0) tablespace sn_logs;
create snapshot vendor_prod refresh fast start with sysdate next sysdate+10/1440as select * from vendor_prod@producttablespace loc_snaps;
On master
On remote snapshot + secondary indexes
167Michael S. Abbey – Advanced DBA Best Practices
Thoroughness of indexing your replicated objects
168Michael S. Abbey – Advanced DBA Best Practices
Distributed computing Indexes on snapshots—completeness check
col inm form a10 head Indexcol column_name form a7 head Columncol column_position form 999 head Pos
break on inm
select index_name inm,column_position,column_name from user_ind_columns where table_name = upper('&1')minusselect index_name inm,column_position,column_name from user_ind_columns@product where table_name = upper('&1') order by 1,2;
169Michael S. Abbey – Advanced DBA Best Practices
Many many listeners
170Michael S. Abbey – Advanced DBA Best Practices
Distributed computing Some port with that?
• Use different ports for different connection requests
• Separate by source– By web server– By connection type (jvm, cgi)
• Speak with the SA before choosing ports
• Must be reflected on client(s)
171Michael S. Abbey – Advanced DBA Best Practices
Distributed computing Multiple ports / multiple listeners
LISTENER1521 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC)))
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = mofo1)(PORT = 1521)))))
LISTENER1522 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC)))
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = mofo1)(PORT = 1522)))))
tnsnames.ora aliases must reflect right port #s
172Michael S. Abbey – Advanced DBA Best Practices
• Know how to replicate• Fundamental to the
Internet environment• Offloading of
processing crucial to life expectancy of sites with very large user community
Distributed computingBest practices
• Completeness in your replication environment
• Multiple listeners• Listener per snapshot (if
enough to go around)• Fluency with
DBMS_JOB package
173Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer
Best practices NOW will payoff down the road
174Michael S. Abbey – Advanced DBA Best Practices
• Collecting of statistics like – Number of rows
– Average row length
– Distinct column values
– High value / low value
• Run unattended periodically from crontab
• Frequency decisions– Consult IT personnel
– Stale statistics more harm than good
• Using SQL*Plus analyze command OR PL/SQL packages
• Inspect last_analyzed
Cost-based optimizer DBA's best-friend
B
C
O
175Michael S. Abbey – Advanced DBA Best Practices
Decisions / approaches
176Michael S. Abbey – Advanced DBA Best Practices
• analyze is not going any where (yet) with 9i and 10g
• Perform from a central user
• Preferably O/S authenticated [externally]
Cost-based optimizer Setup
B
C
O
create user analyzer identified by pw;
alter user analyzer identified externally;
grant create session to analyzer;
grant analyze any to analyzer;
We always identify
externally
177Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer How often
• Size based– Pick a size– Treat those above threshold
differently• Usage based
– Track most frequently changed objects
– Exclude hot objects / treat differently
178Michael S. Abbey – Advanced DBA Best Practices
Ensure you begin at the beginning
179Michael S. Abbey – Advanced DBA Best Practices
• Delete statistics EVERYWHERE
• Flip or set entry in INIT.ora
• Liaise with user community
• Pick 2 or 3 days a week
• Assess run time
• Assess impact on system
Cost-based optimizer In the beginning
180Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Deleting statistics
set echo off pages 0 trimsp on lines 999
spool stat_del.sql
select 'exec dbms_stats.delete_schema_stats (ownname=>'||
''''||username||''''||')'
from sys.dba_users
where username not in ('SYS','SYSTEM');
spool off
set echo on feed on
spool stat_del
@stat_del
spool off
181Michael S. Abbey – Advanced DBA Best Practices
• Tables– Estimate sample {2-10}
percent– Populates USER_TABLES
• Indexes– Compute– Populates
USER_IND_COLUMNS
• Nothing short of a windfall
Cost-based optimizer Method
182Michael S. Abbey – Advanced DBA Best Practices
Always be aware of your options
183Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Using PL/SQL procedure
PROCEDURE GATHER_SCHEMA_STATS Argument Name Type In/Out Default? ----------------- ---------- ------ -------- OWNNAME VARCHAR2 IN ESTIMATE_PERCENT NUMBER IN DEFAULT BLOCK_SAMPLE BOOLEAN IN DEFAULT METHOD_OPT VARCHAR2 IN DEFAULT DEGREE NUMBER IN DEFAULT GRANULARITY VARCHAR2 IN DEFAULT CASCADE BOOLEAN IN DEFAULT STATTAB VARCHAR2 IN DEFAULT STATID VARCHAR2 IN DEFAULT OPTIONS VARCHAR2 IN DEFAULT OBJLIST DBMS_STATS OUT STATOWN VARCHAR2 IN DEFAULT
184Michael S. Abbey – Advanced DBA Best Practices
Four-part approach
1. Initialization parameters
2. Place objects in monitoring mode
3. Place a stake in the ground for each schema
4. Schedule regular statistic collection
I. Do not use for Oracle Applications
II. Do not use for third party apps – liaise with vendors
185Michael S. Abbey – Advanced DBA Best Practices
1 – INIT.ora
186Michael S. Abbey – Advanced DBA Best Practices
set pages 0 lines 999 trimsp on feed off
spool monon
select 'alter table '||owner||'.'||table_name||
' monitoring;'
from sys.dba_tables
where owner not in ('SYS','SYSTEM')
and nvl(duration,'X') <> 'SYS$TRANSACTION'
and nvl(iot_type,'X') <> 'IOT_OVERFLOW'
and nvl(temporary,'X') <> 'Y'
and monitoring <> 'YES';
spool off
2 - Turn on monitoring
187Michael S. Abbey – Advanced DBA Best Practices
set lines 999 trimsp on pages 0
spool sitg
select unique 'exec dbms_stats.gather_schema_stats (ownname=>'||
''''||owner||''''||',estimate_percent=>2,'||
'block_sample=>false,method_opt=>'||
''''||'for all indexed columns size 1'||
''''||',degree=>8,granularity=>'||''''||'ALL'||''''||
',cascade=>true);'
from sys.dba_tables
where owner not in ('SYS','SYSTEM');
spool off
3 – Stake in the ground
188Michael S. Abbey – Advanced DBA Best Practices
4 – Schedule regular collection
• turn on monitoring– for tables not already in monitoring mode
• gather empty– new tables created since last run– tables inadvertently taken out of
monitoring mode
• gather stale– those that have changed >= 10%
189Michael S. Abbey – Advanced DBA Best Practices
4.1 – Turn on monitoring
set pages 0 lines 999 trimsp on feed off
spool monon
select 'alter table '||owner||'.'||table_name||
' monitoring;'
from sys.dba_tables
where owner not in ('SYS','SYSTEM')
and nvl(duration,'X') <> 'SYS$TRANSACTION'
and nvl(iot_type,'X') <> 'IOT_OVERFLOW'
and nvl(temporary,'X') <> 'Y'
and monitoring <> 'YES';
spool off
190Michael S. Abbey – Advanced DBA Best Practices
4.2 – gather empty
select unique 'exec dbms_stats.gather_schema_stats '||
'(ownname=>'||''''||owner||''''||
',estimate_percent=>1,block_sample=>false,'||
'method_opt=>'||''''|| 'for all indexed'||
' columns'||' size 1'||''''||',options=>'||
''''||'gather empty'||''''||',degree=>8,'||
'granularity=>'||''''||'ALL'||''''||
',cascade=>true);'
from sys.dba_tables
where owner not in ('SYS','SYSTEM');
191Michael S. Abbey – Advanced DBA Best Practices
4.3 – gather stale
select unique 'exec dbms_stats.gather_schema_stats '||
'(ownname=>'||''''||owner||''''||
',estimate_percent=>1,block_sample=>false,'||
'method_opt=>'||''''|| 'for all indexed'||
' columns'||' size 1'||''''||',options=>'||
''''||'gather stale'||''''||',degree=>8,'||
'granularity=>'||''''||'ALL'||''''||
',cascade=>true);'
from sys.dba_tables
where owner not in ('SYS','SYSTEM');
192Michael S. Abbey – Advanced DBA Best Practices
Rationalize the approach
break on owner on table_nameset pages 70col table_name form a24col partition_name form a24col owner form a16col pct form 999,999.9select a.owner,a.table_name,b.partition_name, a.num_rows, (inserts+updates+deletes)/num_rows*100 pct, last_analyzed from sys.dba_tables a,sys.dba_tab_modifications b where a.table_name = b.table_name and a.owner = b.table_owner and (inserts+updates+deletes)/num_rows > .1 and nvl(num_rows,0) <> 0 order by 1,2
193Michael S. Abbey – Advanced DBA Best Practices
Tried, tested, and true - analyze
(but not recommended unless you have no choice)
194Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Using analyze
set echo off pages 0 feed off lines 999 trimsp on
spool anaall.sql
{analyze tables and indexes code}
spool off
set echo on timi on feed on
spool anaall
@anaall
spool off
Put the pieces together over the next 3 slides
195Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Using analyze on non-partitioned tables
select 'analyze table '||owner||'.'||table_name||
' estimate statistics for table sample '||
'20 percent;'
from sys.dba_tables
where owner not in ('SYS','SYSTEM')
and partitioned = 'NO'
order by owner,table_name;
196Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Using analyze on non-partitioned indexes
select 'analyze index '||owner||'.'||
index_name||
' compute statistics;'
from sys.dba_indexes
where owner not in ('SYS','SYSTEM')
and partitioned = 'NO'
order by owner,index_name;
197Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Using analyze on partitioned tables
select 'analyze table '||table_owner||'.'||
'.'||table_name||
' partition ('||partition_name||')'||
' estimate statistics sample 2 percent;'
from sys.dba_tab_partitions
where table_owner not in ('SYS','SYSTEM')
order by table_owner,table_name,partition_name;
198Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Using analyze on partitioned indexes
select 'analyze index '||index_owner||
'.'||index_name||
' partition ('||partition_name||')'||
' compute statistics;'
from sys.dba_ind_partitions
where index_owner not in ('SYS','SYSTEM')
order by index_owner,index_name,partition_name;
199Michael S. Abbey – Advanced DBA Best Practices
Not interfering with replication
200Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Exclusions with snapshots
and (owner,table_name) not in (select distinct log_owner,master from sys.dba_snapshot_logs union select log_owner,log_table from sys.dba_snapshot_logs)
and (owner,index_name) not in (select a.owner,a.index_name from sys.dba_indexes a, sys.dba_snapshot_logs b where a.table_name = b.master)
Dark side of the moon
201Michael S. Abbey – Advanced DBA Best Practices
• Analyzing collides with snapshot refreshes
• Restrictive lock inhibits job execution
• System load can skyrocket
• Horrific latch contention
6:57pm up 6 day(s), 7:12, 9 users, load average: 1.06, 1.08, 1.10
4:13am up 8 day(s), 7:12, 9 users, load average: 341.06, 309.08, 301.10
normalduring analyze
Cost-based optimizer Exclusions with snapshots
202Michael S. Abbey – Advanced DBA Best Practices
Stuff just too big to analyze
203Michael S. Abbey – Advanced DBA Best Practices
• DBA nightmare
• exclude based on row count
• gather stale takes care of most very big tables
• if still required– store large table names somwhere– join with dba_tables when building calls to
DBMS_STATS
Cost-based optimizer Exclusions – large objects
204Michael S. Abbey – Advanced DBA Best Practices
Cost-based optimizer Implementation without study
Stab
le e
nviro
nmen
t
Hastily implemented
collection plan
X-DBA
Eehah!
205Michael S. Abbey – Advanced DBA Best Practices
• Know your options
• Adopt an approach
• Liaise with consumer
• No cowboy implementation
• Staleness of statistics
Cost-based optimizerBest practices
• The whole schema• Ensure new objects are
analyzed– Whose responsibility
– Step in promotion of code and dependent objects
• ONLY option
206Michael S. Abbey – Advanced DBA Best Practices
Application tuning
Best practices NOW will payoff down the road
207Michael S. Abbey – Advanced DBA Best Practices
Allow everyone to EXPLAIN
themselves
208Michael S. Abbey – Advanced DBA Best Practices
Application tuning plustrce role
• Create at once when setting up a new instance or inheriting an old one
• plustrce.sql as SYS from ?/sqlplus/admin
• PLAN_TABLE beforehand using ?/rdbms/admin/utlxplan
• There's nothing to hide• Access to dynamic
performance tables used for – v_$sessstat
– v_$statname
– v_$session
• Give access to all
209Michael S. Abbey – Advanced DBA Best Practices
AUTOTRACE and beyond
210Michael S. Abbey – Advanced DBA Best Practices
• Want to write good code
• Arm them with the tools
• Imbed testing into coding – education fosters growth
Application tuning Empowering the developers
set autot trace exp
SP2-0613: Unable to verify PLAN_TABLE format or existence
SP2-0611: Error enabling EXPLAIN report
• Centrally managed PLAN_TABLE with public or private synonyms
211Michael S. Abbey – Advanced DBA Best Practices
Application tuning Foster smart coding habits
SQL> set autot trace exp
SQL> select * from mailing partition (mailing_p04);
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=164 Bytes=337676)
1 0 TABLE ACCESS (FULL) OF 'MAILING' (Cost=1 Card=164 Bytes=337676)
SQL> select * from mailing;
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=984 Bytes=2026056)
1 0 PARTITION RANGE (ALL)
2 1 TABLE ACCESS (FULL) OF 'MAILING' (Cost=2 Card=984 Bytes=2026056)
212Michael S. Abbey – Advanced DBA Best Practices
Understanding the cost
213Michael S. Abbey – Advanced DBA Best Practices
Application tuning Cost analysis
set echo off term off feed off ver off
select decode(id,0,'',
lpad(' ',2*(level-1))||level||'.'||position)||' '||
operation||' '||options||' '||object_name||' '||
object_type||' '||
decode(id,0,'Cost = '||position) Query_plan
from plan_table
connect by prior id = parent_id
and statement_id = upper('&1')
start with id = 0 and statement_id = upper('&1');
214Michael S. Abbey – Advanced DBA Best Practices
Application tuning Listen and listen closely
You can only compare costs between different wordings of the same SQL statement NOT across statements.
You won't get away with it!
215Michael S. Abbey – Advanced DBA Best Practices
Find potentially problematic SQL statements before it's too late
216Michael S. Abbey – Advanced DBA Best Practices
Application tuning Buffer gets measurement
select buffer_gets,sql_text,executions,
buffer_gets/executions
from v$sqlarea
where buffer_gets > 200000
and v$sqlarea.executions != 0
order by buffer_gets/executions desc
Good place to start
217Michael S. Abbey – Advanced DBA Best Practices
Assess I/O balance while applications interact with instance
218Michael S. Abbey – Advanced DBA Best Practices
col file_name form a30 head File
col tablespace_name form a20 head Tbsp
col a new_value preads
col c new_value pwrites
select sum(phyrds) a,sum(phywrts) c
from v$filestat;
select file_name,tablespace_name,
phyrds/&b*100 pctrd,phywrts/&d*100 pctwrt
from sys.dba_data_files ddf,v$filestat vf
where ddf.file_id = vf.file#
and (phyrds/&preads*100 > 5 or phywrts/&pwrites*100 > 5)
order by 3;
Application tuning I/O balance - primer
/u04
/u02
219Michael S. Abbey – Advanced DBA Best Practices
• Share the responsibility
• Make inroads with management
• Balanced I/O patterns
• Arm the developers so they can help themselves
Application tuningBest practices
• Compare relative costs within different wordings of the same statement
• Imbed in program development
• Pick reasonable measurement indicators
220Michael S. Abbey – Advanced DBA Best Practices
Working with OSS
Best practices NOW will payoff down the road
221Michael S. Abbey – Advanced DBA Best Practices
• The first place to start
• Be smart with your search criteria
• Save yourself and OSS time
• Someone else's problem yesterday is yours today
• Learn from others' experience
Working with OSS MetaLink
Me too!
222Michael S. Abbey – Advanced DBA Best Practices
• Use profiles– 10 per account– keep them up-to-date– organize in 1 central account
• Familiarize yourself with updates– current O/S? uname –a– current Oracle version tool herald
Working with OSS Be a smart DBA
223Michael S. Abbey – Advanced DBA Best Practices
Arm yourself with the necessary backup to your
request
224Michael S. Abbey – Advanced DBA Best Practices
Working with OSS Profiles
Organize by client and O/S
225Michael S. Abbey – Advanced DBA Best Practices
Working with OSS Be specific
Problem with rman
Oracle error when doing a
list backup command
Unique constraint
violation when trying to list
backup
226Michael S. Abbey – Advanced DBA Best Practices
• Keyword scan of free form entry
• Routed to subject experts
• Response time – 30-60 minutes– Severity 1 next to immediate
• Preferred contact method is email– ensure OSS has correct address– check incoming mail regularily
Working with OSS TAR intake
Be smartBe smartBe smartBe smartBe smartBe smartBe smart
227Michael S. Abbey – Advanced DBA Best Practices
Working with OSS Tools of the trade
lert log
ode racle error(s)
race file(s)xplain plan
init.ora
228Michael S. Abbey – Advanced DBA Best Practices
• Have realistic expectations
• Do your homework first (MetaLink)
• Correct contact information
• Be prepared
Working with OSSBest practices
• Use email—best communications performance
• Respond to requests• No games
229Michael S. Abbey – Advanced DBA Best Practices
Working with OSS
230Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge
Best practices NOW will payoff down the road
231Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Admin scripts
• ?/rdbms/admin
• Familiarize yourself with the contents of this directory in your spare timespare time
• Two part naming convention– dbmsabcd.sql– prvtabcd.plb
232Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Hard-core education
Just what do you think you're doing Dave?
233Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Smart professionals
$$$$
234Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge In a bind
• Work with your developers to bind everything– perl– SQL*Plus– AOWBI
• Re-usable SQL• Computation of hash
value very restrictive
select sql_text,count(*) from v$sqlarea where instr(sql_text,'":SY"') > 0 group by sql_text;
select count(*) from v$sqlarea;
select count(*) from v$sqlarea where sql_text like '%'||''''||'%';
235Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Index foreign keys
• Development requires primary/foreign key relationships to protect data integrity
• Primary key constraints using index• Never think of or take the time to
index foreign key columns• Locks on deleting from parent
col table_name form a20 head Tablecol column_name form a30 heading 'Missing index for FK'
primary key
foreign key
index
INDEX
HUGE locking problems
oops!
236Michael S. Abbey – Advanced DBA Best Practices
select dc.table_name,dcc.column_name from sys.dba_constraints dc, sys.dba_cons_columns dcc where dc.constraint_type = 'R' and dc.constraint_name = dcc.constraint_name and dc.owner not in ('SYS','SYSTEM') and not exists (select ' ' from sys.dba_indexes di,sys.dba_ind_columns dic where di.index_name = dic.index_name and di.table_name = dc.table_name and dic.column_name = dcc.column_name);
Hodge-podge Finding non-indexed foreign keys
237Michael S. Abbey – Advanced DBA Best Practices
• Frustrating venture• Endless Oracle errors• Protection as well as integrity
• constraint_type – C for check
– R for reference
– P for primary
• r_constraint_name• r_owner
Hodge-podge Manage RI before it manages you
238Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Manage RI before it manages you
SYS_SYS_alter table … add constraint …_pk primary key (…) using index storage (initial N next N pctincrease 0) tablespace …;
alter table … add constraint …_fk foreign key (…) references … (…);
Thou shalt name your constraints
Thou shalt alter table … add constraint
239Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Saving foreign key constraints – part 1
select 'alter table '||uc1.owner||'.'||uc1.table_name|| chr(10)||' drop constraint '|| uc1.constraint_name||';' from user_constraints uc1, -- foreign key constraint def user_constraints uc2, -- primary key constraint def user_cons_columns ucc1, -- columns in foreign key user_cons_columns ucc2 -- columns in primary key where uc1.r_constraint_name = upper(uc2.constraint_name) and ucc2.constraint_name = upper(uc2.constraint_name) and ucc1.constraint_name = uc1.constraint_name and uc2.table_name in ({list_of_tables});
DBAs worth their weight in goldDBAs worth their weight in gold
240Michael S. Abbey – Advanced DBA Best Practices
select 'alter table '||uc1.owner||'.'||uc1.table_name|| ' add constraint '||chr(10)||' '|| uc1.constraint_name||chr(10)||' foreign key ('|| ucc1.column_name||')'|| ' references '||uc2.owner||'.'||uc2.table_name|| ' ('||ucc2.column_name||');' from user_constraints uc1, -- foreign key constraint def user_constraints uc2, -- primary key constraint def user_cons_columns ucc1, -- columns in foreign key user_cons_columns ucc2 -- columns in primary key where uc1.r_constraint_name = upper(uc2.constraint_name) and ucc2.constraint_name = upper(uc2.constraint_name) and ucc1.constraint_name = uc1.constraint_name and uc1.table_name in ({list_of_tables});
Hodge-podge Saving foreign key constraints – part 2
241Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Extract source code – procedures / functions
set lines 9999 trimsp on pages 0 echo off feed off ver off sqlbl onspool pfselect decode(line,1,'create or replace '||text,text) from user_source where name = upper('&1') order by line;prompt /spool off
• Be prepared / be smart• Quicker and more useful than
alter procedure GEO_MAINT compile;sho errors package geo_maint
242Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Extract source code - packages
set lines 9999 trimsp on pages 0 echo off feed off ver off sqlbl onspool pkgselect decode(line,1,'create or replace '||text,text) from user_source where name = upper('&1') and type = 'PACKAGE' order by line;prompt /promptselect decode(line,1,'create or replace '||text,text) from user_source where name = upper('&1') and type = 'PACKAGE BODY' order by line;prompt /spool off
243Michael S. Abbey – Advanced DBA Best Practices
• Do not have the same partition implementation as their data
• Boundaries specified on creation
• Must be rebuilt from scratch when performing partition maintenance– adding or dropping– splitting or merging
Hodge-podge Global partitioned indexes
244Michael S. Abbey – Advanced DBA Best Practices
• List or range partitioning
• Painstakingly adopted naming convention
• Date or surrogate key based approach easiest to work with
• Ensure there are no rows in last 2 partitions
Hodge-podge Avoid global index rebuilds
245Michael S. Abbey – Advanced DBA Best Practices
• Partition naming - table– table name + highest possible date– e.g., SUBS_20020831
• format of date mask important
• allows for pseudo-sequential queries
• Partition naming – index– table name + index name + U/N/F identifier– unique / non-unique / function-based
Hodge-podge Avoid global index rebuilds
it's 3AM – your planning will
pay off
246Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Avoid global index rebuilds
set pages 0 lines 999 trimsp on ver off echo off
col a new_value mxname
select max(partition_name) a from dba_tab_partitions where table_owner = upper('&1') and table_name = upper('&2');
select 'Partitioned table '||upper('&1')||'.'|| upper('&2')||' has '||count(*)|| ' rows in last partition ('||'&mxname'||')' from &1..&2 partition (&mxname) having count(*) = 0;
set lines 75
247Michael S. Abbey – Advanced DBA Best Practices
set echo off feed off pages 0select distinct '@lp_look '||table_owner|| ' '||table_name from sys.dba_tab_partitions order by table_owner,table_name;. . . SQL> @lp_look TERA WORKSQL> @lp_look TERA YIELD. . .Partitioned table TERA.WORK has 3 rows in last partition (TERA_WORK_P20030630)Partitioned table TERA.YIELD has 8 rows in last partition (TERA_YIELD_P20030831)
Hodge-podge Avoid global index rebuilds
248Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Shutdown abort
When running with or without media recovery enabled
SQL> shutdown abortORACLE instance shutdown.SQL> startup restrict. . .SQL> shutdown. . .ORACLE instance shutdown.
No jobs submitted in
restricted mode
249Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge A word on OEM
250Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Weaning yourself of Server Manager
• No more svrmgrl with release 9i• No more internal user• Done exclusively in SQL*Plus,
unlike 8i with either/or• Close the one remaining
inconsistency between the way these 2 tools behave
• Ripple affect on backup scripts
9i
251Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Ensuring tools behave exactly the same way
SVRMGR> select count(*), cus_id
2> from reader
3>
4> group by cus_id
5> having count(*) > 1;
SQL> select count(*), cus_id
2> from reader
3>
SQL>
• Server Manager tolerates
blank lines, whereas
SQL*Plus didn't until set sqlbl on
>= 8i
252Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Change in logon procedures
connect internal
/nologconnect / as sysdba
8i
9i10g
253Michael S. Abbey – Advanced DBA Best Practices
Hodge-podge Online redo log maintenance
• To protect you from yourself, rename the members …
select group#,member from v$logfileorder by group#,memberGROUP# MEMBER------ ----------------------- 1 /redo1/beg9/redo01a.log 1 /redo2/beg9/redo01b.log 2 /redo2/beg9/redo02a.log 2 /redo1/beg9/redo02b.log
Before … After …select group#,member from v$logfileorder by group#,memberGROUP# MEMBER------ ----------------------- 1 /redo1/beg9/log1_g1.log 1 /redo2/beg9/log2_g1.log 2 /redo2/beg9/log1_g2.log 2 /redo1/beg9/log2_g2.log
254Michael S. Abbey – Advanced DBA Best Practices
practices allow your systems to better.
Better systems = users.
The chicken or the egg??
users contribute to a smarter DBA
who
ha
ve
are able
to
and become
256Michael S. Abbey – Advanced DBA Best Practices
DBA Best Practices