签到成功

知道了

CNDBA社区CNDBA社区

ORACLE之搭建DG(RMAN Duplicate方式)

2016-09-22 16:12 1848 0 原创
作者: shenyu_1990

1.准备工作

http://www.cndba.cn/shenyu_1990/article/274

        首先得准备两个能够PING通,并且装了Oracle软件且已经建库的Linux虚拟机。操作系统不限,至少有一个虚拟机已经建好库,最好两个都建好相同SID的库,这样少很多创建目录的麻烦,这里库的SID都是orcl,Linux严格区分大小写,所以SID的大小写得注意。http://www.cndba.cn/shenyu_1990/article/274

        我这里有两个名为PD和ST的Linux虚拟机。

        PD:192.168.56.5(主库)

http://www.cndba.cn/shenyu_1990/article/274

        ST:192.168.56.6(备库)

2.在主库做一些操作

    2.1强制force logging

SQL> shutdown immediate  
Database closed.  
Database dismounted.  
ORACLE instance shut down.  
SQL> startup mount  
ORACLE instance started.  
  
  
Total System Global Area 1653518336 bytes  
Fixed Size          2253784 bytes  
Variable Size        1006636072 bytes  
Database Buffers      637534208 bytes  
Redo Buffers            7094272 bytes  
Database mounted.  
SQL> alter database force logging;    --修改数据库为强制记日志,这是必须的操作,主库的每一步操作都得记录到日志中去。  
  
Database altered.

    2.2开启主库的归档模式

SQL> alter database archivelog;       --修改数据库为归档模式,因为dg是通过传送归档日志到备库然后应用来保证主备库一致的。  
  
Database altered.

    2.3创建standby redo log

SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/u01/app/oracle/oradata/orcl/redo04.log') size 50M;   
Database altered.  
  
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/u01/app/oracle/oradata/orcl/redo05.log') size 50M;   
Database altered.  
  
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/u01/app/oracle/oradata/orcl/redo06.log') size 50M;   
Database altered.  
  
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/u01/app/oracle/oradata/orcl/redo07.log') size 50M;  
  
Database altered

SQL> select group#,type,member from v$logfile;  
  
  
    GROUP# TYPE    MEMBER  
---------- ------- --------------------------------------------------  
         3 ONLINE  /u01/app/oracle/oradata/orcl/redo03.log  
         2 ONLINE  /u01/app/oracle/oradata/orcl/redo02.log  
         1 ONLINE  /u01/app/oracle/oradata/orcl/redo01.log  
         4 STANDBY  /u01/app/oracle/oradata/orcl/redo04.log  
         5 STANDBY  /u01/app/oracle/oradata/orcl/redo05.log  
         6 STANDBY  /u01/app/oracle/oradata/orcl/redo06.log  
         7 STANDBY  /u01/app/oracle/oradata/orcl/redo07.log

    2.4创建pfile

SQL> create pfile from spfile;--这里创建pfile是为了做一些主库参数的配置,并且还得拷贝到备库再次修改成备库的配置。  
  
File created.  
  
SQL> shutdown immediate  
Database closed.  
Database dismounted.  
ORACLE instance shut down.

    2.5创建主库归档目录

[oracle@PD orcl]$ mkdir archivelog  --建立这个目录是为了存放主库的归档日志文件,并且这个目录会和其他数据文件等等一起拷贝到备库。  
[oracle@PD orcl]$ cd archivelog/  
[oracle@PD archivelog]$ ls  
[oracle@PD archivelog]$ pwd  
/u01/app/oracle/oradata/orcl/archivelog

    2.6在主备库同时创建静态监听listener和tnsnamehttp://www.cndba.cn/shenyu_1990/article/274

建议用net manager建立

主库orcl_pd:192.168.56.5http://www.cndba.cn/shenyu_1990/article/274

[oracle@PD admin]$ cat listener.ora   
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
# Generated by Oracle configuration tools.  
  
SID_LIST_LISTENER =  
  (SID_LIST =  
    (SID_DESC =  
      (GLOBAL_DBNAME = orcl)  
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)  
      (SID_NAME = orcl)  
    )  
  )  
  
LISTENER =  
  (DESCRIPTION_LIST =  
    (DESCRIPTION =  
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))  
    )  
    (DESCRIPTION =  
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))  
    )  
  )  
  
ADR_BASE_LISTENER = /u01/app/oracle  

[oracle@PD admin]$ cat tnsnames.ora   
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora  
# Generated by Oracle configuration tools.  
  
ORCL_ST =  
  (DESCRIPTION =  
    (ADDRESS_LIST =  
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.6)(PORT = 1521))  
    )  
    (CONNECT_DATA =  
      (SERVICE_NAME = orcl)  
    )  
  )  
  
ORCL =  
  (DESCRIPTION =  
    (ADDRESS_LIST =  
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))  
    )  
    (CONNECT_DATA =  
      (SERVER = DEDICATED)  
      (SERVICE_NAME = orcl)  
    )  
  )  
  
ORCL_PD =  
  (DESCRIPTION =  
    (ADDRESS_LIST =  
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.5)(PORT = 1521))  
    )  
    (CONNECT_DATA =  
      (SERVICE_NAME = orcl)  
    )  
  )  

[oracle@PD orcl]$ lsnrctl  
  
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 22-SEP-2016 16:41:15  
  
Copyright (c) 1991, 2013, Oracle.  All rights reserved.  
  
Welcome to LSNRCTL, type "help" for information.  
  
LSNRCTL> status  
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
TNS-12541: TNS:no listener  
 TNS-12560: TNS:protocol adapter error  
  TNS-00511: No listener  
   Linux Error: 111: Connection refused  
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))  
TNS-12541: TNS:no listener  
 TNS-12560: TNS:protocol adapter error  
  TNS-00511: No listener  
   Linux Error: 111: Connection refused  
LSNRCTL> start  
Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...  
  
TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
Log messages written to /u01/app/oracle/diag/tnslsnr/PD/listener/alert/log.xml  
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=PD)(PORT=1521)))  
  
  
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
STATUS of the LISTENER  
------------------------  
Alias                     LISTENER  
Version                    TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
Start Date                  22-SEP-2016 16:39:15  
Uptime                    0 days 0 hr. 0 min. 0 sec  
Trace Level                  off  
Security                   ON: Local OS Authentication  
SNMP                      OFF  
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
Listener Log File         /u01/app/oracle/diag/tnslsnr/PD/listener/alert/log.xml  
Listening Endpoints Summary...  
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=PD)(PORT=1521)))  
Services Summary...  
Service "orcl" has 1 instance(s).  
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...  
The command completed successfully  
LSNRCTL> exit

备库orcl_pd:192.168.56.6 

[oracle@ST admin]$ cat listener.ora   
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
# Generated by Oracle configuration tools.  
  
SID_LIST_LISTENER =  
  (SID_LIST =  
    (SID_DESC =  
      (GLOBAL_DBNAME = orcl)  
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)  
      (SID_NAME = orcl)  
    )  
  )  
  
LISTENER =  
  (DESCRIPTION_LIST =  
    (DESCRIPTION =  
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))  
    )  
    (DESCRIPTION =  
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))  
    )  
  )  
  
ADR_BASE_LISTENER = /u01/app/oracle  

[oracle@ST admin]$ cat tnsnames.ora   
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora  
# Generated by Oracle configuration tools.  
  
ORCL_ST =  
  (DESCRIPTION =  
    (ADDRESS_LIST =  
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.6)(PORT = 1521))  
    )  
    (CONNECT_DATA =  
      (SERVICE_NAME = orcl)  
    )  
  )  
  
ORCL =  
  (DESCRIPTION =  
    (ADDRESS_LIST =  
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))  
    )  
    (CONNECT_DATA =  
      (SERVER = DEDICATED)  
      (SERVICE_NAME = orcl)  
    )  
  )  
  
ORCL_PD =  
  (DESCRIPTION =  
    (ADDRESS_LIST =  
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.5)(PORT = 1521))  
    )  
    (CONNECT_DATA =  
      (SERVICE_NAME = orcl)  
    )  
  )  

[oracle@ST dbs]$ lsnrctl  
  
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 22-SEP-2016 16:39:20  
  
Copyright (c) 1991, 2013, Oracle.  All rights reserved.  
  
Welcome to LSNRCTL, type "help" for information.  
  
LSNRCTL> status  
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
TNS-12541: TNS:no listener  
 TNS-12560: TNS:protocol adapter error  
  TNS-00511: No listener  
   Linux Error: 2: No such file or directory  
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))  
TNS-12541: TNS:no listener  
 TNS-12560: TNS:protocol adapter error  
  TNS-00511: No listener  
   Linux Error: 111: Connection refused  
LSNRCTL> start  
Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...  
  
  
TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
Log messages written to /u01/app/oracle/diag/tnslsnr/ST/listener/alert/log.xml  
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ST)(PORT=1521)))  
  
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))  
STATUS of the LISTENER  
------------------------  
Alias                     LISTENER  
Version                    TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
Start Date                  22-SEP-2016 17:39:02  
Uptime                    0 days 0 hr. 0 min. 0 sec  
Trace Level                  off  
Security                   ON: Local OS Authentication  
SNMP                      OFF  
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
Listener Log File         /u01/app/oracle/diag/tnslsnr/ST/listener/alert/log.xml  
Listening Endpoints Summary...  
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ST)(PORT=1521)))  
Services Summary...  
Service "orcl" has 1 instance(s).  
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...  
The command completed successfully

    2.7修改主库pfile文件

[oracle@PD dbs]$ vi initorcl.ora   
orcl.__db_cache_size=637534208  
orcl.__java_pool_size=16777216  
orcl.__large_pool_size=83886080  
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment  
orcl.__pga_aggregate_target=671088640  
orcl.__sga_target=989855744  
orcl.__shared_io_pool_size=0  
orcl.__shared_pool_size=234881024  
orcl.__streams_pool_size=0  
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'  
*.audit_trail='db'  
*.compatible='11.2.0.4.0'  
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'  
*.db_block_size=8192  
*.db_domain=''  
*.db_name='orcl'  
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'  
*.db_recovery_file_dest_size=4385144832  
*.diagnostic_dest='/u01/app/oracle'  
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'  
*.memory_target=1657798656  
*.open_cursors=300  
*.processes=150  
*.remote_login_passwordfile='EXCLUSIVE'  
*.undo_tablespace='UNDOTBS1'  
--下面这个是为了搭建DG添加的配置参数,主备库是有区分的,请注意  
DB_UNIQUE_NAME=orcl_pd  
LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_st)'  
LOG_ARCHIVE_DEST_1=  
 'LOCATION=/u01/app/oracle/oradata/orcl/archivelog  
  VALID_FOR=(ALL_LOGFILES,ALL_ROLES)  
  DB_UNIQUE_NAME=orcl_pd'  
LOG_ARCHIVE_DEST_2=  
 'SERVICE=orcl_st ASYNC  
  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)  
  DB_UNIQUE_NAME=orcl_st'  
LOG_ARCHIVE_DEST_STATE_1=ENABLE  
LOG_ARCHIVE_DEST_STATE_2=ENABLE  
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE  
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc  
FAL_SERVER=orcl_st  
STANDBY_FILE_MANAGEMENT=AUTO

    2.8用pfile启动主库,并创建spfile

SQL> shutdown immediate  
ORA-01109: database not open  
  
  
Database dismounted.  
ORACLE instance shut down.  
SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora'  
ORACLE instance started.  
  
Total System Global Area 1653518336 bytes  
Fixed Size          2253784 bytes  
Variable Size        1006636072 bytes  
Database Buffers      637534208 bytes  
Redo Buffers            7094272 bytes  
SQL> create spfile from pfile;  
  
File created.

     2.9创建主备库的备份目录

主库

[oracle@PD orcl]$ mkdir /u01/app/oracle/oradata/orcl/backup

备库

[oracle@PD orcl]$ mkdir /u01/app/oracle/oradata/orcl/backup

     2.10将口令验证文件和pfile发送到备库

[oracle@PD dbs]$ pwd  
/u01/app/oracle/product/11.2.0/dbhome_1/dbs  
[oracle@PD dbs]$ scp orapworcl 192.168.56.6:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/  
oracle@192.168.56.6's password:  
orapworcl
[oracle@PD dbs]$ scp initorcl.ora 192.168.56.6:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
oracle@192.168.56.6's password:  
initorcl.ora

 

     2.11使用RMAN备份主库

run{  
allocate channel c1 type disk;  
allocate channel c2 type disk;  
sql 'alter system archive log current';  
backup format '/u01/app/oracle/oradata/orcl/backup/db_%U_%T' skip inaccessible filesperset 5 database;  
sql 'alter system archive log current';  
backup format '/u01/app/oracle/oradata/orcl/backup/db_%U_%T' skip inaccessible filesperset 5 archivelog all delete input;  
backup current controlfile for standby format='/u01/app/oracle/oradata/orcl/backup/control_%U';  
release channel c2;  
release channel c1;
}

allocated channel: c1
channel c1: SID=36 device type=DISK

allocated channel: c2
channel c2: SID=37 device type=DISK

sql statement: alter system archive log current

Starting backup at 22-SEP-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel c1: starting piece 1 at 22-SEP-16
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
channel c2: starting piece 1 at 22-SEP-16
channel c2: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_04rgf1el_1_1_20160922 tag=TAG20160922T153132 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:26
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
channel c1: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_03rgf1el_1_1_20160922 tag=TAG20160922T153132 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:30
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel c1: starting piece 1 at 22-SEP-16
including current control file in backup set
channel c2: starting piece 1 at 22-SEP-16
channel c1: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_06rgf1fj_1_1_20160922 tag=TAG20160922T153132 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c2: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_05rgf1fh_1_1_20160922 tag=TAG20160922T153132 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:01
Finished backup at 22-SEP-16

sql statement: alter system archive log current

Starting backup at 22-SEP-16
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=1 STAMP=923233092
channel c1: starting piece 1 at 22-SEP-16
channel c2: starting archived log backup set
channel c2: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=2 STAMP=923233097
input archived log thread=1 sequence=4 RECID=3 STAMP=923233617
input archived log thread=1 sequence=5 RECID=4 STAMP=923233623
input archived log thread=1 sequence=6 RECID=5 STAMP=923235876
input archived log thread=1 sequence=7 RECID=6 STAMP=923235879
channel c2: starting piece 1 at 22-SEP-16
channel c2: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_08rgf1fp_1_1_20160922 tag=TAG20160922T153209 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:01
channel c2: deleting archived log(s)
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_3_923227030.arc RECID=2 STAMP=923233097
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_4_923227030.arc RECID=3 STAMP=923233617
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_5_923227030.arc RECID=4 STAMP=923233623
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_6_923227030.arc RECID=5 STAMP=923235876
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_7_923227030.arc RECID=6 STAMP=923235879
channel c2: starting archived log backup set
channel c2: specifying archived log(s) in backup set
input archived log thread=1 sequence=8 RECID=7 STAMP=923236628
input archived log thread=1 sequence=9 RECID=8 STAMP=923236631
input archived log thread=1 sequence=10 RECID=9 STAMP=923236802
input archived log thread=1 sequence=11 RECID=17 STAMP=923236808
input archived log thread=1 sequence=12 RECID=19 STAMP=923237271
channel c2: starting piece 1 at 22-SEP-16
channel c1: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_07rgf1fp_1_1_20160922 tag=TAG20160922T153209 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:03
channel c1: deleting archived log(s)
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_2_923227030.arc RECID=1 STAMP=923233092
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=21 STAMP=923239813
input archived log thread=1 sequence=14 RECID=22 STAMP=923239819
input archived log thread=1 sequence=15 RECID=23 STAMP=923239849
input archived log thread=1 sequence=16 RECID=24 STAMP=923239892
input archived log thread=1 sequence=17 RECID=25 STAMP=923239928
channel c1: starting piece 1 at 22-SEP-16
channel c2: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_09rgf1fs_1_1_20160922 tag=TAG20160922T153209 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:01
channel c2: deleting archived log(s)
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_8_923227030.arc RECID=7 STAMP=923236628
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_9_923227030.arc RECID=8 STAMP=923236631
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_10_923227030.arc RECID=9 STAMP=923236802
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_11_923227030.arc RECID=17 STAMP=923236808
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_12_923227030.arc RECID=19 STAMP=923237271
channel c2: starting archived log backup set
channel c2: specifying archived log(s) in backup set
input archived log thread=1 sequence=18 RECID=26 STAMP=923239928
channel c2: starting piece 1 at 22-SEP-16
channel c1: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0argf1ft_1_1_20160922 tag=TAG20160922T153209 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c1: deleting archived log(s)
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_13_923227030.arc thread=1 sequence=13
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_14_923227030.arc thread=1 sequence=14
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_15_923227030.arc thread=1 sequence=15
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_16_923227030.arc thread=1 sequence=16
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_17_923227030.arc thread=1 sequence=17
channel c2: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0brgf1ft_1_1_20160922 tag=TAG20160922T153209 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:00
channel c2: deleting archived log(s)
RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_18_923227030.arc thread=1 sequence=18
Finished backup at 22-SEP-16

Starting backup at 22-SEP-16
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including standby control file in backup set
channel c1: starting piece 1 at 22-SEP-16
channel c1: finished piece 1 at 22-SEP-16
piece handle=/u01/app/oracle/oradata/orcl/backup/control_0crgf1fv_1_1 tag=TAG20160922T153215 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 22-SEP-16

released channel: c2

released channel: c1

RMAN> exit

     2.12拷贝备份文件至备库相同目录

[oracle@localhost orcl]$ cd backup/
[oracle@localhost backup]$ scp * 192.168.56.6:/u01/app/oracle/oradata/orcl/backup/
The authenticity of host '192.168.56.6 (192.168.56.6)' can't be established.
ECDSA key fingerprint is 5f:01:53:a3:53:1d:c2:75:d5:f4:9b:59:53:5c:21:51.
Are you sure you want to continue connecting (yes/no)? yes  
Warning: Permanently added '192.168.56.6' (ECDSA) to the list of known hosts.
oracle@192.168.56.6's password:
control_0crgf1fv_1_1                                                                                                                                       100% 9568KB   9.3MB/s   00:01    
db_03rgf1el_1_1_20160922                                                                100%  631MB   7.3MB/s   01:27    
db_04rgf1el_1_1_20160922                                                                100%  363MB   6.9MB/s   00:53    
db_05rgf1fh_1_1_20160922                                                                100% 9568KB   9.3MB/s   00:01    
db_06rgf1fj_1_1_20160922                                                                100%   96KB  96.0KB/s   00:00    
db_07rgf1fp_1_1_20160922                                                                100%   32MB   8.1MB/s   00:04    
db_08rgf1fp_1_1_20160922                                                                100% 3083KB   3.0MB/s   00:00    
db_09rgf1fs_1_1_20160922                                                                100% 1062KB   1.0MB/s   00:00    
db_0argf1ft_1_1_20160922                                                                100% 2470KB   2.4MB/s   00:00    
db_0brgf1ft_1_1_20160922                                                                100% 2560     2.5KB/s   00:00    

3.在主库做一些操作http://www.cndba.cn/shenyu_1990/article/274

    3.1在备库修改从主库拷贝来的pfile

[oracle@ST dbs]$ cat initorcl.ora   
orcl.__db_cache_size=637534208  
orcl.__java_pool_size=16777216  
orcl.__large_pool_size=83886080  
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment  
orcl.__pga_aggregate_target=671088640  
orcl.__sga_target=989855744  
orcl.__shared_io_pool_size=0  
orcl.__shared_pool_size=234881024  
orcl.__streams_pool_size=0  
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'  
*.audit_trail='db'  
*.compatible='11.2.0.4.0'  
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'  
*.db_block_size=8192  
*.db_domain=''  
*.db_name='orcl'  
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'  
*.db_recovery_file_dest_size=4385144832  
*.diagnostic_dest='/u01/app/oracle'  
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'  
*.memory_target=1657798656  
*.open_cursors=300  
*.processes=150  
*.remote_login_passwordfile='EXCLUSIVE'  
*.undo_tablespace='UNDOTBS1'  
  
DB_UNIQUE_NAME=orcl_st  
LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_st)'  
LOG_ARCHIVE_DEST_1=  
 'LOCATION=/u01/app/oracle/oradata/orcl/archivelog  
  VALID_FOR=(ALL_LOGFILES,ALL_ROLES)  
  DB_UNIQUE_NAME=orcl_st'  
LOG_ARCHIVE_DEST_2=  
 'SERVICE=orcl_pd ASYNC  
  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)   
  DB_UNIQUE_NAME=orcl_pd'  
LOG_ARCHIVE_DEST_STATE_1=ENABLE  
LOG_ARCHIVE_DEST_STATE_2=ENABLE  
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE  
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc  
FAL_SERVER=orcl_pd  
STANDBY_FILE_MANAGEMENT=AUTO

     3.2启动备库到nomount状态并执行RMAN恢复

[oracle@localhost backup]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Sep 22 15:43:36 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1586708480 bytes
Fixed Size    2253624 bytes
Variable Size  973081800 bytes
Database Buffers  603979776 bytes
Redo Buffers    7393280 bytes
[oracle@localhost dbs]$ rman target sys/sys@orcl_pd auxiliary sys/sys@orcl_st

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Sep 22 15:43:55 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1451007763)
connected to auxiliary database: ORCL (not mounted)

RMAN> duplicate target database for standby nofilenamecheck dorecover;

Starting Duplicate Db at 22-SEP-16
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK

contents of Memory Script:
{
   set until scn  942832;
   restore clone standby controlfile;
}
executing Memory Script

executing command: SET until clause

Starting restore at 22-SEP-16
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/oradata/orcl/backup/db_05rgf1fh_1_1_20160922
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_05rgf1fh_1_1_20160922 tag=TAG2016092
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orcl/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/orcl/control02.ctl
Finished restore at 22-SEP-16

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 until scn  942832;
   set newname for tempfile  1 to 
 "/u01/app/oracle/oradata/orcl/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to 
 "/u01/app/oracle/oradata/orcl/system01.dbf";
   set newname for datafile  2 to 
 "/u01/app/oracle/oradata/orcl/sysaux01.dbf";
   set newname for datafile  3 to 
 "/u01/app/oracle/oradata/orcl/undotbs01.dbf";
   set newname for datafile  4 to 
 "/u01/app/oracle/oradata/orcl/users01.dbf";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 22-SEP-16
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/oradata/orcl/backup/db_04rgf1el_1_1_20160922
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_04rgf1el_1_1_20160922 tag=TAG2016092
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/oradata/orcl/backup/db_03rgf1el_1_1_20160922
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_03rgf1el_1_1_20160922 tag=TAG2016092
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 22-SEP-16

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=3 STAMP=923240696 file name=/u01/app/oracle/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=4 STAMP=923240696 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=923240696 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=6 STAMP=923240697 file name=/u01/app/oracle/oradata/orcl/users01.dbf

contents of Memory Script:
{
   set until scn  942832;
   recover
   standby
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 22-SEP-16
using channel ORA_AUX_DISK_1

starting media recovery

channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=17
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/oradata/orcl/backup/db_0argf1ft_1_1_20160922
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_0argf1ft_1_1_20160922 tag=TAG2016092
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_17_923227030.arc thread=1 sequence=17
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_17_923227030.arc RECID=1 STAMP=923240706
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=18
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/oradata/orcl/backup/db_0brgf1ft_1_1_20160922
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_0brgf1ft_1_1_20160922 tag=TAG2016092
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_18_923227030.arc thread=1 sequence=18
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_18_923227030.arc RECID=2 STAMP=923240709
media recovery complete, elapsed time: 00:00:01
Finished recover at 22-SEP-16
Finished Duplicate Db at 22-SEP-16

RMAN>

     3.3打开备库并查询状态

此时恢复完的备库已经是mount状态了,打开后就是read only状态。

[oracle@ST orcl]$ sqlplus / as sysdba  
  
SQL*Plus: Release 11.2.0.4.0 Production on Thu Sep 22 15:50:36 2016  
  
Copyright (c) 1982, 2013, Oracle.  All rights reserved.  
  
  
Connected to:  
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  
SQL> select open_mode from v$database;  
  
OPEN_MODE  
--------------------  
MOUNTED  
  
SQL> alter database open;  
  
Database altered.  
  
SQL> select open_mode from v$database;  
  
OPEN_MODE  
--------------------  
READ ONLY

     3.4重新创建standby logfile(这一步也可以不做)

SQL> set lines 200
SQL> col staus for a20  
SQL> col status for a20  
SQL> col member for a100  
SQL> select group#,type,member,status from v$logfile;  

   GROUP# TYPE    MEMBER
---------- ------- ---------------------------------------------------------------------------------------------
3 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_3_cy730ckf_.log
2 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_2_cy730b0m_.log
1 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_1_cy73084f_.log
4 STANDBY /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_4_cy730f61_.log
5 STANDBY /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_5_cy730h6b_.log
6 STANDBY /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_6_cy730jmm_.log
7 STANDBY /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_7_cy730ljv_.log

7 rows selected.

SQL> alter database drop logfile group 4;

Database altered.

SQL> alter database drop logfile group 5;  

Database altered.

SQL> alter database drop logfile group 6;

Database altered.

SQL> alter database drop logfile group 7;  

Database altered.

SQL> alter database add standby logfile group 4 ('/u01/app/oracle/oradata/orcl/redo04.log') size 50m;

Database altered.

SQL> alter database add standby logfile group 5 ('/u01/app/oracle/oradata/orcl/redo05.log') size 50m;  

Database altered.

SQL> alter database add standby logfile group 6 ('/u01/app/oracle/oradata/orcl/redo06.log') size 50m;

Database altered.

SQL> alter database add standby logfile group 7 ('/u01/app/oracle/oradata/orcl/redo07.log') size 50m;  

Database altered.

SQL> select group#,type,member,status from v$logfile;  

   GROUP# TYPE    MEMBER
---------- ------- ---------------------------------------------------------------------------------------------
3 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_3_cy730ckf_.log
2 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_2_cy730b0m_.log
1 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_ST/onlinelog/o1_mf_1_cy73084f_.log
4 STANDBY /u01/app/oracle/oradata/orcl/redo04.log
5 STANDBY /u01/app/oracle/oradata/orcl/redo05.log
6 STANDBY /u01/app/oracle/oradata/orcl/redo06.log
7 STANDBY /u01/app/oracle/oradata/orcl/redo07.log

7 rows selected.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ ONLY
http://www.cndba.cn/shenyu_1990/article/274http://www.cndba.cn/shenyu_1990/article/274

   4.验证主库

SQL> set lines 200  
SQL> col dest_name for a20  
SQL> col error for a20  
SQL> select dest_name,status,process,error,transmit_mode from v$archive_dest where target='STANDBY';  
  
DEST_NAME            STATUS    PROCESS    ERROR                TRANSMIT_MOD  
-------------------- --------- ---------- -------------------- ------------  
LOG_ARCHIVE_DEST_2   VALID     LGWR                            ASYNCHRONOUS


http://www.cndba.cn/shenyu_1990/article/274

   5.备库开启apply service

SQL> alter database recover managed standby database disconnect from session;  
  
Database altered.

   6.主库建表校验

http://www.cndba.cn/shenyu_1990/article/274

主库

SQL> create table Csong(id number(10),name varchar2(20));  
  
Table created.  
  
SQL> insert into Csong values(1,'Csong');  
  
1 row created.  
  
SQL> insert into Csong values(2,'Lyuanyuan');  
  
1 row created.  
  
SQL> commit;  
  
Commit complete.  
  
SQL> alter system switch logfile;  
  
System altered.  
  
SQL> alter system switch logfile;  
  
System altered.

备库

SQL> select sequence#,applied from v$archived_log;  
  
 SEQUENCE# APPLIED  
---------- ---------  
     6 YES  
     7 YES  
     8 YES  
     9 YES  
    10 YES  
    11 YES  
    12 YES  
  
7 rows selected.  
  
SQL> desc Csong  
 Name                                      Null?    Type  
 ----------------------------------------- -------- ----------------------------  
 ID                                                 NUMBER(10)  
 NAME                                               VARCHAR2(20)  
  
SQL> select * from Csong;  
  
    ID NAME  
---------- --------------------  
     1 Csong  
     2 Lyuanyuan




版权声明:本文为博主原创文章,未经博主允许不得转载。

oracle

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
shenyu_1990

shenyu_1990

关注
  • 7
    原创
  • 0
    翻译
  • 0
    转载
  • 2
    评论
  • 访问:16374次
  • 积分:43
  • 等级:注册会员
  • 排名:第47名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ