miércoles, 22 de abril de 2020

Cantidad de Archives por dia generdos por hora.

set linesize 200
 
select
  to_char(first_time,'DD-MM-YY') fecha,
  to_char(first_time,'DY') dia,
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'00',1,0)),'999') "00",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'01',1,0)),'999') "01",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'02',1,0)),'999') "02",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'03',1,0)),'999') "03",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'04',1,0)),'999') "04",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'05',1,0)),'999') "05",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'06',1,0)),'999') "06",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'07',1,0)),'999') "07",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'08',1,0)),'999') "08",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'09',1,0)),'999') "09",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'10',1,0)),'999') "10",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'11',1,0)),'999') "11",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'12',1,0)),'999') "12",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'13',1,0)),'999') "13",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'14',1,0)),'999') "14",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'15',1,0)),'999') "15",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'16',1,0)),'999') "16",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'17',1,0)),'999') "17",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'18',1,0)),'999') "18",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'19',1,0)),'999') "19",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'20',1,0)),'999') "20",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'21',1,0)),'999') "21",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'22',1,0)),'999') "22",
  to_char(sum(decode(substr(to_char(first_time,'HH24'),1,2),'23',1,0)),'999') "23",
  COUNT(*) TOT
  from v$log_history
group by to_char(first_time,'DD-MM-YY'), to_char(first_time,'DY')
order by fecha;

martes, 21 de abril de 2020

Script para analizar tendendencia de crecimiento de tablespaces

A continuación les voy a pasar un script que permite monitorear como van llenandose los tablespaces y ademas obtiene una proyección de crecimiento a futuro. A mi me sirve para minimizar el riesgo de que se queden sin espacio los tablespaces (no suelo usar autoextend) y así poder realizar realocaciones o resizing en forma anticipada.


Rem Tendencia_Crecimiento_x_Tablespace
Rem
Rem NOMBRE
Rem crecimiento.sql
Rem
Rem DESCRIPCION
Rem Reporte para mostrar como fue creciendo un tablespace por hora, dia,
Rem semana y mes. Tambien realiza proyecciones de crecimiento por semana -
Rem mes y muestra STATUS (Aplica para 10+)
Rem
Rem
Rem Fabian Crea 02/08/15 -- Creado
Rem Fabian Crea 21/04/20 -- modificado para GB
Rem
set line 200
col "%Used" format a10
col "%Proy_1s" format a10
col "%Proy_1m" format a10
col tsname format a30
select tsname,
round(tablespace_size*t2.block_size/
1024/1024,2) TSize,
round(tablespace_usedsize*t2.block_size/1024/1024,2) TUsed,
round((tablespace_size-tablespace_usedsize)*t2.block_size/1024/1024,2) TFree,
round(val1*t2.block_size/1024/1024,2) "Dif_1h",
round(val2*t2.block_size/1024/1024,2) "Dif_1d",
round(val3*t2.block_size/1024/1024,2) "Dif_1s",
round(val4*t2.block_size/1024/1024,2) "Dif_1m",
round((tablespace_usedsize/tablespace_size)*100)||'%' "%Used",
round(((tablespace_usedsize+val3)/tablespace_size)*100)||'%' "%Proy_1s",
round(((tablespace_usedsize+val4)/tablespace_size)*100)||'%' "%Proy_1m",
case when ((((tablespace_usedsize+val3)/tablespace_size)*100 < 80) and
(((tablespace_usedsize+val4)/tablespace_size)*100 < 80)) then 'NORMAL'
when ((((tablespace_usedsize+val3)/tablespace_size)*100 between 80 and 90)
or
(((tablespace_usedsize+val4)/tablespace_size)*100 between 80 and 90))
then 'WARNING'
else 'CRITICAL' end STATUS
from
(select distinct tsname,
rtime,
tablespace_size,
tablespace_usedsize,
tablespace_usedsize-first_value(tablespace_usedsize)
over (partition by tablespace_id order by rtime rows 1 preceding) val1,
tablespace_usedsize-first_value(tablespace_usedsize)
over (partition by tablespace_id order by rtime rows 24 preceding) val2,
tablespace_usedsize-first_value(tablespace_usedsize)
over (partition by tablespace_id order by rtime rows 168 preceding) val3,
tablespace_usedsize-first_value(tablespace_usedsize)
over (partition by tablespace_id order by rtime rows 720 preceding) val4
from (select t1.tablespace_size, t1.snap_id, t1.rtime,t1.tablespace_id,
t1.tablespace_usedsize-nvl(t3.space,0) tablespace_usedsize
from dba_hist_tbspc_space_usage t1,
dba_hist_tablespace_stat t2,
(select ts_name,sum(space) space
from recyclebin group by ts_name) t3
where t1.tablespace_id = t2.ts#
and t1.snap_id = t2.snap_id
and t2.tsname = t3.ts_name (+)) t1,
dba_hist_tablespace_stat t2
where t1.tablespace_id = t2.ts#
and t1.snap_id = t2.snap_id) t1,
dba_tablespaces t2
where t1.tsname = t2.tablespace_name
and rtime = (select max(rtime) from dba_hist_tbspc_space_usage)
and t2.contents = 'PERMANENT'
order by "Dif_1h" desc,"Dif_1d" desc,"Dif_1s" desc, "Dif_1m" desc

Ahora voy a describir las columnas del reporte:

TSNAME : Nombre del Tablespace
TSIZE : Espacio total del Tablespace en Mb (no toma en cuenta autoextend del
tablespace)
TUSED : Espacio utilizado (Mb)
TFREE : Espacio Libre (Mb)
Dif_1h : Diferencia entre el espacio alocado hace 1 hora y el espacio actual
(Mb).
Dif_1d : Diferencia entre el espacio alocado hace 1 dia y el espacio actual
(Mb).
Dif_1s : Diferencia entre el espacio alocado hace 1 semana y el espacio actual
(Mb).
Dif_1m : Diferencia entre el espacio alocado hace 1 mes y el espacio actual
(Mb).
%Used : Porcentaje de Uso actual del tablespace.
%Proy_1s : Porcentaje de Uso Proyectado a 1 semana adelante.
%Proy_1m : Porcentaje de Uso Proyectado a 1 mes adelante.
STATUS : Status de alocación: menor al 80% es normal, entre 80% y 90% es
warning y mayor al 90% es critical.

DLL de una tabla.

SELECT DBMS_METADATA.get_ddl ('TABLE', table_name, owner)
FROM   all_tables
WHERE  owner      = UPPER('&1')
AND    table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'));

SET PAGESIZE 14 LINESIZE 100 FEEDBACK ON VERIFY ON

RMAN - Cuando no se encuentra un archive log --- RMAN-06726: could not locate archived log

  Lo importante en todo esto, es estar dentro del catalogo correspondiente, sino el crosscheck NO FNCIONA !!   oracle backup of logfiles is ...