- [oracle@dg1 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 7 14:11:18 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> !mkdir /u01/app/oracle/archivelog
- SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog'
- valid_for=(all_logfiles,primary_role) db_unique_name=dg1;
- System altered.
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/app/oracle/archivelog
- Oldest online log sequence 3
- Next log sequence to archive 5
- Current log sequence 5
- SQL> select force_logging,db_unique_name from v$database;
- FOR DB_UNIQUE_NAME
- --- ------------------------------
- NO dg
- SQL> alter database force logging;
- Database altered.
- SQL> alter system set db_unique_name='dg1' scope=spfile;
- System altered.
- SQL> select force_logging,db_unique_name from v$database;
- FOR DB_UNIQUE_NAME
- --- ------------------------------
- YES dg
- SQL>alter system set log_archive_config='DG_CONFIG=(dg1,dg2,dg3)';
- System altered.
- SQL>alter system set log_archive_dest_2='SERVICE=dg2 valid_for=(online_logfile,primary_role) db_unique_name=dg2' scope=spfile;
- System altered.
- SQL>alter system set log_archive_dest_3='SERVICE=dg3 valid_for=(standby_logfiles,standby_role) db_unique_name=dg3' scope=spfile;
- System altered.
- SQL> show parameter remote_login;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- remote_login_passwordfile string EXCLUSIVE
- SQL> show parameter log_archive_format;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- log_archive_format string %t_%s_%r.dbf
- SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/dg/standby01.log' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/dg/standby02.log' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/dg/standby03.log' size 50M;
- Database altered.
- SQL> alter database add standby logfile group 7 '/u01/app/oracle/oradata/dg/standby04.log' size 50M;
- Database altered.
- SQL> select member,group# from v$logfile order by 2;
- MEMBER GROUP#
- ---------------------------------------- ----------
- /u01/app/oracle/oradata/dg/redo01.log 1
- /u01/app/oracle/oradata/dg/redo02.log 2
- /u01/app/oracle/oradata/dg/redo03.log 3
- /u01/app/oracle/oradata/dg/standby01.log 4
- /u01/app/oracle/oradata/dg/standby02.log 5
- /u01/app/oracle/oradata/dg/standby03.log 6
- /u01/app/oracle/oradata/dg/standby04.log 7
- 7 rows selected.
- SQL> create pfile='/home/oracle/initdg.ora' from spfile;
- File created.
- SQL> shutdown immediate
- Database closed.
- Database dismounted.
- ORACLE instance shut down.
- SQL> startup
- ORACLE instance started.
- Total System Global Area 417546240 bytes
- Fixed Size 2228944 bytes
- Variable Size 281021744 bytes
- Database Buffers 125829120 bytes
- Redo Buffers 8466432 bytes
- Database mounted.
- Database opened.
- SQL> show parameter name;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- db_file_name_convert string
- db_name string dg
- db_unique_name string dg1
- global_names boolean FALSE
- instance_name string dg
- lock_name_space string
- log_file_name_convert string
- processor_group_name string
- service_names string dg1.yang.com
- [oracle@dg1 ~]$ cat initdg.ora
- dg.__db_cache_size=125829120
- dg.__java_pool_size=4194304
- dg.__large_pool_size=4194304
- dg.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
- dg.__pga_aggregate_target=167772160
- dg.__sga_target=251658240
- dg.__shared_io_pool_size=0
- dg.__shared_pool_size=104857600
- dg.__streams_pool_size=0
- *.audit_file_dest='/u01/app/oracle/admin/dg/adump'
- *.audit_trail='db'
- *.compatible='11.2.0.0.0'
- *.control_files='/u01/app/oracle/oradata/dg/control01.ctl','/u01/app/oracle/fast_recovery_area/dg/control02.ctl'
- *.db_block_size=8192
- *.db_domain='yang.com'
- *.db_name='dg'
- *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
- *.db_recovery_file_dest_size=4322230272
- *.db_unique_name='dg2'
- *.diagnostic_dest='/u01/app/oracle'
- *.dispatchers='(PROTOCOL=TCP) (SERVICE=dgXDB)'
- *.log_archive_config='DG_CONFIG=(dg1,dg2,dg3)'
- *.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog valid_for=(all_logfiles,primary_role) db_unique_name=dg2'
- *.log_archive_dest_2='SERVICE=dg1 valid_for=(online_logfiles,primary_role) db_unique_name=dg1'
- *.log_archive_dest_3='SERVICE=dg3 valid_for=(standby_logfiles,standby_role) db_unique_name=dg3'
- *.log_archive_format='%t_%s_%r.dbf'
- *.memory_target=419430400
- *.open_cursors=300
- *.processes=150
- *.remote_login_passwordfile='EXCLUSIVE'
- *.undo_tablespace='UNDOTBS1
- [oracle@dg1 ~]$ scp initdg.ora 192.168.1.62:/home/oracle/
- [oracle@dg2 ~]$ orapwd file=$ORACLE_HOME/dbs/orapwdg password=123456 entries=5
- [oracle@dg2 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 7 15:40:33 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected to an idle instance.
- SQL> create spfile from pfile='/home/oracle/initdg.ora';
- File created.
- SQL> startup nomount
- ORACLE instance started.
- Total System Global Area 417546240 bytes
- Fixed Size 2228944 bytes
- Variable Size 281021744 bytes
- Database Buffers 125829120 bytes
- Redo Buffers 8466432 bytes
- [oracle@dg2 ~]$ rman target sys/123456@dg1 auxiliary sys/123456@dg2
- Recovery Manager: Release 11.2.0.3.0 - Production on Sat Apr 7 16:22:57 2012
- Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
- connected to target database: DG (DBID=1693312161)
- connected to auxiliary database: DG (not mounted)
- RMAN> list backup of database summary; //这个时候主库没有任何的物理备份
- using target database control file instead of recovery catalog
- specification does not match any backup in the repository
- RMAN> duplicate target database for standby nofilenamecheck from active database;
- ————————输出省略——————
- [oracle@dg2 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 7 16:30:11 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> select database_role,open_mode,name from v$database;
- DATABASE_ROLE OPEN_MODE NAME
- ---------------- -------------------- ---------
- PHYSICAL STANDBY MOUNTED DG
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/app/oracle/archivelog
- Oldest online log sequence 8
- Next log sequence to archive 0
- Current log sequence 10
- SQL> alter database open read only;
- Database altered.
- SQL> alter database recover managed standby database using current logfile disconnect from session;
- Database altered.
- SQL> select database_role,open_mode,name from v$database;
- DATABASE_ROLE OPEN_MODE NAME
- ---------------- -------------------- ---------
- PHYSICAL STANDBY READ ONLY WITH APPLY DG
- SQL> alter system switch logfile;
- System altered.
- SQL> select message from v$dataguard_status;
- MESSAGE
- --------------------------------------------------------------------------------
- LNS: Completed archiving log 3 thread 1 sequence 9
- ARC0: Beginning to archive thread 1 sequence 9 (1049579-1050098)
- ARC0: Completed archiving thread 1 sequence 9 (1049579-1050098)
- LNS: Standby redo logfile selected for thread 1 sequence 10 for destination LOG_
- ARCHIVE_DEST_2
- LNS: Beginning to archive log 1 thread 1 sequence 10
- LNS: Completed archiving log 1 thread 1 sequence 10
- ARC2: Beginning to archive thread 1 sequence 10 (1050098-1050271)
- ARC2: Completed archiving thread 1 sequence 10 (1050098-1050271)
- LNS: Beginning to archive log 2 thread 1 sequence 11
- 备库上查看日志应用情况
- SQL> archive log list;
- Database log mode Archive Mode
- Automatic archival Enabled
- Archive destination /u01/app/oracle/archivelog
- Oldest online log sequence 9
- Next log sequence to archive 0
- Current log sequence 11
- SQL> create table t1 as select * from dba_objects;
- Table created.
- SQL> alter system switch logfile;
- System altered.
- SQL> conn sys/123456@dg2 as sysdba
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 74510
|
[oracle@dg2 ~]$ cat initdg.ora dg.__db_cache_size=125829120 dg.__java_pool_size=4194304 dg.__large_pool_size=4194304 dg.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment dg.__pga_aggregate_target=167772160 dg.__sga_target=251658240 dg.__shared_io_pool_size=0 dg.__shared_pool_size=104857600 dg.__streams_pool_size=0 *.audit_file_dest='/u01/app/oracle/admin/dg/adump' *.audit_trail='db' *.compatible='11.2.0.0.0' *.control_files='/u01/app/oracle/oradata/dg/control01.ctl','/u01/app/oracle/fast_recovery_area/dg/control02.ctl' *.db_block_size=8192 *.db_domain='yang.com' *.db_name='dg' *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' *.db_recovery_file_dest_size=4322230272 *.db_unique_name='dg3' *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=dgXDB)' *.log_archive_config='DG_CONFIG=(dg1,dg2,dg3)' *.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog valid_for=(all_logfiles,primary_role) db_unique_name=dg3' *.standby_archive_dest=/u01/app/oracle/standbylog *.log_archive_format='%t_%s_%r.dbf' *.memory_target=419430400 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' |
- [oracle@dg3 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 14 18:01:59 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected to an idle instance.
- SQL> create spfile from pfile='/home/oracle/initdg.ora';
- File created.
- SQL> startup nomount
- ORACLE instance started.
- Total System Global Area 417546240 bytes
- Fixed Size 2228944 bytes
- Variable Size 281021744 bytes
- Database Buffers 125829120 bytes
- Redo Buffers 8466432 bytes
- [oracle@dg3 ~]$ rman target sys/123456@dg1 auxiliary sys/123456@dg3
- Recovery Manager: Release 11.2.0.3.0 - Production on Sat Apr 14 18:02:59 2012
- Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
- connected to target database: DG (DBID=1693928392)
- connected to auxiliary database: DG (not mounted)
- RMAN> duplicate target database for standby nofilenamecheck from active database;
- ————————输出省略——————
- [oracle@dg3 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sat Apr 14 18:49:12 2012
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> alter database open read only;
- Database altered.
- SQL> alter database recover managed standby database using current logfile disconnect from session;
- Database altered.
- SQL> select open_mode,database_role,name from v$database;
- OPEN_MODE DATABASE_ROLE NAME
- -------------------- ---------------- ---------
- READ ONLY WITH APPLY PHYSICAL STANDBY DG
- SQL> conn /as sysdba
- Connected.
- SQL> select open_mode,database_role,name from v$database;
- OPEN_MODE DATABASE_ROLE NAME
- -------------------- ---------------- ---------
- READ WRITE PRIMARY DG
- SQL> truncate table t1;
- Table truncated.
- SQL> conn sys/123456@dg2 as sysdba
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 74510
- SQL> conn sys/123456@dg3 as sysdba
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 74510
- SQL> conn /as sysdba
- Connected.
- SQL> alter system switch logfile; //主库上未切换日志前,数据不能同步
- System altered.
- SQL> conn sys/123456@dg2 as sysdba
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 0
- SQL> conn sys/123456@dg3 as sysdba //在dg3上可以看到明显的延迟情况
- Connected.
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 74510
- SQL> select count(*) from t1;
- COUNT(*)
- ----------
- 0
- SQL> select message from v$dataguard_status; //查看备库dg3的dataguard状态
- MESSAGE
- --------------------------------------------------------------------------------
- Media Recovery Log /u01/app/oracle/standbylog/1_13_780597393.dbf
- Media Recovery Waiting for thread 1 sequence 14
- FAL[client]: Error fetching gap sequence, no FAL server specified
- RFS[1]: Assigned to RFS process 2701
- Media Recovery Log /u01/app/oracle/archivelog/1_14_780597393.dbf
- Media Recovery Waiting for thread 1 sequence 15
- FAL[client]: Error fetching gap sequence, no FAL server specified
- 18 rows selected.
- SQL> alter system set fal_server='dg2';
- System altered.
- SQL> alter system set fal_client='dg3';
- System altered.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25725504/viewspace-1716465/ ,如需转载,请注明出处,否则将追究法律责任。