Oracle Data Guard Concepts and Architecture Brian Hitchcock
Oracle Data. Guard Concepts and Architecture Brian Hitchcock OCP 10 g DBA Sun Microsystems brian. hitchcock@sun. com brhora@aol. com www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 1
Oracle Data. Guard Ÿ Maintains a standby database – – Archived redo logs on primary Sent to standby and applied Ÿ Simple idea Ÿ Many configuration options – – No attempt to cover them all here Discuss several specific sets of options Ÿ Can become very complicated www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 2
Oracle Data. Guard Ÿ Comes in Two Flavors – Physical Standby Ÿ When I was young this was all we had… Ÿ Read only when not applying redo logs – Logical Standby Ÿ Can be read write while applying redo logs Ÿ Can add db objects to standby Indexes for reporting Ÿ Many options www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 3
Themes Ÿ What is a standby? – ‘standby’ implies specific capabilities Ÿ Ready for failover Ÿ Complete copy of primary Ÿ No need to verify standby before failover Ÿ When is a standby not a standby? – When it doesn’t provide what name implies www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 4
What is a standby database? Ÿ Database that we can fail over to Ÿ Kept closely synchronized with primary db – – Up to the minute Once a day Ÿ Primarily dedicated to being ready for failover – May also be used for reporting Ÿ Guaranteed to be an exact copy – – To the point of last synchronization Can catch up as long as redo logs available www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 5
What is a standby database? Ÿ No question about standby – – Is it a complete copy? Is it ready for failover Ÿ Standby for reporting – Is standby providing accurate data for reports? Ÿ No one can change standby – No changes to data/objects in standby Ÿ If changes made to standby – Should be very obvious www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 6
Before Data. Guard? Ÿ Scripts, cron jobs – – Copy archived redo logs from primary to standby Apply redo logs on standby periodically Ÿ When script(s) executes Ÿ Standby db can’t be used for anything else – Constantly recovering Ÿ Failover – – – Open standby db with resetlogs Can’t be standby again without rebuild Can’t fail back to primary without rebuild www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 7
Standby Can’t change standby db objects Primary Database Standby mounted, recovering Can only be opened resetlogs Once opened, can’t switch back Online Redo Logs Archived Redo Logs Scripts, Cron Jobs Archived Redo Logs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 8
Why Data. Guard? Ÿ Part of Oracle RDBMS – – No scripts or cronjobs to maintain Supported by Oracle Can switch between primary/standby repeatedly Redo sent and applied continuously (options) Ÿ Standby db can be used for other things – – Read only when not applying redo logs Read write with limitations (Logical Standby) Ÿ Failover – – Primary fails, standby becomes primary Can’t switch back without rebuild www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 9
Data. Guard Classic* *Before choice of physical or logical standby Primary Database Standby mounted, recovering or Standby read only, no apply Can switch back and forth Primary becomes standby Standby becomes primary Online Redo Logs Archived Redo Logs Data. Guard Archived Redo Logs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 10
Applying Redo Logs Ÿ Default – – Archived redo log complete on primary Sent and applied to standby Ÿ Standby Redo Logs (Optional) – Redo sent to standby as it is written on primary Ÿ Real time apply – No waiting for primary archive redo log complete Ÿ No waiting for primary log switch – Not to be confused with init. ora parameter Ÿ VALID_FOR=(STANDBY_LOGFILES, …) www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 11
Standby Redo Logs Primary Database Primary redo written continuously to standby No waiting for primary log switch Standby Database Online Redo Logs Archived Redo Logs Data. Guard Standby Redo Logs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 12
Typical Configurations Ÿ Standby dedicated for failover – Primary db Ÿ configured for log switch every 15 minutes – Standby db Ÿ always applying redo logs Ÿ Behind primary by 15 minutes at most Less if primary writes redo logs more often Ÿ Use standby redo logs Very close to primary at all times www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 13
Typical Configurations Ÿ Standby for failover and reporting – Primary db Ÿ configured for log switch every 15 minutes – Standby db Ÿ apply redo logs 8 pm to 5 am Long enough to apply 24 hours of redo logs Ÿ Stop applying redo logs 5 am to 8 pm Ÿ Standby up to 15 hours behind primary Ÿ Open for reporting 15 hours a day Reports use ‘old’ data Standby data doesn’t change from 5 am to 8 pm www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 14
Protection Modes Ÿ Maximum Performance (default) – – Primary sends transactions to standby Doesn’t wait for them to commit Ÿ Maximum Protection – – Primary stops if standby doesn’t commit Requires standby redo logs Ÿ Maximum Availability – – Max protection but primary doesn’t stop Switch to max perf until standby catches up Ÿ Switch back to max availability www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 15
Data. Guard Physical Standby Can’t change standby db objects Online Redo Logs Log Transport Services Log Apply Services Physical Standby Database Primary Database Standby mounted, recovering Or Standby read only, no apply Can switch back and forth Archived Redo Logs Data. Guard Archived Redo Logs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 16
Physical Standby a Standby? Ÿ Failover – Ready to failover? Ÿ Block by block copy of primary Ÿ If any changes made, can’t failover Standby had to be opened resetlogs to change Ÿ Refresh – – No questions Complete rebuild from primary Ÿ Only need backup of primary, nothing else www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 17
Physical Standby Ÿ Just a copy of production Ÿ Only needed in production – Don’t need to do any dev, testing Ÿ Don’t need backups – Recover from backups of primary database Ÿ What is added to your infrastructure? – – One database No backups www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 18
Physical vs Logical Standby Ÿ Physical Standby – – – ‘classic’ standby Can’t connect to db while applying redo logs Can be read only when not applying redo logs Ÿ Logical Standby – Applies redo logs from primary all the time Ÿ As long as SQL apply process is running – Open for users for read and write Ÿ Various restrictions Ÿ Many configuration options www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 19
Data. Guard Logical Standby Can change db objects (restrictions) SQL Apply Services Logical Standby Database Primary Database Standby open while redo applied Online Redo Logs Log Transport Services Online Redo Logs Archived Redo Logs Data. Guard Archived Redo Logs Two sets of archived redo logs Archived Redo Logs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 20
Data. Guard Logical Standby Database Primary Database SQL applied to Logical Standby Just like any other database user Online Redo Logs Archived Redo Logs Data. Guard Archived Redo Logs Log. Miner Extract SQL www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 21
Logical Standby Ÿ Standby is open, read write Ÿ Anything copied from primary – Maintained by Data. Guard Ÿ Depending on Guard status – Data. Guard doesn’t maintain things added to standby Ÿ Guard status restricts who can update – This can be bypassed Ÿ Alter session or database Ÿ Needed to import db objects into standby www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 22
Logical Standby Guard Status Ÿ All – SYS can modify anything in standby database Ÿ Standby – – SYS can modify anything Other users can modify objects not maintained by Data. Guard Ÿ Subject to normal user privs Ÿ None – – Standby not protected by Data. Guard Any user can alter db objects Ÿ Subject to normal user privs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 23
Skipping Ÿ Schemas, tables, transactions – – May be skipped automatically Can be skipped manually Ÿ Why anything skipped? – – – Performance Unsupported db objects More later www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 24
Logical Standby a Standby? Ÿ Failover – Ready to failover? Ÿ Not sure if standby is a complete copy Tables, schemas, transactions skipped? Ÿ Standby can be changed Failover not prevented Changes can be made No warning that changes made – Who knows what you are failing over to? www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 25
Logical Standby a Standby? Ÿ Refresh – Additional db objects in standby need backup Ÿ Refresh from primary wipes out these objects – Complete rebuild from primary Ÿ Insert additional db objects – If standby fails Ÿ Need to recover standby db from backups Ÿ Extract additional db objects from standby Ÿ Refresh logical standby Ÿ Insert additional db objects www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 26
Refresh Standby Ÿ Physical Standby – – – Just refresh Standard process No debate Ÿ Logical Standby – – Refresh wipes out unique db objects Must extract them first Refresh from primary Load unique db objects www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 27
Standby Fails Ÿ Physical – – No problem, just a copy of primary Refresh from primary Ÿ Logical – – – What about unique db objects Recover standby from standby backups Extract unique db objects Refresh standby Insert unique db objects Ÿ Logical standby db must be backed up www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 28
Recovering Logical Standby Ÿ You wanted Logical – To add things Ÿ Indexes for reporting Ÿ How to recover Logical? – – – Rebuild physical from primary Convert to logical How to recreate the additional db objects/data? Ÿ If indexes, recreate them Ÿ If data extracted from copy of primary? www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 29
How It Works Log_archive_dest_n Where n is 1 to 10 Specific value doesn’t matter Ÿ Basic Data. Guard setup Ÿ Where to send archived redo logs? Ÿ Primary – – – Log_archive_dest_1 Ÿ Location for local archived redo logs Ÿ Location=/arch 01/NY Valid_for=(All_Logfiles, All_Roles) Log_archive_dest_2 Ÿ Sends archived redo logs to service name Ÿ Service name points to standby Ÿ Service=LA Valid_for=(Online_logfiles, Primary_Role) Tnsnames. ora Ÿ Contains entry for service name for standby www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 30
How it works Ÿ Standby – Log_archive_dest_n Where n is 1 to 10 Specific value doesn’t matter Log_archive_dest_1 Ÿ Location for local archived redo logs Ÿ Not used while db is physical standby Ÿ Location=/arch 01/LA Valid_for=(All_Logfiles, All_Roles) – Log_archive_dest_2 Ÿ Location receives archived redo logs from primary Ÿ Location=/arch 02/LA Valid_for=(Standby_logfiles, Standby_Role) www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 31
Symmetrical init. ora/spfile Ÿ Use three log_archive_dest_n parameters – – – Setup on primary and standby Don’t need to change for failover Don’t need to change for fail back Ÿ Create tnsnames. ora entry – On primary Ÿ Pointing to standby – On standby Ÿ Pointing to primary Ÿ Less maintenance for frequent failover/back www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 32
Data. Guard init. ora/spfile Active Inactive Db_unique_name=NY_DB Primary Database Online Redo Logs Archived Redo Logs Inactive Db_unique_name=LA_DB Log_archive_dest_1 LOCATION=/arch 01/NY VALID_FOR=(ALL_LOGFILES, ALL_ROLES) Log_archive_dest_1 LOCATION=/arch 01/LA VALID_FOR=(ALL_LOGFILES, ALL_ROLES) Log_archive_dest_2 LOCATION=/arch 02/NY VALID_FOR=(STANDBY_LOGFILES, STANDBY_ROLE) Log_archive_dest_2 LOCATION=/arch 02/LA VALID_FOR=(STANDBY_LOGFILES, STANDBY_ROLE) Log_archive_dest_3 SERVICE=LA VALID_FOR=(ONLINE_LOGFILES, PRIMARY_ROLE) Log_archive_dest_3 SERVICE=NY VALID_FOR=(ONLINE_LOGFILES, PRIMARY_ROLE) Tnsnames. ora LA=(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp) (HOST=<hostname. LA>)(PORT=1521)) (CONNECT_DATA= (SID=LA_DB) ) ) Active for Logical Standby Tnsnames. ora NY=(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp) (HOST=<hostname. NY>)(PORT=1521)) (CONNECT_DATA= (SID=NY_DB) ) ) Standby Database Archived Redo Logs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 33
Data. Guard init. ora/spfile Active Inactive Active for Logical Standby Db_unique_name=NY Standby Database Archived Redo Logs Active Inactive Db_unique_name=LA Log_archive_dest_1 LOCATION=/arch 01/NY VALID_FOR=(ALL_LOGFILES, ALL_ROLES) Log_archive_dest_1 LOCATION=/arch 01/LA VALID_FOR=(ALL_LOGFILES, ALL_ROLES) Log_archive_dest_2 LOCATION=/arch 02/NY VALID_FOR=(STANDBY_LOGFILES, STANDBY_ROLE) Log_archive_dest_2 LOCATION=/arch 02/LA VALID_FOR=(STANDBY_LOGFILES, STANDBY_ROLE) Log_archive_dest_3 SERVICE=LA VALID_FOR=(ONLINE_LOGFILES, PRIMARY_ROLE) Log_archive_dest_3 SERVICE=NY VALID_FOR=(ONLINE_LOGFILES, PRIMARY_ROLE) Tnsnames. ora LA=(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp) (HOST=<hostname. LA>)(PORT=1521)) (CONNECT_DATA= (SID=LA_DB) ) ) Tnsnames. ora NY=(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp) (HOST=<hostname. NY>)(PORT=1521)) (CONNECT_DATA= (SID=NY_DB) ) ) Primary Database Online Redo Logs Archived Redo Logs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 34
Data. Guard Reporting Logical Standby Database Primary Database objects added to Logical standby database indexes for reporting Online Redo Logs Archived Redo Logs Database objects Copied from primary Maintained by Data. Guard Archived Redo Logs Log. Miner Extract SQL www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 35
Rebuild Reporting Standby Ÿ If additional standby db objects have no data – Indexes for reporting Ÿ Refresh from primary wipes out indexes Ÿ Refresh standby – Execute script to recreate indexes www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 36
Create Data. Guard Standby Ÿ Physical Standby Ÿ Logical Standby – – Create physical standby Convert to logical standby www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 37
Create Physical Standby Ÿ On Primary database – – – Enable Forced Logging Create password file Setup init. ora/spfile parameters Verify archiving enabled Backup db (hot or cold) Create standby control file Ÿ Don’t use backup control file www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 38
Create Physical Standby Ÿ On Standby database – – – Copy db backup files from primary Copy standby control file from primary Setup init. ora/spfile parameters Ÿ Db_name same as primary db_name – – Start physical standby db Verify physical standby working www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 39
Convert to Logical Standby Ÿ On Primary database – Build Log. Miner dictionary Ÿ On Standby database – – Stop redo apply Convert database to logical standby Ÿ Change db_name – – – Restart db Open resetlogs Verify logical standby working www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 40
Cascaded Standbys Ÿ Data. Guard supports cascading standbys Ÿ Primary sends redo to – – Physical standby A Logical standby B Ÿ Physical standby A sends redo to – – Physical standby B Physical standby C Ÿ Logical standby B sends redo to Ÿ Don’t you have enough to worry about? www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 41
Real World Example Ÿ What I’m supporting now – – – Logical standby 2 added schemas for custom app Primary db supports Oracle Applications 11 i Ÿ Requirements – Provide copy of primary 11 i db for reporting Ÿ Oracle Discoverer – – Provide copy of 20 30 tables for custom app Additional schemas store custom app data Ÿ Extracted from standby copies of primary tables www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 42
Data. Guard Logical Real World Primary Database objects added to Logical standby database 2 schemas for custom app store data extracted from standby copies of primary tables Logical Standby Database objects Copied from primary Maintained by Data. Guard Procs extract data Online Redo Logs Archived Redo Logs Data. Guard Archived Redo Logs Processed Data Stored Log. Miner Extract SQL www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 43
Real World Refresh/Recovery Ÿ Refresh – – – Backup standby db objects not in primary Refresh standby from primary Recreate additional db objects in standby Ÿ If Logical standby fails – – – Db objects not in primary are lost Need to recover standby db Extract db objects Refresh standby from primary Recreate additional db objects in standby www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 44
Logical Standby Issues Does this sound like a standby? Ÿ Unsupported – Data types BFILE, user defined types – PL/SQL supplied packages Ÿ That modify metadata, DBMA_JAVA etc. – Other things, see manual Ÿ If unsupported, automatically skipped – – No notification of skipped objects Examine primary for unsupported things www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 45
Logical Standby Issues Does this sound like a standby? Ÿ Processing – – Everything done on primary has to be extracted from redo logs and applied to standby db Apply process is just another db user session Ÿ Primary db – Objects may not be well designed Ÿ Tables with poor (or no) indexes – Updates on primary can be very slow when applied as SQL to standby www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 46
Logical Standby Issues Does this sound like a standby? Ÿ If applying to standby too slow – – May have to skip for performance To keep standby in synch per business reqmts Ÿ Ready for reporting once per day Ÿ Primary SQL depends on files on primary – Create java class Ÿ Class files not on standby Ÿ Data. Guard doesn’t maintain filesystems – No notification of such problems www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 47
Logical Standby Issues Ÿ Performance impact – – At any time, slow SQL may take days to complete If you need standby in synch once per day Ÿ Must skip table – If you must have this table in standby Ÿ Must do full refresh from primary – If you can and do skip the table Ÿ Can’t support requirement for reporting on standby Ÿ You never know when this will happen www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 48
Logical Standby Issues Ÿ Logical Standby is like an application – Needs control, review, careful release process Ÿ If Logical Standby is an ‘application’ – – Need dev, alpha, beta, prod Logical standby database for dev, alpha, beta Backups for additional dbs Add space to primary production database? Ÿ Need to add space to 4 primary, 4 logical dbs Ÿ What is added to your infrastructure? – – 4 standby databases Backups for 4 standby databases Does this sound like a standby? www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 49
Logical Standby Issues Ÿ How can standby get out of synch? – – Someone bypassed guard and left it off Someone left guard altered to NONE SYS altered db objects in standby Schema, table, transaction skipped Ÿ No record of transactions skipped – No utilities Ÿ Compare logical standby to primary Ÿ Compare tables standby/primary Does this sound like a standby? www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 50
Logical Standby Issues Ÿ Logical apply process examines standby – – When applying update from primary to standby Compares Ÿ Previous values on primary Ÿ Current values on standby – – – Does this sound like a standby? If different, refuses to apply update from primary Apply process fails Can’t apply anything more Ÿ must cure issue or skip table/transaction Ÿ Differences can go undetected indefinitely – Until next time primary updates object www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 51
Logical Standby Issues Does this sound like a standby? Ÿ Need backups of logical standby database – If there any unique database objects Ÿ If there aren’t, why use logical standby? Ÿ Refresh or rebuild – Have to recover db objects unique to standby Ÿ After refresh – Previously skipped tables Ÿ Do we skip them again? Ÿ Do we wait for them to need to be skipped? www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 52
Real World Redesign Separate database dedicated to custom application Primary Database Physical Standby Database 2 schemas for custom app store data extracted from tables in physical standby database Online Redo Logs Procs extract data Archived Redo Logs Data. Guard Processed Data Stored Archived Redo Logs www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 53
Real World Redesign Ÿ Custom Application database – – – Dedicated for app schemas Db link into physical standby Backup provides recovery of app schemas Ÿ Physical Standby database – – – Let Data. Guard do what it does well None of the Logical Standby issues Can be used as read only for reporting Ÿ When not applying redo logs Ÿ Support an extra database – Don’t have to support Logical Standby www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 54
Recommendation Ÿ Logical for reporting – – – Copy of primary Add indexes to speed reporting Add tables for aggregates Ÿ Objects added to standby – – Easily recreated from a SQL script Contain data that can always be regenerated from copy of primary www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 55
Recommendation Ÿ Physical standby – – Is solid, dependable No issues Ÿ Logical standby – – – Is it really a standby? Is it ready for failover? Is it providing complete data for reports? Lots of issues Is it worth the effort/risk? www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 56
Data. Guard Support Issues Ÿ Covered in 2 nd presentation Ÿ “Oracle Data. Guard Logical Standby Support Issues” www. brianhitchcock. net Brian Hitchcock October 23, 2007 Page 57
- Slides: 57