Install Oracle Database 11g Dataguard on RHEL5U10
俗话说,温故而知新。
所以今天打算重新写一下关于Oracle 11gR2如何搭建DG架构。
在开始本文前,你需要做以下准备工作:
1. 两台装好了RHEL5U10的操作系统。
2. 两台Linux上装好Oracle database 11g的软件。
3. 作为主库的Linux上面需要创建好Oracle实例。
在我的环境里这些信息如下:
主库:
oradg1
192.168.232.128
备库:
oradg2
192.168.232.129
关于数据库实例名的部分:
1. 主备库的db_name,均为:orcl
2. db_unique_name:
主库:primaryme
备库:standby1
归档目录:
主备库的归档目录都是:/u01/arch
接下来会详细的呈现搭建过程及其说明。
————————————————————
零、创建归档路径。
主备库都需要创建/u01/arch,要用oracle用户创建:
1 2 3 4 |
[oracle@oradg1 ~]$ whoami oracle [oracle@oradg1 ~]$ mkdir /u01/arch [oracle@oradg1 ~]$ |
一、主库配置:归档 + 强制日志
开归档:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
SQL> archive log list; Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 4 Current log sequence 6 SQL> SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> 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 archivelog; Database altered. SQL> alter database open; Database altered. SQL> |
强制日志:
1 2 3 4 5 |
SQL> alter database force logging; Database altered. SQL> |
二、主库参数配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
[oracle@oradg1 ~]$ cat initorcl_primary.ora orcl.__db_cache_size=671088640 orcl.__java_pool_size=16777216 orcl.__large_pool_size=33554432 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=16777216 *.audit_file_dest='/u01/app/oracle/admin/orcl/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/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 *.db_unique_name='primaryme' *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.fal_client='primaryme' *.fal_server='standby1' *.log_archive_config='dg_config=(primaryme,standby1)' *.log_archive_dest_1='location=/u01/arch valid_for=(all_logfiles,all_roles) db_unique_name=primaryme' *.log_archive_dest_2='service=standby1 lgwr sync noaffirm valid_for=(online_logfiles,primary_role) db_unique_name=standby1' *.memory_target=1654652928 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.standby_file_management='auto' *.undo_tablespace='UNDOTBS1' [oracle@oradg1 ~]$ |
以这个参数文件重新启动主库实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> SQL> create spfile from pfile='/home/oracle/initorcl_primary.ora'; File created. SQL> startup 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. Database opened. SQL> |
三、主库监听与TNSNAME
主库监听状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
[oracle@oradg1 ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 18-JUN-2016 09:30:01 Copyright (c) 1991, 2013, Oracle. All rights reserved. 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 18-JUN-2016 03:58:00 Uptime 0 days 5 hr. 32 min. 1 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/oradg1/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oradg1)(PORT=1521))) Services Summary... Service "orclXDB" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... Service "primaryme" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... The command completed successfully [oracle@oradg1 ~]$ |
注意,上面的Service Name会跟着db_unique_name一致。
TNSNAMES.ORA:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[oracle@oradg1 ~]$ cat $ORACLE_HOME/network/admin/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 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oradg1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) primaryme = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oradg1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = primaryme) ) ) standby1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oradg2)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = standby1) ) ) [oracle@oradg1 ~]$ |
四、主库:RMAN全备
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
[oracle@oradg1 admin]$ df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/VolGroup00-LogVol00 33G 15G 18G 46% / /dev/sda1 99M 13M 81M 14% /boot tmpfs 2.0G 331M 1.7G 17% /dev/shm [oracle@oradg1 admin]$ [oracle@oradg1 admin]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Sat Jun 18 06:24:42 2016 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1442598347) RMAN> list backup; using target database control file instead of recovery catalog specification does not match any backup in the repository RMAN> show all; RMAN configuration parameters for database with db_unique_name PRIMARYME are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE MAXSETSIZE TO UNLIMITED; # default CONFIGURE ENCRYPTION FOR DATABASE OFF; # default CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f'; # default RMAN> RMAN> backup database plus archivelog; Starting backup at 18-JUN-2016 06:25:57 current log archived using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=44 device type=DISK channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=6 RECID=1 STAMP=914824863 input archived log thread=1 sequence=7 RECID=2 STAMP=914826309 input archived log thread=1 sequence=8 RECID=3 STAMP=914826358 channel ORA_DISK_1: starting piece 1 at 18-JUN-2016 06:25:58 channel ORA_DISK_1: finished piece 1 at 18-JUN-2016 06:26:06 piece handle=/u01/app/oracle/fast_recovery_area/PRIMARYME/backupset/2016_06_18/o1_mf_annnn_TAG20160618T062558_cp8y7pnk_.bkp tag=TAG20160618T062558 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08 Finished backup at 18-JUN-2016 06:26:06 Starting backup at 18-JUN-2016 06:26:06 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/oradata/orcl/system01.dbf input datafile file number=00002 name=/oradata/orcl/sysaux01.dbf input datafile file number=00005 name=/oradata/orcl/example01.dbf input datafile file number=00003 name=/oradata/orcl/undotbs01.dbf input datafile file number=00004 name=/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 18-JUN-2016 06:26:06 channel ORA_DISK_1: finished piece 1 at 18-JUN-2016 06:27:46 piece handle=/u01/app/oracle/fast_recovery_area/PRIMARYME/backupset/2016_06_18/o1_mf_nnndf_TAG20160618T062606_cp8y7yv5_.bkp tag=TAG20160618T062606 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:40 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 18-JUN-2016 06:27:49 channel ORA_DISK_1: finished piece 1 at 18-JUN-2016 06:27:52 piece handle=/u01/app/oracle/fast_recovery_area/PRIMARYME/backupset/2016_06_18/o1_mf_ncsnf_TAG20160618T062606_cp8yc5o7_.bkp tag=TAG20160618T062606 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 18-JUN-2016 06:27:52 Starting backup at 18-JUN-2016 06:27:52 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=9 RECID=4 STAMP=914826473 channel ORA_DISK_1: starting piece 1 at 18-JUN-2016 06:27:53 channel ORA_DISK_1: finished piece 1 at 18-JUN-2016 06:27:54 piece handle=/u01/app/oracle/fast_recovery_area/PRIMARYME/backupset/2016_06_18/o1_mf_annnn_TAG20160618T062753_cp8yc94v_.bkp tag=TAG20160618T062753 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 18-JUN-2016 06:27:54 RMAN> exit Recovery Manager complete. [oracle@oradg1 admin]$ |
五、主库:创建STANDBY控制文件
1 2 3 4 5 |
SQL> alter database create standby controlfile as '/home/oracle/orcl_standby.ctl'; Database altered. SQL> |
六、主库:将备库需要的文件传到备库需要的目录下。
将前面“第五步”全备的备份集传给备库:
1 2 3 4 5 6 7 8 9 10 11 12 |
[oracle@oradg1 oracle]$ scp -r fast_recovery_area/ oradg2:$ORACLE_BASE/ The authenticity of host 'oradg2 (192.168.232.129)' can't be established. RSA key fingerprint is 05:cf:f4:e0:cb:4f:b2:b0:7b:63:86:1a:23:77:fd:3a. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'oradg2,192.168.232.129' (RSA) to the list of known hosts. oracle@oradg2's password: o1_mf_nnndf_TAG20160618T062606_cp8y7yv5_.bkp 100% 1132MB 14.0MB/s 01:21 o1_mf_annnn_TAG20160618T062753_cp8yc94v_.bkp 100% 54KB 53.5KB/s 00:00 o1_mf_ncsnf_TAG20160618T062606_cp8yc5o7_.bkp 100% 9600KB 9.4MB/s 00:01 o1_mf_annnn_TAG20160618T062558_cp8y7pnk_.bkp 100% 46MB 6.5MB/s 00:07 control02.ctl 100% 9520KB 4.7MB/s 00:02 [oracle@oradg1 oracle]$ |
将之前创建的备库的STANDBY控制文件发给备库:
1 2 3 4 5 6 |
[oracle@oradg1 oracle]$ scp /home/oracle/* oradg2:/home/oracle oracle@oradg2's password: initorcl_primary.ora 100% 1288 1.3KB/s 00:00 initorcl_standby1.ora 100% 1232 1.2KB/s 00:00 orcl_standby.ctl 100% 9520KB 9.3MB/s 00:01 [oracle@oradg1 oracle]$ |
将主库的dbs发给备库,主要是主库实例的密码文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[oracle@oradg1 oracle]$ cd $ORACLE_HOME/dbs [oracle@oradg1 dbs]$ [oracle@oradg1 dbs]$ ls -ltr 总计 9564 -rw-r--r-- 1 oracle oinstall 2851 2009-05-15 init.ora -rw-r----- 1 oracle oinstall 24 06-18 04:00 lkORCL -rw-r----- 1 oracle oinstall 1536 06-18 04:03 orapworcl -rw-r----- 1 oracle oinstall 24 06-18 06:00 lkPRIMARYME -rw-rw---- 1 oracle oinstall 1544 06-18 06:00 hc_orcl.dat -rw-r----- 1 oracle oinstall 3584 06-18 06:02 spfileorcl.ora -rw-r--r-- 1 oracle oinstall 1288 06-18 06:11 initorcl.ora -rw-r----- 1 oracle oinstall 9748480 06-18 06:27 snapcf_orcl.f [oracle@oradg1 dbs]$ scp orapworcl oradg2:$ORACLE_HOME/dbs oracle@oradg2's password: orapworcl 100% 1536 1.5KB/s 00:00 [oracle@oradg1 dbs]$ |
七、备库:编辑参数文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
[oracle@oradg2 ~]$ cat initorcl_standby1.ora orcl.__db_cache_size=671088640 orcl.__java_pool_size=16777216 orcl.__large_pool_size=33554432 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=16777216 *.audit_file_dest='/u01/app/oracle/admin/orcl/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/oradata/orcl/control01.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 *.db_unique_name='standby1' *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.fal_client='standby1' *.fal_server='primaryme' *.log_archive_config='dg_config=(primaryme,standby1)' *.log_archive_dest_1='location=/u01/arch valid_for=(all_logfiles,all_roles) db_unique_name=standby1' *.log_archive_dest_2='service=primaryme lgwr sync noaffirm valid_for=(online_logfiles,primary_role) db_unique_name=primaryme' *.memory_target=1654652928 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.standby_file_management='auto' *.undo_tablespace='UNDOTBS1' [oracle@oradg2 ~]$ |
注意:
*.control_files=’/oradata/orcl/control01.ctl’
这个设定和主库是不一样的。
这个细节在后面会被用到。
八、备库:创建需要的目录结构
1 2 3 4 |
[oracle@oradg2 ~]$ mkdir -p $ORACLE_BASE/admin/orcl/{adump,dump,dpdump,pfile} [oracle@oradg2 ~]$ [oracle@oradg2 ~]$ mkdir /oradata/orcl/ [oracle@oradg2 ~]$ |
九、备库:启动监听
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
[oracle@oradg2 dbs]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 18-JUN-2016 07:49:39 Copyright (c) 1991, 2013, Oracle. All rights reserved. Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 11.2.0.4.0 - Production Log messages written to /u01/app/oracle/diag/tnslsnr/oradg2/listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oradg2)(PORT=1521))) Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 18-JUN-2016 07:49:40 Uptime 0 days 0 hr. 0 min. 1 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Log File /u01/app/oracle/diag/tnslsnr/oradg2/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oradg2)(PORT=1521))) The listener supports no services The command completed successfully [oracle@oradg2 dbs]$ |
十、备库:配置TNSNAME。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[oracle@oradg2 ~]$ cat $ORACLE_HOME/network/admin/tnsnames.ora primaryme = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oradg1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = primaryme) ) ) standby1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oradg2)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = standby1) ) ) [oracle@oradg2 ~]$ |
注意:在TNSNAMES的配置中,SERVICE_NAME需要与“lsnrctl status”中的service name一致,否则DG同步时,会出问题。
十二、备库:将备库创建的standby控制文件拷贝到参数指定的位置
1 2 |
[oracle@oradg2 dbs]$ cp /home/oracle/orcl_standby.ctl /oradata/orcl/control01.ctl [oracle@oradg2 dbs]$ |
在上面参数文件的“control_files”中设定了控制文件的位置。
十三、备库:根据上面的备库参数文件启动备库数据库到MOUNT。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[oracle@oradg2 dbs]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sat Jun 18 07:51:40 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> create spfile from pfile='/home/oracle/initorcl_standby1.ora'; File created. SQL> 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> 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@oradg2 dbs]$ |
十四、备库:RMAN恢复数据库。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
[oracle@oradg2 dbs]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Sat Jun 18 08:10:48 2016 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1442598347, not open) RMAN> restore database; Starting restore at 18-JUN-2016 08:11:05 Starting implicit crosscheck backup at 18-JUN-2016 08:11:05 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=25 device type=DISK Crosschecked 4 objects Finished implicit crosscheck backup at 18-JUN-2016 08:11:06 Starting implicit crosscheck copy at 18-JUN-2016 08:11:06 using channel ORA_DISK_1 Finished implicit crosscheck copy at 18-JUN-2016 08:11:06 searching for all files in the recovery area cataloging files... no files cataloged using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00001 to /oradata/orcl/system01.dbf channel ORA_DISK_1: restoring datafile 00002 to /oradata/orcl/sysaux01.dbf channel ORA_DISK_1: restoring datafile 00003 to /oradata/orcl/undotbs01.dbf channel ORA_DISK_1: restoring datafile 00004 to /oradata/orcl/users01.dbf channel ORA_DISK_1: restoring datafile 00005 to /oradata/orcl/example01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PRIMARYME/backupset/2016_06_18/o1_mf_nnndf_TAG20160618T062606_cp8y7yv5_.bkp channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PRIMARYME/backupset/2016_06_18/o1_mf_nnndf_TAG20160618T062606_cp8y7yv5_.bkp tag=TAG20160618T062606 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:01:51 Finished restore at 18-JUN-2016 08:12:58 RMAN> exit Recovery Manager complete. [oracle@oradg2 dbs]$ |
这时候,数据库的状态,还是MOUNT:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[oracle@oradg2 dbs]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sat Jun 18 08:15:13 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 instance_name,status from v$instance; INSTANCE_NAME STATUS ---------------- ------------ orcl MOUNTED SQL> |
十五、备库:增加STANDBY REDO。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
SQL> set linesize 400 SQL> col member for a40 SQL> select * from v$logfile order by group#; GROUP# STATUS TYPE MEMBER IS_ ---------- ------- ------- ---------------------------------------- --- 1 ONLINE /oradata/orcl/redo01.log NO 2 ONLINE /oradata/orcl/redo02.log NO 3 ONLINE /oradata/orcl/redo03.log NO SQL> SQL> !ls -ltr /oradata/orcl 总计 1793032 -rw-r----- 1 oracle oinstall 9748480 06-18 07:42 orcl_standby.ctl -rw-r----- 1 oracle oinstall 5251072 06-18 08:11 users01.dbf -rw-r----- 1 oracle oinstall 110108672 06-18 08:11 undotbs01.dbf -rw-r----- 1 oracle oinstall 346693632 06-18 08:12 example01.dbf -rw-r----- 1 oracle oinstall 566239232 06-18 08:12 sysaux01.dbf -rw-r----- 1 oracle oinstall 786440192 06-18 08:12 system01.dbf -rw-r----- 1 oracle oinstall 9748480 06-18 08:18 control01.ctl SQL> SQL> alter database add standby logfile ('/oradata/orcl/standby_redo01.log') size 50M; Database altered. SQL> alter database add standby logfile ('/oradata/orcl/standby_redo02.log') size 50M; Database altered. SQL> alter database add standby logfile ('/oradata/orcl/standby_redo03.log') size 50M; Database altered. SQL> alter database add standby logfile ('/oradata/orcl/standby_redo04.log') size 50M; Database altered. SQL> SQL> select * from v$logfile order by group#; GROUP# STATUS TYPE MEMBER IS_ ---------- ------- ------- ---------------------------------------- --- 1 ONLINE /oradata/orcl/redo01.log NO 2 ONLINE /oradata/orcl/redo02.log NO 3 ONLINE /oradata/orcl/redo03.log NO 4 STANDBY /oradata/orcl/standby_redo01.log NO 5 STANDBY /oradata/orcl/standby_redo02.log NO 6 STANDBY /oradata/orcl/standby_redo03.log NO 7 STANDBY /oradata/orcl/standby_redo04.log NO 7 rows selected. SQL> SQL> show parameter standby_file_management NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ standby_file_management string AUTO SQL> |
十六、备库:准备启动日志应用。
在上面备库恢复完成之后,其实日志应用进程是没有起来的:
1 2 3 4 5 6 7 8 9 10 |
SQL> select process,pid,client_pid,status,delay_mins,known_agents,active_agents from v$managed_standby; PROCESS PID CLIENT_PID STATUS DELAY_MINS KNOWN_AGENTS ACTIVE_AGENTS --------- ---------- -------------------- ------------ ---------- ------------ ------------- ARCH 30200 30200 CONNECTED 0 0 0 ARCH 30205 30205 CONNECTED 0 0 0 ARCH 30210 30210 CONNECTED 0 0 0 ARCH 30215 30215 CONNECTED 0 0 0 SQL> |
你需要重启实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
SQL> shutdown immediate; ORA-01109: database not open Database dismounted. ORACLE instance shut down. SQL> 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> SQL> alter database mount standby database; Database altered. SQL> SQL> select process,pid,client_pid,status,delay_mins,known_agents,active_agents from v$managed_standby; PROCESS PID CLIENT_PID STATUS DELAY_MINS KNOWN_AGENTS ACTIVE_AGENTS --------- ---------- -------------------- ------------ ---------- ------------ ------------- ARCH 30456 30456 CONNECTED 0 0 0 ARCH 30461 30461 CONNECTED 0 0 0 ARCH 30466 30466 CONNECTED 0 0 0 ARCH 30471 30471 CONNECTED 0 0 0 SQL> SQL> alter database recover managed standby database disconnect from session; Database altered. SQL> SQL> select process,pid,client_pid,status,delay_mins,known_agents,active_agents from v$managed_standby; PROCESS PID CLIENT_PID STATUS DELAY_MINS KNOWN_AGENTS ACTIVE_AGENTS --------- ---------- -------------------- ------------ ---------- ------------ ------------- ARCH 30456 30456 CONNECTED 0 0 0 ARCH 30461 30461 CONNECTED 0 0 0 ARCH 30466 30466 CONNECTED 0 0 0 ARCH 30471 30471 CONNECTED 0 0 0 MRP0 30488 N/A WAIT_FOR_GAP 0 0 0 SQL> |
可以看到,“alter database recover managed … ”成功之后,MRP0,进程就启用了。
————————————————
这样,DG的配置就结束了。
十七、测试:
查看下主库上的日志状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[oracle@oradg1 ~]$ cd /u01/arch [oracle@oradg1 arch]$ ls -ltr 总计 101084 -rw-r----- 1 oracle oinstall 43879424 06-18 06:00 1_6_914817615.dbf -rw-r----- 1 oracle oinstall 3886592 06-18 06:25 1_7_914817615.dbf -rw-r----- 1 oracle oinstall 36352 06-18 06:25 1_8_914817615.dbf -rw-r----- 1 oracle oinstall 53248 06-18 06:27 1_9_914817615.dbf -rw-r----- 1 oracle oinstall 12360192 06-18 08:49 1_10_914817615.dbf -rw-r----- 1 oracle oinstall 140800 06-18 08:53 1_11_914817615.dbf -rw-r----- 1 oracle oinstall 85504 06-18 08:55 1_12_914817615.dbf -rw-r----- 1 oracle oinstall 87040 06-18 08:57 1_13_914817615.dbf -rw-r----- 1 oracle oinstall 2804736 06-18 09:24 1_14_914817615.dbf -rw-r----- 1 oracle oinstall 1024 06-18 09:26 1_15_914817615.dbf -rw-r----- 1 oracle oinstall 31744 06-18 09:27 1_16_914817615.dbf -rw-r----- 1 oracle oinstall 53248 06-18 09:27 1_17_914817615.dbf -rw-r----- 1 oracle oinstall 23552 06-18 09:28 1_18_914817615.dbf -rw-r----- 1 oracle oinstall 39907840 06-18 10:10 1_19_914817615.dbf [oracle@oradg1 arch]$ |
而此时备库的日志状态如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[oracle@oradg2 ~]$ cd /u01/arch/ [oracle@oradg2 arch]$ ls -ltr 总计 54348 -rw-r----- 1 oracle oinstall 53248 06-18 08:42 1_9_914817615.dbf -rw-r----- 1 oracle oinstall 140800 06-18 08:42 1_11_914817615.dbf -rw-r----- 1 oracle oinstall 12360192 06-18 08:42 1_10_914817615.dbf -rw-r----- 1 oracle oinstall 85504 06-18 08:42 1_12_914817615.dbf -rw-r----- 1 oracle oinstall 87040 06-18 08:44 1_13_914817615.dbf -rw-r----- 1 oracle oinstall 2804736 06-18 09:11 1_14_914817615.dbf -rw-r----- 1 oracle oinstall 1024 06-18 09:13 1_15_914817615.dbf -rw-r----- 1 oracle oinstall 31744 06-18 09:13 1_16_914817615.dbf -rw-r----- 1 oracle oinstall 53248 06-18 09:14 1_17_914817615.dbf -rw-r----- 1 oracle oinstall 23552 06-18 09:14 1_18_914817615.dbf -rw-r----- 1 oracle oinstall 39907840 06-18 09:57 1_19_914817615.dbf [oracle@oradg2 arch]$ |
主库:执行一次日志切换,以生成新的归档日志
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
[oracle@oradg1 arch]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Sat Jun 18 10:26:19 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> alter system switch logfile; System altered. SQL> !ls -ltr /u01/arch 总计 138872 -rw-r----- 1 oracle oinstall 43879424 06-18 06:00 1_6_914817615.dbf -rw-r----- 1 oracle oinstall 3886592 06-18 06:25 1_7_914817615.dbf -rw-r----- 1 oracle oinstall 36352 06-18 06:25 1_8_914817615.dbf -rw-r----- 1 oracle oinstall 53248 06-18 06:27 1_9_914817615.dbf -rw-r----- 1 oracle oinstall 12360192 06-18 08:49 1_10_914817615.dbf -rw-r----- 1 oracle oinstall 140800 06-18 08:53 1_11_914817615.dbf -rw-r----- 1 oracle oinstall 85504 06-18 08:55 1_12_914817615.dbf -rw-r----- 1 oracle oinstall 87040 06-18 08:57 1_13_914817615.dbf -rw-r----- 1 oracle oinstall 2804736 06-18 09:24 1_14_914817615.dbf -rw-r----- 1 oracle oinstall 1024 06-18 09:26 1_15_914817615.dbf -rw-r----- 1 oracle oinstall 31744 06-18 09:27 1_16_914817615.dbf -rw-r----- 1 oracle oinstall 53248 06-18 09:27 1_17_914817615.dbf -rw-r----- 1 oracle oinstall 23552 06-18 09:28 1_18_914817615.dbf -rw-r----- 1 oracle oinstall 39907840 06-18 10:10 1_19_914817615.dbf -rw-r----- 1 oracle oinstall 38648832 06-18 10:26 1_20_914817615.dbf SQL> |
可以看到,新增了归档日志:1_20_914817615.dbf。
查看备库当前的归档日志文件的装填:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[oracle@oradg2 arch]$ pwd /u01/arch [oracle@oradg2 arch]$ [oracle@oradg2 arch]$ ls -ltr 总计 92136 -rw-r----- 1 oracle oinstall 53248 06-18 08:42 1_9_914817615.dbf -rw-r----- 1 oracle oinstall 140800 06-18 08:42 1_11_914817615.dbf -rw-r----- 1 oracle oinstall 12360192 06-18 08:42 1_10_914817615.dbf -rw-r----- 1 oracle oinstall 85504 06-18 08:42 1_12_914817615.dbf -rw-r----- 1 oracle oinstall 87040 06-18 08:44 1_13_914817615.dbf -rw-r----- 1 oracle oinstall 2804736 06-18 09:11 1_14_914817615.dbf -rw-r----- 1 oracle oinstall 1024 06-18 09:13 1_15_914817615.dbf -rw-r----- 1 oracle oinstall 31744 06-18 09:13 1_16_914817615.dbf -rw-r----- 1 oracle oinstall 53248 06-18 09:14 1_17_914817615.dbf -rw-r----- 1 oracle oinstall 23552 06-18 09:14 1_18_914817615.dbf -rw-r----- 1 oracle oinstall 39907840 06-18 09:57 1_19_914817615.dbf -rw-r----- 1 oracle oinstall 38648832 06-18 10:13 1_20_914817615.dbf [oracle@oradg2 arch]$ |
可以看到主库的日志自动的传递到了备库。
查询日志应用的相关信息:
select name,to_char(first_time,’yyyy-mm-dd hh24:mi:ss’) “First”,to_char(next_time,’yyyy-mm-dd hh24:mi:ss’) “Next”,applied,archived,deleted,status,to_char(completion_time,’yyyy-mm-dd hh24:mi:ss’) “Completion”,sequence# from v$archived_log order by sequence#;
主库:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
SQL> set linesize 400 SQL> set pagesize 400 SQL> col name for a30 SQL> SQL> select name,to_char(first_time,'yyyy-mm-dd hh24:mi:ss') "First",to_char(next_time,'yyyy-mm-dd hh24:mi:ss') "Next",applied,archived,deleted,status,to_char(completion_time,'yyyy-mm-dd hh24:mi:ss') "Completion",sequence# from v$archived_log order by sequence#; NAME First Next APPLIED ARC DEL S Completion SEQUENCE# ------------------------------ ------------------- ------------------- --------- --- --- - ------------------- ---------- /u01/arch1_6_914817615.dbf 2016-06-18 04:07:27 2016-06-18 06:00:59 NO YES NO A 2016-06-18 06:01:03 6 /u01/arch/1_7_914817615.dbf 2016-06-18 06:00:59 2016-06-18 06:25:09 NO YES NO A 2016-06-18 06:25:09 7 /u01/arch/1_8_914817615.dbf 2016-06-18 06:25:09 2016-06-18 06:25:57 NO YES NO A 2016-06-18 06:25:58 8 /u01/arch/1_9_914817615.dbf 2016-06-18 06:25:57 2016-06-18 06:27:52 NO YES NO A 2016-06-18 06:27:53 9 standby1 2016-06-18 06:25:57 2016-06-18 06:27:52 YES YES NO A 2016-06-18 08:55:30 9 standby1 2016-06-18 06:27:52 2016-06-18 08:49:56 YES YES NO A 2016-06-18 08:55:32 10 /u01/arch/1_10_914817615.dbf 2016-06-18 06:27:52 2016-06-18 08:49:56 NO YES NO A 2016-06-18 08:49:57 10 /u01/arch/1_11_914817615.dbf 2016-06-18 08:49:56 2016-06-18 08:53:21 NO YES NO A 2016-06-18 08:53:21 11 standby1 2016-06-18 08:49:56 2016-06-18 08:53:21 YES YES NO A 2016-06-18 08:55:31 11 /u01/arch/1_12_914817615.dbf 2016-06-18 08:53:21 2016-06-18 08:55:35 NO YES NO A 2016-06-18 08:55:38 12 standby1 2016-06-18 08:53:21 2016-06-18 08:55:35 YES YES NO A 2016-06-18 08:55:39 12 /u01/arch/1_13_914817615.dbf 2016-06-18 08:55:35 2016-06-18 08:57:59 NO YES NO A 2016-06-18 08:57:59 13 standby1 2016-06-18 08:55:35 2016-06-18 08:57:59 YES YES NO A 2016-06-18 08:57:59 13 standby1 2016-06-18 08:57:59 2016-06-18 09:24:44 YES YES NO A 2016-06-18 09:24:44 14 /u01/arch/1_14_914817615.dbf 2016-06-18 08:57:59 2016-06-18 09:24:44 NO YES NO A 2016-06-18 09:24:45 14 /u01/arch/1_15_914817615.dbf 2016-06-18 09:24:44 2016-06-18 09:26:56 NO YES NO A 2016-06-18 09:26:56 15 standby1 2016-06-18 09:24:44 2016-06-18 09:26:56 YES YES NO A 2016-06-18 09:26:58 15 /u01/arch/1_16_914817615.dbf 2016-06-18 09:26:56 2016-06-18 09:26:59 NO YES NO A 2016-06-18 09:27:00 16 standby1 2016-06-18 09:26:56 2016-06-18 09:26:59 YES YES NO A 2016-06-18 09:27:00 16 standby1 2016-06-18 09:26:59 2016-06-18 09:27:44 YES YES NO A 2016-06-18 09:27:44 17 /u01/arch/1_17_914817615.dbf 2016-06-18 09:26:59 2016-06-18 09:27:44 NO YES NO A 2016-06-18 09:27:44 17 standby1 2016-06-18 09:27:44 2016-06-18 09:28:17 YES YES NO A 2016-06-18 09:28:17 18 /u01/arch/1_18_914817615.dbf 2016-06-18 09:27:44 2016-06-18 09:28:17 NO YES NO A 2016-06-18 09:28:17 18 standby1 2016-06-18 09:28:17 2016-06-18 10:10:42 YES YES NO A 2016-06-18 10:10:42 19 /u01/arch/1_19_914817615.dbf 2016-06-18 09:28:17 2016-06-18 10:10:42 NO YES NO A 2016-06-18 10:10:46 19 standby1 2016-06-18 10:10:42 2016-06-18 10:26:25 YES YES NO A 2016-06-18 10:26:25 20 /u01/arch/1_20_914817615.dbf 2016-06-18 10:10:42 2016-06-18 10:26:25 NO YES NO A 2016-06-18 10:26:28 20 27 rows selected. SQL> |
备库:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
SQL> set linesize 400 SQL> col name for a30 SQL> set pagesize 300 SQL> SQL> select name,to_char(first_time,'yyyy-mm-dd hh24:mi:ss') "First",to_char(next_time,'yyyy-mm-dd hh24:mi:ss') "Next",applied,archived,deleted,status,to_char(completion_time,'yyyy-mm-dd hh24:mi:ss') "Completion",sequence# from v$archived_log order by sequence#; NAME First Next APPLIED ARC DEL S Completion SEQUENCE# ------------------------------ ------------------- ------------------- --------- --- --- - ------------------- ---------- /u01/arch/1_9_914817615.dbf 2016-06-18 06:25:57 2016-06-18 06:27:52 YES YES NO A 2016-06-18 08:42:06 9 /u01/arch/1_10_914817615.dbf 2016-06-18 06:27:52 2016-06-18 08:49:56 YES YES NO A 2016-06-18 08:42:07 10 /u01/arch/1_11_914817615.dbf 2016-06-18 08:49:56 2016-06-18 08:53:21 YES YES NO A 2016-06-18 08:42:06 11 /u01/arch/1_12_914817615.dbf 2016-06-18 08:53:21 2016-06-18 08:55:35 YES YES NO A 2016-06-18 08:42:14 12 /u01/arch/1_13_914817615.dbf 2016-06-18 08:55:35 2016-06-18 08:57:59 YES YES NO A 2016-06-18 08:44:35 13 /u01/arch/1_14_914817615.dbf 2016-06-18 08:57:59 2016-06-18 09:24:44 YES YES NO A 2016-06-18 09:11:20 14 /u01/arch/1_15_914817615.dbf 2016-06-18 09:24:44 2016-06-18 09:26:56 YES YES NO A 2016-06-18 09:13:33 15 /u01/arch/1_16_914817615.dbf 2016-06-18 09:26:56 2016-06-18 09:26:59 YES YES NO A 2016-06-18 09:13:36 16 /u01/arch/1_17_914817615.dbf 2016-06-18 09:26:59 2016-06-18 09:27:44 YES YES NO A 2016-06-18 09:14:19 17 /u01/arch/1_18_914817615.dbf 2016-06-18 09:27:44 2016-06-18 09:28:17 YES YES NO A 2016-06-18 09:14:52 18 /u01/arch/1_19_914817615.dbf 2016-06-18 09:28:17 2016-06-18 10:10:42 YES YES NO A 2016-06-18 09:57:20 19 /u01/arch/1_20_914817615.dbf 2016-06-18 10:10:42 2016-06-18 10:26:25 YES YES NO A 2016-06-18 10:13:03 20 12 rows selected. SQL> |
十八、其他的一些有关的查询:
主库:
1 2 3 4 5 6 7 |
SQL> select name,database_role,protection_level from v$database; NAME DATABASE_ROLE PROTECTION_LEVEL ------------------------------ ---------------- -------------------- ORCL PRIMARY MAXIMUM PERFORMANCE SQL> |
备库:
1 2 3 4 5 6 7 |
SQL> select name,database_role,protection_level from v$database; NAME DATABASE_ROLE PROTECTION_LEVEL ------------------------------ ---------------- -------------------- ORCL PHYSICAL STANDBY MAXIMUM PERFORMANCE SQL> |
————————————————
Done。
set linesize 400col name for a60select name,to_char(first_time,’yyyy-mm-dd hh24:mi:ss’) “First”,to_char(next_time,’yyyy-mm-dd hh24:mi:ss’) “Next”,applied,archived,deleted,status,to_char(completion_time,’yyyy-mm-dd hh24:mi:ss’) “Completion”,sequence# from v$archived_log order by sequence#