You are on page 1of 16

Creating Logical Standby Database Page 1 of 16

1 INTRODUCTION .............................................................................................................................................................2

2 ASSUMPTIONS ................................................................................................................................................................3

3 CREATING LOGICAL STANDBY FROM COLD BACKUP.....................................................................................3


3.1 PREPARING THE PRIMARY DATABASE .......................................................................................................................3
3.2 CREATING LOGICAL STANDBY DATABASE ................................................................................................................5
4 CREATING LOGICAL STANDBY FROM HOT BACKUP .......................................................................................8
4.1 PREPARING THE PRIMARY DATABASE .......................................................................................................................8
4.2 CREATING LOGICAL STANDBY DATABASE ................................................................................................................9
5 VERIFY LOGICAL STANDBY DATABASE..............................................................................................................14
5.1 IDENTIFY THE EXISTING ARCHIVED REDO LOGS .....................................................................................................14
5.2 ARCHIVING THE CURRENT LOG ................................................................................................................................14
5.3 VERIFY THAT THE NEW ARCHIVED LOGS ARE RECEIVED ........................................................................................14
5.4 VERIFY THAT THE NEW ARCHIVED LOGS ARE APPLIED ...........................................................................................14
5.5 CHECK THE OVERALL PROCESS OF LOG APPLY SERVICES ......................................................................................14
6 TROUBLESHOOTING ..................................................................................................................................................15
6.1 ERROR ORA-01152 AND ORA-01110 WHEN STARTING THE LOGICAL STANDBY DATABASE ...............................15
6.2 WHEN LOGS ARE NOT GETTING SHIFTED TO THE LOGICAL STANDBY LOCATION.................................................15
6.3 WHEN LOGS ARE NOT GETTING APPLIED .................................................................................................................15
6.4 IF LOGS ARE NOT GETTING APPLIED AFTER SHUTTING DOWN AND RESTARTING THE LOGICAL STANDBY
DATABASE .............................................................................................................................................................................16
7 CONCLUSION ................................................................................................................................................................16
Creating Logical Standby Database Page 2 of 16

Creating Logical Standby Database (using cold backup and hot backup)

1 INTRODUCTION

A Data Guard configuration can consists of one production database and up to nine standby databases.
Standby databases are the most effective disaster recovery solution for an Oracle database. A standby
database can also be used to remedy problems caused by user errors, data corruption, and other
operational difficulties.

A standby database can be either a physical standby database or a logical standby database:

• Physical standby database - Provides a physically identical copy of the primary database, with on-
disk database structures that are identical to the primary database on a block-for-block basis.

• Logical standby database - Contains the same logical information as the production database,
although the physical organization and structure of the data can be different. The redo logs received
from the primary database are transformed into SQL statements and then applied into the database.

This allows users to access a logical standby database for queries and reporting purposes at any time.
Thus, a logical standby database can be used concurrently for data protection and reporting.

This white paper lists down the steps which can be followed to create a logical standby database (by
taking either a cold backup or a hot backup). Following all of these steps in the order as written down
should result in a clean creation of Logical Standby Database.
Creating Logical Standby Database Page 3 of 16

2 ASSUMPTIONS

This white paper assumes that the Primary database is created and is already running. It also assumes
that the initialization parameters are specified in server parameter file (SPFILE).

3 Creating Logical Standby from Cold Backup

3.1 Preparing the Primary Database

Before creating the logical database, some tasks will have to be performed and the primary database will
have to be prepared for the Data Guard setup.

The steps for preparing the Primary Database for Logical Standby Database creation are given below:

1. Enable Forced Logging for the Primary Database mode using the following SQL

SQL> ALTER DATABASE FORCE LOGGING;

2. Bring the Primary Database in ARCHIVELOG mode and set LOG_PARALLELISM.

Steps:

Set the init.ora parameters –


LOG_ARCHIVE_START=TRUE
LOG_PARALLELISM=1

SQL> SHUTDOWN IMMEDIATE


SQL> STARTUP PFILE=<file name>
SQL> CREATE SPFILE FROM PFILE=’<full path + file name>’;
SQL> ALTER SYSTEM SET
LOG_ARCHIVE_DEST_1=’LOCATION=/opt/oracle/oradata/MYORA MANDATORY’
SCOPE=BOTH;

3. Check for unsupported Data type and Tables

Some of the database objects like LONG, user-defined types etc. are not supported in logical standby
databases. Use the following Query to check if any of these unsupported data types exists in the
primary database.

To get the list of schema and table names those are not supported by logical standby database-
SQL> SELECT DISTINCT OWNER, TABLENAME FROM DBA_LOGSTDBY_UNSUPPORTED
2> ORDER BY OWNER, TABLE_NAME;

To view the column name and data type for one of the tables listed in the previous query-
SQL> SELECT COLUMN_NAME, DATA_TYPE FROM DBA_LOGSTDBY_UNSUPPORTED
2> WHERE OWNER=<owner name> AND TABLE_NAME=<table name>;
If any of the critical tables in the primary database are unsupported then using a Physical Standby
Database might be a better option.

4. Ensure that the table rows in the Primary Database can be Uniquely Identified.
Creating Logical Standby Database Page 4 of 16

Oracle Corporation recommends that there should be a primary key or a unique index to tables on the
primary database, whenever appropriate and possible, to ensure that SQL apply operations can
efficiently apply data updates to the logical standby database.

Use the following query to display a list of tables that SQL apply operations might not be able to
uniquely identify:

SQL> SELECT OWNER, TABLE_NAME,BAD_COLUMN FROM DBA_LOGSTDBY_NOT_UNIQUE


2> WHERE TABLE_NAME NOT IN
3> (SELECT TABLE_NAME FROM DBA_LOGSTDBY_UNSUPPORTED);

5. Enable Supplemental Logging

Supplemental logging must be enabled on the primary database before creating the logical standby
database. Because Oracle only logs the columns that were modified, this is not always sufficient to
uniquely identify the row that changed and additional (supplemental) information must be put into the
redo log. The supplemental information that is added to the redo logs helps log apply services to
correctly identify and maintain tables in the logical standby database.

To check whether supplemental logging is enabled:


SQL> SELECT SUPPLEMENTAL_LOG_DATA_PK, SUPPLEMENTAL_LOG_DATA_UI
2> FROM V$DATABASE;

SUP SUP
--- ---
NO NO
The NO values indicate that supplemental logging is not enabled on the primary database.

To enable supplemental Logging:


SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE INDEX)
2> COLUMNS;

Switch to a new log file to ensure that the redo logs do not contain both supplemental log data and
nonsupplemental log data.

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

Verify Supplemental Logging


SQL> SELECT SUPPLEMENTAL_LOG_DATA_PK, SUPPLEMENTAL_LOG_DATA_UI
2> FROM V$DATABASE;

SUP SUP
--- ----
YES YES
6. Create an Alternate Tablespace
If a switchover operation between the primary database and a logical standby database is expected
in future, an alternate tablespace in the primary database should be created and the logical standby
system tables are moved to that separate tablespace.

SQL> CREATE TABLESPACE logmnrts DATAFILE


2> '/opt/oracle/oradata/MRORA/logmnrts.dbf'
3> SIZE 25M AUTOEXTEND ON MAXSIZE UNLIMITED;
Creating Logical Standby Database Page 5 of 16

SQL> EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('logmnrts');

3.2 Creating Logical Standby Database


This section lists down the tasks that need to be performed to create the Logical Standby database from
a cold backup.

1. Take a cold backup of the Primary database

To take a cold backup of the Primary database, first


• Find out the location of all the data files and the log files.
• Shutdown the database using shutdown immediate/normal/transactional
• Copy all the data files and log files to the backup location.
Cp /opt/oracle/oradata/MYORA/system01.dbf /backup/MYORA/cold/

2. Startup the Database and create a backup copy of the Control file.

SQL> STARTUP MOUNT


SQL> ALTER DATABASE BACKUP CONTROLFILE TO
2> /backup/MYORA/cold/MYORA_backup.ctl;

3. Build the LogMiner dictionary.

On the primary database, enable restricted session mode to reduce the likelihood of users or
applications performing any DML or DDL operations.

SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;


SQL> ALTER DATABASE OPEN;
SQL> EXECUTE DBMS_LOGSTDBY.BUILD;
SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;

4. Starting point for building the logical standby database

To obtain a starting point for building the logical standby database, query the V$ARCHIVED_LOG
view, identify the latest archived redo log, and record its name for use later in the creation process.
The query below will give the latest archive redo log.

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;


SQL> SELECT NAME FROM V$ARCHIVED_LOG
2> WHERE (SEQUENCE#=(SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG
3> WHERE DICTIONARY_BEGIN = 'YES' AND STANDBY_DEST= 'NO'));

NAME
-----------------------------------------
/opt/oracle/ARC/MYORA/arc0004.001

Note: Remember to record the name of the archived redo log for use later in the creation process.

5. Create the parameter file from spfile in the Primary database. The pfile created will be used to create
the pfile of the standby database.

CREATE PFILE=’/backup/MYORA/cold/Primary_init.ora’ FROM SPFILE;

6. Copy Files from the Primary Database Location to the Standby Location
Creating Logical Standby Database Page 6 of 16

Use an operating system copy utility to copy the following binary files from the primary database site
to the standby site:
• Backup data files and redo logs created in Step 1 above

• Backup of control files created in Step 2 of section

• Latest archived redo log that was identified in step 4 above

• Database initialization parameter file created in step 6.

Note: While copying the control files make sure to rename it according to the parameter in init.ora file.

7. Set the init.ora Parameters

DB_NAME='MYORA'

INSTANCE_NAME='MYORA_C'

LOG_ARCHIVE_DEST_1='LOCATION=/OPT/ORACLE/ARC/MYORA MANDATORY'

LOG_ARCHIVE_DEST_STATE_1=ENABLE

LOG_ARCHIVE_FORMAT='MYORA_%T_%S.ARC'

REMOTE_ARCHIVE_ENABLE=RECEIVE

LOG_ARCHIVE_START=TRUE

LOG_PARALLELISM=1

PARALLEL_MAX_SERVERS=9

STANDBY_FILE_MANAGEMENT='AUTO'

STANDBY_ARCHIVE_DEST='/OPT/ORACLE/ARC/MYORA/STDBY'
# The following parameter is required only if the primary and standby databases
# are located on the same system.
LOCK_NAME_SPACE=MYORA_C

8. Configure the Listener for Both the Primary and Standby Databases and Restart/reload the listener(s)

9. Startup the Logical Standby Database

SQL> STARTUP MOUNT PFILE=initMYORA_C.ora;

10. Rename the Data files on the Logical Standby Database

On the Logical standby database rename all the data files and the redo logs to update the control file.
Following is an example of renaming files.
SQL> ALTER DATABASE RENAME FILE '/opt/oracle/oradata/MYORA/system01.dbf'
2> TO '/opt/oracle/oradata/MYORA_C/system01.dbf';

11. Turn on Data Guard and Open database


Creating Logical Standby Database Page 7 of 16

To prevent users from updating objects in the logical standby database, turn on the database guard
by issuing the following SQL statements on the standby database:
SQL> ALTER DATABASE GUARD ALL;
SQL> ALTER DATABASE OPEN RESETLOGS;

12. Reset the Database Name of the Logical Standby Database

Run the Oracle DBNEWID (nid) utility to change the database name of the logical standby database.
This will change the database name in the control file. Till now the dbname in the control file is
primary db name.

SQL> SHUTDOWN IMMEDIATE;


SQL> STARTUP MOUNT PFILE=’<pfile name with full path>’
SQL> EXIT

$> export ORACLE_SID=MYORA_C


$> nid TARGET=SYS/<password> DBNAME=MYORA_C

Modify the init.ora file and set parameter DB_NAME=MYORA_C and if password file is used the
delete and recreate the password file.

SQL> SHUTDOWN IMMEDIATE;


13. Create a server parameter file for the standby database

SQL> CREATE SPFILE FROM PFILE=<pfile name with full path>;

14. Restart the Logical Standby Database


SQL> STARTUP MOUNT;
SQL> ALTER DATABASE OPEN RESETLOGS;

15. Create a New Temporary File for the Logical Standby Database

The temporary files are not included as a part of the closed backup operation so the temporary file
will have to be recreated manually.

To create a Temporary file:


SQL> ALTER TABLESPACE TEMP ADD TEMPFILE
2> '/opt/oracle/oradata/MYORA_C/temp01.dbf' SIZE 40M REUSE;

16. Register the Archived Redo Log and Start SQL Apply Operations

To register the most recently archived redo log and begin applying data from the redo logs to the
standby database, perform the following steps
Creating Logical Standby Database Page 8 of 16

a. Register the most recently archived redo log with log apply services.

Register the archived redo log that was identified in step 4 of Section 3.2 The following example
specifies the file name and location of the most recently archived redo log:
SQL> ALTER DATABASE REGISTER LOGICAL LOGFILE
2> '/opt/oracle/ARC/MYORA_C/arc0004.001';

b. Start applying redo logs to the logical standby database.

Specify the following SQL statement to begin applying redo logs to the logical standby database.

SQL> ALTER DATABASE START LOGICAL STANDBY APPLY INITIAL;

Note: The INITIAL keyword has to be used only for the first time. To apply redo logs there after, the
following statements should be used.

SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY;


SQL> ALTER DATABASE START LOGICAL STANDBY APPLY;

17. Enable Archiving in Logical standby database.

This step has to be performed in the Primary Database to enable archiving to the Logical Standby
database. Use the following statements to start archiving.
SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_3='SERVICE=payroll3 lgwr NO AFFIRM'
2 > SCOPE=BOTH;
SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_3=ENABLE SCOPE=BOTH;

18. Start Remote archiving

To start remote archiving either of the following statements can be used–


SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
SQL> ALTER SYSTEM SWITCH LOGFILE;

The configuration of Logical database is complete. The logs created in the primary database should be
shifted automatically to the standby location and get applied.

See Section 5 for steps to verify whether the logs are getting shifted and applied.

4 Creating Logical Standby from Hot Backup

4.1 Preparing the Primary Database


The steps for preparing the primary database are same as the steps for creating the Logical database
from cold Backup.

After completing the Steps 1 thru 5 of Section 3.1 for preparing the Primary database follow the steps
listed below for completing the setup of Primary database.

1. Configure Resource Manager

Resource Manager is required to put the database into a quiesced state.


Creating Logical Standby Database Page 9 of 16

SQL> ALTER SYSTEM SET RESOURCE_MANAGER_PLAN=SYSTEM_PLAN SCOPE=BOTH;


SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP

2. Create an Alternate Tablespace

If a switchover operation between the primary database and a logical standby database is expected
in future , an alternate tablespace in the primary database should be created and the logical standby
system tables are moved to that separate tablespace.

SQL> CREATE TABLESPACE logmnrts DATAFILE


2> '/opt/oracle/oradata/MRORA/logmnrts.dbf'
3> SIZE 25M AUTOEXTEND ON MAXSIZE UNLIMITED;
SQL> EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('logmnrts');

4.2 Creating Logical Standby Database


This section lists down the tasks that need to be performed to create the Logical Standby database from
a Hot Backup.

This section lists down the tasks that need to be performed to create the Logical Standby database.

1. Take a hot backup of the Primary database

To take a hot backup of the Primary database, first


a. Find out the list of tablespaces in the database and the data files belonging to each
tablespace.
b. Bring a tablespace to backup mode, copy the data file of that tablespace using an OS
command, bring back the tablespace to online.

An Example of taking a backup of the SYSTEM tablespace


SQL> ALTER TABLESPACE SYSTEM BEGIN BACKUP;
! cp /opt/oracle/oradata/MYORA/system01.dbf /backup/MYORA/HOT/
SQL> ALTER TABLESPACE SYSTEM END BACKUP;

c. Preform step (b) for all the tablespaces in the database.

2. Create a backup copy of the Control file.


SQL> ALTER DATABASE BACKUP CONTROLFILE TO
2> /backup/MYORA/HOT/MYORA_backup.ctl;

3. Bring the Database to a Quiesced state

Before building the LogMiner Dictionary the database has to be bought to the Quiesced state.
Execute the command below to bring the Database to a Quiesced state-
SQL> ALTER SYSTEM QUIESCE RESTRICTED;

4. Build the LogMiner dictionary.


SQL> EXECUTE DBMS_LOGSTDBY.BUILD;

5. Identify the archived redo log that contains the LogMiner dictionary and the starting SCN.
Creating Logical Standby Database Page 10 of 16

First switch log file to create the archived log and then query from V$ARCHIVED_LOG

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

SQL> SELECT NAME FROM V$ARCHIVED_LOG WHERE


2 >(SEQUENCE#=(SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG
3 > WHERE DICTIONARY_BEGIN = 'YES' AND STANDBY_DEST='NO'));

NAME
-----------------------------------------------------------
/opt/oracle/ARC/MYORA/MYORA_0001_0000000005.arc

SQL> SELECT MAX(FIRST_CHANGE#) FROM V$ARCHIVED_LOG


2> WHERE DICTIONARY_BEGIN='YES';

MAX(FIRST_CHANGE#)
------------------
2856516

Note: Remember to record the name of the archived redo log for use later in the creation process.

6. Bring the database back to normal


SQL> ALTER SYSTEM UNQUIESCE;
SQL> ALTER SYSTEM SWITCH LOGFILE;

7. Create the parameter file from spfile in the Primary database. The pfile created will be used to create
the pfile of the standby database.

CREATE PFILE=’/backup/MYORA/HOT/Primary_init.ora’ FROM SPFILE;

8. Copy Files from the Primary Database Location to the Standby Location
Use an operating system copy utility to copy the following binary files from the primary database site
to the standby site:

• Backup data files created in Step 1 above

• Backup of control files created in Step 2 of section

• Latest archived redo log that was identified in step 5 above

• Database initialization parameter file created in step 7.

Note: While copying the control files make sure to rename it according to the parameter in init.ora file.

9. Set the init.ora Parameters on the Logical standby site


Creating Logical Standby Database Page 11 of 16

DB_NAME='MYORA'

INSTANCE_NAME='MYORA_H'

LOG_ARCHIVE_DEST_1='LOCATION=/OPT/ORACLE/ARC/MYORA MANDATORY'

LOG_ARCHIVE_DEST_STATE_1=ENABLE

LOG_ARCHIVE_FORMAT='MYORA_%T_%S.ARC'

REMOTE_ARCHIVE_ENABLE=RECEIVE

LOG_ARCHIVE_START=TRUE

LOG_PARALLELISM=1

PARALLEL_MAX_SERVERS=9

STANDBY_FILE_MANAGEMENT='AUTO'

STANDBY_ARCHIVE_DEST='/OPT/ORACLE/ARC/MYORA/STDBY'
# The following parameter is required only if the primary and standby databases
# are located on the same system.
LOCK_NAME_SPACE=MYORA_H

10. Configure the Listener for Both the Primary and Standby Databases and Restart/reload the listener(s)

19. Clear Logfiles

Because the online logs were not copied from the primary system the redo logs will have to be
cleared. To clear redo logs use the following statement for all the groups
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1;
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 2;

11. Recover the Logical Standby Database until SCN recorded at step 5 above.

Use the command below to recover the database –

SQL> ALTER DATABASE RECOVER AUTOMATIC FROM '/opt/oracle/ARC/MYORA_H/'


2> UNTIL CHANGE 2856516 USING BACKUP CONTROLFILE;

If error ‘ORA-279: change %s generated at %s needed for thread %s’ comes the recovery will have to
be canceled and recover it manually using the following command.

SQL> ALTER DATABASE RECOVER LOGFILE


2>‘/opt/oracle/ARC/MYORA_H/MYORA_0001_0000000004.arc’

Notice that the log file taken here is one less than the one noted in Step 5 of Section 4.2

12. Turn on the Data Guard on Logical Standby Database

SQL> ALTER DATABASE GUARD ALL;

13. Open the Logical standby database


SQL> ALTER DATABASE OPEN RESETLOGS;
Creating Logical Standby Database Page 12 of 16

14. Reset the Database Name of the Logical Standby Database

Run the Oracle DBNEWID (nid) utility to change the database name of the logical standby database.
This will change the database name in the control file. Till now the dbname in the control file is
primary db name.

SQL> SHUTDOWN IMMEDIATE;


SQL> STARTUP MOUNT PFILE=’<pfile name with full path>’
SQL> EXIT

$> export ORACLE_SID=MYORA_H


$> nid TARGET=SYS/<password> DBNAME=MYORA_H

Modify the init.ora file and set parameter DB_NAME=MYORA_H and if password file is used the
delete and recreate the password file.

SQL> SHUTDOWN IMMEDIATE;

15. Create a server parameter file for the standby database

SQL> CREATE SPFILE FROM PFILE=<pfile name with full path>;

16. Restart the Logical Standby Database

SQL> STARTUP MOUNT;


SQL> ALTER DATABASE OPEN RESETLOGS;

17. Create a New Temporary File for the Logical Standby Database

The temporary files, are not included as a part of the closed backup operation so the temporary file
will have to be recreated manually.

To create a Temporary file


SQL> ALTER TABLESPACE TEMP ADD TEMPFILE
2> '/opt/oracle/oradata/MYORA_H/temp01.dbf' SIZE 40M REUSE;

18. Register the Archived Redo Log and Start SQL Apply Operations

To register the most recently archived redo log and begin applying data from the redo logs to the
standby database, perform the following steps:
Creating Logical Standby Database Page 13 of 16

a. Register the most recently archived redo log with log apply services.

Register the archived redo log that was identified in step 5 of Section 4.2 The following
example specifies the filename and location of the most recently archived redo log:
SQL> ALTER DATABASE REGISTER LOGICAL LOGFILE
2> '/opt/oracle/ARC/MYORA_H/MYORA_0001_0000000005.arc’;

b. Start applying redo logs to the logical standby database.

Specify the following SQL statement to begin applying redo logs to the logical standby
database using the SCN number identified in Step 5 Section 4.2.

SQL> ALTER DATABASE START LOGICAL STANDBY APPLY INITIAL 2856516;

Note: The INITIAL keyword has to be used only for the first time. To apply redo logs there after, the
following statements should be used.

SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY;


SQL> ALTER DATABASE START LOGICAL STANDBY APPLY;

19. Enable Archiving in Logical standby database

This step has to be performed in the Primary Database to enable archiving to the Logical Standby
database. Use the following statements to start archiving.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_3='SERVICE=payroll3 lgwr NO AFFIRM'


2 > SCOPE=BOTH;
SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_3=ENABLE SCOPE=BOTH;

20. Start Remote archiving

To start remote archiving either of the following statements can be used–


SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
SQL> ALTER SYSTEM SWITCH LOGFILE;

This completes the configuration of Logical Standby Database from Hot Backup. The logs created in the
primary database should be shifted automatically to the standby location and get applied.
See Section 5 for steps to verify whether the logs are getting shifted and applied
Creating Logical Standby Database Page 14 of 16

5 Verify Logical Standby Database


After the creating the Logical Standby Database, it will have to be verified whether the archived logs are
being applied or not.

Following are the procedures which can be used to verify the standby database:

5.1 Identify the Existing Archived redo logs


On the standby database, query the V$ARCHIVED_LOG view to identify existing archived redo logs.

For example
SQL> ALTER SESSION SET NLS_DATE_FORMAT=’DD-MM-YY HH24:MI:SS’;
SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME
2> FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

SEQUENCE# FIRST_TIME NEXT_TIME


---------- ------------------ ------------------
8 15-AUG-04 17:50:45 15-AUG-04 17:50:53
9 15-AUG-04 17:50:53 15-AUG-04 17:50:58
10 15-AUG-04 17:50:58 15-AUG-04 17:51:03

5.2 Archiving the current log


On the primary database, archive the current log using the following SQL statement:
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

5.3 Verify that the new archived logs are received

SQL> ALTER SESSION SET NLS_DATE_FORMAT=’DD-MM-YY HH24:MI:SS’;


SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME
2> FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

SEQUENCE# FIRST_TIME NEXT_TIME


---------- ------------------ ------------------
8 15-AUG-04 17:50:45 15-AUG-04 17:50:53
9 15-AUG-04 17:50:53 15-AUG-04 17:50:58
10 15-AUG-04 17:50:58 15-AUG-04 17:51:03
11 15-AUG-04 17:51:03 15-AUG-04 18:34:11

5.4 Verify that the new archived logs are applied

SQL> SELECT SEQUENCE#, APPLIED FROM V$ARCHIVED_LOG


2> ORDER BY SEQUENCE#;

SEQUENCE# APP
--------- ---
8 YES
9 YES
10 YES
11 YES

5.5 Check the overall process of log apply services

SQL> SELECT APPLIED_SCN, NEWEST_SCN FROM DBA_LOGSTDBY_PROGRESS;


Creating Logical Standby Database Page 15 of 16

APPLIED_SCN NEWEST_SCN
----------- ----------
2858715 2858715

When the numbers in the APPLIED_SCN and NEWEST_SCN columns are equal, it means that all of the
available data in the redo log was applied.

6 Troubleshooting

6.1 Error ORA-01152 and ORA-01110 when starting the Logical Standby Database
If the above errors are encountered when starting the Logical Standby Database during the Step9 of
Section 3.2 then it might be that the backup of control file in step of Section 3.2 is taken after opening the
primary database or not immediately after taking the cold backup.

6.2 When Logs are not getting shifted to the Logical Standby Location
Some of the causes for logs not getting shifted to the logical standby location might be –
• Listener not running. Check the listener and start the listener.
• Tnsnames not set properly.
• If the databases are on two different locations then the network connection might be lost
• Check the alert log for more information.

6.3 When Logs are not getting applied


• Check whether the logs are getting shifted or not.

If the logs are getting shifted then –

• Check the alert log for any ORA errors – take appropriate action after looking at the messages in the
alert log. Some of the action points that can be taken are noted below.

• If the alert log message is – LGWR is actively archiving destination LOG_ARCHIVE_DEST_2 then
wait for some time. The logs are getting applied and it is just taking some time.
• Stop the applying of archived logs and restart-
SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY;
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY;
Check whether logs are getting applied or not

• Find out the last archived log which has been applied and register the next archived log using ‘ALTER
DATABASE REGISTER LOGICAL LOGFILE’ statement on the logical standby database and start log
apply services again.

• Do ‘ALTER DATABASE SWITCH LOGFILE’ in the primary database and Check whether the logs are
getting applied or not.

• LOG_ARCHIVE_DEST_2=’SERVICE=..’ parameter not set properly and not applied at the correct
moment. Enable Archiving in Logical standby database must be done after completing the
configuration of the Logical Standby Database. If this is the causes of the error the whole procedure
will have to be done from the beginning by making sure that the parameters LOG_ARCHIVE_DEST_2
and LOG_ARCHIVE_DEST_STATE_2 are unconfigured before starting the logical standby database
creation.
• Check for any archive gaps-
Use the following query to find if there are any archive gaps –
SQL> COLUMN FILE_NAME FORMAT a55
Creating Logical Standby Database Page 16 of 16

SQL> SELECT THREAD#, SEQUENCE#, FILE_NAME FROM DBA_LOGSTDBY_LOG L


2> WHERE NEXT_CHANGE# NOT IN
3> (SELECT FIRST_CHANGE# FROM DBA_LOGSTDBY_LOG WHERE L.THREAD# = THREAD#)
4> ORDER BY THREAD#,SEQUENCE#;
If there is any archive gap then copy the missing logs to the logical standby location and register them
using the ALTER DATABASE REGISTER LOGICAL LOGFILE statement on the logical standby
database and can restart log apply services.

6.4 If logs are not getting applied after shutting down and restarting the Logical Standby
Database

When a standby database is restarted the log apply services don’t start automatically. It has to be started
manually. If even after starting the log apply services manually the logs are not getting applied then find
out the last archived log which has been applied and register the next archived log using ‘ALTER
DATABASE REGISTER LOGICAL LOGFILE’ statement on the logical standby database and start log
apply services again.

7 Conclusion
The success in creating a Logical Standby Database depends a lot on how the tasks are executed.
Whether the initialization parameters are set properly. Before starting the creation of Logical standby
Database make sure that all the Initialization Parameters are set correctly. Are all the steps followed in
the correct order and whether the appropriate parameters are used?

If everything is done properly then you should be able to do a clean configuration of the Logical Standby
Database in the first go.

Good Luck.