Quando usar snapshot standby no Oracle Data Guard
Em ambientes com Oracle Data Guard, há situações em que se torna necessário executar alterações estruturais, aplicar patches, validar funcionalidades ou simular cargas sem afetar a integridade do banco primário. Nestes casos, o uso do snapshot standby permite converter o standby temporariamente para modo leitura e escrita, viabilizando testes completos em um ambiente isolado.
Essa funcionalidade só é possível porque, durante a conversão para snapshot standby, o Data Guard Broker cria automaticamente um Guaranteed Restore Point no banco standby. A partir daí, o Flashback Database garante a reversão exata ao estado anterior. Após os testes, o banco é revertido para Physical Standby, descartando todas as mudanças feitas durante o snapshot e retomando a sincronização com o primário.
Operacionalmente, é obrigatório que o Flashback esteja habilitado e que a Fast Recovery Area (FRA) tenha espaço suficiente.
Ambiente Oracle 19c com Data Guard
| Função | Datacenter | Host | IP | Instância | Unique Name |
|---|---|---|---|---|---|
| Primário | BR | srvora4 | 192.168.56.11 | AUTOBR | AUTO_U_BR |
| Standby | US | srvora3 | 192.168.56.10 | AUTOUS | AUTO_U_US |
Passo a passo para usar snapshot standby com segurança
1. Preparação inicial
Antes de executar qualquer comando:
- Abrir o
alert.logdo primário e do standby comtail -f - Abrir também o
drc.log(log do Data Guard Broker) nos dois lados:tail -f - Usar dois terminais por banco: um para comandos, outro só para logs
- Não continuar se o broker não estiver funcional (
Configuration Status = SUCCESS)
2. Verificar o status do Data Guard Broker
2.1 Status geral
DGMGRL> SHOW CONFIGURATION;
Esperado: Configuration Status: SUCCESS
DGMGRL> SHOW CONFIGURATION;
Configuration - DG_AUTO
Protection Mode: MaxPerformance
Members:
AUTO_U_BR - Primary database
AUTO_U_US - Physical standby database
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 8 seconds ago)
DGMGRL>
2.2 Detalhes completos
DGMGRL> SHOW CONFIGURATION VERBOSE;
DGMGRL> SHOW CONFIGURATION VERBOSE;
Configuration - DG_AUTO
Protection Mode: MaxPerformance
Members:
AUTO_U_BR - Primary database
AUTO_U_US - Physical standby database
Properties:
FastStartFailoverThreshold = '30'
OperationTimeout = '30'
TraceLevel = 'USER'
FastStartFailoverLagLimit = '30'
CommunicationTimeout = '180'
ObserverReconnect = '0'
FastStartFailoverAutoReinstate = 'TRUE'
FastStartFailoverPmyShutdown = 'TRUE'
BystandersFollowRoleChange = 'ALL'
ObserverOverride = 'FALSE'
ExternalDestination1 = ''
ExternalDestination2 = ''
PrimaryLostWriteAction = 'CONTINUE'
ConfigurationWideServiceName = 'AUTO_CFG'
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS
DGMGRL>
2.3 Consultar Lag
DGMGRL> SHOW CONFIGURATION LAG;
Esperado: Apply Lag e Transport Lag = 0 seconds ou próximo disso
PULO DO GATO: gap ou apply parado? parar aqui.
DGMGRL> SHOW CONFIGURATION LAG;
Configuration - DG_AUTO
Protection Mode: MaxPerformance
Members:
AUTO_U_BR - Primary database
AUTO_U_US - Physical standby database
Transport Lag: 0 seconds (computed 1 second ago)
Apply Lag: 0 seconds (computed 1 second ago)
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 38 seconds ago)
DGMGRL>
2.4 Validar standby antes da conversão
DGMGRL> VALIDATE DATABASE 'AUTO_U_US';
Esperado: Confirmar que o broker está pronto para switchover/failover e verificar o status do Flashback = Yes – ⚠️ Se o flashback estiver Off, não continuar.
DGMGRL> VALIDATE DATABASE 'AUTO_U_US';
Database Role: Physical standby database
Primary Database: AUTO_U_BR
Ready for Switchover: Yes
Ready for Failover: Yes (Primary Running)
Managed by Clusterware:
AUTO_U_BR: YES
AUTO_U_US: YES
Standby Apply-Related Information:
Apply State: Running
Apply Lag: Unknown
Apply Delay: 0 minutes
DGMGRL>
3. Verificar FRA no standby
Mesmo com flashback ativo, o restore point só funciona se a FRA tiver espaço suficiente.
3.1 Parâmetros da FRA
SQL> SHOW PARAMETER db_recovery_file_dest;
SQL> SHOW PARAMETER db_recovery_file_dest_size;
Esses parâmetros mostram o caminho e o tamanho total disponível da FRA.
srvora3:AUTOUS\sys = MOUNTED> SHOW PARAMETER db_recovery_file_dest;
NAME | TYPE | VALUE
------------------------------------ | ---------------------------- | --------------------
db_recovery_file_dest | string | +FRA
db_recovery_file_dest_size | big integer | 100G
srvora3:AUTOUS\sys = MOUNTED>
3.2 Uso atual da FRA
SQL> SELECT file_type, percent_space_used, percent_space_reclaimable,
FROM v$flash_recovery_area_usage;
Esse comando mostra o que está consumindo espaço na FRA (archive logs, backups, restore points, etc).
srvora3:AUTOUS\sys = MOUNTED>
SELECT file_type, percent_space_used, percent_space_reclaimable, number_of_files
2 FROM v$flash_recovery_area_usage;
FILE_TYPE | PERCENT_SPACE_USED | PERCENT_SPACE_RECLAIMABLE | NUMBER_OF_FILES
----------------------- | ------------------ | ------------------------- | ---------
CONTROL FILE | 0 | 0 | 0
REDO LOG | 1.37 | 0 | 7
ARCHIVED LOG | .02 | .01 | 13
BACKUP PIECE | 0 | 0 | 0
IMAGE COPY | 0 | 0 | 0
FLASHBACK LOG | .39 | .2 | 2
FOREIGN ARCHIVED LOG | 0 | 0 | 0
AUXILIARY DATAFILE COPY | 0 | 0 | 0
8 rows selected.
srvora3:AUTOUS\sys = MOUNTED>
4. Converter para snapshot standby via broker
DGMGRL> CONVERT DATABASE 'AUTO_U_US' TO SNAPSHOT STANDBY;
O broker:
- Cria restore point automático
- Abre o banco em modo
READ WRITE
Não interromper o processo.
DGMGRL> CONVERT DATABASE 'AUTO_U_US' TO SNAPSHOT STANDBY;
Converting database "AUTO_U_US" to a Snapshot Standby database, please wait...
Database "AUTO_U_US" converted successfully
DGMGRL>