The classic "log switches per hour" grid: one row per day, one column per hour. It shows at a glance when the database generates the most redo, which is when the nightly batch, the purge job or the index rebuild runs.
groups.sql answers the follow-up question: how many groups each thread has, and how big each member is.
Usage
SQL> @redo.sql 7
SQL> @groups.sql
redo.sql takes the number of days to look back. It stops at midnight last night, so today isn't included.
-- redo.sql: redo log switches per hour, one row per day
-- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/)
-- https://hashjoin.com/kb/oracle/redo-log-switches-per-hour/
--
-- Usage: @redo.sql <days>
-- @redo.sql 7 last 7 days, not counting today
--
-- Reads v$log_history. On RAC, every thread's switches are counted together.
col day format a12
set lines 132
SELECT
to_char(first_time,'YYYY-MON-DD') day,
to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'99') "00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'99') "01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'99') "02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'99') "03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'99') "04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'99') "05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'99') "06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'99') "07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'99') "08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'99') "09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'99') "10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'99') "11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'99') "12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'99') "13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'99') "14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'99') "15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'99') "16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'99') "17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'99') "18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'99') "19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'99') "20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'99') "21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'99') "22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'99') "23"
from
v$log_history
where first_time between trunc(sysdate-&&1) and
trunc(sysdate)
GROUP by
to_char(first_time,'YYYY-MON-DD')
order by day;curl -O https://hashjoin.com/kb/oracle/redo-log-switches-per-hour/redo.sql
-- groups.sql: redo log groups, members and size per thread
-- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/)
-- https://hashjoin.com/kb/oracle/redo-log-switches-per-hour/
--
-- Usage: @groups.sql
break on report
compute sum of gb_tot on report
compute sum of members on report
select count(*) groups, thread#, sum(members) members,
avg(bytes)/1024/1024 member_size_mb,
sum(bytes)/1024/1024/1024 gb_tot
from v$log
group by thread#
/curl -O https://hashjoin.com/kb/oracle/redo-log-switches-per-hour/groups.sql
Reading the output
A cell is the number of switches in that hour, across all threads. Steady single digits are normal. An hour in the 30s or 40s means a switch every minute or two: either a job is generating far more redo than it needs to, or the logs are too small for the load. To find the exact minutes, use the burst finder.
To size the logs, take the busiest hour you see, divide by the number of switches you'd like in that hour (a common target is 3 to 4), and multiply by the current member size from groups.sql.
Gotchas
- History only goes back as far as the control file keeps it (
control_file_record_keep_time, 7 days by default). - On RAC, every thread is added together. A cell of 40 on a four-node cluster is 10 per instance.
groups.sqlreportsv$log.bytesper member.GB_TOTsums one member per group, not every multiplexed copy.
What it reads
Related
Tired of fixing the same thing twice?
HASHJOIN turns the checks and fixes your on-call runs by hand into tooling that gives the same answer every time. Fixed scope, and you own all of the code.
New fixes and field notes by email, about once a month.