Post on 23-Mar-2020
SessionID:
Preparedby:
UsetheOracleLogminertoprotectyourdataandmovetotheCloud!
439
KonstantinKerekovski,RaymondJamesFinancial
April2-6,2017inLasVegas,NVUSA#C17LV
BIO
KonstantinRomanovKerekovski
WorkExperience:• AmericanExpress– OracleDBA11g,12c,RAC,GG,DG• RaymondJamesFinancial– OracleDBA11g,12c,Exadata,ODA
ExperiencewithReplicationTechnologies:• Goldengate11g,12c• Dataguard11g,12c• Logminer11g,12c
WhatistheLogminer?
• Asuiteofpackagesandviews• Atooltoanalyzeyourarchivedlogs
April2-6,2017inLasVegas,NVUSA#C17LV
RecommendedSettings
• MinimumDatabaseSupplementalloggingenabled.
• (Optional)SupplementalloggroupsontablesinvolvedinanyLogminerreplication.
April2-6,2017inLasVegas,NVUSA#C17LV
WhatisSupplementalLogging?
• Extraredologgingotherthanwhatisrequiredtorecoverdatabasechangesviamediarecovery(RMAN).
Examples:• Sessionlevelinformation• Beforeimagesofcolumns
April2-6,2017inLasVegas,NVUSA#C17LV
WhyisSupplementalLoggingimportant?
• LogminercannotreturnvalidSQLstatementswithoutsupplementallogging.• Logminerwillnotbeusableforanyauditingpurposesduetomissingredodata.
April2-6,2017inLasVegas,NVUSA#C17LV
AddingDatabaseMinimumSupplementalLogging
SQL> alter database add supplemental log data;
Database altered.
April2-6,2017inLasVegas,NVUSA#C17LV
AddingDatabaseMinimumSupplementalLogging(cont’d)
April2-6,2017inLasVegas,NVUSA#C17LV
OtherLevelsofDBSupplementalLogging
April2-6,2017inLasVegas,NVUSA#C17LV
DatabaseSupplementalLoggingconsiderations
• In12c,supplementalloggingdoneatCDB$ROOTenablessupplementalloggingonallPDBs.• IncreasesamountofREDOgeneratedbyALLtransactions.
April2-6,2017inLasVegas,NVUSA#C17LV
Whyistable-levelSupplementalLoggingneeded?
• Tostorebefore-imagesofkeycolumnsintoredostream.
• ToensureSQLretrievedfromSQL_REDOcolumnhastheproperpredicatesinwhereclause.
• ToavoidusingROW_ID’swhenrerunningSQL_REDOdata.
April2-6,2017inLasVegas,NVUSA#C17LV
Addingtable-levelSupplementalLogging
IdentificationKeyLogging
April2-6,2017inLasVegas,NVUSA#C17LV
Addingtable-levelSupplementalLogging
CustomLogGroups
April2-6,2017inLasVegas,NVUSA#C17LV
SupplementalLogTestCase
April2-6,2017inLasVegas,NVUSA#C17LV
Whathappenswithnotable-levelSupplementalLogging?
April2-6,2017inLasVegas,NVUSA#C17LV
Whathappenswithnotable-levelSupplementalLogging?(cont’d)
April2-6,2017inLasVegas,NVUSA#C17LV
NoSupplementalLoggingwhatsoever
April2-6,2017inLasVegas,NVUSA#C17LV
WhathappenswithallcolumnSupplementalLogging?
April2-6,2017inLasVegas,NVUSA#C17LV
WhathappenswithallcolumnSupplementalLogging?(cont’d)
April2-6,2017inLasVegas,NVUSA#C17LV
WhathappenswithPKSupplementalLogging?
April2-6,2017inLasVegas,NVUSA#C17LV
WhathappenswithPKSupplementalLogging?(cont’d)
April2-6,2017inLasVegas,NVUSA#C17LV
WhyPrimaryKey IdentificationKeySupplementalLoggingissafer
April2-6,2017inLasVegas,NVUSA#C17LV
WhyPrimaryKey IdentificationKeySupplementalLoggingissafer(cont’d)
April2-6,2017inLasVegas,NVUSA#C17LV
DatabaseObjectsofinterest
• DBMS_LOGMNR_D
• DBMS_LOGMNR
• V$LOGMNR_CONTENTS
April2-6,2017inLasVegas,NVUSA#C17LV
DBMS_LOGMNR_D
• DatabasePackage• Usedtostoredatadictionaryinflatfilesortheredologs.
April2-6,2017inLasVegas,NVUSA#C17LV
TheDataDictionary
• MapsObjectIDstoObjectNames,aidsinDDLtracking.
• Canbeaccessedin3differentways1. Fromstoredversioninredologs2. Fromstoredversionaflatfile3. Fromthedatabaseitself.
April2-6,2017inLasVegas,NVUSA#C17LV
Whyyoushoulduse1ofthe3datadictionaryoptions
April2-6,2017inLasVegas,NVUSA#C17LV
DBMS_LOGMNR
• Startsandendslogminingsessions.
• Specifieswhichredologsaretobeanalyzed.
• SpecifieshowtodisplaySQL_REDOandSQL_UNDOviaOPTIONSargumentinSTART_LOGMNR
April2-6,2017inLasVegas,NVUSA#C17LV
START_LOGMNROptions
• NO_SQL_DELIMITER• NO_ROW_ID_IN_STMT• COMMITTED_DATA_ONLY• CONTINUOUS_MINE
• DDL_DICT_TRACKING• DICT_FROM_ONLINE_CATALOG• DICT_FROM_REDO_LOGS
April2-6,2017inLasVegas,NVUSA#C17LV
COLUMN_PRESENTandMINE_VALUE
April2-6,2017inLasVegas,NVUSA#C17LV
COLUMN_PRESENTandMINE_VALUE(cont’d)
April2-6,2017inLasVegas,NVUSA#C17LV
V$LOGMNR_CONTENTS
• ViewexposingREDOandUNDOminedviaDBMS_LOGMNR• SystemPrivilegeNeeded(12c)
• LOGMINING• SELECT_CATALOG_ROLE
• SystemPrivilegeNeeded(11g)• SELECTANYTRANSACTION• SELECT_CATALOG_ROLE
April2-6,2017inLasVegas,NVUSA#C17LV
WhathappenswhenV$LOGMNR_CONTENTSisqueried?
• RedoisanalyzedaccordingtoSTARTSCN/ENDSCNorSTARTTIME/ENDTIME.• Logfiles aredynamicallyaddedtologminingsessionifCONTINUOUS_MINEwasspecified.• REDOandUNDOdataisreturnedintheformofROWS.• ChangerecordsreturnedinascendingSCNorderunlessotherwisespecifiedinSQLstatement.
April2-6,2017inLasVegas,NVUSA#C17LV
Additionalinterestingviews• V$LOGMNR_LOGS- ContainsadditionalinformationonARCHIVELOGS.
• V$LOGMNR_PARAMETERS– Informationoncurrentlogminingsession.
April2-6,2017inLasVegas,NVUSA#C17LV
AlittlemoreonV$LOGMNR_PARAMETERS
AuditingDatabaseActivity
April2-6,2017inLasVegas,NVUSA#C17LV
Databasechangecausesoutage
• Databasesuddenlybecomesunresponsive.
• Databaseserverisunabletocreateanynewprocessesandneedstoberebooted.
• Everyoneispanickingandmanagementisverydispleased.
April2-6,2017inLasVegas,NVUSA#C17LV
Whatdoweknow?
1. Aheavilyusedindex(HR.EMP_EMP_ID_PK)wasrecentlyalteredtoPARALLEL99.
2.Thedatabaseisauditingchangestoindexes.
3.DBA_AUDIT_TRAILhasnoauditrecordsforindex!
April2-6,2017inLasVegas,NVUSA#C17LV
DBMS_LOGMNRtotherescue!
April2-6,2017inLasVegas,NVUSA#C17LV
Verifyingoursuspicions
RecoveringfromLogicalCorruption
April2-6,2017inLasVegas,NVUSA#C17LV
BotchedUpdateScript
SQL> !cat update_salary.sql
set echo on;
update hr.employees set salary = 100000;
where employee_id =100;
commit;
April2-6,2017inLasVegas,NVUSA#C17LV
OutcomeSQL> @update_salary.sql
SQL> update hr.employees set salary = 100000;
107 rows updated.
SQL> where employee_id =100;
SP2-0734: unknown command beginning "where empl..." - rest of
line ignored.
SQL> commit;
Commit complete.
April2-6,2017inLasVegas,NVUSA#C17LV
DBMS_LOGMNRtotherescue!
April2-6,2017inLasVegas,NVUSA#C17LV
RetrievingtheSQL_UNDO
References
https://github.com/kerekovskik/COLLABORATE_2017https://github.com/kerekovskik/COLLABORATE_2017/wikihttps://docs.oracle.com/database/121/SUTIL/toc.htmhttps://docs.oracle.com/database/121/ARPLS/d_sql.htm
Q&A