您的位置:首页 > 数据库 > Oracle

ORACLE之搭建DG(RMAN Duplicate方式)

2018-02-07 10:28 453 查看
目录(?)[+]

1.准备工作

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

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

        PD:192.168.56.42(主库)

        ST:192.168.56.43(备库)

2.在主库做一些操作

    2.1强制force logging

[sql]
view plain
copy

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]
view plain
copy

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

    2.3创建standby redo log

[sql]
view plain
copy

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]
view plain
copy

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]
view plain
copy

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

    2.5创建主库归档目录

[sql]
view plain
copy

[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和tnsname

建议用net manager建立

主库orcl_pd:192.168.56.42

[sql]
view plain
copy

[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  

[sql]
view plain
copy

[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.43)(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.42)(PORT = 1521))  
    )  
    (CONNECT_DATA =  
      (SERVICE_NAME = orcl)  
    )  
  )  

[sql]
view plain
copy

[oracle@PD orcl]$ lsnrctl  
  
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 21-MAR-2016 00:59:09  
  
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                  21-MAR-2016 00:59:16  
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.43

[sql]
view plain
copy

[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  

[sql]
view plain
copy

[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.43)(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.42)(PORT = 1521))  
    )  
    (CONNECT_DATA =  
      (SERVICE_NAME = orcl)  
    )  
  )  

[sql]
view plain
copy

[oracle@ST dbs]$ lsnrctl  
  
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 19-MAR-2016 21:10:49  
  
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                  19-MAR-2016 21:10:53  
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文件

[sql]
view plain
copy

[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]
view plain
copy

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创建主备库的备份目录

主库

[sql]
view plain
copy

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

备库

[sql]
view plain
copy

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

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

[sql]
view plain
copy

[oracle@PD dbs]$ pwd  
/u01/app/oracle/product/11.2.0/dbhome_1/dbs  
[oracle@PD dbs]$ scp orapworcl 192.168.56.43:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/  
oracle@192.168.56.43's password:   
orapworcl                                                                                        100% 1536     1.5KB/s   00:00      

[sql]
view plain
copy

[oracle@PD dbs]$ scp initorcl.ora 192.168.56.43:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/<div><pre name="code" class="sql">oracle@192.168.56.43's password:   
initorcl.ora                                                                             100% 1408    1.4KB/s  00:00  

    2.11使用RMAN备份主库

[sql]
view plain
copy

RMAN> alter database open;  
  
database opened  
  
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;  
11> }  
  
released channel: ORA_DISK_1  
allocated channel: c1  
channel c1: SID=20 device type=DISK  
  
allocated channel: c2  
channel c2: SID=19 device type=DISK  
  
sql statement: alter system archive log current  
  
Starting backup at 22-MAR-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=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf  
channel c1: starting piece 1 at 22-MAR-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  
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf  
channel c2: starting piece 1 at 22-MAR-16  
channel c2: finished piece 1 at 22-MAR-16  
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0cr15h8g_1_1_20160322 tag=TAG20160322T235600 comment=NONE  
channel c2: backup set complete, elapsed time: 00:00:45  
channel c2: starting full datafile backup set  
channel c2: specifying datafile(s) in backup set  
including current control file in backup set  
channel c2: starting piece 1 at 22-MAR-16  
channel c2: finished piece 1 at 22-MAR-16  
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0dr15h9v_1_1_20160322 tag=TAG20160322T235600 comment=NONE  
channel c2: backup set complete, elapsed time: 00:00:03  
channel c2: starting full datafile backup set  
channel c2: specifying datafile(s) in backup set  
including current SPFILE in backup set  
channel c2: starting piece 1 at 22-MAR-16  
channel c1: finished piece 1 at 22-MAR-16  
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0br15h8g_1_1_20160322 tag=TAG20160322T235600 comment=NONE  
channel c1: backup set complete, elapsed time: 00:01:07  
channel c2: finished piece 1 at 22-MAR-16  
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0er15hai_1_1_20160322 tag=TAG20160322T235600 comment=NONE  
channel c2: backup set complete, elapsed time: 00:00:02  
Finished backup at 22-MAR-16  
  
sql statement: alter system archive log current  
  
Starting backup at 22-MAR-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=13 RECID=15 STAMP=907199541  
channel c1: starting piece 1 at 22-MAR-16  
channel c2: starting archived log backup set  
channel c2: specifying archived log(s) in backup set  
input archived log thread=1 sequence=14 RECID=16 STAMP=907199545  
input archived log thread=1 sequence=15 RECID=17 STAMP=907199598  
input archived log thread=1 sequence=16 RECID=18 STAMP=907199686  
input archived log thread=1 sequence=17 RECID=19 STAMP=907199686  
channel c2: starting piece 1 at 22-MAR-16  
channel c1: finished piece 1 at 22-MAR-16  
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0fr15hal_1_1_20160322 tag=TAG20160322T235709 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_906917775.arc thread=1 sequence=13  
channel c1: starting archived log backup set  
channel c1: specifying archived log(s) in backup set  
input archived log thread=1 sequence=18 RECID=20 STAMP=907199760  
input archived log thread=1 sequence=19 RECID=21 STAMP=907199829  
input archived log thread=1 sequence=20 RECID=22 STAMP=907199829  
channel c1: starting piece 1 at 22-MAR-16  
channel c2: finished piece 1 at 22-MAR-16  
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0gr15hal_1_1_20160322 tag=TAG20160322T235709 comment=NONE  
channel c2: backup set complete, elapsed time: 00:00:02  
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_14_906917775.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_906917775.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_906917775.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_906917775.arc thread=1 sequence=17  
channel c1: finished piece 1 at 22-MAR-16  
piece handle=/u01/app/oracle/oradata/orcl/backup/db_0hr15han_1_1_20160322 tag=TAG20160322T235709 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_18_906917775.arc thread=1 sequence=18  
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_19_906917775.arc thread=1 sequence=19  
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_20_906917775.arc thread=1 sequence=20  
Finished backup at 22-MAR-16  
  
Starting backup at 22-MAR-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-MAR-16  
channel c1: finished piece 1 at 22-MAR-16  
piece handle=/u01/app/oracle/oradata/orcl/backup/control_0ir15hap_1_1 tag=TAG20160322T235712 comment=NONE  
channel c1: backup set complete, elapsed time: 00:00:03  
Finished backup at 22-MAR-16  
  
released channel: c2  
  
released channel: c1  

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

[sql]
view plain
copy

[oracle@PD backup]$ pwd  
/u01/app/oracle/oradata/orcl/backup  
[oracle@PD backup]$ scp * 192.168.56.43:/u01/app/oracle/oradata/orcl/backup/  
oracle@192.168.56.43's password:   
control_0ir15hap_1_1                                                                               100% 9568KB   9.3MB/s   00:00  
db_0br15h8g_1_1_20160322                                                                           100%  712MB  54.7MB/s   00:13  
db_0cr15h8g_1_1_20160322                                                                           100%  508MB  42.4MB/s   00:12  
db_0dr15h9v_1_1_20160322                                                                           100% 9568KB   9.3MB/s   00:00  
db_0er15hai_1_1_20160322                                                                           100%   96KB  96.0KB/s   00:00  
db_0fr15hal_1_1_20160322                                                                           100% 6388KB   6.2MB/s   00:01   
db_0gr15hal_1_1_20160322                                                                           100%  495KB 495.0KB/s   00:00  
db_0hr15han_1_1_20160322                                                                           100%   56KB  56.0KB/s   00:00  

3.在主库做一些操作

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

[sql]
view plain
copy

[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恢复

[sql]
view plain
copy

[oracle@ST orcl]$ sqlplus / as sysdba  
  
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 23 00:34:32 2016  
  
Copyright (c) 1982, 2013, Oracle.  All rights reserved.  
  
Connected to an idle instance.  
  
SQL> startup nomount  
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> shutdown immediate  
ORA-01507: database not mounted  
  
  
ORACLE instance shut down.  
SQL> exit  
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
[oracle@ST orcl]$ sqlplus / as sysdba  
  
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 23 00:35:22 2016  
  
Copyright (c) 1982, 2013, Oracle.  All rights reserved.  
  
Connected to an idle instance.  
  
SQL> create spfile from pfile;  
  
File created.  
  
SQL> startup nomount  
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> exit  
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production  
With the Partitioning, OLAP, Data Mining and Real Application Testing options  
[oracle@ST orcl]$ rman target sys/sys@orcl_pd auxiliary sys/sys@orcl_st  
  
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Mar 23 00:36:27 2016  
  
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.  
  
connected to target database: ORCL (DBID=1434698509)  
connected to auxiliary database: ORCL (not mounted)  
  
RMAN> duplicate target database for standby nofilenamecheck dorecover;  
  
Starting Duplicate Db at 23-MAR-16  
using target database control file instead of recovery catalog  
allocated channel: ORA_AUX_DISK_1  
channel ORA_AUX_DISK_1: SID=19 device type=DISK  
  
contents of Memory Script:  
{  
   set until scn  1021413;  
   restore clone standby controlfile;  
}  
executing Memory Script  
  
executing command: SET until clause  
  
Starting restore at 23-MAR-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_0dr15h9v_1_1_20160322  
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_0dr15h9v_1_1_20160322 tag=TAG20160322T235600  
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 23-MAR-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  1021413;  
   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";  
   set newname for datafile  5 to   
 "/u01/app/oracle/oradata/orcl/example01.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  
  
executing command: SET NEWNAME  
  
Starting restore at 23-MAR-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: 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_0cr15h8g_1_1_20160322  
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_0cr15h8g_1_1_20160322 tag=TAG20160322T235600  
channel ORA_AUX_DISK_1: restored backup piece 1  
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15  
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 00005 to /u01/app/oracle/oradata/orcl/example01.dbf  
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/oradata/orcl/backup/db_0br15h8g_1_1_20160322  
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_0br15h8g_1_1_20160322 tag=TAG20160322T235600  
channel ORA_AUX_DISK_1: restored backup piece 1  
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25  
Finished restore at 23-MAR-16  
  
contents of Memory Script:  
{  
   switch clone datafile all;  
}  
executing Memory Script  
  
datafile 1 switched to datafile copy  
input datafile copy RECID=3 STAMP=907202274 file name=/u01/app/oracle/oradata/orcl/system01.dbf  
datafile 2 switched to datafile copy  
input datafile copy RECID=4 STAMP=907202274 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf  
datafile 3 switched to datafile copy  
input datafile copy RECID=5 STAMP=907202274 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf  
datafile 4 switched to datafile copy  
input datafile copy RECID=6 STAMP=907202274 file name=/u01/app/oracle/oradata/orcl/users01.dbf  
datafile 5 switched to datafile copy  
input datafile copy RECID=7 STAMP=907202274 file name=/u01/app/oracle/oradata/orcl/example01.dbf  
  
contents of Memory Script:  
{  
   set until scn  1021413;  
   recover  
   standby  
   clone database  
    delete archivelog  
   ;  
}  
executing Memory Script  
  
executing command: SET until clause  
  
Starting recover at 23-MAR-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=19  
channel ORA_AUX_DISK_1: restoring archived log  
archived log thread=1 sequence=20  
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/oradata/orcl/backup/db_0hr15han_1_1_20160322  
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/oradata/orcl/backup/db_0hr15han_1_1_20160322 tag=TAG20160322T235709  
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_19_906917775.arc thread=1 sequence=19  
channel clone_default: deleting archived log(s)  
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_19_906917775.arc RECID=1 STAMP=907202275  
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_20_906917775.arc thread=1 sequence=20  
channel clone_default: deleting archived log(s)  
archived log file name=/u01/app/oracle/oradata/orcl/archivelog/1_20_906917775.arc RECID=2 STAMP=907202275  
media recovery complete, elapsed time: 00:00:01  
Finished recover at 23-MAR-16  
Finished Duplicate Db at 23-MAR-16  

    3.3打开备库并查询状态

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

[sql]
view plain
copy

[oracle@ST orcl]$ sqlplus / as sysdba  
  
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 23 00:38:55 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]
view plain
copy

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                                               STATUS  
---------- ------- ---------------------------------------------------------------------------------------------------- --------------------  
     3 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_3_ch2x7798_.log  
     2 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_2_ch2x76dd_.log  
     1 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_1_ch2x75bq_.log  
     4 STANDBY /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_4_ch2x78t6_.log  
     5 STANDBY /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_5_ch2x79nh_.log  
     6 STANDBY /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_6_ch2x7btx_.log  
     7 STANDBY /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_7_ch2x7cpq_.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                                               STATUS  
---------- ------- ---------------------------------------------------------------------------------------------------- --------------------  
     3 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_3_ch2x7798_.log  
     2 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_2_ch2x76dd_.log  
     1 ONLINE  /u01/app/oracle/fast_recovery_area/ORCL_PD/onlinelog/o1_mf_1_ch2x75bq_.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.  

4.验证主库

[sql]
view plain
copy

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  

5.备库开启apply service

[sql]
view plain
copy

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

6.主库建表检验

主库

[sql]
view plain
copy

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]
view plain
copy

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 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: