Implementing Data Guard
Implementing Data Guard
Implementing Data Guard
General Concepts
Architecture
DataGuard Protection Modes
DataGuard Physical Implementation
DataGuard Logical Implementation
Quick Steps for creating the Physical Standby from a Hot backup
Cancel Managed Standby Recovery
DataGuard Monitoring (Detect Gap)
Activate Standby (on Read-Only Mode or PROD Mode)
Switchover Steps
Failover Steps
Implementation Tips
Applying Pacthes with Standby
Resolving Problems
Synchronize a GAP on the STANDBY when ARCH Logs are lost
More Information
GENERAL CONCEPTS
Oracle Data Guard is the management, monitoring, and automation software that work with a
production database and one or more standby databases to protect data against failures, errors, and
corruption that might otherwise destroy your database.
PRIMARY DATABASE:
A primary database is a production database. The primary database is used to create a standby
database. Every standby database is associated with one and only one primary database.
STANDBY DATABASE:
A physical or logical standby database is a database replica created from a backup of a primary
database.
NETWORK CONFIGURATION:
The primary database is connected to one or more remote standby database via Oracle Net.
FAILOVER
During a failover, one of the standby databases takes the primary database role.
SWITCHOVER
The primary database can switch the role to a standby database; and one of the standby databases
can switch roles to become the primary.
$ dgmgrl
Welcome to DGMGRL, type "help" for information.
DGMGRL> help
The following commands are available:
quit
exit
show See "help show" for syntax
enable See "help enable" for syntax
disable See "help disable" for syntax
help [<command>]
connect <user>/<password> [@<connect>]
alter See "help alter" for syntax
create See "help create" for syntax
remove See "help remove" for syntax
switchover See "help switchover" for syntax
failover See "help failover" for syntax
startup See "help startup" for syntax
shutdown See "help shutdown" for syntax
Note: The use of an SPFILE is required with Oracle Release 2 when using a Data Guard Broker
Configuration.
PROCESS ARCHITECTURE
DBAs have the option to set up two different types of standby databases. They are a physical standby
database and a logical standby database.
Physical standby databases are physically identical to primary databases, meaning all objects in the
primary database are the same as in standby database. Physical Standby databases are traditionally
standby databases, identical to primary databases on a block for block basis. It is updated by
performing media recovery; imagine a DBA sitting in the office and recovering the database
constantly.
Logical Standby Databases are logically identical to primary databases although the physical
organization and structure of the data can be different. Logical Standby Databases are updated using
SQL statements. The advantage of a logical standby database is that it can be used for recovery and
reporting simultaneously. I am very interested in the logical standby feature as it can be used for my
disaster recover project as well as it can be used by data warehouse users for their reporting purpose.
Note: Starting in 9.2, the LGWR SYNC actually does use the LNS as well. Only SYNC=NOPARALLEL
goes directly from the LGWR. The default SYNC mode is SYNC=PARALLEL.
NOTE = It is highly recommended that a Data Guard configuration that is run in maximum protection
mode contain at least two physical standby databases that meets the requirements listed in the table
above. That way, the primary database can continue processing if one of the physical standby
databases cannot receive redo data from the primary database. If only one standby database is
configured with the minimum requirements listed above, the primary database will shut down when
the physical standby databases cannot receive redo data from the primary database!
Maximum Availability: Provides the highest level of data protection that is possible without affecting
the availability of the primary database. This protection mode is very similar to maximum protection
where a transaction will not commit until the redo data needed to recover that transaction is written to
both the local (online) redo log and to at least one remote standby redo log. Redo records
aresynchronously transmitted from the primary database to the standby database using LGWR
process. Unlike maximum protection mode; however, the primary database will not shut down if a
fault prevents it from writing its redo data to a remote standby redo log. Instead, the primary database
will operate in maximum performance mode until the fault is corrected and all log gaps have been
resolved. After all log gaps have been resolved, the primary database automatically resumes operating
in maximum availability mode. This protection mode supports both physical and logical standby
databases. Standby online redo logs are required in this mode. The log_archive_des_n parameter
needs to have the LGWR SYNC AFFIRM option, for example:
log_archive_dest_2='service=testdb_standby LGWR SYNC AFFIRM'
Maximum Performance: It is the default protection mode. It offers slightly less primary database
protection than maximum availability mode but with higher performance. Redo logs
are asynchronouslyshipped from the primary database to the standby database using either LGWR
or ARCH process. When operating in this mode, the primary database continues its transaction
processing without regard to data availability on any standby databases and there is little or no effect
on performance. It supports both physical and logical standby databases. The log_archive_des_n
parameter needs to have the LGWR ASYNC AFFIRM or NOAFFIRM option, for example:
log_archive_dest_2='service=testdb_standby ARCH NOAFFIRM'
or
log_archive_dest_2='service=testdb_standby LGWR ASYNC NOAFFIRM'
Mode Log Writing Network Trans Disk Write Redo Log Supported on
Process Mode Option Reception
Option
Maximum LGWR SYNC AFFIRM Standby redo Physical standby
Protection logs are required databases
Maximum LGWR SYNC AFFIRM Standby redo Physical and
Availability logs logical standby
databases
Maximum LGWR or ARCH ASYNC if LGWR NOAFFIRM Standby redo Physical and
Performance logs logical standby
databases
Terms or Options to know
These can be found in the Oracle documentation in Chapter 5 of the Data Guard Concepts and
Administration Manual.
• AFFIRM assures that archive logs are written to disk, primary or standby.
• MANDATORY assures that redo logs are not overwritten until archive logs are successfully created.
This should only apply to the primary database.
• REOPEN=30 means that there will be a 30 second delay until ARCn and/or LGWR processes try
again on a MANDATORY destination which failed.
• DELAY is in minutes and does not stop the copy of an archive log file to a standby server but the
application of redo on the standby after copying the archive log to the standby. This will not help
primary database performance.
• Using ARCH instead of LGWR for the second standby database may help primary database
performance but smaller sized log files would probably be required. SYNC=PARALLEL applies to LGWR
only. Using ARCH waits for a switch on the primary, LGWR copies entries to a standby archive log,
applied only at switch. ARCH will copy and apply at switch. LGWR is more efficient since it writes redo
entries to all standby databases at once but a primary and two standby databases could possibly
cause a performance issue for the primary database, possibly but unlikely! Additionally multiple
archiver processes can be created on the primary database. Increase the value of the
LOG_ARCHIVE_MAX_PROCESSES parameter to start additional archiver processes. The default on my
machine appears to be 2 and not 1 as stated in the manuals; probably because I have two standby
databases.
• The ARCHIVE_LAG_TARGET parameter could be used to increase the frequency of log switches,
thus sending less data to the standby databases more often. Specifies the maximum number of
seconds between each log switch, so it will force a log switch when that number in seconds is reached.
Used on Physical Implementation Only.
Now check for missing primary keys. Application tables without unique primary keys will require them,
as rows will not be identifiable in the logical standby database for update by SQL Apply. Drop any
objects listed or create primary keys for them.
SELECT OWNER, TABLE_NAME, BAD_COLUMN FROM DBA_LOGSTDBY_NOT_UNIQUE;
Best Practices for Network Configuration and Highest Network Redo Rates
• Set SDU=32768 (32K) for the Oracle Net connections between the primary and standby. Setting the
Oracle network services session data unit (SDU) to its maximum setting of 32K resulted in a 5%
throughput improvement over the default setting of 2048 (2K) for LGWR ASYNC transport services and
a 10% improvement for the LGWR SYNC transport service. SDU designates the size of the Oracle Net
buffer used to collect data before it is delivered to the TCP network layer for transmission across the
network. Oracle internal testing of Oracle Data Guard has demonstrated that the maximum setting of
32767 performs best. The gain in performance is a result of the reduced number of system calls
required to pass the data from Oracle Net buffers to the operating system TCP network layer. SDU can
be set on a per connection basis with the SDU parameter in the local naming configuration file
(tnsnames.ora) and the listener configuration file (listener.ora), or SDU can be set for all Oracle Net
connections with the profile parameter DEFAULT_SDU_SIZE in the sqlnet.ora file. This is specially true
for WAN environment.
• Use SSH port forwarding with compression for WAN’s with a large RTT when using maximum
performance mode. Do not use SSH with compression for Maximum Protection and Maximum
Availability modes since it adversely affected the primary throughput. Using SSH port forwarding with
compression reduced the network traffic by 23-60% at a 3-6% increase in CPU usage. This also
eliminated network timeout errors. With the ARCH transport, using SSH also reduced the log transfer
time for RTT’s of 50 ms or greater. For RTT’s of 10ms or less, the ARCH transport log transfer time was
increased when using SSH with compression.
• Ensure TCP.NODELAY is YES
To preempt delays in buffer flushing in the TCP protocol stack, disable the TCP Nagle algorithm by
setting TCP.NODELAY to YES in the SQLNET.ORA file on both the primary and standby systems.
The protection mode can be found by executing this query. PERFORMANCE is the default.
SELECT name, protection_mode, protection_level FROM v$database;
-No Data Loss Mode. The PROTECTION mode applies only to physical standby databases, using LGWR
SYNC and will shutdown the primary database if no standby database can be written to.
-Minimal Data Loss. The AVAILABILITY mode prevents a transaction committing on the primary until all
redo entries are written to at least one standby database. SYNC transport is required and this option is
available to both logical and physical standby type databases. Unlike PROTECTION mode, which shuts
down the primary database in the event of failure to pass redo entries to the standby, this mode
simply lowers the protection mode to PERFORMANCE until the error is corrected.
- No Data Divergence. PERFORMANCE mode is the default setting and available for both physical and
logical standby type databases. A transaction will commit to the primary before all redo entries are
written to any standby database.
To ensure that minimal data loss will be encountered execute this command on the primary database.
The database must be in mounted exclusive mode to execute this command.
ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE AVAILABILITY;
The best way to understand Data Guard implementation is to setup one manually.
The following shows how to set up Data Guard in this given environment:
1. The production database name is FGUARD
2. One primary database instance called FGUARD on host server1; one physical standby database
instance called FGUARD on host server2.
3. Listener listener is on host server1, and pointed by TNS entry FGUARD
4. Listener listener is on host server2, and pointed by TNS entry FGUARD.
5. The purpose of TNS entry FGUARD and FGUARD are used for LGWR/ARCH process to ship redo logs
to the standby site, and for FAL process to fetch redo logs from the primary site.
6. Since Data Guard broker is used here, we set dg_broker_start to true.
7. The protection mode is set to best performance. Therefore, only local archive destination
(log_archive_dest_1) is set to mandatory; the standby archive destination (log_archive_dest_2) is set to
optional for LGWR process, with network transmission method of asynchronous and disk write option of
no affirm.
8. The standby site is not using standby online redo logs. Therefore, the redo log reception option is
archived logs.
Standby Site:
Database Name: FGUARD
Standby Server: server_02
Standby Instance name: FGUARD
Standby Listener: LISTENER
Production DB: PROD_FGUARD
Optional parameters:
log_archive_dest_2='service=stby lgwr sync affirm mandatory reopen=180'
LOG_ARCHIVE_DEST_2 - Specifies the net service name of the standby database (check tnsnames.ora
on primary database).You can either per destination use LGWR or ARCH or both, due to network traffic
it is advised to use LGWR for at most one remote destination. Also the network transmission mode
(SYNC or ASYNC) has to be specified in case primary database modifications are propagated by the
LGWR. The NO DATA LOSS situation demands the SYNC mode, control is not returned to the executing
application or user until the redo information is received by the standby site (this can have impact on
the performance as mentioned).
Optional Parameters:
db_file_name_convert=('/disk1/oracle/oradata/payroll/','/disk1/oracle/oradata/payroll/standby/')
log_file_name_convert=('/disk1/oracle/oradata/payroll/','/disk1/oracle/oradata/payroll/standby/')
DB_FILE_NAME_CONVERT - Specifies the location of datafiles on standby database.The two arguments
that this parameter needs are: location of datafiles on primary database , location of datafiles on
standby database. This parameter will convert the filename of the primary database datafiles to the
filename of the standby datafile filenames. If the standby database is on the same system as the
primary database or if the directory structure where the datafiles are located on the standby site is
different from the primary site then this parameter is required. See Section 3.2.1 for the location of the
datafiles on the primary database. Used on Physical Implementation ONLY.
LOG_FILE_NAME_CONVERT - Specifies the location of redo logfiles on standby database.The two
arguments that this parameter needs are: location of redo logfiles on primary database , location of
redo logfiles on standby database. This parameter will convert the filename of the primary database
log to the filenames of the standby log. If the standby database is on the same system as the primary
database or if the directory structure where the logs are located on the standby site is different from
the primary site then this parameter is required. Used on Physical Implementation ONLY.
DR_FGUARD = PROD_FGUARD =
(DESCRIPTION = (DESCRIPTION =
(ADDRESS_LIST = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = (ADDRESS = (PROTOCOL =
TCP)(HOST = server2)(PORT = TCP)(HOST = server1)(PORT =
1521)) 1521))
) )
(CONNECT_DATA = (CONNECT_DATA =
(SERVER = DEDICATED) (SERVER = DEDICATED)
(SERVICE_NAME = FGUARD) (SID = FGUARD)
) )
) )
Put those parameters into the spfile and startup the database. Next, place the primary database in
archive log mode:
SQL> shutdown immediate;
SQL> create spfile from pfile;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
You should place the primary database in FORCE LOGGING mode. This option ensures that even in the
event that a 'nologging' operation is done, force logging takes precedence and all operations are
logged
into the redo logs.
SQL> alter database force logging;
· Setup the init.ora file for both primary and standby databases. (see section 3)
NOTE: In the above example db_file_name_convert and log_file_name_convert are not needed as the
directory structure on the two hosts are the same. If the directory structure is not the same then
setting of these parameters is recommended. Please reference ML notes 47325.1 and 47343.1 for
further information.
Note here that the Primary init.ora on the Standby host to have log_archive_dest_2 use the alias that
points to the Primary host. You must modify the Standby init.ora on the standby host to have
fal_server and fal_client use the aliases when standby is running on the Primary host.
· Setup the tnsnames.ora and listener.ora file for both primary and standby databases. (see
section 4)
· Startup the Primary database and issue the following command to create the standby control file
(it must be done AFTER the backup):
SQL> alter database create standby controlfile as '/oracle/BCKUP/standby.ctl';
NOTE: The controlfile must be created after the last time stamp for the backup datafiles.
STEP 4: TRANSFER THE DATAFILES AND CONTROL FILE TO THE STANDBY SITE
· Transfer the backuped datafiles, redo log files and archived redo logs to the standby site.
$ rcp /oracle/BCKUP/* server2:/u02/oradata/FGUARD
· Transfer the standby control file to the standby site
$ rcp /oracle/BCKUP/standby.ctl server2:/u01/app/oracle/admin/FGUARD/ctl/control01.ctl
· Also copy the orapwd file and init.ora files. A password file must be created on the Primary and
copied over to the Standby site. The sys password must be identical on both sites. This is
a key pre requisite in order to be able to ship and apply archived logs from Primary to Standby. If you
need to generate a password file perform the following:
cd $ORACLE_HOME/dbs
orapwd file=orapwFGUARD password=oracle force=y
· Set the correct Oracle environment and copy all the files to each location
If the standby is on a separate site with the same directory structure as the primary database then you
can use the same path names for the standby files as the primary files. In this way, you do not have to
rename the primary datafiles in the standby control file.
If the standby is on the same site as the primary database, or the standby database is on a separate
site with a different directory structure the you must rename the primary datafiles in the standby
control file after copying them to the standby site. This can be done using the db_file_name_convert
and log_file_name_convert parameters or by manually using the alter database statements. If the
directory structure is not the same then reference notes 47325.1 and 47343.1 for further information.
If you decided to rename them manually, you MUST use ALTER DATABASE RENAME FILE <oldname>
TO <newname> after the standby database is mounted to rename the database files and redo log
files..
If needed, copy the Standby Controlfile that your created FROM the production DB to the appropiate
location on the standby DB according your init.ora file
$ cd
$ cp standby.ctl /u03/app/oradata/FGUARD/control01.ctl
$ cp standby.ctl /u04/app/oradata/FGUARD/control02.ctl
$ cp standby.ctl /u05/app/oradata/FGUARD/control03.ctl
· Connect as sysdba.
SQL> connect /as sysdba;
SQL> create spfile from pfile;
· Bring the database in nomount mode first.
SQL> startup nomount;
· Mount the standby database.
SQL> alter database mount standby database;
If you decided to rename the database files manually, you MUST use ALTER DATABASE RENAME FILE
<oldname> TO <newname> after the standby database is mounted.
· Issue the following command to bring the standby database in managed recover mode (start log
apply services).
SQL> alter database recover managed standby database disconnect from session;
NOTE: The example includes the DISCONNECT FROM SESSION option so that log apply services run in
a background session.
STEP 8: MONITOR THE LOG TRANSPORT SERVICES AND LOG APPLY SERVICES
· With the protection mode we are using, Maximum Performance, archiving of redo logs to the
remote standby location do not occur until after a log switch. A log switch occurs, by default, when an
online redo log becomes full. Issue a few log switches on the primary database.
SQL> alter system switch logfile;
or
SQL> alter system archive log current;
From the standby database, query the V$ARCHIVED_LOG view to verify the archived redo log was
applied.
select sequence#, archived, applied
from v$archived_log order by sequence#;
- Ensure that table rows in the primary database can be uniquely identified.
select owner, table_name, bad_column from dba_logstdby_not_unique;
- Ensure supplemental logging is enabled and log parallelism is enabled on the primary database.
Supplemental logging must be enabled because the logical standby database cannot use archived
redo logs that contain both supplemental log data and no supplemental log data.
select supplemental_log_data_pk,supplemental_log_data_ui from v$database;
SUP SUP
--- ---
YES YES
- If you plan to be performing switchover operations with the logical standby then you must create an
alternate tablespace in the primary database for logical standby system tables. Use the
DBMS_LOGMNR_D.SET_TABLESPACE procedure to move the tables into the new tablespace. For
example:
EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('logical_tblsp');
Step 1. Enable logging. On your primary database, instruct Oracle Database to force all logging of
changes to the redo, even if nologging or unrecoverable data loads are performed:
Verify that forced logging has been enabled on your primary database, by issuing the following:
Step 2. Enable archiving. Ensure that your primary database is in archive log mode:
If archiving hasn't been enabled on your primary database, run the following:
Note that the LOG_ARCHIVE_START initialization parameter is obsolete in Oracle Database 10g.
Archiving is automatically enabled when you put your database into archive log mode.
Step 3. Put a primary key on every replicated table. The SQL Apply process must be able to
match rows changing in the primary database to the corresponding rows changing in the standby
database. SQL Apply can't use a rowid, because it can be different between the two databases.
Therefore, each table being replicated to a logical standby database must have a primary or unique
key defined.
To identify tables that have rows that cannot be uniquely identified, query
the DBA_LOGSTDBY_NOT_UNIQUE view.
Step 4. Enable supplemental logging. Enabling supplemental logging will direct Oracle Database
to add a small amount of extra information to the redo stream. The SQL Apply process uses this
additional information to maintain tables being replicated. On your primary database, enable
supplemental logging as follows:
SQL> alter database add supplemental log data (primary key, unique index) columns;
SQL> alter system archive log current;
You can verify that supplemental logging has been enabled, by issuing the following on your primary
database:
Step 5. Create a password file for the primary database. Every database in a Data Guard
environment must use a password file. Additionally, the password used by SYS must be the same for
all primary and standby databases. On your primary database server, navigate to ORACLE_HOME/dbs
and issue the following command:
$ orapwd file=orapw<sid_name> password=top_secret
Also, instruct Oracle Database to use the newly created password file, by setting the
init.ora/spfile remote_login_ passwordfile parameter to either EXCLUSIVE or SHARED.
Step 6. Take a backup of your primary database. Take an offline backup of your primary
database. Also in mount state create a backup controlfile.
Step 7. Create a logical standby controlfile. You must create a special logical standby database
controlfile and then copy it to your standby machine. On your primary database, issue the following
SQL:
Note the use of the keyword logical; it's critical to use the correct syntax.
After creating the logical standby controlfile, copy it to your standby machine. In this example, the
standby controlfile must be placed in the /ora01/ oradata/BRDSTN directory on the standby machine
· Identify the archived redo log that contains the logminer dictionary for use in the standby creation
process.
SQL> SELECT NAME FROM V$ARCHIVED_LOG WHERE DICTIONARY_BEGIN='YES' and
STANDBY_DEST='NO';
Step 8. Copy the files to the Standby server. Copy backup datafiles, backup control file and the
latest archived redo log that was identified in the previous steps, and a copy of the primary
initialization parameter file to the standby host.
Step 9. Configure the primary database init.ora/spfile. If you are using an spfile, you may find it
easier to switch to using an init.ora file while implementing your logical standby. After implementation,
you can easily switch back to using an spfile. In this example, BRDSTN is the database name of both
the primary and the standby. Primarydb is the Oracle Net service name of the primary database,
andstandbydb is the Oracle Net service name of the standby database.
db_name=BRDSTN
db_unique_name=primarydb
# dg_config specifies unique Oracle Net service names in Data Guard environment
log_archive_config='dg_config=(primarydb, standbydb)'
log_archive_dest_1='LOCATION=/orarchive/BRDSTN db_unique_name=primarydb'
log_archive_dest_2='service=standbydb valid_for=(online_logfiles,primary_role)
db_unique_name=standbydb'
log_archive_dest_state_1=enable
log_archive_dest_state_2=enable
remote_login_password=exclusive
parallel_max_servers=9
standby_archive_dest=/orarchive/BRDSTN
Step 10. Create init.ora for logical standby. Copy the primary init.ora file to the standby machine,
and then make the necessary modifications for your logical standby database, as shown HERE:
# Change db_unique_name to standby Oracle Net name
db_unique_name=standbydb
# FAL parameters facilitate initial LS setup, but are not required after setup
fal_server=primarydb
fal_client=standbydb
Step 11. Create a password file for the logical standby database. As noted in Step 2, every
Oracle Data Guard-enabled database needs a password file using the same password. On your standby
machine, go to ORACLE_HOME/dbs and issue the following command:
Step 12. Configure Oracle Net for primary and standby databases. The primary and logical
standby databases need to communicate with each other via Oracle Net. Ensure that both the primary
and the logical standby databases have listeners and that the appropriate Oracle Net service
information is in place. Here are examples of the entries in the tnsnames.ora file on both the primary
and the standby servers:
primarydb =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp) (PORT=1521) (HOST=primary_host))
(CONNECT_DATA=(SERVICE_NAME=BRDSTN)))
standbydb=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp) (PORT=1521) (HOST=standby_host))
(CONNECT_DATA=(SERVICE_NAME=BRDSTN)))
Also, Oracle recommends enabling dead connection detection by the setting of sqlnet.expire_time to
one minute in your sqlnet.ora file, as shown:
sqlnet.expire_time=1
Step 13. Start up and activate the logical standby database. On your logical standby server,
start up and activate your logical standby database, as follows:
You may need to give the above ALTER command a few minutes to complete. When it is finished, you
can activate your standby database as follows:
Use the nid utility to reset the name of your logical standby database. Before running nid, shut down
and start up your database in mount mode.
In this example, BRDLS is the new name of your logical standby database. You should now see the
following line prompting you:
Enter Y and a return. At this point, you should see at the bottom of the message text:
Step 14. Change the logical standby db_name in the init.ora file. Now you need to change
the db_name initialization parameter. For example, in your logical standby database init.ora file, make
this change:
db_name=BRDLS
Step 15. Re-create the password file for the logical standby database. After running the nid
utility, you need to re-create your logical standby password file. To do this, navigate to
ORACLE_HOME/dbs, remove the old password file, and issue the following OS command:
Step 16. Open the logical standby database with resetlogs. You can now make your logical
standby database accessible. Start up your database, and open it with the RESETLOGS command, as
follows:
Step 17. Add temp files to the logical standby database. You'll need a temp tablespace in your
logical database if you plan to do any reporting or if you ever transition the logical standby database to
a primary database role. Add the temp file(s) to the logical standby as they existed on the primary
database:
Step 18. Restart the logical standby database SQL Apply process. All you need to do now is
restart the SQL Apply process on your logical standby database:
Quick Steps for Creating the Physical Standby from Hot Backup
At PROD Site
put proper values on the primary db using "alter system set...... "
create pfile from spfile;
alter system switch logfile;
alter system archive log current;
perform hot backup
vi Quick_Hot_Backup.sql
set serveroutput on
set heading off
set feedback off
Set verify off
accept destination prompt 'Enter destination (like /home/dpafumi/) : '
Set Termout off
spool hotbackups.sql
declare
fname varchar2(80);
tname varchar2(80);
tname1 varchar2(80);
aux varchar2(100);
cursor cur1 is
select tablespace_name,file_name
from v$datafile,sys.dba_data_files
where enabled like '%WRITE%'
and file# = file_id
order by 1;
begin
dbms_output.enable(32000);
dbms_output.put_line('spool hotbackups.txt');
if cur1%ISOPEN
then
close cur1;
end if;
open cur1;
fetch cur1 into tname,fname;
tname1 := tname;
dbms_output.put_line('alter tablespace '||tname||' begin backup;');
while cur1%FOUND loop
if tname1 != tname then
dbms_output.put_line('alter tablespace '||tname1||' end backup;');
dbms_output.put_line('alter tablespace '||tname||' begin backup;');
tname1 := tname;
end if;
dbms_output.put_line('!cp '||fname||' &&destination');
fetch cur1 into tname,fname;
end loop;
dbms_output.put_line('alter tablespace '||tname1||' end backup;');
close cur1;
dbms_output.put_line('alter system switch logfile;');
dbms_output.put_line('!sleep 10');
-- dbms_output.put_line('!cp /oracle/oracle7/app/oracle/admin/DIE/ARCHIVE/*.arc '||' &&destination');
dbms_output.put_line('alter database backup controlfile to trace;');
dbms_output.put_line('alter database backup controlfile to '|| CHR(39)|| '&&destination' || '/control.'||
to_char(sysdate,'DDMMYYYYHH24MISS')|| CHR(39) ||';');
dbms_output.put_line('REM *** Copy Last file from udump ***' );
dbms_output.put_line('spool off');
end;
/
spool off
set heading on
set feedback on
set serveroutput off
-- Unremark/Uncomment the following line to run the script
-- or can be run from the sqlplus prompt.
-- @hotbackups
@Quick_Hot_Backup.sql
@hotbackups
- Compress files
- Copy compressed files to standby site
scp CC_*.Z oracle@10.10.10.10:/home/oracle/DBA_SCRIPTS/BCKP
.........
.........
- sqlplus "/ as sysdba"
alter database create standby controlfile as '/home/dpafumi/standby.ctl';
alter database backup controlfile to trace;
- transfer init.ora, passwd and ctrlfile.bin files to standby DB
scp standby.ctl oracle@10.10.10.10:/home/oracle/DBA_SCRIPTS/BCKP
At standby site:
- Copy *.dbf, *log, standby.ctl and *.ora to proper locations
- If needed, copy the Standby Controlfile that your created FROM the production DB to the appropiate
location on the standby DB according your init.ora file
$ cd
$ cp standby.ctl /u03/app/oradata/FGUARD/control01.ctl
$ cp standby.ctl /u04/app/oradata/FGUARD/control02.ctl
$ cp standby.ctl /u05/app/oradata/FGUARD/control03.ctl
- Modify init.ora file containing correct information (like udump, contrl file, etc)
Use if needed
db_file_name_convert=('/opt/oracle/product/10.1.0/db_1/oradata/FGUARD/','/data/oradata/FGUARD/')
log_file_name_convert=('/opt/oracle/product/10.1.0/db_1/oradata/FGUARD/','/data/oradata/FGUARD/')
- sqlplus "/ as sysdba"
create spfile from pfile;
startup nomount;
alter database mount standby database;
recover standby database;
alter database recover managed standby database disconnect from session;
Perform a query of the V$ARCHIVE_GAP view from the physical standby database:
select * from v$archive_gap;
If you get results from this query, it means there is a gap. You can easily detect what is the problem by
checking the alert.log file on your Primary DB.
Potential data loss window for a physical standby database (Archived logs not applied on a physical
standby database)
--On the standby, Get the sequence number of the last applied archive log.
select max(sequence#) Last_applied_arch_log from v$archived_log where applied='YES';
-- On the standby, Get the sequence number of the last complete archive log on the standby.
-- This is the last log the standby can apply without receiving
-- additional archive logs from the primary.
SELECT min(sequence#) Last_archive_log_received FROM v$archived_log
WHERE (sequence#+1) NOT IN (SELECT sequence# FROM v$archived_log)
AND sequence# > &Last_applied_arch_log;
--Connect to the primary database and obtain the sequence number of the current online log:
select sequence# from v$log where status='CURRENT';
Another Method
Use the following SQL on the standby database (the database must be mounted).
--Try to receive and apply the latest Arch Logs from PROD
RECOVER MANAGED STANDBY DATABASE;
or
RECOVER STANDBY DATABASE;
shutdown immediate;
startup nomount;
alter database mount standby database;
SWITCHOVER STEPS
Unlike failover, a switchover operation is a planned operation. All the archive logs required bringing
the standby to the primary’s point in time need to be available. The primary database’s online redo
logs also must be available and intact. During switchover operation, primary and standby databases
switch roles.
For the purpose of the following list, let's pretend the master server is called PROD_01 and the standby
server STDBY_PROD. In a nutshell, these are the steps involved.
1. STDBY_PROD -- Suspend recovery on the standby site.
2. PROD_01 -- Suspend log shipping from the master to the standby site.
3. PROD_01 -- Perform one or more log switches on the master using alter system switch logfile;
commands.
4. PROD_01 -- Note the log sequence numbers generated on the master.
5. PROD_01 -- Shutdown the master using the immediate option.
6. PROD_01 -- Ship the archived redo logs to the standby site.
7. STDBY_PROD -- Apply those archived redo to the standby instance.
8. STDBY_PROD -- Shutdown the standby using the immediate option.
9. PROD_01 -- Ship a copy of the master control files to the standby site positioned in the proper
location.
10. PROD_01 -- Ship a copy of the master's online redo logs to the standby site positioned in the
proper location.
11. STDBY_PROD -- Startup the new master database.
12. STDBY_PROD -- Create a new standby control file.
13. PROD_01 -- Get that new standby control file and position properly.
14. PROD_01 -- Startup mount (standby) the new standby to verify it is OK.
15. PROD_01 -- Shutdown the standby using the immediate option.
In this FULL Example, the old standby database (prod_02) becomes the new primary, and the old
primary (prod_01) becomes the new standby database.
The following are steps for switchover operation:
· Initiate the switchover operation on the primary database. Convert Primary DB to standby
SQL> alter database commit to switchover to standby;
STEP 2: SHUTDOWN THE PRIMARY DATABASE AND BRING UP AS THE NEW STANDBY
DATABASE
· Shutdown the primary database normally
SQL> shutdown immediate;
DATABASE_ROLE SWITCHOVER_STATUS
------------------------- -----------------------------------
PHYSICAL STANDBY TO PRIMARY
STEP 4: SHUTDOWN THE STANDBY DATABASE AND BRING UP AS THE NEW PRIMARY
DATABASE
· Shutdown the standby database
SQL> shutdown immediate;
Failover is only performed as a result of an unplanned outage of the primary database. During a
failover, the standby database (prod_02) becomes the new primary database. It is possible to have
data loss.
Starting in 9.2, you can gracefully Failover even without standby redo log files. Issue the following
command on the standby site to Failover to a new primary database.
SQL> alter database recover managed standby database skip standby logfiles;
This will apply all available redo and make the standby available to become a Primary. Complete the
operation by switching the standby over to the primary role with the following command:
SQL> alter database commit to switchover to primary;
The old primary (prod_01) has to be discarded and can not be used as the new standby
database. You need to create a new standby database by backing up the new primary and restore it
on hostserver_01. The time to create a new standby database exposes the risk of having no standby
database for protection.
After failover operation, you need to modify TNS entry for ‘prod’ to point to the new instance and host
name.
IMPLEMENTATION TIPS
TIP #2: STANDBY ONLINE REDO LOGS VS. STANDBY ARCHIVED REDO LOGS
Online redo logs transferred from the primary database are stored as either standby redo logs or
archived redo logs. Which redo log reception option should we choose? Here is the comparison chart:
Standby Online Redo Logs Standby Archived Redo Logs
Advantages - Pre-allocated files - No extra ARCH process
- Can place on raw devices - Reduce lag time
- Can be duplexed for more protection
- Improve redo data availability
- No Data Loss capable
TIP #5: DISABLE LOG TRANSPORT SERVICES WHEN STANDBY DATABASE IS DOWN
When a standby database or host is down for maintenance, it is advisable to temporarily disable the
log transport services for that site. Especially during a heavily transaction period, one behavior
observed in Oracle is that when one of the standby database is down for maintenance, it can
temporarily freeze the primary database even the data protection mode is set to rapid mode. To avoid
such problem, you can issue this command on the primary database before bring down the standby
database:
SQL> alter system set log_archive_dest_state_2 = defer;
TIP #9: ALWAYS MONITOR LOG APPLY SERVICES AND CHECK ALERT. LOG FILE FOR
ERRORS.
If you are not using Data Guard broker, here is a script to help you to monitor your standby database
recover process:
$ cat ckalertlog.sh
##############################################################
######
## ckalertlog.sh ##
##############################################################
######
#!/bin/ksh
export EDITOR=vi
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0
export ORACLE_HOME LD_LIBRARY_PATH=$ORACLE_HOME/lib
export TNS_ADMIN=/var/opt/oracle
export ORATAB=/var/opt/oracle/oratab
PATH=$PATH:$ORACLE_HOME:$ORACLE_HOME/bin:/usr/ccs/bin:/bin:/usr/bin:/usr/sbin:/
sbin:/usr/openwin/bin:/opt/bin:.; export PATH
DBALIST="primary.dba@company.com,another.dba@company.com";export
Resolving Problems
After adding a datafile to primary database, recovery of the standby database fails with the following
error messages:
ORA-01157: cannot identify/lock data file 16 - see DBWR trace file
ORA-01110: data file 16: '/oracle/oradata/FGUARD/undotbs02.dbf'
ORA-27037: unable to obtain file status
Problem Explanation:
The datafiles do not exist on the standby database.
Solution Description:
Create the datafile(s) on the standby database. When the files exist, recovery can continue.
The datafiles are not automatically created on the standby site. For example, the redo does not create
a new datafile for you.
Then create datafile command from startup mount is:
alter database create datafile '/home/orahome/data/721/users02.dbf';
Gap Detected
If there is a gap on the arch log files, then you need to perform the following:
1- Copy the arch logs that doesn't exist on the DR box
2- Apply them by using the following command:
SQL> alter database recover managed standby database disconnect from session;
If the output from the query displays "Yes," a log switch is possible; if the output displays "No," a log
switch is not possible.
The V$ARCHIVE_DEST view contains the network error and identifies which standby database cannot
be reached. On the primary database, issue the following SQL statement for the archived log
destination that experienced the network failure. For example:
SELECT DEST_ID, STATUS, ERROR FROM V$ARCHIVE_DEST WHERE DEST_ID = 2;
The query results show there are errors archiving to the standby database, and the cause of the error
as TNS:no listener. You should check whether the listener on the standby site is started. If the listener
is stopped, then start it
If you cannot solve the network problem quickly, and if the physical standby database is specified as a
mandatory destination, try to prevent the database from stalling by doing one of the following:
# Disable the mandatory archive destination:
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2 = DEFER;
When the network problem is resolved, you can enable the archive destination again:
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2 = ENABLE;
When the network problem is resolved, you can change the archive destination from optional back to
mandatory:
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2 = 'SERVICE=standby1 MANDATORY REOPEN=60';
DataGuard Scenarios
Synchronyze a GAP on the STANDBY when the required archived logs are lost
Scenario:
All archived logs were removed from primary database. The standby had lagged far behind the
primary, many required archived logs to close the gap were removed and no backup of them was
available.
In order to close the gap you need to create an incremental backup that will contain all transactions
since the last scn recorded on the standby database.
Implementation Steps
3- Create a Primary Database Incremental Backup from this SCN and a Control File for Standby
Z:\backup>rman target sys/pass@PROD
connected to target database: PROD(DBID=1342263826)
RMAN> RUN {
ALLOCATE CHANNEL C1 TYPE DISK FORMAT 'Z:\BACKUP\FOR_STANDBY_%U';
ALLOCATE CHANNEL C2 TYPE DISK FORMAT 'Z:\BACKUP\FOR_STANDBY_%U';
ALLOCATE CHANNEL C3 TYPE DISK FORMAT 'Z:\BACKUP\FOR_STANDBY_%U';
ALLOCATE CHANNEL C4 TYPE DISK FORMAT 'Z:\BACKUP\FOR_STANDBY_%U';
backup incremental from scn 4146871738 database tag 'FORSTANDBY';
RELEASE CHANNEL C1;
RELEASE CHANNEL C2;
RELEASE CHANNEL C3;
RELEASE CHANNEL C4;
}
If more archived logs were created on the primary since the finish of the SCN based incremental
backup then you can copy tehm over and recover the standby database using the command : “recover
standby database"
More Information