How to find Log switches in oracle 11g Database


let we discuss how to find Log switches in Database with Details of oracle11g


Note: V$LOG_HISTORY displays log history information from the control file.

Method-1:

I am going to take log switches count till before the month end
(i.e current date is '27-Sep-17' using last_day function 
it consider the date is '30-Sep-2017')


SQL> col c1 for a10 heading "Month"
SQL> col c2 for a25 heading "ArchiveDate"
SQL> col c3 for 999 heading "Switches"
SQL>  SQL> col c1 for a10 heading "Month"
SQL> col c2 for a25 heading "ArchiveDate"
SQL> col c3 for 999 heading "Switches"
SQL>  select to_char(trunc(first_time),'Month') c1,
to_char(trunc(first_time),'DAY:DD-MM-YY') c2,
count(*) c3 from V$log_history 
where first_time > last_day(trunc
(sysdate) - 30)+1 
group by trunc(first_time) order by trunc(first_time);



Month      ArchiveDate        Switches
---------- ----------------   --------
September  THURSDAY :14-09-17     2
September  FRIDAY   :15-09-17     1
September  MONDAY   :18-09-17     1
September  TUESDAY  :19-09-17     2
September  WEDNESDAY:20-09-17     1
September  THURSDAY :21-09-17     2
September  FRIDAY   :22-09-17     4
September  MONDAY   :25-09-17     1
September  TUESDAY  :26-09-17     2
September  WEDNESDAY:27-09-17     2
Method-2: from the sysdate into last no of days if we want to take long switches count Let remove the "last_day" function.

SQL> col c1 for a10 heading "Month"
SQL> col c2 for a25 heading "ArchiveDate"
SQL> col c3 for 999 heading "Switches"
SQL>  select to_char(trunc(first_time),'Month') c1,
to_char(trunc(first_time),'DAY:DD-MM-YY') c2,
count(*) c3 from V$log_history 
where first_time > (trunc(sysdate) - 30)  
group by trunc(first_time) 
order by trunc(first_time);

Note: First_time=Lowest system change number (SCN) in the log, Method-3:
For global view of all instances of RAC databases

SQL> select  to_char(first_time,  'dd-mon-yy hh24:mi:ss' )"ArchiveDate",
sequence#, thread# from gv$log_history; ArchiveDate SEQUENCE# THREAD# --------------------------- ---------- ---------- 14-sep-17 16:21:42 1 1 14-sep-17 16:21:53 2 1 15-sep-17 15:08:36 3 1 18-sep-17 09:42:27 4 1 19-sep-17 09:40:55 5 1 19-sep-17 12:36:53 6 1 20-sep-17 09:43:03 7 1 21-sep-17 09:44:31 8 1 21-sep-17 15:31:55 9 1 22-sep-17 09:44:11 10 1 22-sep-17 10:41:59 11 1 22-sep-17 12:59:20 12 1 22-sep-17 13:29:42 13 1 25-sep-17 09:00:19 14 1 26-sep-17 09:43:03 15 1 26-sep-17 15:44:32 16 1 27-sep-17 10:24:34 17 1 27-sep-17 10:29:09 18 1 18 rows selected.

Popular posts from this blog

Error in starting the service (OracleMTSRecovery)

ORA-39000, ORA-39143 ORA- 31619 invalid dump file in datapump

ORA-00439: feature not enabled: Flashback Database