Skip to content

Instantly share code, notes, and snippets.

@flinox
Created February 15, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flinox/f2cb5d05cad1f0cfcdfa4a99ec72d83e to your computer and use it in GitHub Desktop.
Save flinox/f2cb5d05cad1f0cfcdfa4a99ec72d83e to your computer and use it in GitHub Desktop.
Oracle: Analyze database statistics based on v$log_history
-- Source: https://www.dba-scripts.com/scripts/diagnostic-and-tuning/troubleshooting/database-activity-log_history/
-- You can adapt the query to your needs, you just have to change the way you format the date to be able to drilldown to the precision you want.
-- Oracle PL/SQL
select round(avg(LOG_SWITCHES)) LOG_SWITCHES, DAY
from (
select to_char(trunc(first_time), 'Day') DAY, TRUNC(FIRST_TIME, 'DDD'), count(*) LOG_SWITCHES
from v$log_history
group by TRUNC(FIRST_TIME, 'DDD'), to_char(trunc(first_time), 'Day')
order by 2
)
group by day;
-- You can find out which day of the week is the most active. You can also have a day to day analysis for the last month
select round(avg(LOG_SWITCHES)) LOG_SWITCHES, DAY
from (
select TRUNC(FIRST_TIME, 'DDD') DAY, count(*) LOG_SWITCHES
from v$log_history
where first_time between sysdate -30 and sysdate
group by TRUNC(FIRST_TIME, 'DDD'), to_char(trunc(first_time), 'Day')
order by 1
)
group by day
order by 2;
-- You can also drilldown to hours in the day:
select Hour , round(avg(LOG_SWITCHES)) LOG_SWITCHES
from (
select to_char(trunc(first_time, 'HH'),'HH24') Hour, TRUNC(FIRST_TIME, 'DDD'), count(*) LOG_SWITCHES
from v$log_history
group by TRUNC(FIRST_TIME, 'DDD'), trunc(first_time, 'HH')
order by 1
)
group by Hour
order by Hour;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment