Documente Academic
Documente Profesional
Documente Cultură
Oracle DataGuard
Maintains a standby database
No attempt to cover them all here Discuss several specific sets of options
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 2
Oracle DataGuard
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?
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 4
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
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 6
Before DataGuard?
Scripts, cron jobs
Copy archived redo logs from primary to standby Apply redo logs on standby periodically
When script(s) executes
Constantly recovering Open standby db with resetlogs Cant be standby again without rebuild Cant fail back to primary without rebuild
Page 7
Failover
www.brianhitchcock.net
Brian Hitchcock October 23, 2007
Standby
Cant change standby db objects
Primary Database
Standby Database
Standby mounted, recovering Can only be opened resetlogs Once opened, cant switch back
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 8
Why DataGuard?
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) Read-only when not applying redo logs Read-write with limitations (Logical Standby) Primary fails, standby becomes primary Cant switch back without rebuild
Page 9
Failover
www.brianhitchcock.net
Brian Hitchcock October 23, 2007
DataGuard Classic*
*Before choice of physical or logical standby
Primary Database
Standby Database
Can switch back and forth -Primary becomes standby -Standby becomes primary
DataGuard
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 10
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 11
Primary redo written continuously to standby No waiting for primary log switch
Standby Database
DataGuard
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 8pm to 5am - Long enough to apply 24 hours of redo logs Stop applying redo logs 5am to 8pm Standby up to 15 hours behind primary Open for reporting 15 hours a day - Reports use old data - Standby data doesnt change from 5am to 8pm
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 14
Protection Modes
Maximum Performance (default)
Primary sends transactions to standby Doesnt wait for them to commit Primary stops if standby doesnt commit Requires standby redo logs Max protection but primary doesnt stop Switch to max perf until standby catches up
Switch back to max availability
Maximum Protection
Maximum Availability
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 15
Primary Database
DataGuard
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 16
Ready to failover?
Block by block copy of primary If any changes made, cant failover - Standby had to be opened resetlogs to change
Refresh
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 17
Physical Standby
Just a copy of production Only needed in production
Dont need to do any dev, testing Recover from backups of primary database One database No backups
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 18
classic standby Cant connect to db while applying redo logs Can be read only when not applying redo logs
Applies redo logs from primary all the time
As long as SQL apply process is running
Logical Standby
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 19
Primary Database
DataGuard
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 20
SQL applied to Logical Standby Just like any other database user
DataGuard
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 21
Logical Standby
Standby is open, read-write Anything copied from primary
Maintained by DataGuard
Depending on Guard status
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 22
Standby
None
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 23
Skipping
Schemas, tables, transactions
May be skipped automatically Can be skipped manually Performance Unsupported db objects More later
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 24
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
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 25
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 Refresh wipes out unique db objects Must extract them first Refresh from primary Load unique db objects
Logical Standby
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 27
Standby Fails
Physical
Logical
To add things
Indexes for reporting
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_1 Location for local archived redo logs Location=/arch01/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_1
Location for local archived redo logs Not used while db is physical standby Location=/arch01/LA Valid_for=(All_Logfiles, All_Roles)
Log_archive_dest_2
Location receives archived redo logs from primary Location=/arch02/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 Dont need to change for failover Dont need to change for fail-back On primary
Pointing to standby
On standby
Pointing to primary
DataGuard init.ora/spfile
Active Inactive Active Inactive Active for Logical Standby Db_unique_name=NY_DB Db_unique_name=LA_DB
Primary Database
Standby Database
Log_archive_dest_3 SERVICE=NY VALID_FOR=(ONLINE_LOGFILES, PRIMARY_ROLE) Tnsnames.ora NY=(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp) (HOST=<hostnameNY>)(PORT=1521)) (CONNECT_DATA= (SID=NY_DB) ) )
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 33
DataGuard init.ora/spfile
Active Inactive Active for Logical Standby Active Inactive Db_unique_name=NY Db_unique_name=LA
Standby Database
Primary Database
Log_archive_dest_3 SERVICE=NY VALID_FOR=(ONLINE_LOGFILES, PRIMARY_ROLE) Tnsnames.ora NY=(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp) (HOST=<hostnameNY>)(PORT=1521)) (CONNECT_DATA= (SID=NY_DB) ) )
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 34
DataGuard Reporting
Primary Database
Logical Standby Database
Database objects Copied from primary Maintained by DataGuard
DataGuard
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 35
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 36
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 37
Enable Forced Logging Create password file Setup init.ora/spfile parameters Verify archiving enabled Backup db (hot or cold) Create standby control file
Dont use backup control file
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 38
Copy db backup files from primary Copy standby control file from primary Setup init.ora/spfile parameters
Db_name same as primary db_name
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 39
Build LogMiner dictionary Stop redo apply Convert database to logical standby
Change db_name
On Standby database
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 40
Cascaded Standbys
DataGuard supports cascading standbys Primary sends redo to
Logical standby B sends redo to Dont you have enough to worry about?
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 41
Logical standby 2 added schemas for custom app Primary db supports Oracle Applications 11i
Provide copy of primary 11i db for reporting
Oracle Discoverer
Requirements
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
DataGuard
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 43
Backup standby db objects not in primary Refresh standby from primary Recreate additional db objects in standby 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
Unsupported
Data types
BFILE, user-defined types
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 45
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 Objects may not be well designed
Tables with poor (or no) indexes
Primary db
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 46
May have to skip for performance To keep standby in synch per business reqmts
Ready for reporting once per day
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 47
At any time, slow SQL may take days to complete If you need standby in synch once per day
Must skip table
Needs control, review, careful release process 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
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 49
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
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 50
If different, refuses to apply update from primary Apply process fails Cant apply anything more
must cure issue or skip table/transaction
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 51
Refresh or rebuild
After refresh
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 52
Primary Database
Physical Standby Database Online Redo Logs
-- 2 schemas for custom app -- store data extracted from tables in physical standby database
DataGuard
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 53
Dedicated for app schemas Db link into physical standby Backup provides recovery of app schemas Let DataGuard do what it does well None of the Logical Standby issues Can be used as read-only for reporting
When not applying redo logs
www.brianhitchcock.net
Brian Hitchcock October 23, 2007
Recommendation
Logical for reporting
Copy of primary Add indexes to speed reporting Add tables for aggregates 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 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?
Logical standby
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 56
www.brianhitchcock.net
Brian Hitchcock October 23, 2007 Page 57