How to Create an Oracle Standby Database in 5 Steps
Setting up Oracle Data Guard for a database might be daunting for many DBAs. The process involves creating a standby database from the primary database and it seems complicated and convoluted, but is it really? When we come across something that we are not familiar with, we tend to stay away from it. So it happens to be with Data Guard! But once you understand the process of setting up Data Guard, and creating a standby database, you will want to try it yourself, at least in your test or sandbox environment!
New DBAs might be asking what is Oracle Data Guard, and what is the difference between Data Guard and a standby database. Oracle Data Guard is an extension to the Oracle Database software, that helps you maintain and administer the standby-primary database setups. You could have different setups for the standby, however the most common ones are using physical standby databases. That is why in this post, we’ll focus on a physical standby database creation!
With some preparation upfront, it really only takes 5 main steps to create a physical standby database, in as little as 10 minutes! The preparation steps are important and can take some time, as this is where you plan your setup. I would say, this is the most important step.
If you don’t plan it right, that is when things don’t work! You know the saying “if you fail to plan, you plan to fail!”. This applies here too!
Things to consider during your planning session:
- where is the standby database going to be created, which server? Theoretically the standby and the primary database could share the same server/host, but what would be the point of that? The reason to setup Data Guard is to provide high availability (HA) for your system. For learning and demonstration purposes, you can have the two, the primary and standby on the same server. However, please, do not have your production databases setup that way!
- create datafile locations and other directories, ensure you have enough storage space for your standby. Remember that the physical standby is an exact copy block for block, of the primary database. If the primary database is 100GB in size, you need at least the same amount of space for the standby, plus room for growth!
- decide on a database unique name for the standby database. This has to be different from the primary’s unique name!
- create a deployment plan, and the scripts with all your steps and commands! Remember, a good DBA always has a deployment plan!
Once you have things planned and mapped out, creating the standby database is really a 5 steps process:
- Prepare the primary database
- Configure Oracle Net
- Instantiate or create the physical standby database
- Start the redo propagation/transport from the primary to the standby
- Start the redo apply at the standby
Let’s see what is required in each of those steps!
1. Prepare the primary database
- enable archived log mode, if not already enabled. This is mandatory! If the primary database is in noarchive log mode, you cannot create a standby database.
shutdown immediate; startup mount; alter database archivelog;
- enable flashback database. This is optional, but recommended!
alter database flashback on;
- enable force logging. Nologging operations can cause real problems, imagine missing indexes on the standby database!
alter database force logging;
- add standby redo logs to the primary. This is also optional, but recommended!
alter database add standby logfile size 50m; alter database add standby logfile size 50m; alter database add standby logfile size 50m; alter database add standby logfile size 50m;
- make the appropriate parameter changes. There are about 9 parameters that need to be adjusted or setup on the primary.
alter system set db_unique_name=london scope=spfile; -- primary db name alter system set log_archive_config='dg_config=(london,berlin)'; alter system set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles)'; alter system set log_archive_dest_2='service=berlin lgwr async noaffirm valid_for=(online_logfiles, primary_role) db_unique_name=berlin'; -- tns alias pointing to the standby db service alter system set log_archive_dest_state_2=defer; alter system set fal_server=berlin; -- where to go if you need to resolve gaps. this is optional. alter system set db_file_name_convert='berlin','london','BERLIN','LONDON' scope=spfile; alter system set log_file_name_convert='berlin','london','BERLIN','LONDON' scope=spfile; alter system set standby_file_management=auto; startup force; --restart the database for changes to take effect
2. Configure Oracle Net
The listener.ora and the tnsnames.ora have to have entries for the primary and standby. If the standby is on a different server, then you need to make the changes on the standby server as well. The listener cannot use dynamic database registration. The listener needs to know what databases are there and register the database.
-- entry for the listener.ora file, for each database sid_list_listener=(sid_list=(sid_desc=(sid_name=london)) (sid_desc=(sid_name=berlin)) ) lsnrctl stop lsnrctl start
-- entry for the tnsnames.ora file london=(description=(address=(protocol=tcp)(host=127.0.0.1)(port=1521))(connect_data=(sid=london))) berlin=(description=(address=(protocal=tcp)(host=127.0.0.1)(port=1521))(connect_data=(sid=berlin)))
3. Instantiate or create the physical standby database
As with any database creation, before creating the standby database you need a few things setup for it: the pfile and a password file.
You can create the pfile from your primary database and alter a few parameters, that are specific to the standby: control_files, db_file_name_convert, db_unique_name, dispatchers, fal_server, log_file_name_convert. Once this is complete, generate an spfile from the pfile. The standby database must have a password file as well, identical to the primary’s password file. You must copy the primary’s password file over to the standby database and rename it.
To actually create the standby database use RMAN. Create a backup of the primary, and restore it to the standby! There is special syntax to be used for this! For performance reasons, we recommend restoring from backup instead of active database! You want as little impact on the primary database as possible.
startup nomount; -- startup the standby database in nomount; rman target sys/***@london auxiliary sys/***@berlin run (backup current controlfile for standby; backup as compressed backupset database; backup as compressed backupset archivelog all; duplicate target database for standby dorecover;}
4. Start the redo propagation/transport from the primary to the standby
Primary database has to start sending the archived logs to the standby database. This step enables the log_archive_dest_2 parameter and starts sending the logs.
alter system set log_archive_dest_state_2=enable; alter system switch logfile;5. Start the redo apply at the standby
Once the standby is receiving the archived logs from the primary, it has to start applying them to the standby.
alter database recover managed standby database using current logfile disconnect from session;This is it! Now you have a functioning primary-standby database setup. There are a few more optional steps, such as setting up Data Guard Broker and testing a switchover back and forth from the primary to the standby and back! Now it’s your turn to try and create a standby database!
Diana
Free Video Tutorial
Do you want to see John setup a standby database in just 10 min? Check out John Watson’s tutorial with full demo on How to Configure Oracle Data Guard in Ten Minutes !