第一章 概述
1.1 主库(primary)上有一个运行的实例dell,备库(standby)上
只是安装了Oracle数据库软件。设置主库的db_name为dell,
db_unique_name为dell;备库的db_name为dell,
db_unique_name为std。
第二章 主库配置
2.1 登录主库
2.2 启用归档
SQL>SELECT LOG_MODE FROM V$DATABASE;
修改数据库为归档模式:
SQL>SHUTDOWN IMMEDIATE;SQL>STARTUP MOUNT;
SQL>ALTER DATABASE ARCHIVELOG;
SQL>ALTER DATABASE OPEN;
SQL>ARCHIVE LOG LIST;
SQL>SELECT LOG_MODE FROM V$DATABASE;
2.3 启用force logging
SQL>SELECT FORCE_LOGGING FROM V$DATABASE;
SQL>ALTER DATABASE FORCE LOGGING;
SQL>SELECT FORCE_LOGGING FROM V$DATABASE;
2.4 验证主库db_name,db_unique_name,并将备库的
db_unique_name设置上去
SQL>SHOW PARAMETER DB_NAME
SQL>SHOW PARAMETER DB_UNIQUE_NAME
SQL>ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(dell,std)';
2.5 设置主库的监听和TNS
关闭数据库和监听,编辑监听文件和TNS文件
SQL>SHUTDOWN IMMEDIATE
#lsnrctl stop
#vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
主库的监听配置:
# Generated by Oracleconfiguration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dell)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = dell)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =primary)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY =EXTPROC1521))
)
)
ADR_BASE_LISTENER =/u01/app/oracle
#vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
主库的 TNS配置:
# Generated by Oracleconfiguration tools.
DELL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =primary)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dell)
)
)
STD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =standby)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = std)
)
)
2.6 启动监听和数据库
#lsnrctl start
#sqlplus / as sysdba
SQL>startup
2.7 设置archive destinations
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=std VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=std';
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_1=ENABLE;
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;
2.8 设置远程登录密码
SQL>ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;
SQL>SHOW PARAMETER REMOTE_LOGIN
2.9 设置fal服务器和文件名转换参数
SQL>ALTER SYSTEM SET FAL_SERVER=std;
SQL>ALTER SYSTEM SET DB_FILE_NAME_CONVERT='std','dell' SCOPE=SPFILE;
SQL>ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='std','dell' SCOPE=SPFILE;
SQL>ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
2.10 利用RMAN方式备份主库
SQL>exit
#rman target=/
RMAN>backup database plus archivelog;
2.11 创建备库的controlfile和pfile
SQL>ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/stdcontrol.ctl';
SQL>CREATE PFILE='/tmp/initstd.ora' FROM SPFILE;
2.12 编辑备库pfile文件(另开一个控制台)
#vi /tmp/initstd.ora,修改内容如下:
2.13 创建目录
另开一个控制台,可从主库上操纵备库,也可直接在备库上创建
#ssh oracle@standby
#mkdir -p /u01/app/oracle/admin/std/adump
#mkdir -p /u01/app/oracle/oradata/std/
#mkdir -p /u01/app/oracle/flash_recovery_area/std/
2.14 复制controlfile到备库
#scp /tmp/stdcontrol.ctl oracle@standby:/u01/app/oracle/oradata/std/control01.ctl
然后将control01.ctl复制成control02.ctl,复制时一定要分清主库还
是备库
#cd /u01/app/oracle/oradata/std/
#cp control01.ctl /u01/app/oracle/flash_recovery_area/std/control02.ctl
#cd /u01/app/oracle/flash_recovery_area/
#ls -l std/
2.15 复制其他文件到备库
#scp -r /u01/app/oracle/flash_recovery_area/DELL oracle@standby:/u01/app/oracle/flash_recovery_area/
#scp /tmp/initstd.ora oracle@standby:/tmp/initstd.ora
#scp /u01/app/oracle/product/11.2.0/db_1/dbs/orapwdell oracle@standby:/u01/app/oracle/product/11.2.0/db_1/dbs/
2.16 修改orapwdell为orapwstd(注意控制台所属)
#cd /u01/app/oracle/product/11.2.0/db_1/dbs/
#mv orapwdell orapwstd
第三章 备库配置
3.1 配置备库监听和TNS
#cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
#vi listener.ora
备库的监听配置:
# Generated by Oracleconfiguration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = std)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = dell)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =standby)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
#vi tnsnames.ora
备库的TNS配置
# Generated by Oracleconfiguration tools.
DELL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =primary)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dell)
)
)
STD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =standby)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = std)
)
)
3.2 启动备库监听
#lsnrctl start
3.3 编辑oratab文件
#vi /etc/oratab
在最后添加一行:
std:/u01/app/oracle/product/11.2.0/db_1/:N
3.4 启动备库并创建spfile文件
#. oraenv
#std
#sqlplus / as sysdba
SQL>create spfile from pfile='/tmp/initstd.ora';
3.5 利用RMAN方式恢复备库
SQL>exit
#rman target=/
RMAN>startup mount
RMAN>restore database;
RMAN>exit
3.6 在备库上创建redolog
#sqlplus / as sysdba
SQL>ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/std/standby_redo01.log') SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/std/standby_redo02.log') SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/std/standby_redo03.log') SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/std/standby_redo04.log') SIZE 50M;
SQL> SELECT MEMBER FROM V$LOGFILE WHERE TYPE='STANDBY';
SQL> SELECT MEMBER FROM V$LOGFILE;
3.7 在主库上创建redolog(这步可放在第二章)
SQL>ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/dell/standby_redo01.log') SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/dell/standby_redo02.log') SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/dell/standby_redo03.log') SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/dell/standby_redo04.log') SIZE 50M;
SQL> SELECT MEMBER FROM V$LOGFILE WHERE TYPE='STANDBY';
SQL> SELECT MEMBER FROM V$LOGFILE;
3.8 在备库上启动redo应用
再打开一个备库控制台执行以下命令,进行日志追踪
#tail -f /u01/app/oracle/diag/rdbms/std/std/trace/alert_std.log
再执行命令(备库数据库):
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
日志会显示序列号
3.9 更改主库redo日志显示格式,并查询序列号
SQL>ALTER SESSION SET nls_date_format='DD-MON-YYYY HH24:MI:SS';
SQL>SELECT sequence#,first_time,next_time FROM v$archived_log ORDER BY sequence#;
3.10 依次生成主库redo日志,并查询序列号
SQL>ALTER SYSTEM SWITCH LOGFILE;
SQL>SELECT sequence#,first_time,next_time FROM v$archived_log ORDER BY sequence#;
3.11 更改备库redo日志显示格式,并查询序列号
SQL>ALTER SESSION SET nls_date_format='DD-MON-YYYY HH24:MI:SS';
SQL>SELECT sequence#,first_time,next_time,applied FROM v$archived_log ORDER BY sequence#;
显示YES,就表示主库的日志已经同步到了备库,动态日志也有显示。可多次执行3.10和3.11进行验证,到此DataGuard就配置完成了。