Data Guard Aus der Praxis Alexander Hofstetter Trivadis GmbH München BASLE BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH
About me Consultant, Trivadis GmbH, München seit 2008 Oracle DBA Schwerpunkte Hochverfügbarkeit SLA Betreuung Migration & Upgrades 2 11.05.2016
Agenda 1. Einführung 2. Fast Start Failover 3. Backup auf der Standby 4. Monitoring 5. Rollenbasierender Service 6. Fazit 3 11.05.2016
Einführung 4 11.05.2016
Data Guard Data Guard ist eine Enterprise Edition Funktion Data Guard Broker erleichtert die Administration Physical-, Logical- und Snapshot Standby Verschiedene Schutzstufen & Synchronisationswege Sync Primary DB Standby DB 5 11.05.2016
Data Guard Broker Framework Oracle Data Guard broker GUI or command line interface Primary Site Primary database Data Guard broker Data Guard broker Standby Site Standby database Local archiving Remote archiving Archived log files Online log files Standby log files 6 11.05.2016
Standby Typen Physical Standby Kopie der Primary Datenbank auf Datenbankebene Logical Standby Zusätzlich die Möglichkeit eigene Daten zu schreiben Neue DBID! Snapshot Standby In Read / Write Modus geöffnete Physical Standby Datenbank 7 11.05.2016
Protection Modes MaxPerformance Kein Einfluss auf die Performance der Primary Datenbank Commits auf der Primary werden sofort abgesetzt MaxAvailability Commit auf Primary: erst nach Bestätigung der Standby wenn keine Standby verfügbar MaxProtection Zero Data Loss Commit auf Primary erst nach Bestätigung der Standby! Shutdown nach ~10 Minuten wenn keine Standby verfügbar 8 11.05.2016
Protection Modes und Log Transport Mode Mode Processes LogXPTMode Log Transport Attributes Redo Daten Maximum Protection LNS/NSS RFS SYNC SYNC AFFIRM SRL Zero Data Loss Maximum Avaliability LNS/NSS RFS SYNC SYNC AFFIRM SRL Near Zero Data Loss Maximum Avaliability LNS/NSS RFS FASTSYNC SYNC NOAFFIRM SRL Near Zero Data Loss Maximum Performance LNS/NSS RFS ASYNC ASYNC NOAFFIRM SRL Recovery Maximum Performance ARCH RFS ARCH N/A SRL falls Verfügbar Data Loss Redo 9 11.05.2016
Fast Start Failover 10 11.05.2016
Fast Start Failover Überwachung der Konfiguration durch den Observer Automatischer Failover und Reinstate Flashback Database muss aktiv sein Data Guard Broker erforderlich primary DB standby DB 11 11.05.2016
Observer Standort Serverraum A 1 2 Serverraum B log transport primary DB standby DB 3 Public LAN 12 11.05.2016
Observer Standort 1 + FSFO funktioniert in wichtigen Fällen + Keine unnötiges Failover bei Netzwerk Störung - Keine Abdeckung bei Ausfall Serverraum A 13 11.05.2016
Observer Standort 2 + Ausfall Serverraum A ist abgedeckt - Failover kann bei Netzwerkproblemen zu zwei Primarys führen 14 11.05.2016
Observer Standort 3 + FSFO funktioniert in allen Fällen + Observer im gleichen Netz wie Clients - Oft kein dritten Serverraum 15 11.05.2016
Observer Setup 1 Vorbereitung Datenbank Flashback aktivieren (10g + 11GR1 nur im Mount / ab 11.2 auch bei Open) SQL> alter database flashback on; alter system set db_flashback_retention_target=2880; Force Logging setzen SQL> alter database force logging; 16 11.05.2016
Observer Setup 2 fast_start failover Konfiguration DGMGRL> edit database 'DB_SITE2' set property FastStartFailoverTarget = 'DB_SITE1'; edit database 'DB_SITE1' set property FastStartFailoverTarget = 'DB_SITE2'; edit configuration set property FastStartFailoverThreshold = 120; enable fast_start failover; 17 11.05.2016
Observer Setup 3 Observer Start: DGMGRL> connect sys@db_site1 DGMGRL> start observer Observer starten Best Practice: dgmgrl -logfile /u00/app/oracle/local/dba/log/observer.log \ Sys/pw@DB_SITE1 "start observer file='fsfo_db_dg.dat'" Besser als Skript im Hintergrund starten Linux: nohup sh script.sh & Windows: start /b cmd /c "skript.bat" 18 11.05.2016
Backup auf der Standby 19 11.05.2016
Backup auf der Standby (Physical) 1 Entlastung der Primary DB Erhöhung der Komplexität RMAN Catalog wird empfohlen Disk Backup ist nur auf lokaler DB nutzbar Gleicher Pfad erforderlich und Catalog der Files Reset DB_UNIQUE_NAME RMAN> CHANGE BACKUP TAG 'TAG20160502T015121' FOR DB_UNIQUE_NAME DB_SITE2 RESET DB_UNIQUE_NAME TO DB_SITE1; 20 11.05.2016
Backup auf der Standby (Physical) 1 Block Change Tracking File auf der Standby erfordert Active Data Guard! Nur Primary muss explizit im Catalog registriert werden RMAN (target standby, auxiliary primary) Backup as Copy Auxiliary Format RMAN> BACKUP AS COPY REUSE DATAFILE 5 AUXILIARY FORMAT '' Archive Deletion Policy RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO \ APPLIED ON ALL STANDBY \ BACKED UP 1 TIMES TO DEVICE TYPE DISK; 21 11.05.2016
Monitoring 22 11.05.2016
Monitoring Log Files (Alert und Data Guard) alert.dbame.log / drcdbname.log dgmgrl config v$database srvctl config database Log Apply (v$archived_log & v$log_history) MOS Note: 2064281.1 v$dataguard_stats, v$dataguard_status und v$dataguard_config 23 11.05.2016
Monitoring (dgmgrl) DGMGRL show configuration dgmgrl / "show configuration" > ${TmpStatusFile} & sleep 30 grep SUCCESS ${TmpStatusFile} 1>/dev/null 2>&1 if [ $? -eq 0 ]; then echo "Data Guard Configuration in Ordnung" Check FSFO Enabled grep ENABLED ${TmpStatusFile} 1>/dev/null 2>&1 if [ $? -eq 0 ]; then echo "Fast Start Failover in Ordnung" 24 11.05.2016
Monitoring (dgmgrl) DGMGRL show database report DGMGRL> SHOW DATABASE DB_SITE1 StatusReport STATUS REPORT INSTANCE_NAME SEVERITY ERROR_TEXT PHYS ERROR ORA-16737: the redo transport service for standby database "PHYS_SITE2" has an error 25 11.05.2016
Monitoring (v$database) Observer SQL> SELECT fs_failover_observer_present, fs_failover_observer_host FROM v$database; DB-Role, Protection Mode & Level SQL> SELECT database_role, protection_mode, protection_level FROM v$database; Flashback & Open Mode SQL> SELECT flashback_on, open_mode FROM v$database; 26 11.05.2016
Monitoring FRA SQL> SELECT trim(trunc(sum(percent_space_used)- sum(percent_space_reclaimable))) FROM v$flash_recovery_area_usage; Startup Option (Oracle Restart) srvctl config database -d DB_SITE1 grep Start Start options: open Hidden Parameter: "_query_on_physical"=false 27 11.05.2016
Monitoring (Log Apply) Prüfung auf beiden Seiten SQL> SELECT al.rseq "Last Seq Received", lh.aseq "Last Seq Applied" FROM (SELECT max(sequence#) rseq FROM v$archived_log) al, (SELECT max(sequence#) aseq FROM v$log_history) lh; Last Seq Received Last Seq Applied ----------------- ---------------- 15364 15364 28 11.05.2016
Rollenbasierender Service 29 11.05.2016
Rollenbasierender Service Client verbindet nur gegen Service Keine Änderung der TNSNAMES nach Switch- / Failover notwendig DB_RW = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver01)(port = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = dbserver02)(port = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = DB_RW) ) ) 30 11.05.2016
Rollenbasierender Service CREATE OR REPLACE TRIGGER service_trigger AFTER STARTUP ON DATABASE BEGIN IF sys_context('userenv','database_role') = ('PRIMARY') dbms_service.stop_service('db_ro'); dbms_service.disconnect_session('db_ro',dbms_service.immediate); END IF; IF sys_context('userenv','database_role') = 'PRIMARY' THEN dbms_service.start_service('db_rw'); END IF; END; / 31 11.05.2016
Fazit 32 11.05.2016
Fazit Observer ist einfach einzurichten Data Guard Überwachung ist skriptbar Backup auf der Standby Seite entlastet die Primary Vorsicht vor ungewünschter Nutzung von Active Data Guard! 33 11.05.2016
Noch Fragen? Alexander.Hofstetter@trivadis.com 34 11.05.2016
sql select al.thread#,al.aseq "Last Seq Received", lh.hseq "Last Seq Applied" from (select thread#, max(sequence#) aseq from v$archived_log where (RESETLOGS_ID = (select distinct(resetlogs_id) from v$archived_log where ((first_time = (select max(first_time) from v$archived_log))))) group by thread#) al, (select thread#,max(sequence#) hseq from v$log_history where first_time in (select max(first_time) from v$log_history group by thread#) group by thread#) lh where al.thread# = lh.thread#; 35 11.05.2016