My Env config:
Database Name :prod1
Primary db_unique_name :prod1
standby db_unique_name :sbdb1
SYS@SBDB1> select * from v$VERSION;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
[root@ORACLERAC1 etc]# cat /proc/version
Linux version 2.6.32-358.el6.x86_64 (mockbuild@x86-022.build.eng.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Tue Jan 29 11:47:41 EST 2013
[root@ORACLERAC1 etc]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@ORACLERAC1 etc]#
1. Make the necessary changes to the primary database.
a. Enable force logging.
b. Creating the password file if one does not exist.
c. Create standby redologs.
d. Modify the parameter file suitable for Dataguard.
2. Ensure that the sql*net connectivity is working fine.
3. Create the standby database over the network using the active(primary) database files.
a. Create the password file
b. Create the initialization parameter file for the standby database (auxiliary database)
c. Create the necessary mount points or the folders for the database files
d. Run the standby creation ON STANDBY by connecting to primary as target database.
FOR STANDBY
FROM ACTIVE DATABASE
SPFILE
PARAMETER_VALUE_CONVERT '', ''
SET DB_FILE_NAME_CONVERT '', ''
SET LOG_FILE_NAME_CONVERT '', ''
SET SGA_MAX_SIZE 200M
SET SGA_TARGET 125M;
4. Check the log shipping and apply.
PROCEDURE:
While creating the standby database we use the active database files i.e., this command will be useful in creating the physical standby database using active database files over the network.
1. Prepare the production database to be the primary database
a. Ensure that the database is in archivelog mode .
SQL> alter database archivelog;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 40
Next log sequence to archive 42
Current log sequence 42
b. Enable force logging
SQL> select force_logging from v$database;
FOR
---
NO
SQL> ALTER DATABASE FORCE LOGGING;
Database altered.
SQL> alter database flashback off;
Database altered.
c. Create standby redologs
SQL> set linesize 200
SQL> col member for a60
SQL> select group#,member from v$logfile;
GROUP# MEMBER
---------- ------------------------------------------------------------
3 /u01/app/oracle/oradata/PROD1/redo03.log
2 /u01/app/oracle/oradata/PROD1/redo02.log
1 /u01/app/oracle/oradata/PROD1/redo01.log
SQL>
SQL> select bytes/1024/1024 "Size MB" from v$log;
Size MB
----------
100
100
100
SQL> alter database add standby logfile '/u01/app/oracle/oradata/PROD1/redo04.log' size 100m;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/PROD1/redo05.log' size 100m;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/PROD1/redo06.log' size 100m;
Database altered.
SQL> select group#,member,type from v$logfile where type='STANDBY';
GROUP# MEMBER TYPE
---------- ------------------------------------------------------------ -------
4 /u01/app/oracle/oradata/PROD1/redo04.log STANDBY
5 /u01/app/oracle/oradata/PROD1/redo05.log STANDBY
6 /u01/app/oracle/oradata/PROD1/redo06.log STANDBY
d. Modify the primary initialization parameter for dataguard on primary,
SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(prod1,sbdb1)';
System altered.
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/ prod1 /redo/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME= prod1 ';
System altered.
SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE= sbdb1 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME= sbdb1 ';
System altered.
SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
System altered.
SQL> alter system set FAL_SERVER= sbdb1 ;
System altered.
SQL> alter system set FAL_CLIENT=prod1;
System altered.
SQL> alter system set DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/sbdb1/','/u01/app/oracle/oradata/PROD1/' scope=spfile;
System altered.
SQL> alter system set LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/PROD1/redo/','/u01/app/oracle/oradata/PROD1/redo' scope=spfile;
System altered.
2. Ensure that the sql*net connectivity is working fine.
Insert a static entry for Boston in the listener.ora file of the standby system.
NOTE : For non default port set the REMOTE_LISTENER
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=135.149.96.153)(PORT=1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=PROD1.us.oracle.com)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0)
(SID_NAME=PROD1))
(SID_DESC=
(SID_NAME=plsextproc)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0)
(PROGRAM=extproc)))
TNSNAMES.ORA for the Primary and Standby should have BOTH entries
PROD1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = tcp)(HOST = 135.149.96.153)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = PROD1)
)
)
SBDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = tcp)(HOST = 135.149.96.152)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = SBDB1.us.oracle.com)
)
)
Check with the SQL*Net configuration using the following commands on the Primary AND Standby
% tnsping PROD1
% tnsping SBDB1
3. Create the standby database
a. Copy the password file from the primary $ORACLE_HOME/dbs and rename it to the standby database name.
The username is required to be SYS and the password needs to be the same on the Primary and Standby.
The best practice for this is to copy the passwordfile as suggested.
The password file name must match the instance name/SID used at the standby site, not the DB_NAME.
b. Create a initialization parameter with only one parameter DB_NAME.
DB_NAME= PROD1
DB_UNIQUE_NAME= SBDB1
DB_BLOCK_SIZE=
#####################################################################################
SBDB1.__db_cache_size=683671552
SBDB1.__java_pool_size=4194304
SBDB1.__large_pool_size=12582912
SBDB1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
SBDB1.__pga_aggregate_target=314572800
SBDB1.__sga_target=943718400
SBDB1.__shared_io_pool_size=0
SBDB1.__shared_pool_size=226492416
SBDB1.__streams_pool_size=4194304
*.audit_file_dest='/u01/app/oracle/admin/SBDB1/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/SBDB1/control01.ctl','/u01/app/oracle/fast_recovery_area/SBDB1/control02.ctl'
*.db_block_size=8192
*.db_cache_size=683671552
*.db_domain=''
*.db_name='PROD1'
*.db_recovery_file_dest_size=4294967296
*.db_recovery_file_dest='/home/oracle/flash'
*.DB_UNIQUE_NAME='SBDB1'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=SBDB1XDB)'
*.FAL_SERVER='PROD1'
*.java_pool_size=4194304
*.job_queue_processes=1000
*.large_pool_size=12582912
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(SBDB1,PROD1)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/home/oracle/flash
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=SBDB1'
*.LOG_ARCHIVE_DEST_2='SERVICE=PROD1 ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=PROD1'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.log_archive_format='%t_%s_%r.dbf'
*.LOG_ARCHIVE_MAX_PROCESSES=30
*.LOG_FILE_NAME_CONVERT='SBDB1','PROD1'
*.open_cursors=300
*.pga_aggregate_target=314572800
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.result_cache_max_size=15728640
*.result_cache_mode='MANUAL'
*.sessions=335
*.sga_target=943718400
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.streams_pool_size=4194304
*.undo_tablespace='UNDOTBS1'
#####################################################################################
c. Create the necessary directories in the standby location to place database files and trace files ($ADR_HOME).
SQL> sho parameter diag
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
diagnostic_dest string /u01/app/oracle
d. Set the environment variable ORACLE_SID to the standby service and start the standby-instance.
SYS@SBDB1> create spfile from pfile;
File created.
SYS@SBDB1> startup nomount;
ORACLE instance started.
Total System Global Area 939495424 bytes
Fixed Size 2258840 bytes
Variable Size 352323688 bytes
Database Buffers 578813952 bytes
Redo Buffers 6098944 bytes
e. Verify if the connection 'AS SYSDBA' is working
[oracle@ORACLERAC2 ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Wed Sep 27 16:09:04 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn sys/oracle@prod1 as SYSDBA;
Connected.
SQL> conn sys/oracle@sbdb1 as sysdba;
Connected.
f. On the primary system invoke the RMAN executable and connect to the primary and the auxiliary database ( i.e., the standby)
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Sep 27 15:09:49 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD1 (DBID=2173443108)
using target database control file instead of recovery catalog
connected to auxiliary database: PROD1 (not mounted)
RMAN> run {
2> allocate channel prmy1 type disk;
3> allocate channel prmy2 type disk;
4> allocate auxiliary channel stby type disk;
5> duplicate target database for standby from active database nofilenamecheck;
6> }
allocated channel: prmy1
channel prmy1: SID=374 device type=DISK
allocated channel: prmy2
channel prmy2: SID=21 device type=DISK
allocated channel: stby
channel stby: SID=241 device type=DISK
Starting Duplicate Db at 27-SEP-17
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2.0/dbs/orapwPROD1' auxiliary format
'/u01/app/oracle/product/11.2.0/dbs/orapwSBDB1' ;
}
executing Memory Script
Starting backup at 27-SEP-17
Finished backup at 27-SEP-17
contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/SBDB1/control01.ctl';
restore clone primary controlfile to '/u01/app/oracle/fast_recovery_area/SBDB1/control02.ctl' from
'/u01/app/oracle/oradata/SBDB1/control01.ctl';
}
executing Memory Script
Starting backup at 27-SEP-17
channel prmy1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/dbs/snapcf_PROD1.f tag=TAG20170927T150955 RECID=15 STAMP=955811395
channel prmy1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 27-SEP-17
Starting restore at 27-SEP-17
channel stby: copied control file copy
Finished restore at 27-SEP-17
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/PROD1/temp01.dbf";
set newname for tempfile 2 to
"/u01/app/oracle/oradata/PROD1/temp101.dbf";
set newname for tempfile 3 to
"/u01/app/oracle/oradata/PROD1/temp201.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/PROD1/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/PROD1/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/PROD1/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/PROD1/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/PROD1/example01.dbf";
set newname for datafile 6 to
"/u01/app/oracle/oradata/PROD1/test.dbf";
set newname for datafile 7 to
"/u01/app/oracle/oradata/PROD1/index.dbf";
set newname for datafile 8 to
"/u01/app/oracle/oradata/PROD1/tools.dbf";
set newname for datafile 9 to
"/u01/app/oracle/oradata/PROD1/oltp.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oracle/oradata/PROD1/system01.dbf" datafile
2 auxiliary format
"/u01/app/oracle/oradata/PROD1/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oracle/oradata/PROD1/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oracle/oradata/PROD1/users01.dbf" datafile
5 auxiliary format
"/u01/app/oracle/oradata/PROD1/example01.dbf" datafile
6 auxiliary format
"/u01/app/oracle/oradata/PROD1/test.dbf" datafile
7 auxiliary format
"/u01/app/oracle/oradata/PROD1/index.dbf" datafile
8 auxiliary format
"/u01/app/oracle/oradata/PROD1/tools.dbf" datafile
9 auxiliary format
"/u01/app/oracle/oradata/PROD1/oltp.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/PROD1/temp01.dbf in control file
renamed tempfile 2 to /u01/app/oracle/oradata/PROD1/temp101.dbf in control file
renamed tempfile 3 to /u01/app/oracle/oradata/PROD1/temp201.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting backup at 27-SEP-17
channel prmy1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
channel prmy2: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf
output file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf tag=TAG20170927T151002
channel prmy1: datafile copy complete, elapsed time: 00:00:25
channel prmy1: starting datafile copy
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD1/test.dbf
output file name=/u01/app/oracle/oradata/PROD1/system01.dbf tag=TAG20170927T151002
channel prmy2: datafile copy complete, elapsed time: 00:00:25
channel prmy2: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf
output file name=/u01/app/oracle/oradata/PROD1/example01.dbf tag=TAG20170927T151002
channel prmy2: datafile copy complete, elapsed time: 00:00:07
channel prmy2: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
output file name=/u01/app/oracle/oradata/PROD1/test.dbf tag=TAG20170927T151002
channel prmy1: datafile copy complete, elapsed time: 00:00:11
channel prmy1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
output file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf tag=TAG20170927T151002
channel prmy2: datafile copy complete, elapsed time: 00:00:06
channel prmy2: starting datafile copy
input datafile file number=00009 name=/u01/app/oracle/oradata/PROD1/oltp.dbf
output file name=/u01/app/oracle/oradata/PROD1/users01.dbf tag=TAG20170927T151002
channel prmy1: datafile copy complete, elapsed time: 00:00:06
channel prmy1: starting datafile copy
input datafile file number=00007 name=/u01/app/oracle/oradata/PROD1/index.dbf
output file name=/u01/app/oracle/oradata/PROD1/index.dbf tag=TAG20170927T151002
channel prmy1: datafile copy complete, elapsed time: 00:00:01
channel prmy1: starting datafile copy
input datafile file number=00008 name=/u01/app/oracle/oradata/PROD1/tools.dbf
output file name=/u01/app/oracle/oradata/PROD1/oltp.dbf tag=TAG20170927T151002
channel prmy2: datafile copy complete, elapsed time: 00:00:04
output file name=/u01/app/oracle/oradata/PROD1/tools.dbf tag=TAG20170927T151002
channel prmy1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 27-SEP-17
sql statement: alter system archive log current
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=15 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=16 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=17 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=18 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=19 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/example01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=20 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/test.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=21 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/index.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=22 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/tools.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=23 STAMP=955811447 file name=/u01/app/oracle/oradata/PROD1/oltp.dbf
Finished Duplicate Db at 27-SEP-17
released channel: prmy1
released channel: prmy2
released channel: stby
4. Start managed recovery
Connect to standby using SQL*Plus and start the MRP (Managed Recovery Process). Compare the primary last sequence and MRP (Managed Recovery Process) applying sequence.
Example :
5. Open standby database in Read Only (active dataguard)
If you are licensed to use Active Dataguard (ADG) than open the Standby Database in READ ONLY and start the recovery.
SQL> alter database open;
SQL> alter database recover managed standby database disconnect;
6. TEST
primary database:SQL> create table a(id number);
Table created.
SQL> insert into a values(9);
1 row created.
SQL>
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> select * from a;
ID
----------
9
9
9
9
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL>
standby database:
SYS@SBDB1> sho parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string PROD1
db_unique_name string SBDB1
global_names boolean FALSE
instance_name string SBDB1
lock_name_space string
log_file_name_convert string SBDB1, PROD1
processor_group_name string
service_names string SBDB1
SYS@SBDB1>
SYS@SBDB1> select * from a;
no rows selected
SYS@SBDB1> /
ID
----------
9
9
9
9
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13750068/viewspace-2145529/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/13750068/viewspace-2145529/