Created
February 15, 2019 15:04
-
-
Save flinox/f2cb5d05cad1f0cfcdfa4a99ec72d83e to your computer and use it in GitHub Desktop.
Oracle: Analyze database statistics based on v$log_history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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