Oracle 11g R2 Dataguard配置手册
1.判断DataGuard是否安装
select * from v$option where parameter = 'Oracle Data Guard';
2.网络配置
192.168.1.10(orcl)------------------------------------192.168.1.20(dg)
3.监听配置
主库
[oracle@node1 ~]$cd/u01/app/product/11.2.0/db_1/network/admin [oracle@node1 admin]$cat listener.ora
LISTENER =
(DESCRIPTION_LIST = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = node1)(PORT = 1521)) ) )
[oracle@node1 admin]$cat tnsnames.ora ORCL=
(DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = node1)(PORT = 1521)) )
(CONNECT_DATA =
(SERVICE_NAME = orcl) ) ) DG =
(DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = node2)(PORT = 1521)) )
(CONNECT_DATA =
(SERVICE_NAME = dg)
Oracle 11g R2 Dataguard配置手册
) ) 备库
[oracle@node1 admin]$cat listener.ora
LISTENER =
(DESCRIPTION_LIST = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = node2)(PORT = 1521)) ) )
[oracle@node1 admin]$cat tnsnames.ora ORCL=
(DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = node1)(PORT = 1521)) )
(CONNECT_DATA =
(SERVICE_NAME = orcl) ) ) DG =
(DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = node2)(PORT = 1521)) )
(CONNECT_DATA =
(SERVICE_NAME = dg) ) )
4.主库前期准备
设置强制写日志
SQL> select FORCE_LOGGING fromv$database; NO
SQL>alter databaseforce logging;
SQL>select FORCE_LOGGING from v$database; YES
Oracle 11g R2 Dataguard配置手册
5.创建口令文件
orapwdfile=$ORACLE_HOME/dbs/orapwdb1 password=oracle entries=5
6.修改主库初始化参数
创建主库pfile
sql> create pfile from spfile; 修改pfile
DB_UNIQUE_NAME=orcl
LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,dg)' LOG_ARCHIVE_DEST_1= 'LOCATION=/u01/app/archive
VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl' LOG_ARCHIVE_DEST_2= 'SERVICE=dg LGWR
ASYNCVALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)DB_UNIQUE_NAME=dg' LOG_ARCHIVE_DEST_STATE_1=ENABLE LOG_ARCHIVE_DEST_STATE_2=ENABLE LOG_ARCHIVE_FORMAT=%t_%s_%r.arc FAL_SERVER=dg FAL_CLIENT=orcl
STANDBY_FILE_MANAGEMENT=AUTO
Pfile 拷贝到备库上
scp–rp/u01/app/product/11.2.0/db_1/dbs/initorcl.oranode2:/u01/app/product/11.2.0/db_1/dbs/
7.修改数据库运行在归档模式下
SHUTDOWN IMMEDIATE; STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG; ALTER DATABASE OPEN;
8.创建备份库需要的控制文件
创建控制文件
Shutdown immediate STARTUP MOUNT;
ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/orcl.ctl'; ALTER DATABASE OPEN; 创建主库pfile
Shutdown immediate
Oracle 11g R2 Dataguard配置手册
startuppfile='//u01/app/oracle/product/11.2.0/dbhome_1/dbs/20011.ora' sql> create spfile pfile='//u01/app/oracle/product/11.2.0/dbhome_1/dbs/20011.ora' ;
(先把原来的干掉) shutdown immediate; startup
from
9.备份生产数据库
scp -rp /u01/oradata/ORCLnode2:/u01/oradata/
scp–rp /u01/app/admin/orcl node2:/u01/app/admin(记得在备库创建admin)
10.修改备库pfile
DB_UNIQUE_NAME=orcl
LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,dg)' LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc LOG_ARCHIVE_DEST_1=
'LOCATION=/u01/app/archive
VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg' LOG_ARCHIVE_DEST_2=
'SERVICE=orclASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
LOG_ARCHIVE_DEST_STATE_1=ENABLE LOG_ARCHIVE_DEST_STATE_2=ENABLE FAL_SERVER=orcl FAL_CLIENT=dg
STANDBY_FILE_MANAGEMENT=AUTO
11.将控制文件
scp-rp/tmp/dg.ctl node2:/u01/oradata/ORCL/controlfile/
scp-rp/tmp/dg.ctl node2:/u01/flash_recovery_area/orcl/controlfile/
12.在备库上创建口令文件
orapwdfile=$ORACLE_HOME/dbs/orapwdb1 password=oracle entries=5
Oracle 11g R2 Dataguard配置手册
13.在备库上创建spfile
Shutdown immediate
startuppfile='//u01/app/oracle/product/11.2.0/dbhome_1/dbs/20011.ora'
CREATE SPFILE FROM PFILE;
14.启动物理备用数据库
STARTUP MOUNT;
15.配置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 LOGFILEgroup 4('/oracle/dbs/slog1.rdo') SIZE 50M; SQL> ALTER DATABASE ADD STANDBY LOGFILE group 5 ('/oracle/dbs/slog2.rdo') SIZE 50M; SQL>ALTER DATABASE ADD STANDBY LOGFILE group6 ('/oracle/dbs/slog3.rdo') SIZE 50M; SQL> ALTER DATABASE ADD STANDBY LOGFILE group7('/oracle/dbs/slog4.rdo') SIZE 50M;
16. Start Redo Apply---备机启动实时同步
重启备机机器后,oracle 在备机执行实时同步:
startup
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
在备机执行取消实时同步:
alter database recover managed standby database cancel;
查看哪些归档日志被APPLY了,在主、备库都可以查,判断主、备库是否数据同步的一致性: SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;