Oracle 11gR2 – Data Guard Broker

18 October 2010

I have installed Data Guard for about 30 customers over the past five or six years, but so far all have chosen to use SQL*Plus to perform standby role management.

This week I have been working on an Oracle 11.2.0.2 single-instance standby configuration which has been an ideal opportunity to become reaquainted with the Data Guard Broker. I have to say I was impressed…

But I probably cheated; prior to configuring the Broker, I spent the best part of a day building and configuring a physical standby database and then testing redo transport, redo apply, switchover and switchback using the traditional SQL*Plus commands. Before I even started to look at the Broker, I had fixed the usual handful of stupid mistakes, mainly typos, in the configuration.

However, given a solid foundation, implementing the Broker was almost trivial. This post assumes that the db_name is PROD and that the db_unique_names are PROD and STBY.  These names follow my customers existing standards; where possible I prefer to use geographic names for the DB_UNIQUE_NAME parameter as I think it is easier to visualize the configuration during role management.

Configure LISTENER.ORA

First, on each node add a static entry to the LISTENER.ORA file. For example:

SID_LIST_LISTENER =
 (SID_LIST =
   (SID_DESC =
     (GLOBAL_DBNAME = PROD_DGMGRL)
     (ORACLE_HOME= /u01/app/oracle/product/11.2.0/dbhome_1)
     (SID_NAME = PROD)
   )
  )

The Data Guard Broker defaults to static service names with the DGMGRL suffix. It is possible to override the default service names, but in this case I chose the lazy option and stuck with the Oracle defaults.

Note that listener.ora will be different on each node, so don’t copy it around.

Configure TNSNAMES.ORA

We also specified entries for both the primary and standby databases in $ORACLE_HOME/network/admin/tnsnames.ora. For example:

PROD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL=TCP)(HOST=server14.juliandyke.com)(PORT=1521))
   (CONNECT_DATA = 
       (SERVER = DEDICATED)
       (SERVICE_NAME = PROD)
   )
)
STBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL=TCP)(HOST=server15.juliandyke.com)(PORT=1521))
   (CONNECT_DATA = 
       (SERVER = DEDICATED)
       (SERVICE_NAME = STBY)
   )
)

In this example, the PROD database will run on server14 and the STBY database will run on server15.

Enable Data Guard Broker

Next enable the Data Guard Broker for each database (primary and standby) in the configuration by setting the DG_BROKER_START parameter to TRUE.

ALTER SYSTEM SET dg_broker_start = TRUE;

The Data Guard Broker maintains two copies of its configurations. The locations of these files are specified by the DG_BROKER_CONFIG_FILE1 and DG_BROKER_CONFIG_FILE2 parameters. For a single instance database, the default values are:

  • $ORACLE_HOME/dbs/dr1<db_unique_name>.dat
  • $ORACLE_HOME/dbs/dr2<db_unique_name>.dat

The defaults are probably adequate for a single instance database; in a RAC environment the defaults should be modified to specify a location in a shared file system or ASM diskgroup(s).

Start DGMGRL

On any node in the configuration, start the Data Guard Broker command utility (DGMGRL) and connect as the SYS user.

[oracle@server14]$ dgmgrl
DGMGRL> CONNECT SYS
Password: <Enter Password>

Note that it is not necessary to specify the SYSDBA privilege as this is assumed by DGMGRL. 

Create Data Guard Broker Configuration 

Create a configuration. For example:

DGMGRL> CREATE CONFIGURATION DG1' AS
> PRIMARY DATABASE IS 'PROD'
> CONNECT IDENTIFIER IS 'PROD';
Configuration "DG1" created with primary database "PROD"

You will need to specify a configuration name and the unique name of the primary database.

Add standby database(s)

Add all standby databases to the configuration. In this example we just have one physical standby database:

 DGMGRL> ADD DATABASE ‘STBY’ AS
> CONNECT IDENTIFIER IS ‘STBY’;
Database ‘STBY’ added

Enable the configuration

By default the Data Guard configuration is disabled. Enable the configuration as follows:

DGMGRL> ENABLE CONFIGURATION
Enabled.

Switchover to standby

As we started with a working Data Guard configuration, it should be possible to switchover to the standby database at this stage. Switchover is achieved using a single command e.g.:

DGMGRL> SWITCHOVER TO 'STBY'
Performing switchover NOW, please wait...
New primary database "STBY" is opening...
Operation requires shutdown of instance "PROD" on database "PROD"
Shutting down instance "PROD"...
ORACLE instance shut down.
Operation requires startup of instance "PROD" on database "PROD"
Starting instance "PROD"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "STBY"

Switchover worked first time for us. However, we have experienced problems with the restart of the new standby (old primary) in subsequent tests. As these problems are intermittent we think they may be due to timing issues; the servers have new Intel 6-core processors.

Switchback

Switchback is very similar to switchover.

DGMGRL> SWITCHOVER TO 'PROD'
Performing switchover NOW, please wait...
New primary database "PROD" is opening...
Operation requires shutdown of instance "STBY" on database "STBY"
Shutting down instance "STBY"...
ORACLE instance shut down.
Operation requires startup of instance "STBY" on database "STBY"
Starting instance "STBY"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "PROD"

As with switchover we have seen occasional failures with switchback which again we think are timing-related.

Disabling Configuration

The configuration can be disabled at any time using:

DGMGRL> DISABLE CONFIGURATION
Disabled.

Removing the configuration

The configuration can be removed using:

DGMGRL> REMOVE CONFIGURATION
Removed configuration

We have removed the Data Guard Broker configuration a couple of times to fix problems with underlying parameters; it is possible to edit properties within DGMGRL that update parameters, but we wanted to ensure that the underlying configuration was also correct in case the Broker was subsequently deconfigured.

Checking the Data Guard Configuration

You can check the Data Guard configuration in DGMGRL using the SHOW CONFIGURATION command which has both default and verbose modes. For example:

DGMGRL> SHOW CONFIGURATION
 Configuration - DG1
  Protection Mode: MaxAvailability
  Databases:
    PROD - Primary database
    STBY - Physical standby database
  Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS

The verbose option includes some additional properties:

DGMGRL> SHOW CONFIGURATION VERBOSE
Configuration - DG1 
  Protection Mode: MaxAvailability
  Databases:
    PROD - Primary database
    STBY - Physical standby database   
  Properties:
    FastStartFailoverThreshold      = '30'
    OperationTimeout                = '30'
    FastStartFailoverLagLimit       = '30'
    CommunicationTimeout            = '180'
    FastStartFailoverAutoReinstate  = 'TRUE'
    FastStartFailoverPmyShutdown    = 'TRUE'
    BystandersFollowRoleChange      = 'ALL'
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS

Checking the Primary Database Configuration

The primary database configuration can be checked using the SHOW DATABASE command. This command also has a default and verbose mode:

DGMGRL> SHOW DATABASE 'PROD' 
Database - PROD

  Role:            PRIMARY
  Intended State:  TRANSPORT-ON
  Instance(s):
    PROD
Database Status:
SUCCESS

 The verbose mode includes properties for the database, many of which reflect the underlying initialization parameters:

DGMGRL> SHOW DATABASE VERBOSE 'PROD'
 Database - PROD
   Role:            PRIMARY
   Intended State:  TRANSPORT-ON
  Instance(s):
    PROD
 Properties:
  DGConnectIdentifier            = 'PROD'
  ObserverConnectIdentifier      = ''
  LogXptMode                     = 'SYNC'
  DelayMins                      = '0'
  Binding                        = 'OPTIONAL'
  MaxFailure                     = '0'
  MaxConnections                 = '1'
  ReopenSecs                     = '300'
  NetTimeout                     = '30'
  RedoCompression                = 'DISABLE'
  LogShipping                    = 'ON'
  PreferredApplyInstance         = ''
  ApplyInstanceTimeout           = '0'
  ApplyParallel                  = 'AUTO'
  StandbyFileManagement          = 'AUTO'
  ArchiveLagTarget               = '0'
  LogArchiveMaxProcesses         = '5'
  LogArchiveMinSucceedDest       = '1'
  DbFileNameConvert              = '+DATA2, +DATA1'
  LogFileNameConvert             = '+FRA2, +FRA1'
  FastStartFailoverTarget        = ''
  InconsistentProperties         = '(monitor)'
  InconsistentLogXptProps        = '(monitor)'
  SendQEntries                   = '(monitor)'
  RecvQEntries                   = '(monitor)'
  SidName                        = 'PROD'
  StaticConnectIdentifier        =
  '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.227.27.1)
   (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PROD_DGMGRL)
  (INSTANCE_NAME=PROD)(SERVER=DEDICATED)))'
  StandbyArchiveLocation         = '+FRA1'
  AlternateLocation              = ''
  LogArchiveTrace                = '0'
  LogArchiveFormat               = '%t_%s_%r.dbf'
  TopWaitEvents                  = '(monitor)'
Database Status:
SUCCESS

Checking the Physical Standby Database Configuration

The physical standby database configuration can also be checked using the SHOW DATABASE command. Again this command has a default and verbose mode:

DGMGRL> SHOW DATABASE 'STBY'
Database - STBY 
  Role:            PHYSICAL STANDBY
  Intended State:  APPLY-ON
  Transport Lag:   0 seconds
  Apply Lag:       0 seconds
  Real Time Query: OFF
  Instance(s):
    STBY
Database Status:
SUCCESS

I can never remember the names of the Data Guard dynamic performance views so I really like the Transport Lag and Apply Lag fields in the above output.

Again the verbose mode includes properties for the standby database:

DGMGRL> SHOW DATABASE VERBOSE 'STBY'
Database - STBY 
  Role:            PHYSICAL STANDBY
  Intended State:  APPLY-ON
  Transport Lag:   0 seconds
  Apply Lag:       0 seconds
  Real Time Query: OFF
  Instance(s):
    STBY 
Properties:
  DGConnectIdentifier            = 'STBY'
  ObserverConnectIdentifier      = ''
  LogXptMode                     = 'SYNC'
  DelayMins                      = '0'
  Binding                        = 'OPTIONAL'
  MaxFailure                     = '0'
  MaxConnections                 = '1'
  ReopenSecs                     = '300'
  NetTimeout                     = '30'
  RedoCompression                = 'DISABLE'
  LogShipping                    = 'ON'
  PreferredApplyInstance         = ''
  ApplyInstanceTimeout           = '0'
  ApplyParallel                  = 'AUTO'
  StandbyFileManagement          = 'AUTO'
  ArchiveLagTarget               = '0'
  LogArchiveMaxProcesses         = '5'
  LogArchiveMinSucceedDest       = '1'
  DbFileNameConvert              = '+DATA1, +DATA2'
  LogFileNameConvert             = '+FRA1, +FRA2'
  FastStartFailoverTarget        = ''
  InconsistentProperties         = '(monitor)'
  InconsistentLogXptProps        = '(monitor)'
  SendQEntries                   = '(monitor)
  RecvQEntries                   = '(monitor)'
  SidName                        = 'PROD'
  StaticConnectIdentifier        =
  '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.221.27.2)
  (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=STBY_DGMGRL)
  (INSTANCE_NAME=STBY)(SERVER=DEDICATED)))'
  StandbyArchiveLocation         = '+FRA2'
  AlternateLocation              = ''
  LogArchiveTrace                = '0'
  LogArchiveFormat               = '%t_%s_%r.dbf'
  TopWaitEvents                  = '(monitor)'
 Database Status:
SUCCESS

Oracle 11gR2 – Active Data Guard

14 October 2010

Active Data Guard allows a standby database to be opened for read-only access whilst redo is still being applied. For some applications Active Data Guard can represent a more efficient use of Oracle licenses on the standby database.  However, this benefit is offset to a certain extent by the fact that Active Data Guard is available on Enterprise Edition only and is cost option which must be licensed on both the primary and standby database.

Several of my customers are currently using Active Data Guard; in general they are very happy with it. A few others have discovered that it is very easy to inadvertently enable Active Data Guard. This is not desirable or advisable as Oracle have instigated licence audits with a large number of UK customers over the past couple of years.

To determine whether a standby database is using Active Data Guard use the following query:

SELECT database_role, open_mode FROM v$database;

For example:

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY

If you start a database in SQL*Plus using the STARTUP command and then invoke managed recovery, the Active Data Guard will be enabled. For example:

[oracle@server14]$ sqlplus / as sysdba
SQL> STARTUP
ORACLE instance started.
Total System Global Area 6497189888 bytes
Fixed Size 2238672 bytes
Variable Size 3372222256 bytes
Database Buffers 3103784960 bytes
Redo Buffers 18944000 bytes
Database mounted
Database opened

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
USING CURRENT LOGFILE
WITH SESSION SHUTDOWN;

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY

However, if the database is started in SQL*Plus using the STARTUP MOUNT command and then managed recovery is invoked, Active Data Guard will not be enabled.

[oracle@server14]$ sqlplus / as sysdba
SQL> STARTUP MOUNT
ORACLE instance started.
Total System Global Area 6497189888 bytes
Fixed Size 2238672 bytes
Variable Size 3372222256 bytes
Database Buffers 3103784960 bytes
Redo Buffers 18944000 bytes
Database mounted
Database opened

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
USING CURRENT LOGFILE
WITH SESSION SHUTDOWN;

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED

In the database has been started in SQL*Plus using STARTUP MOUNT and the database is subsequently opened read only, then invoking managed recovery will enable Active Data Guard. For example:

[oracle@server14]$ sqlplus / as sysdba
SQL> STARTUP MOUNT
ORACLE instance started.
Total System Global Area 6497189888 bytes
Fixed Size 2238672 bytes
Variable Size 3372222256 bytes
Database Buffers 3103784960 bytes
Redo Buffers 18944000 bytes
Database mounted
Database opened

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED

SQL> ALTER DATABASE OPEN READ ONLY;

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
USING CURRENT LOGFILE
WITH SESSION SHUTDOWN;

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY

Of course not all databases are started using SQL*Plus.

If you start the database using SRVCTL then the default open mode can be specified in the OCR.

You can check the default open mode for a database using SRVCTL CONFIG DATABASE. For example if the database is called PROD:

[oracle@server14]$ srvctl config database -d PROD
Database unique name: PROD
Database name: PROD
Oracle home: /u01/app/oracle/product/11.2.0/dbhome_1
Oracle user: oracle
Spfile: +DATA1/PROD/spfilePROD.ora
Domain:
Start options: open
Stop options: immediate
Database role: PHYSICAL_STANDBY
Management policy: AUTOMATIC
Server pools: PROD
Disk Groups: DATA1, FRA1
Mount point paths:
Services:
Type: SINGLE
Database is administrator managed

In the above example, if the PROD database is started using SRVCTL then the database will be opened in read-only mode. For example:

[oracle@server14]$ srvctl start database -d PROD
[oracle@server14]$ sqlplus / as sysdba

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
USING CURRENT LOGFILE
WITH SESSION SHUTDOWN;

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY

The default start mode can be modified in the OCR using the SRVCTL MODIFY DATABASE command.

For example:

[oracle@server14]$ srvctl modify database -d PROD -s mount

The database configuration is updated as follows:

[oracle@server14]$ srvctl config database -d PROD
Database unique name: PROD
Database name: PROD
Oracle home: /u01/app/oracle/product/11.2.0/dbhome_1
Oracle user: oracle
Spfile: +DATA1/PROD/spfilePROD.ora
Domain:
Start options: mount
Stop options: immediate
Database role: PHYSICAL_STANDBY
Management policy: AUTOMATIC
Server pools: PROD
Disk Groups: DATA1, FRA1
Mount point paths:
Services:
Type: SINGLE
Database is administrator managed

When the default start mode is set to mount, Active Data Guard will not be enabled when managed recovery is invoked. For example:

[oracle@server14]$ srvctl start database -d PROD
[oracle@server14]$ sqlplus / as sysdba

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
USING CURRENT LOGFILE
WITH SESSION SHUTDOWN;

SQL> SELECT database_role, open_mode FROM v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED

You can also specify the start mode as a parameter to the SRVCTL START DATABASE command

For example:

[oracle@server14] srvctl start database -d PROD -o open
[oracle@server14] srvctl start database -d PROD -o mount

Take care when performing a switchover or switchback that the OCR is updated as part of the procedure.


Follow

Get every new post delivered to your Inbox.

Join 32 other followers