d17316 gc20 l05_phys_sql

29
5 Copyright © 2006, Oracle. All rights reserved. Creating a Physical Standby Database by Using SQL

Upload: moeenuddin

Post on 19-May-2015

568 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: D17316 gc20 l05_phys_sql

5Copyright © 2006, Oracle. All rights reserved.

Creating a Physical Standby Databaseby Using SQL

Page 2: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 2

Objectives

After completing this lesson, you should be ableto use SQL commands to create a physical standby database.

Page 3: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 3

Steps to Create a Physical Standby Database

1. Prepare the primary database.

2. Back up the primary database.

3. Copy files to the standby system.

4. Set parameters on the physical standby database.

5. Start the standby database.

6. Configure Oracle Net Services.

7. Set parameters on the primary database.

8. Start the transport of redo.

Page 4: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 4

Preparing the Primary Database

• Enable FORCE LOGGING at the database level.

• Create a password file.

• Set initialization parameters.

• Enable archiving.

SQL> ALTER DATABASE FORCE LOGGING;

SQL> SHUTDOWN IMMEDIATE;SQL> STARTUP MOUNT;SQL> ALTER DATABASE ARCHIVELOG;SQL> ALTER DATABASE OPEN;

Page 5: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 5

Setting Initialization Parameters on the Primary Database

Parameter Name Description

LOG_ARCHIVE_CONFIG Specifies the unique database name for each database in the configuration

LOG_ARCHIVE_DEST_n Controls redo transport services

LOG_ARCHIVE_DEST_STATE_n Specifies destination state

DB_FILE_NAME_CONVERT Converts primary database file names

LOG_FILE_NAME_CONVERT Converts primary database log file names

STANDBY_FILE_MANAGEMENT Controls automatic standby file management

ARCHIVE_LAG_TARGET Forces a log switch after the specified

number of seconds elapses

LOG_ARCHIVE_TRACE Traces redo data transmission

Page 6: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 6

LOG_ARCHIVE_CONFIG

• Specify the DG_CONFIG attribute to list the DB_UNIQUE_NAME for the primary database and each standby database in the Data Guard configuration.

• Additional LOG_ARCHIVE_CONFIG parameter values:– SEND: enables a database to send redo data to remote

destinations.– RECEIVE: enables the standby database to receive redo

from another database.– Use the NOSEND and NORECEIVE keywords to disable

these settings.

DB_NAME=chicagoDB_UNIQUE_NAME=chicagoLOG_ARCHIVE_CONFIG='DG_CONFIG=(chicago,boston)'

Page 7: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 8

LOG_ARCHIVE_DEST_n

• Specify at least two LOG_ARCHIVE_DEST_n parameters.

• Must contain (at a minimum) one of the following:– LOCATION– SERVICE

• LOG_ARCHIVE_DEST_STATE_n parameter for each defined destination

LOG_ARCHIVE_DEST_2='SERVICE=bostonVALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)DB_UNIQUE_NAME=boston'LOG_ARCHIVE_DEST_STATE_2=ENABLE

Page 8: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 9

LOCATION and SERVICE Attributes

Each archive log destination includes one of the following attributes:• LOCATION: specifies a valid path name.• SERVICE: specifies a valid Oracle Net Services name

referencing a standby database.

LOG_ARCHIVE_DEST_1='LOCATION=/arch1/chicago/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=chicago'LOG_ARCHIVE_DEST_2='SERVICE=boston VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=boston'

Page 9: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 10

LOG_ARCHIVE_DEST_STATE_n

• Defines the current state of an archive log destination:– ENABLE (default)– DEFER– RESET

• Applies to the primary and standby database

log_archive_dest_3='SERVICE=stby1_path1 ALTERNATE=LOG_ARCHIVE_DEST_4'log_archive_dest_4='SERVICE=stby1_path2'log_archive_dest_state_3=ENABLE

Page 10: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 11

Specifying Values for DB_FILE_NAME_CONVERT

• Must be defined on standby databases that have different disk or directory structures from the primary

• Allows multiple pairs of file names

• Applies to a database when in physical standby mode

DB_FILE_NAME_CONVERT =('/oracle1/dba/', '/ora1/stby_dba/', '/oracle2/dba/', '/ora2/stby_dba/')

Page 11: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 12

Specifying Values for LOG_FILE_NAME_CONVERT

• Similar to DB_FILE_NAME_CONVERT• Must be defined on standby databases that have

different disk or directory structures from the primary

• Online redo log files are used only when the standby becomes a primary.

• Applies to a database when in physical standby mode

LOG_FILE_NAME_CONVERT = ('/oracle1/logs/', '/ora1/stby_logs/')

Page 12: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 13

Specifying a Value for LOG_ARCHIVE_FORMAT

• Indicates the format for redo log file names• Format directives:

– %t: Thread number– %T: Zero-filled thread number– %s: Sequence number– %S: Zero-filled sequence number– %d: Database ID– %D: Zero-filled database ID – %a: Current activation ID– %A: Zero-filled activation ID– %r: Resetlogs ID

• Default value is operating-system dependent.

LOG_ARCHIVE_FORMAT = %d_%t_%s_%r.arc

Page 13: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 14

Specifying a Value for STANDBY_FILE_MANAGEMENT

• Used to maintain consistency when you add or delete a data file on the primary database– MANUAL (default)

— Data files must be manually added to the standby database.

– AUTO— Adds the data file automatically to the standby database— Certain ALTER statements are no longer allowed on the standby

database.

• Applies to the primary database and physical standby database

STANDBY_FILE_MANAGEMENT = auto

Page 14: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 15

ARCHIVE_LAG_TARGET

• Configure on primary database only

• Set to the number of seconds after which a log switch must happen even if the log file is not full

• Sets maximum time that a standby database must wait to process the redo

• Default is 0 (disabled)

• Range of values: 60 to 7,200

• Recommended value: 1,800 (30 minutes)

ARCHIVE_LAG_TARGET = 1800

Page 15: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 16

LOG_ARCHIVE_TRACE Parameter

• LOG_ARCHIVE_TRACE is optional and is used for diagnostic purposes.

• Set this parameter to an integer value to see the progression of the archiving of redo logs to the standby system.– On the primary database, processes write an audit trail of

the archived logs sent to the standby system into a trace file.

– On the standby database, processes write an audit trail of the archived logs received from the primary database into a trace file.

• Trace files are located in the directory specified by the USER_DUMP_DEST parameter.

Page 16: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 18

Example: Setting Initialization Parameters on the Primary Database

DB_NAME=chicagoDB_UNIQUE_NAME=chicagoSERVICE_NAMES=chicagoLOG_ARCHIVE_CONFIG='DG_CONFIG=(chicago,boston)'CONTROL_FILES='/arch1/chicago/control1.ctl', '/arch2/chicago/control2.ctl'LOG_ARCHIVE_DEST_1='LOCATION=/arch1/chicago/VALID_FOR=(ALL_LOGFILES,ALL_ROLES)DB_UNIQUE_NAME=chicago'LOG_ARCHIVE_DEST_2='SERVICE=bostonVALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)DB_UNIQUE_NAME=boston'LOG_ARCHIVE_DEST_STATE_1=ENABLELOG_ARCHIVE_DEST_STATE_2=ENABLEREMOTE_LOGIN_PASSWORDFILE=EXCLUSIVELOG_ARCHIVE_FORMAT=%t_%s_%r.arc

Page 17: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 19

Backing Up the Primary Database by Using RMAN

RMAN> BACKUP DATABASE

• Create a backup copy of the primary database.

• Use of RMAN is recommended.

Page 18: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 20

Creating a Control File for the Standby Database

SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE 2 AS '/tmp/boston.ctl';

Create a control file on the primary database to be used for the standby database:

Page 19: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 21

Copying Files to the Standby Database System

Copy the following files to the standby database system:

• Backup of the data files

• Standby control file

• Initialization parameter file

Primary Standby

Page 20: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 22

Oracle Managed Files (OMF) and Automatic Storage Management (ASM)

• OMF: Use same on each database.

• ASM: Use the RMAN DUPLICATE … FOR STANDBY command.

OMF primary

OMF standby

Page 21: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 23

Setting Initialization Parameters on the Standby Database

DB_NAME=chicagoDB_UNIQUE_NAME=bostonSERVICE_NAMES=bostonLOG_ARCHIVE_CONFIG='DG_CONFIG=(chicago,boston)'CONTROL_FILES='/arch1/boston/control1.ctl', '/arch2/boston/control2.ctl'DB_FILE_NAME_CONVERT= '/arch1/chicago/','/arch1/boston/', '/arch2/chicago/','/arch2/boston/'LOG_FILE_NAME_CONVERT='/arch1/chicago/','/arch1/boston/', '/arch2/chicago/','/arch2/boston/'LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc

Continued on the next page…

Page 22: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 24

Setting Initialization Parameters on the Standby Database

LOG_ARCHIVE_DEST_1= 'LOCATION=/arch1/boston/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=boston'LOG_ARCHIVE_DEST_2= 'SERVICE=chicago VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=chicago'LOG_ARCHIVE_DEST_STATE_1=ENABLELOG_ARCHIVE_DEST_STATE_2=ENABLEREMOTE_LOGIN_PASSWORDFILE=EXCLUSIVESTANDBY_FILE_MANAGEMENT=AUTOINSTANCE_NAME=bostonFAL_SERVER=chicagoFAL_CLIENT=boston

Page 23: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 25

Specifying a Value for STANDBY_ARCHIVE_DEST

• Defines the standby database directory where the archived redo log files are created

• Overrides the directory location that is specified with the LOG_ARCHIVE_DEST_n parameter

STANDBY_ARCHIVE_DEST = '/standby/arc_dest/'

STANDBY_ARCHIVE_DEST = 'LOCATION=/standby/arc_dest/'

Page 24: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 26

Setting Up the Environment to Support the Standby Database

1. If creating a standby database on a Windows platform, create a Windows-based service.

2. Create a password file.

3. Configure listeners for the primary and standby databases.

Page 25: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 27

Setting Up the Environment to Support the Standby Database

4. Create Oracle Net Services names.

5. Create a server parameter file for the standby database.

Page 26: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 28

Starting the Physical Standby Database

To start the physical standby database:

1. Bring it to the OPEN READ ONLY stage.

2. Start Redo Apply.

3. Test archival operations to the physical standby database:

SQL> STARTUP;

SQL> ALTER DATABASE RECOVER MANAGED STANDBY

2 DATABASE DISCONNECT FROM SESSION;

Page 27: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 29

Additional Configuration Tasks

Perform the following tasks as appropriate for your configuration:

• Configure standby redo logs.

• Enable real-time apply.

• Enable Flashback Database.

• Upgrade the data protection mode.

Page 28: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 31

Special Note:Standby Database on the Same System

• Standby database data files must be at a different location.

• Each database instance must archive to different locations.

• Service names must be unique.

• The standby database does not protect against disaster.

Primary Standby /oracle/dba /oracle/standby/dba

Page 29: D17316 gc20 l05_phys_sql

Copyright © 2006, Oracle. All rights reserved.5 - 32

Summary

In this lesson, you should have learned how to:

• Create a physical standby with SQL commands

• Enable FORCE LOGGING• Back up the primary database

• Copy files to the standby system

• Set parameters on the physical standby database

• Start the standby database

• Configure Oracle Net Services

• Set parameters on the primary database

• Start the transport of redo