Mi lista de blogs

martes, 15 de septiembre de 2015

Informa AWR - AWR en Oracle Database 10g

El informe AWR nos permite extraer informes del estado de nuestra base de datos para poder relizar tareas de Tuning:





declare
dbid number;
instance_id number;
start_id number;
end_id number;
begin
dbms_output.enable(1000000);
select max(snap_id)-1,max(snap_id) into start_id,end_id from dba_hist_snapshot;
select dbid into dbid from v$database;
select instance_number into instance_id from v$instance;

dbms_output.put_line('<PRE>');
for rc in ( select output from
   table(dbms_workload_repository.awr_report_text(dbid,instance_id,start_id,end_id))
           ) loop
  -- dbms_output.put_line('<BR>');
   dbms_output.put_line(rc.output);
end loop;
dbms_output.put_line('</PRE>');
end;

viernes, 11 de septiembre de 2015

VERIFICAR BLOQUEOS POR USUARIO

Verificar bloqueos por usuario en la base de datos ORACLE.

Esto nos va a servir para poder identificar los bloqueos que cada usuario esta produciendo en el online de la base operativa.


select /*+ ORDERED */
   blocker.sid blocker_sid
,  waiting.sid waiting_sid
,  TRUNC(waiting.ctime/60) min_waiting
,  waiting.request
from (select *
      from v$lock
      where block != 0
      and type = 'TX') blocker
,    v$lock            waiting
where waiting.type='TX'
and waiting.block = 0
and waiting.id1 = blocker.id1

COMO VERIFICAR LAS ESTADISTICAS !!!!


Con este select podremos visualizar las estadísticas de nuestra base de datos.

                         select owner         "Owner",
                                         table_name    "Table_Name",
                                         last_analyzed "Last_Analyzed",
                                         num_rows      "Rows",
                                         avg_row_len   "Average_Row_Length",
                                         decode(iot_type,'YES','IOT','HEAP')||
                                                decode(temporary,'N',null,'-Temporary')||
                                                decode(trim(cache),'N',null,'-Cached')||
                                                decode(partitioned,'NO',null,'-Partitioned')||
                                                decode(compression,'DISABLED',null,'-Compressed') "Table_Type",
                                         owner       sdev_link_owner,
                                         table_name  sdev_link_name,
                                         'TABLE'     sdev_link_type
                                    from sys.dba_tables
                                   where (:OWNER is null or instr(owner,upper(:OWNER)) > 0)
                                     and substr(table_name,1,4) != 'BIN$'
                                     and substr(table_name,1,3) != 'DR$'
                                     and (:TABLE_NAME is null or
                                          instr(upper(table_name),upper(:TABLE_NAME))>0)
                                   order by owner, table_name

INDICES NO UTILIZADOS

                       
Verificar los indices no utilizados, es muy importante a la hora de preocuparnos por la performance de nuestra base de datos. No obstante, es necesario tener periódicamente una reconstrucción de nuestros indices y cálculos de estadisticas. Para optimizar todo tipo de demora de nuestra base es importante contar con varios de estos querys que iremos colocando en el blog.


select owner      "Owner",
                                         index_name "Index Name",
                                         index_type "Index Type",
                                         table_name "Table Name",
                                         owner       sdev_link_owner,
                                         index_name  sdev_link_name,
                                         'INDEX'     sdev_link_type
                                    from sys.dba_indexes
                                   where status = 'UNUSABLE'
                                   order by index_name

INDICES POR TIPO

INDICES POR TIPO:

Es sumamente importante contar con esta información, para poder verificar que tipos de indices tenemos.

select index_type "Index Type",
                                         count(*)   "Index Count"
                                    from sys.dba_indexes
                                   group by index_type
                                   order by index_type

INDICES POR ESTADO

Saber el estado de los indices, es fundamental para poder tener en nuestra estructura los rebuild o recreación que tenemos que tener en cuenta para el manteniemiento de nuestra base de datos.

   select status   "Status",
                                         count(*) "Index Count"
                                    from sys.dba_indexes
                                   group by status
                                   order by status

Reconstruccion de Indices y Estadisticas



Recrear indices

alter index OWNER.NOMBREDELINDICE  compute rebuild;

Reconstruir estadísticas

alter index OWNER.NOMBREDELINDICE  compute statistics;



Reporte para ver todos los INDICES con : Owner, Index_name, Index_type, table_owner, table_name, uniqueness.


   select owner      "Owner",
                                         index_name "Index_Name",
                                         index_type "Index_Type",
                                         table_owner "Table_Owner",
                                         table_name "Table_Name",
                                         uniqueness "Uniqueness",
                                         owner       sdev_link_owner,
                                         index_name  sdev_link_name,
                                         'INDEX'     sdev_link_type
                                    from sys.dba_indexes
                                   where (:OWNER is null or instr(owner,upper(:OWNER)) > 0)
                                     and substr(table_name,1,4) != 'BIN$'
                                     and substr(table_name,1,3) != 'DR$'
                                     and (:TABLE_NAME is null or
                                         instr(upper(table_name),upper(:TABLE_NAME)) > 0)
                                   order by owner, index_name