SQL Library
Table LAST_ANALYZED
set ver off
set linesize 60
col table_name format a15
col last_analyzed format a40
select TABLE_NAME "Table Name",to_char(LAST_ANALYZED,'DD-MON-YY HH24:MI:SS') "Date and Time" from dba_TABLES where lower(TABLE_NAME)='&tname';
Displays Last Analyzed Details for a given Schema. (All schema owners if 'ALL' specified).
--
SET PAUSE ON
SET PAUSE 'Press Return to Continue'
SET PAGESIZE 60
SET LINESIZE 300
SELECT t.owner,
t.table_name AS "Table Name",
t.num_rows AS "Rows",
t.avg_row_len AS "Avg Row Len",
Trunc((t.blocks * p.value)/1024) AS "Size KB",
to_char(t.last_analyzed,'DD/MM/YYYY HH24:MM:SS') AS "Last Analyzed"
FROM dba_tables t,
v$parameter p
WHERE t.owner = Decode(Upper('&&Table_Owner'), 'ALL', t.owner, Upper('&&Table_Owner'))
AND p.name = 'db_block_size'
ORDER by t.owner,t.last_analyzed,t.table_name
/
This script is intended for daily use to get tables where percentage of changed records is above 10%:
SELECT DT.OWNER,
DT.TABLE_NAME,
ROUND ( (DELETES + UPDATES + INSERTS) / NUM_ROWS * 100) PERCENTAGE
FROM dba_tables dt, ALL_TAB_MODIFICATIONS atm
WHERE DT.OWNER = ATM.TABLE_OWNER
AND DT.TABLE_NAME = ATM.TABLE_NAME
AND NUM_ROWS > 0
AND ROUND ( (DELETES + UPDATES + INSERTS) / NUM_ROWS * 100) >= 10
ORDER BY 3 desc
Login into sqlplus as sys user
To start trace run procedure with a module name and database name:
begin
dbms_monitor.serv_mod_act_trace_enable( service_name => '<db_name>'
, module_name => '<module_name>'
, action_name => dbms_monitor.all_actions
,waits => true
,binds => true
,instance_name => null
,plan_stat => null
);
end;
/
To stop trace run procedure:
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE('<db_name>','<module_name>');
*** statistics of objects of a specific sql id
set lines 300 set pages 300
col table_name for a40
col owner for a30
select distinct owner, table_name, STALE_STATS, last_analyzed, stattype_locked
from dba_tab_statistics
where (owner, table_name) in
(select distinct owner, table_name
from dba_tables
where ( table_name)
in ( select object_name
from gv$sql_plan
where upper(sql_id) = upper('&sql_id') and object_name is not null))
--and STALE_STATS='YES'
/