Documentos de Académico
Documentos de Profesional
Documentos de Cultura
AFINAMIENTO EN ORACLE
Las bases de datos necesitan tcnicas para mejorar su rendimiento, por lo que su afinamiento es imprescindible para obtener su mximo aprovechamiento.
TUNING EN ORACLE
Cuatro reas principales SGA(System Global Area)
Causas de una respuesta pobre
Razones para un pobre desempeo RDBMS
Programas 60% Diseo 20%
Sistema 2.5%
Source: ORACLE Performance Tuning1
DB_BLOCK_BUFFERS
SHARED_POOL_SIZE SORT_AREA_SIZE
A. DB_BLOCK_BUFFERS
Si DB_BLOCK_BUFFERS es bajo, los usuarios podran no tener suficiente espacio en memoria para trabajar eficientemente.
B. El SHARED_POOL_SIZE:
Esta es la porcin de memoria localizada para la librera y el cache del diccionario de datos.
Si el SHARED_POOL_SIZE esta seteado demasiado bajo no se aprovechara adecuadamente el DB_BLOCK_BUFFERS.
Meta # 3: Encuentre los queries que estn obstruyendo la memoria y causan problemas de I/O
Use V$SQLAREA para encontrar problemas de Queries
Disk_reads SQL_TEXT
12,987 select order#,columns,types from orders where substr(orderid,1,2)=:1 select custid, city from customer where city = CHICAGO
11,131
Buffer_gets
300,219
SQL_TEXT
select order#,cust_no, from orders where division = 1
TEXT___________________________
procedure process_date is test_num number; begin test_num := 10; if test_num = 10 then update order_main set process_date = sysdate where order_num = 12345; end if; end;
Algunos metodos :
El Optimizers Usando Hints (sugerencias) Usando Histograms Driving Tables Partitions Parallel Query
El Optimizers
El Parmetro de Optimizer_Mode - los Valores Regla Escoja Optimizer_Goal - los Valores Regla (no tiene tiempo para poner a punto todos esto) All_Rows - Consigue todas las filas rpidamente (Informes) First_Row - Consigue la primera fila rpidamente (Formas) Escoja (Arregle reas del problema)
El comando ANALYZE
En General:
Las estadsticas son generadas con el comando ANALYZE Deben generarse estadsticas de Cost Based Optimization Una vez que tabla es analizada; usar Cost Based Optimization (a menos que se sobreescriba INIT.ora ) Una tabla tambin se puede-ANALYZEd; Usando el 'Delete Statistics'
El comando ANALYZE
PURPOSE:
To perform one of these functions on an index, table, or cluster: To collect statistics about the object used by the optimizer and store them in the data dictionary To delete statistics about the object from the data dictionary To validate the structure of the object To identify migrated and chained rows of the table or cluster
ANALYZE Ejemplos:
SQL> ANALYZE TABLE CUSTOMER ESTIMATE STATISTICS sample 5000 rows; SQL> ANALYZE TABLE CUSTOMER ESTIMATE STATISTICS sample 25 percent; SQL> ANALYZE TABLE CUSTOMER DELETE STATISTICS;
execute dbms_utility.analyze_schema(SCOTT,COMPUTE);
ANALYZE Ejemplos:
desc dba_tab_modifications; SQL> exec dbms_stats.gather_schema_stats( > ownname => 'SCOTT', > options => 'GATHER AUTO'); There are several values for the options parameter that we need to know about: gather re-analyzes the whole schema.
gather empty Only analyze tables that have no existing statistics. gather stale Only re-analyze tables with more than 10% modifications (inserts, updates, deletes). gather auto This will re-analyze objects which currently have no statistics and objects with stale statistics. Using gather auto is like combining gather stale and gather empty.
La regla 95/5
cuando "Optimizerencuentra un query para recuperar menos 4-7% de las filas, el optimizer escoger manejar el query con un index si este existe.
Optimizer Modes
There are two types of optimizer modes:
Rule-based:
Uses a ranking system Syntax and data dictionary driven
Cost-based:
Chooses the path with lowest cost Statistics-driven
Using hints
Plan Equivalence
SQL statement text must match the text in a stored outline. Plans are maintained through:
New Oracle versions New statistics on objects Initializacion parameter changes Database reorganization Schema changes
SQL ordered by gets SQL ordered by reads SQL ordered by executions SQL ordered by parse calls
SQL_Trace = True | False Alter session set sql_trace = TRUE | FALSE EXECUTE dbms_session.set_sql_trace (True|False); EXECUTE dbms_system.set_sql_trace_in_session (session_id, serial_id, {True|False});
Tracefile.trc
Output.txt
User_dump_dest
TKPROF Statistics
Count:Number of execution calls CPU: CPU seconds used Elapsed: Total elapsed time Disk: Physical reads Query: Logical reads for consistent read Current: Logical reads in current mode Rows: Rows processed
SQL*Plus Autotrace
Create the plan_table Table Create and grant the plustrace role @$oracle_home/sqlplus/admin/plustrce.sql Grant plustrace To scott;
3.
4.
Generar y optimizar al mximo el plan de las vistas. Esto es importante porque el SQL de una vista, no se ejecuta mientras que la vista no es utilizada en una consulta, as que todas las consultas de esa vista se ven afectadas por su plan. Hay que tener especial cuidado de hacer joins entre vistas.
Sugerencias o hints
Un hint es un comentario dentro de una consulta SELECT que informa a Oracle del modo en que tiene que trazar el plan de ejecucin. Los hint deben ir junto detrs de la palabra SELECT: SELECT /*+ HINT */ . . .
Sugerencias o hints
Hint /*+ CHOOSE */ Descripcin Pone la consulta a costes.
/*+ RULE */
/*+ ALL_ROWS */
/*+ FIRST_ROWS */
/*+ ORDERED */
Ejemplos
EXPLAIN PLAN FOR SELECT ename, job, sal, dname FROM emp, dept WHERE emp.deptno = dept.deptno AND NOT EXISTS (SELECT * FROM salgrade WHERE emp.sal BETWEEN losal AND hisal);