Data Guard 环境:(oracle 10g)
操作系统: redhat 5.4
Primary数据库:
IP地址:192.168.2.200
数据库SID:orcl
DB_UNIQUE_NAME:orcl_pd
Standby数据库:
IP地址:192.168.2.2
数据库SID:orcl。
DB_UNIQUE_NAME:orcl_st
一. Primary 端的配置
1. 主库设置为force logging 模式
SQL> alter database force logging;
SQL> select FORCE_LOGGING from v$database ;
FOR
---
YES
2. 主库设为归档模式
归档路径:/u01/arch1
mkdir /u01/arch1
[oracle@jackdba ~]$ cd /u01/
[oracle@jackdba u01]$ ll
drwxr-xr-x 2 oracle oinstall 4096 Dec 16 16:45 arch1
sqlplus / as sysdba
SQL> archive log list;
如果不在归档模式,则需要设定归档模式
alter system set log_archive_dest_1='location=/u01/arch1';
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> archive log list;
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/arch1
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
3. 添加standby redo log
SQL> select group# from v$log ;
GROUP#
----------
1
2
3
SQL> select group#,bytes/1024/1024 ||'M' from v$log ;
GROUP# BYTES/1024/1024||'M'
---------- -----------------------------------------
1 50M
2 50M
3 50M
添加4个standby log file 每个大小50M
添加一个新的Standby Redologs组(注意组号不要与当前存在的Online Redologs组重复),并为该组指定一个成员:
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/u01/app/oracle/oradata/orcl/redo04.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/u01/app/oracle/oradata/orcl/redo05.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/u01/app/oracle/oradata/orcl/redo06.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/u01/app/oracle/oradata/orcl/redo07.log') size 50M;
查看
SQL> SELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS FROM
V$STANDBY_LOG;
GROUP# THREAD# SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------
4 0 0 YES UNASSIGNED
5 0 0 YES UNASSIGNED
6 0 0 YES UNASSIGNED
7 0 0 YES UNASSIGNED
问题:什么是否有一定要建立stadnby redo log
工作模式:最大保护模式 最高可用性性模式
如果实施应用 lgwr sync 传送日志 则备库必须建立standby redo log
为了将来切换成功---》主库和备库上都要做
4. 修改listener.ora 和tnsnames.ora 文件 用图形做(减少故障率)
数据库服务orcl 静态注册
[oracle@jackdba u01]$ export DISPLAY=192.168.2.111:0.0
[oracle@jackdba u01]$ xhost +
access control disabled, clients can connect from any host
[oracle@yutianedu u01]$ netmgr
查看:Listener.ora 文件:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/10.2/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = yutianedu)(PORT = 1521))
)
)
生效:
lsnrctl reload
查看静态注册额结果
lsnrctl status
Service "orcl" has 2 instance(s).
Instance "orcl", status UNKNOWN 静态注册, has 1 handler(s) for this service...
Instance "orcl", status READY动态注册, has 1 handler(s) for this service...
注意:SID_LIST_LISTENER 配置的是静态注册,如果没有该参数,而且Data Guard 启动顺序又不正确,那么在主库可能会报 PING[ARC1]: Heartbeat failed to connect to standby 'orcl_st'. Error is 12514. 错误,导致归档无法完成。
数据库唯一名 ---》服务别名 orcl_pd,orcl_st ---》图形做
tnsnames.ora 文件
ORCL_ST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
ORCL_PD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.200)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl )
)
)
最好测试
Tnsping orcl_pd
Tnsping orcl_st
5. 创建备库的密码文件
创建备库的口令文件
orapwd file= orapworcl password=oracle
如果已经存在,就不用创建了。
Linux默认位置为$ORACLE_HOME/dbs目录下下,Windows 默认为$ORACLE_HOME/database目录
用SCP命令将这个口令文件传输到备库的对应位置:
scp orapworcl 192.168.2.2:/u01/app/oracle/product/10.2/db_1/dbs/dbs
注意,如果不用RMAN 复制的话,还需要创建备库的控制文件。
RMAN复制的话,自己会创建控制文件。
6. 初始化参数文件的修改
alter system set DB_UNIQUE_NAME='orcl_pd' scope=spfile ;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_st)' ;
alter system set LOG_ARCHIVE_DEST_1='LOCATION=/u01/arch1 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_pd';
alter system set LOG_ARCHIVE_DEST_2='service=orcl_st DB_UNIQUE_NAME=orcl_st';
alter system set FAL_SERVER=orcl_st;
alter system set FAL_CLIENT=orcl_pd;
alter system set standby_file_management='AUTO' ;
alter system set standby_archive_dest='/u01/arch1';
#如果主备库目录不同,还需要添加:
#*.log_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
#*.db_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
二. Standby 端配置
1. 创建备库存放数据文件和后台跟踪目录。
这个目录可以和主库相同, 如果不同,就需要在主库的初始化文件中进行转换。 如:
*.log_file_name_convert
*.db_file_name_convert
这里建立的和主库一样的目录
$ORACLE_BASE/oradata/orcl
$ORACLE_BASE/admin/orcl
$ORACLE_BASE/admin/orcl/adump
$ORACLE_BASE/admin/orcl/bdump
$ORACLE_BASE/admin/orcl/cdump
$ORACLE_BASE/admin/orcl/dpdump
$ORACLE_BASE/admin/orcl/pfile
$ORACLE_BASE/admin/orcl/udump
建立归档目录
mkdir /u01/arch1
2. 修改初始化参数文件
从主库copy过来,修改如下:
在主库上拷贝
sqlplus / as sysdba
create pfile from spfie ;
然后把pfile拷贝过去
scp initorcl.ora 192.168.2.2:$ORACLE_HOME/dbs
然后在备库上修改
####主库参数######
*.DB_NAME ='orcl';
#--监听中配置的
*.DB_UNIQUE_NAME='orcl_st'
#--列出DG中所有DB_UNIQUE_NAME
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_st)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/arch1 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_st'
*.LOG_ARCHIVE_DEST_2='service=orcl_pd DB_UNIQUE_NAME=orcl_pd'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
#####备库参数#######
*.FAL_SERVER=orcl_pd
*.FAL_CLIENT=orcl_st
*.standby_file_management='AUTO'
*.standby_archive_dest='/u01/arch1'
log_file_name_convert =('orcl','orcl') -- 该参数用于RMAN复制时重建redo 文件。
#如果主备库目录不同,还需要添加:
#*.log_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
#*.db_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
4. 修改listener.ora 和 tnsnames.ora 文件,同主库。如果不存在,就从主库上copy 过去。
scp listener.ora 192.168.2.2:$ORACLE_HOME/network/admin
修改一个listener.ora 把计算机名修改为备库的192.168.2.2
lsnrctl start
scp tnsnames.ora 192.168.2.2:$ORACLE_HOME/network/admin
tnsping orcl_pd
tnsping orcl_st
5. RMAN 复制数据库
5.1 备份主库
建立备份目录
mkdir /u01/backup
rman target sys/oracle@orcl
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Jul 18 18:26:16 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1248423599)
RMAN>RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
sql 'alter system archive log current';
backup current controlfile for standby format='/u01/backup/control_%U';
BACKUP FORMAT '/u01/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE ;
sql 'alter system archive log current';
BACKUP FORMAT '/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL;
release channel c2;
release channel c1;
}
也可以用下面的命令:
backup full database include current controlfile for standby plus archivelog FORMAT '/u01/backup/orcl_%U_%T' skip inaccessible filesperset 5 ;
5.2 将源库的备份拷贝到辅助数据库的相同位置,要在辅助数据上建立一个文件/u01/backup
这里有两种方法,一种直接在辅助库上建相同的目录结构,在用SCP 命令把这些备份文件copy过去,但是这样会占用大量的网络资源, 如果用SCP复制,复制结束要后注意文件用户和权限。
还有一种就是建好目录结构后用NFS直接Mount上去。
这里演示的就是使用NFS挂载
在备库服务器上
因为我们在源库上备份是备份到/u01/backup目录中的,所以我们在辅助库上也建这个目录
mkdir -p /u01/backup
chmod 777 /u01/backup
将源库的备份挂载到辅助库上
在主库上将/u01/backup 目录添加到共享
su - root要用root执行
vim /etc/exports
/u01/backup 192.168.2.2(rw,async,anonuid=65534,anongid=65534)
启动NFS服务
service nfs start
chkconfig nfs on
在备库上挂载源库的目录,注意,mount命令必须以root用户执行
mount -t nfs -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 192.168.2.200:/u01/backup /u01/backup
写入/etc/fstab
vim /etc/fstab
192.168.2.200:/u01/backup /u01/backup nfs rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 0 0
-- 注意: 在挂载NFS的时候,一定要加上-t -o 参数,不然在RMAN 复制的时候会报错:
--ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
最后测试一下
# cd /u01/backup/
看是否一致
ls
arch_06muca74_1_1_20111216 arch_08muca79_1_1_20111216 orcl_02muca53_1_1_20111216 orcl_04muca6g_1_1_20111216
arch_07muca74_1_1_20111216 control_01muca51_1_1 orcl_03muca53_1_1_20111216 orcl_05muca6u_1_1_20111216
和主库一样的
5.3 用pfile文件将备库启动到nomout状态
sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jul 21 09:35:07 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 247463936 bytes
Fixed Size 1218772 bytes
Variable Size 79693612 bytes
Database Buffers 163577856 bytes
Redo Buffers 2973696 bytes
退出会话!!! 一定要退出会话哦! (一定保证备库没有人连接)
5.4 执行duplicate 复制standby库
rman target / auxiliary sys/oracle@orcl_st
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Jul 20 22:32:59 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1248423599)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby nofilenamecheck dorecover;
Starting Duplicate Db at 21-JUL-10
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=155 devtype=DISK
contents of Memory Script:
{
set until scn 800873;
restore clone standby controlfile;
sql clone 'alter database mount standby database';
}
executing Memory Script
executing command: SET until clause
Starting restore at 21-JUL-10
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/control_6mljbc6r_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/control_6mljbc6r_1_1 tag=TAG20100721T115609
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/app/oracle/oradata/orcl/control01.ctl
output filename=/u01/app/oracle/oradata/orcl/control02.ctl
output filename=/u01/app/oracle/oradata/orcl/control03.ctl
Finished restore at 21-JUL-10
sql statement: alter database mount standby database
released channel: ORA_AUX_DISK_1
contents of Memory Script:
{
set until scn 800873;
set newname for tempfile 1 to "/u01/app/oracle/oradata/orcl/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to "/u01/app/oracle/oradata/orcl/system01.dbf";
set newname for datafile 2 to "/u01/app/oracle/oradata/orcl/undotbs01.dbf";
set newname for datafile 3 to "/u01/app/oracle/oradata/orcl/sysaux01.dbf";
set newname for datafile 4 to "/u01/app/oracle/oradata/orcl/users01.dbf";
set newname for datafile 5 to "/u01/app/oracle/oradata/orcl/example01.dbf";
restore
check readonly
clone database
;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
renamed temporary file 1 to /u01/app/oracle/oradata/orcl/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 21-JUL-10
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=155 devtype=DISK
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/orcl_6oljbc7f_1_1_20100721
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/orcl_6oljbc7f_1_1_20100721 tag=TAG20100721T115629
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:39
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/orcl_6nljbc7e_1_1_20100721
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/orcl_6nljbc7e_1_1_20100721 tag=TAG20100721T115629
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:06
Finished restore at 21-JUL-10
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy recid=10 stamp=724981117 filename=/u01/app/oracle/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=11 stamp=724981117 filename=/u01/app/oracle/oradata/orcl/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=12 stamp=724981117 filename=/u01/app/oracle/oradata/orcl/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=13 stamp=724981118 filename=/u01/app/oracle/oradata/orcl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=14 stamp=724981118 filename=/u01/app/oracle/oradata/orcl/example01.dbf
contents of Memory Script:
{
set until scn 800873;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 21-JUL-10
using channel ORA_AUX_DISK_1
starting media recovery
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=74
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/arch_6sljbcd4_1_1_20100721
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/arch_6sljbcd4_1_1_20100721 tag=TAG20100721T115930
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
archive log filename=/u01/archivelog/1_74_720642866.dbf thread=1 sequence=74
channel clone_default: deleting archive log(s)
archive log filename=/u01/archivelog/1_74_720642866.dbf recid=1 stamp=724981127
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=75
channel ORA_AUX_DISK_1: reading from backup piece /u02/backup/arch_6vljbcd7_1_1_20100721
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u02/backup/arch_6vljbcd7_1_1_20100721 tag=TAG20100721T115930
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
archive log filename=/u01/archivelog/1_75_720642866.dbf thread=1 sequence=75
channel clone_default: deleting archive log(s)
archive log filename=/u01/archivelog/1_75_720642866.dbf recid=2 stamp=724981133
media recovery complete, elapsed time: 00:00:03
Finished recover at 21-JUL-10
Finished Duplicate Db at 21-JUL-10
RMAN>
6. 在备库添加redo log file
如果主库没有添加redo log file,可以先用copy 过来的初始化文件将数据库启动到mount 状态。在创建个spfile,最后添加redo log。
至此,Data Guard 的操作已经完成,下面来开始验证。
注意Data Guard 启动顺序:
启动顺序:先standby ,后primary;
闭顺序:先primary 后standby;
在备库将实例启动到mount 状态:
SQL> startup nomount;
SQL>alter database mount standby database ;
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; 取消日志应用
SQL>alter database recover managed standby database disconnect from session;
在备库启动监听:
$lsnrctl start
在主库启动实例:
SQL> startup;
在主库启动监听:
$lsnrctl start
在主库验证归档目录是否有效:
SQL> SELECT STATUS,DESTINATION, ERROR FROM V$ARCHIVE_DEST;
如果有错误,要排查原因。
SQL> alter system switch logfile;
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
7
在备库上看一下
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
7
主备查询结果一致,Data Guard 搭建结束。
oracle(11g)
Oracle: 11.2.0.1
OS: redhat 5.5
Primary IP: 192.168.2.42
DB_NAME=orcl
Standby IP: 192.168.2.43
DB_NAME=orcl
一. Primary 端操作:
1. 设置归档模式
这个生产库都是这种模式。
SQL> archive log list;
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> archive log list;
2. Primary 设置force logging
SQL> alter database force logging;
SQL> select force_logging from v$database;
FORCE_LOG
---------
YES
3. 配置Oracle Net
在Primary 库和Standby 都要修改。也可以使用netca 和netmgr命令配置。
注意:修改完后记得重启listener。
Listener.ora
[oracle@qs-dmm-rh1 admin]$ cat listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =jackdba2)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = jackdba)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = jackdba)
)
)
-- 配置静态注册
tnsname.ora
[oracle@qs-dmm-rh1 admin]$ cat tnsnames.ora
ORCL_ST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.43)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
ORCL_PD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.42)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
4vi . 添加data guard 参数
创建pfile, 添加如下文件:
SQL> create pfile from spfile;
*.db_name='orcl'
*.db_unique_name='orcl_pd'
*.log_archive_config='dg_config=(orcl_pd,orcl_st)'
*.log_archive_dest_1='location=/u01/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=orcl_pd'
*.log_archive_dest_2='service=orcl_st reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcl_st'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
*.fal_server='orcl_st'
*.fal_client='orcl_pd'
在Oracle 11g的Data Guard中,standby_archive_dest参数已经被取消了。
Standby归档文件的存放位置按如下规则来进行:
(1)当LOG_ARCHIVE_DEST_n设置了valid_for=(all_logfiles,all_roles),那么在不定义standby_archive_dest参数时,Oracle就会选择LOG_ARCHIVE_DEST_n参数作为归档目标。
(2)如果在第一步设置的同时,又独立设置LOG_ARCHIVE_DEST_n参数为 valid_for=(standby_logfile,*) 属性,那么当compatible参数大于10.0的时候,会自动的选择任意一个LOG_ARCHIVE_DEST_n的值。
(3)如果LOG_ARCHIVE_DEST_n 没有设置的话,默认位置是:
$ORACLE_HOME/dbs.
不过valid_for参数的默认值就是all_logfiles和all_roles. 所以只要设置了本地的归档位置,远程的归档文件也会放到这个目录下面。
5. 用新pfile重启主库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora';
File created.
SQL> startup
ORACLE instance started.
Total System Global Area 422670336 bytes
Fixed Size 1336960 bytes
Variable Size 310380928 bytes
Database Buffers 104857600 bytes
Redo Buffers 6094848 bytes
Database mounted.
Database opened.
SQL>
二. Standby 端设置:
1. 创建相关目录结构
[oracle@qs-dmm-rh2 trace]$ mkdir -p /u01/app/oracle/oradata/dave
--这里我们创建的目录和Target 库不同,我们在参数文件里需要转换一下。
2. 创建standby的口令文件
[oracle@qs-dmm-rh2 trace]$ orapwd file=?/dbs/orapwdave password=oracle
3. 创建standby的初始化参数:
*db_name=orcl
*.control_files='/u01/app/oracle/oradata/dave/control01.ctl', '/u01/app/oracle/oradata/dave/control02.ctl',
'/u01/app/oracle/oradata/dave/control03.ctl'
*.db_unique_name='orcl_st'
*.log_archive_config='dg_config=(orcl_st,orcl_pd)'
*.log_archive_dest_1='location=/u01/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=orcl_st'
*.log_archive_dest_2='service=orcl_pd reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcl_pd'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
*.fal_server='orcl_pd'
*.fal_client='orcl_st'
*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/dave'
*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/dave'
4. 用pfile 将standby 启动到nomount状态:
SQL> startup nomount pfile=?/dbs/initorcl.ora
ORACLE instance started.
Total System Global Area 146472960 bytes
Fixed Size 1335080 bytes
Variable Size 92274904 bytes
Database Buffers 50331648 bytes
Redo Buffers 2531328 bytes
5. 开始duplicate
[oracle@qs-dmm-rh2 dbs]$ rman target sys/oracle@orcl_pd auxiliary sys/oracle@orcl_stnofilenamecheck
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 8 16:10:25 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1272955137)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby from active database;
Starting Duplicate Db at 08-MAR-11
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl' auxiliary format
'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl' ;
--用duplicate 创建standby 时会复制口令文件
}
executing Memory Script
Starting backup at 08-MAR-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=45 device type=DISK
Finished backup at 08-MAR-11
contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/dave/control01.ctl';
restore clone controlfile to '/u01/app/oracle/oradata/dave/control02.ctl' from
'/u01/app/oracle/oradata/dave/control01.ctl';
restore clone controlfile to '/u01/app/oracle/oradata/dave/control03.ctl' from
'/u01/app/oracle/oradata/dave/control01.ctl';
--创建控制文件
}
executing Memory Script
Starting backup at 08-MAR-11
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f tag=TAG20110308T161152 RECID=4 STAMP=745258313
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 08-MAR-11
Starting restore at 08-MAR-11
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 08-MAR-11
Starting restore at 08-MAR-11
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 08-MAR-11
contents of Memory Script:
{
sql clone 'alter database mount standby database';
--将备库启动到mount standby
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/dave/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/dave/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/dave/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/dave/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/dave/users01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oracle/oradata/dave/system01.dbf" datafile
2 auxiliary format
"/u01/app/oracle/oradata/dave/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oracle/oradata/dave/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oracle/oradata/dave/users01.dbf" ;
sql 'alter system archive log current';
--将datafile convert 到其他目录
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/dave/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting backup at 08-MAR-11
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
--开始copy datafile,如果数据文件比较大,这个会比较慢
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
output file name=/u01/app/oracle/oradata/dave/system01.dbf tag=TAG20110308T161204
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
output file name=/u01/app/oracle/oradata/dave/sysaux01.dbf tag=TAG20110308T161204
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
output file name=/u01/app/oracle/oradata/dave/undotbs01.dbf tag=TAG20110308T161204
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
output file name=/u01/app/oracle/oradata/dave/users01.dbf tag=TAG20110308T161204
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 08-MAR-11
sql statement: alter system archive log current
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=745258432 file name=/u01/app/oracle/oradata/dave/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=5 STAMP=745258432 file name=/u01/app/oracle/oradata/dave/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=745258432 file name=/u01/app/oracle/oradata/dave/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=745258432 file name=/u01/app/oracle/oradata/dave/users01.dbf
Finished Duplicate Db at 08-MAR-11
RMAN>
DG 复制到这一步已经操作完成了。但是还有一些细节需要处理。
两点注意事项:
(1)如果使用的是非catalog,在rman 连接时,加上nocatalog关键字,如:
DG2:/home/oracle> rman targetsys/oracle@DG_PD auxiliarysys/oracle@DG_ST nocatalog
Recovery Manager: Release 11.2.0.3.0 -Production on Fri Oct 28 18:46:46 2011
Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved.
connected to target database: DG(DBID=1679060044)
using target databasecontrol file instead of recovery catalog
connected to auxiliary database: DG (notmounted)
不然会报如下错误:
DBGSQL: TARGET> begin :fhdbi := dbms_rcvcat.getDbid; end;
DBGSQL: sqlcode = 6550
DBGSQL: B :fhdbi = 32767
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGESTACK FOLLOWS ===============
RMAN-00571:===========================================================
RMAN-03002: failure of Duplicate Db commandat 10/28/2011 17:53:04
RMAN-05501: aborting duplication of targetdatabase
RMAN-03015: error occurred in stored scriptMemory Script
ORA-06550: line 1, column 17:
PLS-00201: identifier'DBMS_RCVCAT.GETDBID' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
(2)在执行duplicate的时候,如果源库和目标库目录相同,那么在duplicate 时,需要加上nofilenamecheck,如下:
RMAN> duplicate target database forstandby from active database dorecover nofilenamecheck;
我在上面的示例中,目录结构不同,所以没有用该参数,如果目录相同,而又没有加该参数,那么就会报如下错误:
RMAN> duplicate target database forstandby from active database dorecover nofilenamecheck;
RMAN-05501: aborting duplication of targetdatabase
RMAN-05001: auxiliary file name/u01/app/oracle/oradata/dg/users01.dbf conflicts with a file used by the targetdatabase
RMAN-05001: auxiliary file name/u01/app/oracle/oradata/dg/undotbs01.dbf conflicts with a file used by thetarget database
RMAN-05001: auxiliary file name/u01/app/oracle/oradata/dg/sysaux01.dbf conflicts with a file used by thetarget database
RMAN-05001: auxiliary file name/u01/app/oracle/oradata/dg/system01.dbf conflicts with a file used by thetarget database
三. 后续工作
1. 主库已经使用了spfile,但是备库用的还是之前的pfile:
Primary:
SQL> show parameter pfile
NAME TYPE VALUE
------------------------------------ ------- ------------------------------
spfile string /u01/app/oracle/product/11.2.0
Standby:
SQL> show parameter pfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string
pfile里面都是我们设置的一些基本参数。但是备库有冗余的作用,所以这里还是建议用主库的pfile copy过来,然后修改相关参数后,在创建spfile。这样即使切换了,对DB的影响也不大。
2. 只要备库的监听不重启,重启备库后,主库还是能识别的。如果备库的监听重启了。那么主库也就需要重启。
3. 复制结束后的Standby 只启动到mount standby 的状态。并没有启动MRP的应用归档程序。所以这个时候查询主备库,归档是不同步的。需要手动的启动MRP进程。
SQL> alter database recover managed standby database disconnect from session;
4. 备库Standby redo log 问题:
在duplicate 结束后,备库没有添加standby redo log file。但是主库采用的是:lgwr async传送的日志。当备库的RFS 进程接收到日志后,发现备库没有standby redo log的时候,备库会自动用ARCH将其写入归档文件。
以下是备库的alert log:
Tue Mar 08 16:53:32 2011
Archived Log entry 9 added for thread 1 sequence 21 rlc 745174404 ID 0x4bdfd301 dest 2:
RFS[2]: Opened log for thread 1 sequence 22 dbid 1272955137 branch 745174404
Tue Mar 08 16:53:36 2011
Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_21_745174404.dbf
Media Recovery Waiting for thread 1 sequence 22 (in transit) --传输中
Tue Mar 08 16:58:58 2011
Archived Log entry 10 added for thread 1 sequence 22 rlc 745174404 ID 0x4bdfd301 dest 2:
RFS[2]: Opened log for thread 1 sequence 23 dbid 1272955137 branch 745174404
Tue Mar 08 16:59:00 2011
Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_22_745174404.dbf
Media Recovery Waiting for thread 1 sequence 23 (in transit)
-- 注意这里归档文件目录,使用的是$ORACLE_HOME/dbs, 自动转换为ARCH时,也是使用默认的归档目录。
5. 在备库添加standby redo log:
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo01.log' size 50m;
alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo01.log' size 50m
*
ERROR at line 1:
ORA-01156: recovery or flashback in progress may need access to files
--在备库添加standby redo log需要先停MRP
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo01.log' size 50m;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo02.log' size 50m;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo03.log' size 50m;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo04.log' size 50m;
Database altered.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
在看一下日志:
Tue Mar 08 17:47:39 2011
Archived Log entry 15 added for thread 1 sequence 27 ID 0x4bdfd301 dest 1:
RFS[2]: Selected log 4 for thread 1 sequence 28 dbid 1272955137 branch 745174404
Tue Mar 08 17:47:43 2011
Archived Log entry 16 added for thread 1 sequence 28 ID 0x4bdfd301 dest 1:
Media Recovery Log /u01/archivelog/1_27_745174404.dbf
RFS[2]: Selected log 4 for thread 1 sequence 29 dbid 1272955137 branch 745174404
Media Recovery Log /u01/archivelog/1_28_745174404.dbf
Media Recovery Waiting for thread 1 sequence 29 (in transit)
--我们添加standby redo log 之后,归档文件变成了我们指定的Log_archive_dest_n 指定的参数。
6. 在主库也添加一下standby redo log
SQL> alter database add standby logfile '/u01/app/oracle/oradata/orcl/stdbyredo01.log' size 50m;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/orcl/stdbyredo02.log' size 50m;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/orcl/stdbyredo03.log' size 50m;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/orcl/stdbyredo04.log' size 50m;
Database altered.
7. 启用real-time apply,从而实现real-time query:
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> ALTER DATABASE OPEN;
Database altered.
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;
Database altered.
8. 验证real-time apply 和real-time query:
Primary:
SQL> create table dave(id number,name varchar2(20));
Table created.
SQL> insert into dave values(1,'tianlesoftware');
1 row created.
SQL> commit;
Commit complete.
Standby:
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
本文转自东方之子736651CTO博客,原文链接:http://blog.51cto.com/ecloud/1381003 ,如需转载请自行联系原作者