oracle-11g-Dataguard详细配置手册 下载本文

LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcl2)' LOG_ARCHIVE_DEST_1= 'LOCATION=/u01/app/archive DB_UNIQUE_NAME=orcl'

LOG_ARCHIVE_DEST_2= 'SERVICE=orcl2 LGWR ASYNC DB_UNIQUE_NAME=orcl2'

LOG_ARCHIVE_DEST_STATE_1=ENABLE LOG_ARCHIVE_DEST_STATE_2=ENABLE LOG_ARCHIVE_FORMAT=%t_%s_%r.arc FAL_SERVER=orcl2 FAL_CLIENT=orcl STANDBY_

把修改后的pfile 也拷贝到备库上:

scp –rp /u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora lin-2:/u01/app/oracle/product/11.2.0/db_1/dbs/

注意:根据实际情况更改用户的环境变量

VALID_FOR=(ALL_LOG) VALID_FOR=(ONLINE_LOG)

六.修改主库运行在归档模式下

SQL> archive log list;

Database log mode No Archive Mode Automatic archival Disabled

Archive destination USE_DB_RECOVERY_ Oldest online log sequence 4 Current log sequence 6

SQL> alter system set LOG_ARCHIVE_DEST_1= 'LOCATION=/u01/app/archive';

System altered.

SQL> shutdown immediate; Database closed.

Database dismounted.

ORACLE instance shut down. SQL> startup mount; ORACLE instance started.

Total System Global Area 1570009088 bytes Fixed Size 2213696 bytes Variable Size 922749120 bytes Database Buffers 637534208 bytes Redo Buffers 7512064 bytes

Database mounted.

SQL> alter database archivelog;

Database altered.

SQL> alter database open; Database altered. SQL>

七. 创建备份库需要的控制文件

在主库创建备库控制文件 注:以下操作在主库上进行 SQL>Shutdown immediate; SQL>STARTUP MOUNT;

SQL>ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/orcl.ctl'; SQL>ALTER DATABASE OPEN;

创建主库spfile

SQL>Shutdown immediate

SQL>startup pfile= '/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora' sql> create sp pfile=

'/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora';

关闭数据库

sql> shutdown immediate;

八. 备份生产数据库并把数据复制到对端

说明:这里采用关闭主库数据库,进行冷备份的方法进行备份,数据库的控制文件和数据文件全部位于/u01/app/oracle/oradata/orcl/目录

scp -rp /u01/app/oracle/oradata/orcl/* lin-2:/u01/app/oracle/oradata/orcl/

九.修改备库pfile

[oracle@lin-2 dbs]$ cat initorcl.ora orcl.__db_cache_size=637534208 orcl.__java_pool_size=16777216

orcl.__large_pool_size=16777216

orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment orcl.__pga_aggregate_target=637534208 orcl.__sga_target=939524096 orcl.__shared_io_pool_size=0

orcl.__shared_pool_size=251658240 orcl.__streams_pool_size=0

*.audit_'/u01/app/oracle/admin/orcl/adump' *.audit_trail='db'

*.compatible='11.2.0.0.0'

*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='orcl'

*.db_recovery_'/u01/app/oracle/flash_recovery_area' *.db_recovery_

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.memory_target=1562378240 *.open_cursors=300 *.processes=150

*.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' *.DB_UNIQUE_NAME=orcl2

*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcl2)' *.LOG_ARCHIVE_DEST_1= 'LOCATION=/u01/app/archive VALID_FOR=(ALL_LOG) DB_UNIQUE_NAME=orcl2'

*.LOG_ARCHIVE_DEST_2= 'SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOG) DB_UNIQUE_NAME=orcl'

*.LOG_ARCHIVE_DEST_STATE_1=ENABLE *.LOG_ARCHIVE_DEST_STATE_2=ENABLE *.LOG_ARCHIVE_FORMAT=%t_%s_%r.arc *.FAL_SERVER=orcl *.FAL_CLIENT=orcl2 *.STANDBY_

十、将控制文件传输到对端

下面命令在主库上执行:

scp -rp /tmp/orcl.ctl lin-2:/u01/app/oracle/oradata/orcl/

传输到对端后,并更改控制文件的名称

在备库上修改名称为control01.ct

[oracle@lin-2 orcl]$ mv orcl.ctl control01.ctl [oracle@lin-2 orcl]$ ls

control01.ctl redo02.log sysaux01.dbf temp01.dbf users01.dbf redo01.log redo03.log system01.dbf undotbs01.dbf

十一、在备库上创建口令文件

orapwd file=$ORACLE_HOME/dbs/orapworcl password=oracle entries=5

十二、在备库上创建spfile

在备库上,根据第九章创建的pfile 生成spfile

SQL>Shutdown immediate

SQL>startup pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora' SQL>CREATE SPFILE FROM PFILE;

十三、启动物理备用数据库

SQL>STARTUP MOUNT;

十四、配置Standby Redo Log

在两边都配置standby redo log

在主库查看日志组的数量和每个日志文件的大小 SQL> SELECT GROUP#, BYTES FROM V$LOG;

在备库库查看日志组的数量和每个日志文件的大小 SQL> SELECT GROUP#, BYTES FROM V$STANDBY_LOG;

在主备库上创建日志组和redo log文件 SQL>ALTER DATABASE ADD STANDBY LOG 4('/u01/app/oracle/oradata/orcl/stdby_redo04.log') SIZE 50M; SQL>ALTER DATABASE ADD STANDBY LOG 5('/u01/app/oracle/oradata/orcl/stdby_redo05.log') SIZE 50M; SQL>ALTER DATABASE ADD STANDBY LOG 6('/u01/app/oracle/oradata/orcl/stdby_redo06.log') SIZE 50M;

十五、配置闪回数据库

说明:这一步为可选操作,但强烈建议开启数据库闪回功能。闪回允许你将数据库还原到以前的某一时间点。当发生故障转移时,这个功能非常有用,它能让你将老的主库闪回到故障前,然后将其转换为备库。如果没有启用闪回功能,你就必须重建备库,意味着要再复制一次数据文件。除了这个好处,闪回还能在某些情况下让你避免从备份恢复数据。

(1)快速恢复区(Flash/Fast Recovery Area),默认是配置的,但是需要确认这个区域的磁盘够大,至少50G以上(默认3G) sql>show parameter db_recovery_ 可以修改位置:

sql>alter system set db_recovery_'新路径'; 更改大小:

sql>alter system set db_recovery_G; (2)查看是否启用,默认是不开启的

sql>select flashback_on from v$database; 开启闪回:

sql>alter database flashback on;

如果你碰到 ORA-01153 报错,那一定是在备库进行此操作。你需要先取消重做日志应用,启用闪回日志,然后重新启用日志应用。

在主库启用闪回日志,不会同步备库也启用。你必须手动在主库和备库上均启用闪回日志。 如果不启用闪回日志,当出现故障转移时,你将需要完全重新开始创建一个备库。

十六、 Start Redo Apply

在备库上执行:

sql>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOG FROM SESSION;

查看哪些归档日志被APPLY了 在备库上执行:

sql>SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

在主库强制日志切换到当前的online redo log file. sql>ALTER SYSTEM ARCHIVE LOG CURRENT; 在备库查看新的被归档的redo data