Академический Документы
Профессиональный Документы
Культура Документы
Agenda
Preamble / raison d'tre Monitoring INIT.ora Do not wait for waits Integrity of your backups
Agenda
Infrastructure setup Schema environments Cost-based optimizer Distributed computing Application tuning
Agenda
Working with Oracle Support Services Hodge podge
Apps
Terminology is Instance parameters portable across version v$parameter v$instance Same background processes SQL statement v$sqlarea Method rather than v$sqltext guesswork Ripple affect Memory structures
Fix this / break that v$librarycache
Turn this
Tune I/O
Into this!!!!!
Monitoring
10
Caveat
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.
11
12
Monitoring
The 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_DATA AD_INDEX RBS SYSTEM TEMP select distinct a.tablespace_name from dba_tablespaces a, dba_free_space b where a.tablespace_name = b.tablespace_name (+);
13
Monitoring
I'm too full
set pages 100 col ts_name form a20 head 'Tablespace'
Environment
14
Monitoring
I'm too full
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,
Code
15
Monitoring
Thresholds
Percentage based on
Growth patterns Past experiences Archival habits
LM tablespaces with extent management local uniform size The dba_free_space poltergeist
Infrastructure issues
16
Ensure you trap potential object extension problems before your applications
17
Monitoring
Unable to extend
Less free space available than potential object extension Objects within 5 extents of their maximum
col col col col col col owner form a5 head Owner segment_type form a5 head Type segment_name form a24 head Name next_extent form 999,999,990 head NextEXT max_extents form 9,999 head MaxEXT extents form 9,999 head CurrEXT
18
Monitoring
Unable to extend available extents
prompt prompt Objects that cannot extend ... prompt
select from where and owner,segment_type,segment_name,next_extent sys.dba_segments ds segment_type in ('TABLE','INDEX') next_extent > (select max(bytes) from sys.dba_free_space dfs where dfs.tablespace_name = ds.tablespace_name) order by 1,2,3;
19
Monitoring
Unable to extend within 5
prompt prompt Objects within 5 of max extents ... prompt select from where and owner,segment_type,segment_name,max_extents,extents sys.dba_segments ds segment_type in ('TABLE','INDEX') max_extents - extents <= 5;
Avoid maxextents unlimited will never detect objects with too many extents Number arbitrary -- based on DBA experiences
20
21
Monitoring
Locally managed is what!!
22
Monitoring
Locally managed temp Use V$TEMP_FILE and V$TEMP_SPACE_HEADER Useful to assess cleanup of temporary segments
col col col col trname form a23 head File tablespace_name form a7 head TSName bytes form 9,999,999,990 bytes_free like bytes
23
Monitoring
Locally managed temp
select tsh.tablespace_name, '..'||substr(tf.name,length(name)-23) trname, tf.bytes,tsh.bytes_free from v$tempfile tf, v$temp_space_header tsh where tf.file# = tsh.file_id;
TS Name -------LOC_TEMP LOC_TEMP LOC_TEMP LOC_TEMP File BYTES BYTES_FREE ----------------------- -------------- -------------../od01/loc_temp01.dbf 2,098,200,576 1,887,436,800 ../od02/loc_temp02.dbf 2,098,200,576 1,258,291,200 ../od04/loc_temp03.dbf 2,098,200,576 1,887,436,800 ../od02/loc_temp04.dbf 2,098,200,576 1,887,436,800
24
Ensure you protect what precious space exists in the SYSTEM tablespace
25
Monitoring
Outa SYSTEM buddy!!
SYSTEM is the last place you can afford object extension SOURCE$ and OBJ$ love space
select username from dba_users where default_tablespace = 'SYSTEM';
select username from dba_users where temporary_tablespace = 'SYSTEM';
What did your DBA tell you?? I would never use SYSTEM!!
26
Ensure you are in synch with the status of your rollback segments
27
Monitoring
Rollback segments
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
select from where and segment_name dba_rollback_segs status <> 'ONLINE' tablespace_name <> 'SYSTEM';
RBS01
28
Detect problems with your job stream before it plagues your application operations
29
Monitoring
The job stream
30
Monitoring
Job run details
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)
INTERVAL
Exclusions
and what <> 'abcdefghi'; and job not in (210,222,388); and instr (replace (lower(interval, ' ',null)) <> 'sysdate+1';
31
Monitoring
Unbreakable
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'; Smarts to ensure you begin do not un-break what is for jobrec in jobstofix supposed to be broken loop dbms_job.run(jobrec.job); end loop; end; /
32
Ensure unusable index partitions are caught by you, not your apps
33
Monitoring
Unusable index partitions
Automagically, index partitions are marked unusable Aborted direct path Loader sessions Some partition maintenance operations local Partition maintenance operations global
select 'alter index '||owner||'.'||index_name|| ' rebuild partition '||partition_name||';' from dba_ind_partitions where status= 'UNUSABLE';
34
3 "L" words locks & latches turn into lousy performance if not detected early
35
Monitoring
Locks
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
v$session paddr
v$process
addr spid
36
Monitoring
Latches
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
37
Monitoring
Latches
col Requests form 999,999,999,990 head 'Requests' col PctMiss form 99.90 head 'PCTMiss'
from v$latch
where misses/decode(gets+misses,0,-1,gets+misses)*100 > 10 order by gets desc;
38
Monitoring
Latches
X:Y
39
Monitoring
Latches
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
40
41
Monitoring
System load
#!/bin/ksh typeset -i THRESHOLD typeset -i LOAD HOUR=$(date +%H) if (( $HOUR > 7 && $HOUR < 17 )); then THRESHOLD=$1 else THRESHOLD=$2 fi tmpuptime=`uptime` tmploads=${tmpuptime##*average:} LOAD=${tmploads%%.*} if (( $LOAD > $THRESHOLD )); then echo "Load of $LOAD exceeded threshold of $THRESHOLD" exit 1 fi exit 0
42
43
Monitoring
Disk usage
44
45
Monitoring
SQL statement contention
46
Monitoring
SQL statement contention
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
group by substr(sql_text,1,80)
having count(*) > 100;
47
48
Monitoring
Alert log
Ignore list
Err on the side of the clientif the pages are not necessary, add to the exclude list.
49
50
Monitoring
Invalid objects
oracle> grep il dbms_job *sql a0800150.sql catjobq.sql dbmsjob.sql e0800150.sql statsauto.sql statscusr.sql statspack.sql oracle> sqlplus /nolog
SQL> connect / as sysdba . . . SQL> @dbmsjob . . . . . . SQL> @prvtjob.plb
51
52
Monitoring
Standby database is it up?
But I'm still on 8, what should I do?? typeset -i LINES Replace line export log_history=\$log_history 1 with echo "connect / as sysdba internal, and desc v$log_history get rid of the exit"| sqlplus -s /nolog > recid.log /nolog! LINES=`grep RECID recid.log|wc -l` if (( $LINES = 0 )) then echo Standby down exit 1 else echo Standby OK exit 0 fi
53
Monitoring
Standby 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
54
Monitoring
Is standby useable?
Do an a regular basis Weekly, bi-weekly, every 48 hours? Script and inspect output Significant output (dual??)
echo "/ as sysdba alter database open read only; describe dual; shutdown immediate startup nomount; alter database mount standby database;" | sqlplus -s > roc.log LINES=`grep DUMMY roc.log|wc -l` if [ $LINES = 1 ] then echo OK exit 0 else echo Problem @standby ... exit 1 fi
55
Monitoring
Direct inserts on master
This is a problem on the standby, so ya'd better watch out!
All transactions propagated from master to standby via archived redo logs. Direct inserts not logged!
Beware or else
56
Monitoring
Direct inserts on master
57
Monitoring
Detection of nologging activities
col col col col tablespace_name form a20 head 'Tablespace' file_name form a30 head 'File' tablespace_name form a20 head 'Tablespace' 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');
Resolution Babette
58
59
Monitoring
Table statistics
-- Not select from where and or
-- Not select from where and and
60
61
Monitoring
The 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}
62
Monitoring
The real story
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
63
Monitoring
Dollar signs
Familiarize yourself with the v$ views Available when database mounted and not open Column names inconsistent with dba_ counterparts
select table_name from dict where table_name like 'V$%' order by 1;
64
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
65
Monitoring
sys_dba_segs
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
66
Monitoring
This is the end
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
sys.tab$ t sys.tabpart$ tp sys.clu$ c sys.ind$ i sys.indpart$ ip sys.lob$ l sys.tabsubpart$ tsp sys.indsubpart$ isp sys.lobfrag$ lf
67
Monitoring
Caveat at upgrade time
68
Monitoring
So many alerts!!
69
70
Monitoring
Autoextension
Oracle is known to not do a very good job of recovering from aborted autoextension Cleanup after abend not handled well
71
Monitoring
Autoextension create table aemon ( file_name sdate bytes insert select from where
72
Monitoring
Autoextension
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;
73
Monitoring
Best practices
Connection testing Anticipate common problematic areas Be thorough and proactive Email gateway Share the load
Page and/or email Document via some form of tracking system MetaLink MetaLink MetaLink MetaLink MetaLink MetaLink
74
INIT.ora
75
INIT.ora
Organization Compatibility Shared pool Ramifications Undocumented parameters
76
77
INIT.ora
Organization
Significant defaults
Hard-code Movements between versions
78
INIT.ora
Compatibility
Hard-code
Surprises during upgrades Are you going far enough
New features
Can I use them? Can I go back?
79
80
INIT.ora
Shared pool
81
INIT.ora
82
83
INIT.ora
Ramifications of higher values
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
DB_CACHE_SIZE LARGE_POOL_SIZE SHARED_POOL_SIZE
set set set set set set set set set shmsys:shminfo_shmmax=4294967295 shmsys:shminfo_shmmin=1 shmsys:shminfo_shmmni=100 shmsys:shminfo_shmseg=10 semsys:seminfo_semmni=100 semsys:seminfo_semmsl=500 semsys:seminfo_semmns=500 semsys:seminfo_semopm=1000 semsys:seminfo_semvmx=32767
OPEN_CURSORS
PROCESSES
84
85
INIT.ora
Undocumented parameters x$ksppi
Name --------ADDR INDX INST_ID KSPPINM KSPPITY KSPPDESC KSPPIFLG Type ---------------RAW(4) NUMBER NUMBER VARCHAR2(64) NUMBER VARCHAR2(64) NUMBER
x$ksppcv
Name ----------ADDR INDX INST_ID KSPPSTVL KSPPSTDF KSPPSTVF KSPPSTCMNT Type -------------RAW(4) NUMBER NUMBER VARCHAR2(512) VARCHAR2(9) NUMBER VARCHAR2(255)
86
INIT.ora
Undocumented 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 _allow_resetlogs_corruption _corrupted_rollback_segments _db_handles_cached _shared_pool_reserved_min_alloc 5 4400 KSPPSTVL FALSE KSPPDESC allow resetlogs even if it will cause corruption corrupted undo segment list Buffer handles cached each process minimum allocation size in bytes for reserved area of shared pool -------------------------------- --------- ---------------------------------
87
INIT.ora
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
Issues Rich
88
89
90
DBA_ views
dba_blockers (catblock.sql)
91
92
93
94
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 SQL*Net message from client wait situations
db_file sequential read db file scattered read
95
96
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 multitasking
Issues Rich
97
98
3. Control file
99
100
Best case scenario Separate server to restore image Deliberate complete media recovery
recover database . . . recover datafile . . . recover tablespace . . .
101
Make sure you have performed the recovery portion of your image is NOT tested
102
103
104
Create the database (see in Infrastructure section) Run 3 or 4 full database imports
Just definitions NOT data
1 inctype=system
online rollback segments just built
inctype=restore
rows=n ignore=y
rows=n ignore=y
105
106
107
set pages 0 trimsp on lines 999 echo off feed off select 'cp standby.ctl '||name from v$controlfile;
108
109
Mismatch between UNIX environment and Server character set Determined by NLS_LANG
(c) Copyright 2001 Oracle Corporation. All rights reserved.
Wake-up
Export: Release 9.2.0.5 - Production on Sat Sep 31 16:47:52 2004 Connected to: Oracle9i Enterprise Edition Release 9.2.0.5 - Production
110
Collge Brbeuf
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!
111
112
triggers=n
9i
113
114
115
Export file created by EXPORT:V09.20.00.05 via conventional path import done in US7ASCII character set and AL16UTF16 NCHAR character set Import terminated successfully without warnings.
116
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
117
Infrastructure setup
The
Oracle
9i
118
Infrastructure setup
A 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 N more than me!!
Please sit
119
Infrastructure setup
Creating the database
Do it yourself
Create database
controlfile character set maxlogfiles maxloghistory maxlogmembers maxdatafiles
create database umc undo tablespace rollback default temporary tablespace temp;
120
121
Infrastructure setup
Creating the database yourself
122
Infrastructure setup
Create database phase 1
startup nomount create database umc controlfile reuse maxlogfiles 16 maxlogmembers 2 maxdatafiles 2048 maxloghistory 1000 character set we8iso8859p1 datafile '/data01/oracle/umc/dbs1_umc.dbf' size 250m logfile 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;
123
Infrastructure setup
Create database (1) important points
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 smaller 6. 2 dual membered groups
startup nomount
create database umc controlfile reuse maxlogfiles 16 maxlogmembers 2 maxdatafiles 30 maxloghistory 1000 character set
1 2
3 4 5 6
124
Infrastructure setup
A 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
125
Infrastructure setup
Create database phase 2
shutdown startup alter tablespace system default
126
Infrastructure setup
Create database (2) important points
1 1. No more to be done nomount rest of work requires 2 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
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);
127
Infrastructure setup
Create 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
SQL utilities
""
128
Infrastructure setup
Create database phase 4
Right option(s)
129
Infrastructure setup
Database is created
Data dictionary has been populated
First non-system rollback segment exists and is online
130
Infrastructure setup
pupbld.sql
131
132
Infrastructure setup
Rollback segments
4 to 6 equally-sized Large segment for large segments transactions minextents and maxextents 2 to 4Gb the same at creation time Larger extent size 500k to 2Mb extents Cap at creation time Not in locally managed No guarantee unless the tablespaces only one online Mentioned in INIT.ora
133
Infrastructure setup
Rollback segment tablespace(s)
'/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;
134
Infrastructure setup
Rollback segment creation
create rollback segment rbs01 tablespace storage (initial 2m next 2m minextents 499 maxextents 499); create rollback segment rbs02 tablespace storage (initial 2m next 2m minextents 499 maxextents 499); create rollback segment rbs03 tablespace storage (initial 2m next 2m minextents 499 maxextents 499); create rollback segment rbs04 tablespace storage (initial 2m next 2m minextents 499 maxextents 499); rollback
rollback
rollback
rollback
ROLLBACK_SEGMENTS = (rbs01,rbs02,rbs03,rbs04)
135
136
Infrastructure setup
v$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 ??
137
Infrastructure setup
v$dba
connect / as sysdba set echo off pages 0 lines 999 trimsp on feed off spool veedba select '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 avoid
ORA-02030: can only select from fixed tables/views
138
139
Infrastructure setup
Locally managed tablespaces
Different syntax than DM counterparts Temporary files end up in DBA_TEMP_FILES Free space bitmap in datafile headers Reduced recursive I/O
140
Infrastructure setup
Locally managed tablespaces
create tablespace loc_geo_index datafile '/u01/oradata/loc_geo_index01.dbf' size 2000m, '/u04/oradata/loc_geo_index01.dbf' size 2000m extent management local autoallocate ;
create tablespace loc_geo_index datafile '/u01/oradata/loc_geo_index01.dbf' size 2000m, '/u04/oradata/loc_geo_index01.dbf' size 2000m extent management local uniform size 20m;
141
Infrastructure setup
LM temp tablespace
create temporary tablespace loc_temp datafile '/u01/oradata/loc_temp01.dbf' size 2000m, '/u04/oradata/loc_temp02.dbf' size 2000m extent 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$)
142
Infrastructure setup
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
143
Schema Environments
144
145
Schema environments
Guidelines
Thou shalt not give user an overrich 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
146
147
Schema environments
User creation
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;
148
Schema environments
Application data users
Who has more than they need?? Who has been given DBA Are the any privileges given out correctly?
149
Schema environments
Who has more than they need??
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') UNION select grantee, granted_role from sys.dba_role_privs where granted_role in ('DBA','CONNECT', 'RESOURCE','EXP_FULL_DATABASE', 'IMP_FULL_DATABASE') order by 1;
150
Schema environments
Who has more than they need??
GRANTEE -----------------ABRAMSON ABRAMSOM JACKSON JACKSON JONES REDMOND THOMSON THOMSON THOMSON UQUART UQUART PRIVILEGE ----------------------DBA DROP PUBLIC SYNONYM CONNECT RESOURCE DBA SELECT ANY TABLE DBA INSERT ANY TABLE UPDATE ANY TABLE DBA UNLIMITED TABLESPACES
151
152
Schema environments
Naming conventions
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
153
Schema environments
Naming tablespaces
Based on USERNAME
create tablespace DELIVERY datafile -- Data segments '/u01/oracle/oradata/delivery01.dbf' size 1024m, '/u05/oracle/oradata/delivery02.dbf' size 1024m default storage (initial 100m next 100, pctincrease 0);
154
Schema environments
Naming tablespaces - violators
155
Schema environments
Naming partitions
Object name Index non-unique or unique indicator + sequential number Underscore separators Pnnnn forcing fixedlength names for sorts Abbreviate carefully
156
Schema environments
Data partitions
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);
157
Schema environments
Index partitions
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);
158
Schema environments
Naming indexes
Table name Abbreviation(s) for column(s) in index Table name
159
160
Schema environments
Unique index vs. constraint
161
Schema environments
Best practices
Users allowed to do what they need and nothing more Segregate users by function
Adopt and follow naming conventions
Trap and report on violators 30 character limit Abbreviate smartly Abbreviate consistently Ensure all players are aware
162
Distributed computing
163
164
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 . . .
165
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 forgetdo so on a regular basis
166
Distributed computing
Indexes on snapshots
On master
create snapshot log on vendor_prod storage (initial 2m next 2m pctincrease 0) tablespace sn_logs;
On remote
create snapshot vendor_prod refresh fast start with sysdate next sysdate+10/1440 as select * from vendor_prod@product tablespace loc_snaps;
167
168
Distributed computing
Indexes on snapshotscompleteness check
col inm form a10 head Index col column_name form a7 head Column col column_position form 999 head Pos
break on inm
select from where minus select from where order index_name inm,column_position,column_name user_ind_columns table_name = upper('&1') index_name inm,column_position,column_name user_ind_columns@product table_name = upper('&1') by 1,2;
169
170
Distributed computing
Some port with that?
171
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 = tnsnames.ora aliases must reflect right port (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = mofo1)(PORT = 1522)))))
#s
172
Distributed computing
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
Completeness in your replication environment Multiple listeners Listener per snapshot (if enough to go around) Fluency with DBMS_JOB package
173
Cost-based optimizer
174
Cost-based optimizer
DBA's best-friend
Frequency decisions
Consult IT personnel Stale statistics more harm than good
175
Decisions / approaches
176
Cost-based optimizer
Setup
analyze is not going any where (yet) with C 9i and 10g Perform from a central user Preferably O/S authenticated [externally]
create user analyzer identified by pw; alter user analyzer identified externally;
177
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
178
179
Cost-based optimizer
In the beginning
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
180
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
181
Cost-based optimizer
Method
Tables
Estimate sample {2-10} percent Populates USER_TABLES
Indexes
Compute Populates
USER_IND_COLUMNS
182
183
Cost-based optimizer
Using PL/SQL procedure
PROCEDURE GATHER_SCHEMA_STATS Argument Name Type ----------------- ---------OWNNAME VARCHAR2 ESTIMATE_PERCENT NUMBER BLOCK_SAMPLE BOOLEAN METHOD_OPT VARCHAR2 DEGREE NUMBER GRANULARITY VARCHAR2 CASCADE BOOLEAN STATTAB VARCHAR2 STATID VARCHAR2 OPTIONS VARCHAR2 OBJLIST DBMS_STATS STATOWN VARCHAR2 In/Out -----IN IN IN IN IN IN IN IN IN IN OUT IN Default? -------DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT
184
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
185
1 INIT.ora
186
2 - 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'
187
'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
188
gather empty
new tables created since last run tables inadvertently taken out of monitoring mode
gather stale
those that have changed >= 10%
189
190
191
192
193
Tried, tested, and true analyze (but not recommended unless you have no choice)
194
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
195
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;
196
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;
197
Cost-based optimizer
Using analyze on partitioned tables
select 'analyze table '||table_owner||'.'|| '.'||table_name||
198
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;
199
200
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)
201
Cost-based optimizer
Exclusions with snapshots
Analyzing collides with snapshot refreshes Restrictive lock inhibits job execution System load can skyrocket Horrific latch contention
normal during analyze
202
203
Cost-based optimizer
Exclusions large objects
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
204
Cost-based optimizer
Implementation without study
XDBA
205
Cost-based optimizer
Best practices
ONLY option
206
Application tuning
207
208
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
209
AUTOTRACE
and beyond
210
Application tuning
Empowering the developers
Want to write good code Arm them with the tools Imbed testing into coding education fosters growth
set autot trace exp SP2-0613: Unable to verify PLAN_TABLE format or existence SP2-0611: Error enabling EXPLAIN report
211
Application tuning
Foster smart coding habits
SQL> set autot trace exp SQL> select * from mailing partition (mailing_p04); Execution Plan ---------------------------------------------------------0 1 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=164 Bytes=337676) TABLE ACCESS (FULL) OF 'MAILING' (Cost=1 Card=164 Bytes=337676)
---------------------------------------------------------0 1 2 0 1 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=984 Bytes=2026056) PARTITION RANGE (ALL) TABLE ACCESS (FULL) OF 'MAILING' (Cost=2 Card=984 Bytes=2026056)
212
213
Application tuning
Cost analysis
set echo off term off feed off ver off select decode(id,0,'', lpad(' ',2*(level-1))||level||'.'||position)||' '||
214
Application tuning
Listen and listen closely
You can only compare costs between different wordings of the same SQL statement NOT across statements.
215
216
Application tuning
Buffer gets measurement
select buffer_gets,sql_text,executions, buffer_gets/executions from v$sqlarea where buffer_gets > 200000
217
218
Application tuning
I/O balance - primer
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;
/u02 /u04
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;
219
Application tuning
Best practices
Compare relative costs within different wordings of the same statement Imbed in program development Pick reasonable measurement indicators
220
221
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
222
Use profiles
10 per account keep them up-to-date organize in 1 central account
223
224
225
226
Keyword scan of free form entry Routed to subject experts Response time
30-60 minutes Severity 1 next to immediate
227
lert log
228
Be prepared
229
230
Hodge-podge
231
Hodge-podge
Admin scripts
?/rdbms/admin Familiarize yourself with the contents of this directory in your spare time Two part naming convention
dbmsabcd.sql prvtabcd.plb
232
Hodge-podge
Hard-core education
Just what do you think you're doing Dave?
233
Hodge-podge
Smart professionals
$$
234
Hodge-podge
In a bind
select count(*) from v$sqlarea; select count(*) from v$sqlarea where sql_text like '%'||''''||'%';
235
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 oops! index foreign key columns Locks on deleting from parent
primary key
index foreign key INDEX
col table_name form a20 head Table col column_name form a30 heading 'Missing index for FK'
236
Hodge-podge
Finding non-indexed foreign keys
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);
237
Hodge-podge
Manage RI before it manages you Frustrating venture Endless Oracle errors constraint_type C for check Protection as well as integrity
R for reference P for primary
r_constraint_name r_owner
238
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
239
Hodge-podge
240
Hodge-podge
241
Hodge-podge
242
Hodge-podge
Extract source code - packages
set lines 9999 trimsp on pages 0 echo off feed off ver off sqlbl on spool pkg select decode(line,1,'create or replace '||text,text) from user_source where name = upper('&1') and type = 'PACKAGE' order by line; prompt / prompt select 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
243
Hodge-podge
Global partitioned indexes
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
244
Hodge-podge
Avoid global index rebuilds
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
245
Hodge-podge
Avoid global index rebuilds
246
Hodge-podge
Avoid global index rebuilds
set pages 0 lines 999 trimsp on ver off echo off col a new_value mxname select from where and max(partition_name) a dba_tab_partitions table_owner = upper('&1') 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
247
Hodge-podge
Avoid global index rebuilds
set echo off feed off pages 0 select distinct '@lp_look '||table_owner|| ' '||table_name from sys.dba_tab_partitions order by table_owner,table_name; . . . SQL> @lp_look TERA WORK SQL> @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)
248
Hodge-podge
Shutdown abort
When running with or without media recovery enabled
SQL> shutdown abort ORACLE instance shutdown. SQL> startup restrict . . . SQL> shutdown . . . ORACLE instance shutdown.
249
Hodge-podge
A word on OEM
250
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
251
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>
252
Hodge-podge
Change in logon procedures
connect internal
8i
253
Hodge-podge
Online redo log maintenance
After
select group#,member from v$logfile order by group#,member GROUP# 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
254
Better systems
users.
256