--History:
--  Version  2013.03.31 Tangjun Chen Created

--
--For check ckpt on disk
--
set pagesize 50
set lines 200
set sqlprompt "_USER'@'_CONNECT_IDENTIFIER> "
set echo off
set feedback off

prompt
prompt @@@
prompt @@@<1> checkpoint: Low RBA => on memory, on disk RBA => on disk
prompt @@@
col cpdrt heading "Number of|dirty blocks"
col "Low Cache RBA" heading "Memory|Buffer Cache|Low Cache RBA|seq.block#.offset" format a25 trunc;
col "On Disk RBA" heading "Disk|Current Redo Log last items|On Disk RBA|seq.block#.offset"format a30 trunc;
col cpods heading "SCN of |On Disk RBA" for a20
col cpodt heading "timestamp of|On Disk RBA" for a25
col cphbt heading "ckpt|heart beat"
SELECT
  cpdrt,   --number of dirty blocks
  cplrba_seq ||','|| cplrba_bno||'.' || cplrba_bof "Low Cache RBA",
  cpodr_seq  ||'.'|| cpodr_bno ||'.' || cpodr_bof  "On Disk RBA",
  cpods,   --scn of on disk rba
  cpodt,   --timestamp of on disk rba
  cphbt    --heart beat
FROM x$kcccp;


--alter system switch logfile
--  Incremental ckpt to move the low cache RBA to
--  current logfile, we could see the status of log from active to inactive.
--  Only the time from active to inactive, the ckpt process would write the new
--  ckpt to datafile_header and controlfile together.
--alter system checkpoint
--  Complete ckpt to move the low cache RBA until last item of current redo log.
--  And the ckpt process would wirte new scn to datafile_header and controlfile.
--  However, the last_change# in datafile do not be written, only the shutdown
--  normally could be written, on the other word, it is a flag about whether
--  last period is shutdown normally.
--shutdown immediate
--  it do everything.
prompt
prompt
prompt @@@
prompt @@@<2> check the current SCN and timestamp
prompt @@@
set echo on
SELECT
    dbms_flashback.get_system_change_number AS current_scn
  , SCN_TO_TIMESTAMP(dbms_flashback.get_system_change_number) AS scn_to_timestamp
FROM dual;
set echo off

prompt
prompt @@@
prompt @@@<3> check the ckpt on CONTROLFILE on view v$database
prompt @@@  
col name format a70 word_wrapped
SELECT  checkpoint_change#, current_scn, name    FROM v$database;

prompt
prompt @@@
prompt @@@<4> start scn and end scn on CONTROLFILE on view v$datafile
prompt @@@
col checkpoint_change# for 9999999999
col last_change# for 9999999999
SELECT checkpoint_change#, last_change#, name FROM v$datafile;
--SELECT last_change#,name       FROM v$datafile;

prompt
prompt @@@
prompt @@@<5> SCN on DATAFILES header on view v$datafile_header
prompt @@@
col checkpoint_change# for 9999999999
SELECT checkpoint_change#, name FROM v$datafile_header;

prompt
prompt @@@
prompt @@@<6> SCN on redo log on view
prompt @@@
col redo_size for a10
col status for a11
col start_time for a11
col end_time for a11
SELECT
    SEQUENCE#
  , round(bytes/1024/1024)||'M' AS redo_size
  , archived
  , status
  , first_change# AS start_scn
  , next_change#  AS end_scn
  , to_char(first_time,'yyyy-mm-dd hh24:mi:ss') AS start_time
  , to_char(next_time,'yyyy-mm-dd hh24:mi:ss') AS end_time
FROM v$log;


prompt
prompt @@@
prompt @@@<7> SCN on archivelog on view v$archive_log
prompt @@@
col archivelog_size for a6
col interval for a22
col start_time for a11
col end_time for a11
SELECT * FROM
(
    SELECT
       sequence#
     , first_change#
     , next_change#
     , to_char(first_time,'yyyy-mm-dd HH24:mi:ss') AS start_time
     , to_char(next_time,'yyyy-mm-dd HH24:mi:ss') AS  end_time
     , round(BLOCKS*block_size/1024/1024)||'M' AS archivelog_size
     , next_change#-first_change#  AS changed_scn
     , lpad(EXTRACT(DAY FROM (next_time-first_time) DAY TO SECOND),2)
            ||'d '||
            lpad(EXTRACT(HOUR FROM (next_time-first_time) DAY TO SECOND),2 )
            ||'h '||
            lpad(EXTRACT(MINUTE FROM (next_time-first_time) DAY TO SECOND),2 )
            ||'m '||
            lpad(EXTRACT(SECOND FROM (next_time-first_time) DAY TO SECOND),2)
            ||'s'      
            AS interval
    FROM v$archived_log
    ORDER BY sequence# DESC
)
WHERE rownum < 10
;