Dưới đây là hướng dẫn về cài đặt Oracle Active – standby 2 Node mình đã cài đặt thành công:
Data Guard Physical Standby Setup Using the Data Guard Broker in Oracle Database 11g Release 2
- You have two servers (physical or VMs) with an operating system and Oracle installed on them. In this case I’ve used Oracle Linux 7.2 and Oracle Database 22.214.171.124.
- The primary server (TBDB1) has a running instance.
- The standby server (TBDB2) has a software only installation.
- There is nothing blocking communication between the machines over the listener ports. If you are using the default 1521 port, node 1 should be able to communicate to node 2 on 1521 and node 2 should be able communicate with node 1 on 1521. Check network and local firewalls are not blocking the communication.
Primary Server Setup
Check that the primary database is in archivelog mode.
If it is noarchivelog mode, switch is to archivelog mode.
Enabled forced logging by issuing the following command.
Create standby redo logs on the primary database (in case of switchovers). The standby redo logs should be at least as big as the largest online redo log and there should be one extra group per thread compared the online redo logs. In my case, the following standby redo logs must be created on both servers.
If you want to user flashback database, enable it on the primary now, so it will be enabled on the standby also. It’s very useful as you will see below.
Check the setting for the DB_NAME and DB_UNIQUE_NAME parameters. In this case they are both set to “db11g” on the primary database.
The DB_NAME of the standby database will be the same as that of the primary, but it must have a different DB_UNIQUE_NAME value. For this example, the standby database will have the value “db11g_stby”.
Set suitable remote archive log destinations. In this case I’m using the fast recovery area for the local location, but you could specify an location explicitly if you prefer. Notice the SERVICE and the DB_UNIQUE_NAME for the remote location reference the standby location.
Make sure the STANDBY_FILE_MANAGEMENT parameter is set.
Entries for the primary and standby databases are needed in the “$ORACLE_HOME/network/admin/tnsnames.ora” files on both servers. You can create these using the Network Configuration Utility (netca) or manually. The following entries were used during this setup. Notice the use of the SID, rather than the SERVICE_NAME in the entries. This is important as the broker will need to connect to the databases when they are down, so the services will not be present.
The “$ORACLE_HOME/network/admin/listener.ora” file on the primary server contains the following configuration. Since the broker will need to connect to the database when it’s down, we can’t rely on auto-registration with the listener, hence the explicit entry for the database.
The “$ORACLE_HOME/network/admin/listener.ora” file on the standby server contains the following configuration.
Once the listener.ora changes are in place, restart the listener on both servers.
Standby Server Setup
Prepare for Duplicate
Create a parameter file for the standby database called “/tmp/ initORCL_stby.ora” with the following contents.
Create the necessary directories on the standby server.
Create a password file, with the SYS password matching that of the primary database.
Create Standby Using DUPLICATE
Start the auxiliary instance on the standby server by starting it using the temporary “init.ora” file.
Connect to RMAN, specifying a full connect string for both the TARGET and AUXILIARY instances. Do not attempt to use OS authentication.
Now issue the following DUPLICATE command.
If you need to convert file locations, or alter any initialisation parameters, you can do this during the DUPLICATE using the SET command.
A brief explanation of the individual clauses is shown below.
- FOR STANDBY: This tells the DUPLICATE command is to be used for a standby, so it will not force a DBID change.
- FROM ACTIVE DATABASE: The DUPLICATE will be created directly from the source datafiles, without an additional backup step.
- DORECOVER: The DUPLICATE will include the recovery step, bringing the standby up to the current point in time.
- SPFILE: Allows us to reset values in the spfile when it is copied from the source server.
- NOFILENAMECHECK: Destination file locations are not checked.
Once the command is complete, we can start using the broker.
At this point we have a primary database and a standby database, so now we need to start using the Data Guard Broker to manage them. Connect to both databases (primary and standby) and issue the following command.
On the primary server, issue the following command to register the primary server with the broker.
Now add the standby database.
Now we enable the new configuration.
The following commands show how to check the configuration and status of the databases from the broker.
Configuration RMAN Delete Policy
Login to RMAN and execute command:
1. On the standby database:
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
2. On the primary database:
CONFIGURE ARCHIVELOG DELETION POLICY TO SHIPPED TO ALL STANDBY;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
alter database recover managed standby database cancel;
alter database open;
alter database recover managed standby database using current logfile disconnect;
SELECT log_mode,open_mode FROM v$database;
select process,sequence#,status from v$managed_standby;
A database can be in one of two mutually exclusive modes (primary or standby). These roles can be altered at runtime without loss of data or resetting of redo logs. This process is known as a Switchover and can be performed using the following commands.
Connect to the primary database (orcl) and switchover to the standby database (orcl_stby).
Let’s switch back to the original primary. Connect to the new primary (db11g_stby) and switchover to the new standby database (db11g).
If the primary database is not available the standby database can be activated as a primary database using the following statements. Connect to the standby database (db11g_stby) and failover.
Since the standby database is now the primary database it should be backed up immediately.
The original primary database can now be configured as a standby. If flashback database was enabled on the primary database, then this can be done relatively easily with the following command.
If flashback database is not enabled, you would have to manually recreate db11g as a standby. The basic process is the reverse of what you did previously.
It was already mentioned in the previous section, but it is worth drawing your attention to Flashback Database once more. Although a switchover/switchback is safe for both the primary and standby database, a failover renders the original primary database useless for converting to a standby database. If flashback database is not enabled, the original primary must be scrapped and recreated as a standby database.
An alternative is to enable flashback database on the primary (and the standby if desired) so in the event of a failover, the primary can be flashed back to the time before the failover and quickly converted to a standby database, as shown above.
Read-Only Standby and Active Data Guard
Once a standby database is configured, it can be opened in read-only mode to allow query access. This is often used to offload reporting to the standby server, thereby freeing up resources on the primary server. When open in read-only mode, archive log shipping continues, but managed recovery is stopped, so the standby database becomes increasingly out of date until managed recovery is resumed.
To switch the standby database into read-only mode, do the following.
To resume managed recovery, do the following.
In 11g, Oracle introduced the Active Data Guard feature. This allows the standby database to be open in read-only mode, but still apply redo information. This means a standby can be available for querying, yet still be up to date. There are licensing implications for this feature, but the following commands show how active data guard can be enabled.
Since managed recovery continues with active data guard, there is no need to switch back to managed recovery from read-only mode in this case.
Introduced in 11g, snapshot standby allows the standby database to be opened in read-write mode. When switched back into standby mode, all changes made whilst in read-write mode are lost. This is achieved using flashback database, but the standby database does not need to have flashback database explicitly enabled to take advantage of this feature, thought it works just the same if it is.
Connect to the primary (db11g) database and convert the standby database (db11g_stby) to a snapshot standby.
When you are finished with the snapshot standby, convert it back to a standby database.
The standby is once again in managed recovery and archivelog shipping is resumed. Notice that flashback database is still not enabled.