Oracle LogMiner Viewer and Flashback Transaction.doc

download Oracle LogMiner Viewer and Flashback Transaction.doc

of 21

Transcript of Oracle LogMiner Viewer and Flashback Transaction.doc

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    1/21

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    2/21

    )nderstanding LogMiner

    LogMiner by &'a"(le

    Requireents

    The following are re%uire"ents for the source database that LogMiner will "ine.

    Oracle LogMiner Viewer and !lash"ac# Transaction

    The source8"ining database "ust be Oracle atabase 22gor higher with Oracle &nter(rise

    Manager atabase 7ontrol or 0rid Manager configured.

    Archivelog Mode

    !rchielog "ode "ust be enabled in order to generate usable redo log files.

    SQL> select log_mode from v$database;

    LOG_MODE------------NOARCHIVELOG

    SQL> shutdown immediateDatabase closed.Database dismo!ted.

    ORACLE i!sta!ce s"t do#!.

    SQL> startup mountORACLE i!sta!ce sta$ted.

    %otal S&stem Global A$ea '()*)'+**( b&tes,ied Sie ///+012 b&tesVa$iable Sie '/0'+2012+ b&tesDatabase 344e$s *)/*/')*( b&tesRedo 344e$s 5''++2+ b&tesDatabase mo!ted.

    SQL> alter database archivelog;

    Database alte$ed.

    SQL> alter database open;

    Database alte$ed.

    http://www.idevelopment.info/data/Oracle/DBA_tips/LogMiner/LOGMINER_13.shtmlhttp://www.idevelopment.info/data/Oracle/DBA_tips/LogMiner/LOGMINER_15.shtmlhttp://www.idevelopment.info/data/Oracle/DBA_tips/LogMiner/LOGMINER_13.shtmlhttp://www.idevelopment.info/data/Oracle/DBA_tips/LogMiner/LOGMINER_15.shtml
  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    3/21

    SQL> select log_mode from v$database;

    LOG_MODE------------ARCHIVELOG

    $ecurit%

    ! new role na"ed LOGMNR_ADMINwill be created and assigned the a((ro(riate (riileges for

    LogMiner analysis. This role will be assigned to a new user na"ed MINERthat will be used to

    (erfor" the LogMiner e'a"(les (resented in this guide.

    SQL> create role logmnr_admin;

    Role c$eated.

    SQL> grant create session to logmnr_admin;

    G$a!t scceeded.

    SQL> grant select on v_$logmnr_contents to logmnr_admin;

    G$a!t scceeded.

    SQL> grant select on v_$logmnr_dictionary to logmnr_admin;

    G$a!t scceeded.

    SQL> grant select on v_$logmnr_parameters to logmnr_admin;

    G$a!t scceeded.

    SQL> grant select on v_$logmnr_logs to logmnr_admin;

    G$a!t scceeded.

    SQL> grant select on v_$archived_log to logmnr_admin;

    G$a!t scceeded.

    SQL> grant execute_catalog_role , select any dictionary , select any transaction , select any table , create tablespace

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    4/21

    , drop tablespaceto logmnr_admin;

    G$a!t scceeded.

    SQL> create user miner identified by miner;

    6se$ c$eated.

    SQL> grant logmnr_admin to miner;

    G$a!t scceeded.

    -- Needed 4o$ ,las"bac7 %$a!sactio!.

    SQL> grant execute on dbms_flashback to miner;

    G$a!t scceeded.

    -- Needed 4o$ ,las"bac7 %$a!sactio!.

    SQL> grant select any transaction to miner;

    G$a!t scceeded.

    -- Needed 4o$ ,las"bac7 %$a!sactio!.

    SQL> grant create any table to miner;

    G$a!t scceeded.

    -- Needed 4o$ ,las"bac7 %$a!sactio!.

    SQL> grant flashback any table to miner;

    G$a!t scceeded.

    $uppleental Logging

    LogMiner is a redo*based a((lication and as such, re%uires at least "ini"al su((le"entallogging be enabled on the source database. Oracle does not enable any su((le"ental logging bydefault. !dditionally, su((le"ental logging for (ri"ary key colu"ns "ust be enabled for

    Flashback Transaction to work.

    !fter erifying su((le"ental logging is enabled, force a log switch in order for the new

    su((le"ental log configuration to begin archiing the additional colu"n data to the redo logs.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    5/21

    SQL> alter database add supplemental log data;

    Database alte$ed.

    SQL> alter database add supplemental log data (primary key) columns;

    Database alte$ed.

    SQL> select supplemental_log_data_min, supplemental_log_data_pk fromv$database;

    S688LEMEN%AL_LOG_DA%A_MIN S688LEMEN%AL_LOG_DA%A_89-------------------------- -------------------------:ES :ES

    SQL> alter system switch logfile;

    S&stem alte$ed.

    $e"e"ber that su((le"ental logging "ust be enabled on the source database "eforegeneratingredo log files that will be analy9ed by LogMiner.

    !lash"ac# Transaction &'aple (sing

    Oracle LogMiner Viewer

    This section de"onstrates how to use Oracle LogMiner Viewer to ca(ture L and MLactiity and how to use Flashback Transaction to backout a bad transaction including de(endenttransactions/.

    Initiate &'aple Data

    #n order to test the LogMiner and Flashback Transaction functionality, create a test eniron"ent

    in the source database. )se the following scri(t to create a test table and (erfor" a few

    transactions against it that will be analy9ed by LogMiner.

    oracle:log"iner:iewer:scri(t2.s%l

    C!!"C# scotttigerCo!!ected.

    %"# &'"%*" +%"# -!"%*" ./0C-12! 3Current 1ser3 452'# '.6C-12! 3Current #ime3 452'# '.+C-12! 3Current %C!3 452'# +++++++++++

    http://www.idevelopment.info/data/Oracle/DBA_tips/LogMiner/resources/OracleLogMinerViewerFlashbackTransaction/oracle_logminer_viewer_script1.sql
  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    6/21

    C-12! first_name 452'# '.C-12! last_name 452'# '..C-12! email 452'# '/.C-12! phone_number 452'# '.6

    77 et current user, datetime, and %C!8

    %"-"C# user '% 3Current 1ser3 , #_C9'5(systimestamp, :22 to co!ti!e.

    !%"5# !# scott8employees D'-1"% (.., :Fulia:, :esai:, :GdesaiHnodomain8com:, :/+70007./.=:);

    ' $o# c$eated.

    !%"5# !# scott8employees

    D'-1"% (./, :4ranklin:, :Dick:, :fvickHnodomain8com:, :/+70007./.+:);

    ' $o# c$eated.

    !%"5# !# scott8employees D'-1"% (.6, :Beth:, :Ialton:, :bwaltonHnodomain8com:, :/+70007././:);

    ' $o# c$eated.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    7/21

    !%"5# !# scott8employees D'-1"% (.=, :&at:, :'llen:, :pallenHnodomain8com:, :/+70007./.6:);

    ' $o# c$eated.

    !%"5# !# scott8employees D'-1"% (.0, :%tacy:, :lsen:, :solsenHnodomain8com:, :/+70007.//=:);

    ' $o# c$eated.

    C22#;

    Commit comlete.

    %"-"C# employee_id , first_name , last_name , email , phone_number

    452 scott8employees5"5 B< employee_id;

    EM8LO:EE_ID ,IRS%_NAME LAS%_NAME EMAIL 8HONE_N6M3ER----------- ---------- ----------- --------------------- ------------- '11' ?lia Desai @desai!odomai!.com /10-)))-'/'2 '11/ ,$a!7li! Vic7 4Bic7!odomai!.com /10-)))-'/'0 '11* 3et" alto! b#alto!!odomai!.com /10-)))-'/'/ '112 8at Alle! alle!!odomai!.com /10-)))-'/'* '11) Stac& Olse! solse!!odomai!.com /10-)))-'//2

    77 #he following transaction (#5'!%'C#! .) will be backed out77 using racle -og2iner Diewer and 4lashback #ransaction877 4lashback #ransaction will detect a dependent transaction77 (#5'!%'C#! /) and prompt the user with a list of options on77 how to continue8

    77 J#5'!%'C#! .K

    &'1%" 2odify test data (#5'!%'C#! .)8 9it @"!#"5A to continue8

    Modi4& test data %RANSAC%ION '. Hit =EN%ER> to co!ti!e.

    1&'#" scott8employees

    %"# phone_numberL:/+70007++++: I9"5" employee_idL.0;

    ' $o# dated.

    "-"#" 452 scott8employees I9"5" employee_idL..;

    ' $o# deleted.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    8/21

    C22#;

    Commit comlete.

    77 J#5'!%'C#! /K

    &'1%" 2odify test data (#5'!%'C#! /)8 9it @"!#"5A to continue8

    Modi4& test data %RANSAC%ION /. Hit =EN%ER> to co!ti!e.

    "-"#" 452 scott8employees I9"5" employee_idL.0;

    ' $o# deleted.

    C22#;

    Commit comlete.

    %"-"C# employee_id , first_name , last_name , email , phone_number452 scott8employees5"5 B< employee_id;

    EM8LO:EE_ID ,IRS%_NAME LAS%_NAME EMAIL 8HONE_N6M3ER----------- ---------- ----------- --------------------- -------------

    '11/ ,$a!7li! Vic7 4Bic7!odomai!.com /10-)))-'/'0 '11* 3et" alto! b#alto!!odomai!.com /10-)))-'/'/ '112 8at Alle! alle!!odomai!.com /10-)))-'/'*

    77 et current user, datetime, and %C!8

    %"-"C# user '% 3Current 1ser3 , #_C9'5(systimestamp, :22

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    9/21

    2 second as the ML state"ents that we intend to backout using Flashback Transaction.

    #f this occurs, Oracle LogMiner Viewer will throw the following e'ce(tion when

    atte"(ting to (erfor" a Flashback Transaction belieing that the transactions beingbacked out occurred before the CREA%E %A3LEL state"ent>

    &rror

    Flashback transaction error.2. 7ause* The Flashback Transaction Aackout (rocess encountered an

    interesting obBect which had its last L o(eration done on it after the

    "ining start ti"e. !n interesting obBect is one that has been "odified by

    either the s(ecified transactions or any of their de(endents.4. !ction* S(ecify transactions that hae co""itted after the last L done

    on all the obBects they touched.

    6. S-L&'ce(tion* Baa.s%l.S-L&'ce(tion> O$!*@@@5@> L done on an

    interesting obBect after "ining start S73 O$!*5C@24> at

    =SDS.AMS:FL!SHA!7E=, line 6 O$!*5C@24> at=SDS.AMS:FL!SHA!7E=, line 5 O$!*5C@24> at line 4

    Bac#out !ailed Transaction using Oracle LogMiner Viewer

    Oracle LogMiner Viewer and Flashback Transaction will be used to backout the 68DA%EG

    68DA%E...HERE emlo&ee_idF'11)/ and DELE%EG DELE%E...HERE emlo&ee_idF'11'/

    state"ents fro" the scri(t shown aboe. These two state"ents are (art of TRA)$ACTIO) *.

    Aefore backing out the target transaction, Flashback Transaction will detect that there is ade(endent transaction DELE%E...HERE emlo&ee_idF'11)/ and (ro"(t the user with a list of

    o(tions on how to continue. Since the transaction we intend to backout TRA)$ACTIO) */

    de(ends on the second transaction TRA)$ACTIO) +/, we cannot backout the first transactionwithout first backing out the second transaction.

    To access Oracle LogMiner Viewer, launch Oracle &nter(rise Manager, select the Availa"ilit%

    tab and click the View and Manage Transactionslink in the Managesection.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    10/21

    !igure *> Oracle LogMiner Viewer

    Fro" the LogMiner screen, filter the transactions that LogMiner will return by selecting the

    Ti"e $ange or S73 $ange that is likely to (ick u( the recorded transactions for LogMiner to

    analy9e.

    )se the o(tional ,uer% !ilter(ara"eters to further filter the nu"ber of transaction records for

    LogMiner to analy9e. For this e'a"(le, include the Ta"le )aeand DB (serto s(ecify which

    table and database user to which the transactions belong.

    )se the Advanced ,uer%section to enter any additional filter infor"ation which allows you toedit the actual HEREclause. 7lick the Info Iconunder !danced -uery for a descri(tion of

    colu"ns in VLOGMNR_CON%EN%Sthat can be included in the HEREclause. #n this e'a"(le, # will

    leae the !danced -uery section set to its default alue click the -Continue.button.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    11/21

    !igure +> &nter Search 7riteria

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    12/21

    !igure /> Searching Online and !rchied $edo Log Files

    The resulting (age shows the transaction records that "atch the search criteria you entered. The

    left"ost colu"n shows the transaction identifier #/, which is used by Oracle to uni%uelyidentify a transaction. The Transaction $uar%colu"n shows how "any 68DA%Ed/,

    INSER%i!s/, and DELE%Edel/ state"ents were (erfor"ed for each transaction record.

    7lick on the Transaction # associated with the 68DA%Eand DELE%Estate"ents being rolled back

    in this e'a"(le TRA)$ACTIO) */. #n this case it is Transaction # 1511'1111A*A1111and

    listed as =$COTT0&M1LO2&&$ 3* upd4 * del5=.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    13/21

    !igure 6> LogMiner $esults

    This dis(lays the Transaction Details(age which shows the 68DA%Eand DELE%Estate"ents.

    7lick the -!lash"ac# Transaction.button.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    14/21

    !igure 7> Transaction etails

    7onfir" the Flashback Transaction o(eration re%uest by clicking the -2es.button.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    15/21

    !igure 8> 7onfir" Flashback Transaction O(eration

    The Flashback Transaction o(eration detected the de(endent transaction DELE%E...HERE

    emlo&ee_idF'11)/ fro" TRA)$ACTIO) +. Dou need to decide how the Flashback

    Transaction o(eration should handle any de(endent transactions.

    The Flashback Transaction o(eration is currently using the NONCON,LIC%_ONL:o(tion. 7lick the

    -Change Recover% Option.button to change the recoery o(tion settings.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    16/21

    !igure 9> e(endent Transactions etected

    Select the Cascadeo(tion to backout the target transaction and all de(endent transactions.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    17/21

    !igure :> Aackout !ll e(endent Transactions 7ascade/

    This brings you back to the $how Dependenciesscreen showing the Cascadeo(tion selected.7lick on the target transaction and any de(endent transactions to erify each state"ent will be

    e'ecuted G eecF&es.

    !fter erifying the target and de(endent transactions, click the -)e't.button.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    18/21

    !igure ;> 7onfir" 7ascade O(tion Selected

    The Reviewscreen (roides you with the ability to show the )ndo S-L scri(t that will be usedto backout the target and de(endency/ transactions. #n addition, you can (roide a S-L

    state"ent that will allow you to iew the effect of the changes (rior to co""itting the Flashback

    Transaction.

    7lick the -!inish.button to co""it the Flashback Transaction o(eration.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    19/21

    !igure * $eiew Flashback Transaction etails

    !fter the Flashback Transaction o(eration is co"(lete, click the -O=.button on the Resultsscreen.

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    20/21

    !igure **> Flashback Transaction $esults Screen

    7licking -O=.on the $esults screen will return you to the Transaction Detailsscreen.

    7licking -O=.again will return you to the LogMiner Resultsscreen.

    Finally, click the -Done.button to return the to( leel of the Availa"ilit%tab screen.

    Verify the Flashback Transaction successfully backed out the target and any de(endent/

    transactions.

    %"-"C# employee_id , first_name

    , last_name , email , phone_number452 scott8employees5"5 B< employee_id;

    EM8LO:EE_ID ,IRS%_NAME LAS%_NAME EMAIL 8HONE_N6M3ER

  • 8/14/2019 Oracle LogMiner Viewer and Flashback Transaction.doc

    21/21

    ----------- ---------- ----------- --------------------- ------------- '11' ?lia Desai @desai!odomai!.com /10-)))-'/'2 '11/ ,$a!7li! Vic7 4Bic7!odomai!.com /10-)))-'/'0 '11* 3et" alto! b#alto!!odomai!.com /10-)))-'/'/ '112 8at Alle! alle!!odomai!.com /10-)))-'/'* '11) Stac& Olse! solse!!odomai!.com /10-)))-'//2

    A"out the Author

    Jeffrey Hunter is an Oracle 7ertified 1rofessional, Jaa eelo("ent 7ertified 1rofessional,

    !uthor, and an Oracle !7&. Jeff currently works as a Senior atabase !d"inistrator for TheA! Ione, #nc.located in 1ittsburgh, 1ennsylania. His work includes adanced (erfor"ance

    tuning, Jaa and 1L8S-L (rogra""ing, deelo(ing high aailability solutions, ca(acity

    (lanning, database security, and (hysical 8 logical database design in a )3#, Linu', and+