前言:在11G版本中duplicate可以直接复制,但是10G版本需要手工Rman备份+cp
问题:如果监听不再1521端口?
要注意一点,PMON进程默认只注册1521端口,当监听不在1521端口时,就需要设置local_listener参数。
将监听的信息添加到tnsnames.ora 文件中。pmon在动态注册监听时要从tnsnames.ora中读取信息。
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = IP)(PORT = 1522))
)
然后以sys用戶运行:
SQL> alter system set local_listener=listener;
SQL> alter system register;
SQL> alter system set LOCAL_LISTENER='(ADDRESS = (PROTOCOL = TCP)(HOST = IP)(PORT = 1522))';
SQL> alter system register;
安装DG的主要步骤:
DG:环境 说明。
主库设置为force logging
主库设置为归档模式
在主备库分别创建 listener,并启动
在主备库添加Oracle Net Service
从主库创建pfile文件并修改pfile的内容。
在备库上面创建相关的目录
将主库的参数文件copy到备库
使用RMAN备份主库
将主库的备份文件全部copy到备库的相同位置
在备库使用rman恢复备库
启动备库
在主备库添加online redo log和standby redo log
验证DG
总结
6.6.1 DG 环境说明
一个主库,一个备库
主库IP:
[oracle@dg1 dbs]$ cat /etc/hosts
127.0.0.1 localhost
192.168.2.20 dg1
备库IP:
[oracle@dg2 dbs]$ cat /etc/hosts
127.0.0.1 localhost
192.168.2.30 dg2
6.6.2 主库设置为force logging 模式
SQL> alter database force logging;
6.6.3 主库修改为归档模式
SQL> archive log list;
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter system set log_archive_dest_1='location=/u01/archive/' scope=spfile;
SQL> archive log list;
6.6.4 在主备库分别创建Listener,并启动
使用net manger 工具来配置,命令:netmgr 或者netca 都可以配置。 添加一个lisnter就可以了。
[oracle@dg1 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dave)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = anqing)
)
)
注意:SID_LIST_LISTENER 配置的是静态注册,如果没有该参数,而且Data Guard 启动顺序又不正确,那么在主库可能会报 PING[ARC1]: Heartbeat failed to connect to standby 'orcl_st'. Error is 12514. 错误,导致归档无法完成。
6.6.5 在主备库添加Oracle Net Service
就是往主备库的tnsnames.ora 文件里添加如下内容。
[oracle@dg1 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
--注意我这里的提示,它是使用工具生成的。
DAVE_PD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.20)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dave)
)
)
DAVE_ST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.30)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dave)
)
)
如果手动编辑可以使用下面这种写法避免空格问题,数据库是识别的。
DAVE_ST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.30)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dave)
)
)
配置完成后,使用tnsping 命令效验:
[oracle@dg1 admin]$ tnsping dave_pd
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 29-MAR-2013 16:57:46
Copyright (c) 1997, 2011, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.20)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dave)))
OK (10 msec)
[oracle@dg1 admin]$ tnsping dave_st
6.6.6 在主库创建pfile 文件并修改pfile 内容
一般要多执行一次lsnrctl stop/lsnrctl start
SQL> create pfile from spfile;
在pfile添加如下内容:
#add for primary dg
*.db_unique_name='dave_pd'
*.log_archive_config='dg_config=(dave_pd,dave_st)'
*.log_archive_dest_1='location=/u01/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=dave_pd'
*.log_archive_dest_2='service=dave_st reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=dave_st'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
*.fal_server='dave_st'
alter system
(4) 如果主备库的路径不同,修改在主库的参数文件里添加如下2个参数:
*.log_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
*.db_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/'
*.db_file_name_convert='/u02/oradata/orcl/','/u03/oradata/orcl/','/u02/oradata/orcl/','/u03/oradata/orcl/'
--用修改过的pfile重新生成spfile:
SQL> create spfile from pfile;
6.6.7 在备库创建相关的目录
根据pfile 来创建
6.6.8 将主库的参数文件copy到备库并修改
[oracle@dg1 u01]$ cd $ORACLE_HOME/dbs
[oracle@dg1 dbs]$ ls
hc_dave.dat initdave.ora init.ora lkDAVE lkDAVE_PD orapwdave snapcf_dave.f spfiledave.ora
[oracle@dg1 dbs]$ scp initdave.ora 192.168.2.30:/u01/app/oracle/product/11.2.0/db_1/dbs
参数文件,我们在主库的pfile中已经修改,我们这里只需要该2个参数即可:
#add for standby dg
*.db_unique_name='dave_st'
*.log_archive_config='dg_config=(dave_pd,dave_st)'
*.log_archive_dest_1='location=/u01/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=dave_st'
*.log_archive_dest_2='service=dave_pd reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=dave_pd'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
*.fal_server='dave_pd'
然后生成pfile。
*.log_archive_dest_2='service=dave_pd reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=dave_pd'
6.6.9 检查主库的口令文件并copy到备库
[oracle@dg1 dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@dg1 dbs]$ ls ora*
orapwdave
[oracle@dg1 dbs]$
如果不存在,手工创建,使用orapwd命令。 这个命令怎么用,就不多做说明,不清楚的google一下:
[oracle@dg1 /]$ orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/ orapwdave password=admin entries=30
缺省情况下,win下口令文件的格式是pwdsid.ora,unix下的格式是orapwSID(大小写敏感)。
Linux默认位置为$ORACLE_HOME/dbs目录下下,Windows 默认为$ORACLE_HOME/database目录。
6.6.10 使用RMAN备份主库
备份语句如下:
RMAN>RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
sql 'alter system archive log current';
BACKUP FORMAT '/u01/backup/db_%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 DELETE INPUT;
backup current controlfile for standby format='/u01/backup/control_%U';
release channel c2;
release channel c1;
}
注意这里面对控制文件的备份。
6.6.11 将主库的备份文件全部copy到备库的相同位置
因为我们的RMAN 采用的是nocatalog的模式,因此RMAN 备份的记录,会记录到控制文件中。 这些路径就是固定的。 所以要想使用之前的备份来恢复,就需要保证备份路径的相同。
[oracle@dg1 backup]$ pwd
/u01/backup
[oracle@dg1 backup]$ ls
arch_0co5p2f5_1_1_20130329 arch_0fo5p2fc_1_1_20130329 db_08o5p2d5_1_1_20130329 db_0bo5p2es_1_1_20130329
arch_0do5p2f5_1_1_20130329 arch_0go5p2fd_1_1_20130329 db_09o5p2d6_1_1_20130329
arch_0eo5p2fa_1_1_20130329 control_0ho5p2fg_1_1 db_0ao5p2el_1_1_20130329
[oracle@dg1 backup]$ scp * 192.168.2.30:/u01/backup
6.6.12 在备库使用RMAN 恢复备库
--启动备库到nomount状态:
[oracle@dg2 backup]$ sqlplus / as sysDBA
SQL*Plus: Release 11.2.0.3.0 Production on Fri Mar 29 22:09:23 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 814227456 bytes
Fixed Size 2232760 bytes
Variable Size 478154312 bytes
Database Buffers 331350016 bytes
Redo Buffers 2490368 bytes
SQL>
--在备库执行duplicate操作:
[oracle@dg2 ~]$ rman target sys/oracle@dave_pd auxiliary sys/oracle@dave_st;
duplicate target database for standby nofilenamecheck
--因为我们的数据文件路径相同,所以这里加上了nofilenamecheck,如果不同,就不需要加了。
在我们演示使用Active Data Guard的时候,我们会看路径不同的情况。
RMAN> duplicate target database for standby nofilenamecheck dorecover;
RMAN>
duplicate 就是一个封装的东西
那没有dorecover呢? 就是只有restore
media recovery complete
Finished restore at 29-MAR-13
Finished recover at 29-MAR-13
6.6.13 启动备库
--完成duplicate 之后,备库就是mount状态:
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
SQL> alter database open;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
6.6.14 在主备库添加online redo log 和standby redo log
6.6.14.1 主库
--主库添加standby redo log:大小和online redo 相同,比online redo group 多一组。
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/u01/app/oracle/oradata/dave/redo04.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/u01/app/oracle/oradata/dave/redo05.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/u01/app/oracle/oradata/dave/redo06.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/u01/app/oracle/oradata/dave/redo07.log') size 50M;
SQL>select GROUP#,SEQUENCE#,BYTES/1024/1024,STATUS from v$log;
--验证:
SQL> col member for a50
SQL> select group#,type, member from v$logfile;
GROUP# TYPE MEMBER
---------- ------- --------------------------------------------------
3 ONLINE /u01/app/oracle/oradata/dave/redo03.log
2 ONLINE /u01/app/oracle/oradata/dave/redo02.log
1 ONLINE /u01/app/oracle/oradata/dave/redo01.log
4 STANDBY /u01/app/oracle/oradata/dave/stdbyredo01.log
5 STANDBY /u01/app/oracle/oradata/dave/stdbyredo02.log
6 STANDBY /u01/app/oracle/oradata/dave/stdbyredo03.log
7 STANDBY /u01/app/oracle/oradata/dave/stdbyredo04.log
我们在备库
SQL> alter database drop logfile group 4;
alter database drop logfile group 4
*
ERROR at line 1:
ORA-01156: recovery or flashback in progress may need access to files
SQL> alter database recover managed standby database cancel;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/u01/app/oracle/oradata/dave/redo05.log') size 50M;
--必要忘记:
SQL> alter database recover managed standby database disconnect from session;
Database altered.
6.6.15 验证DG
6.6.14.1 主库
v$archive_dest
SQL> col error for a10
SQL> col dest_name for a20
SQL> select DEST_NAME,STATUS,PROCESS,ERROR,TRANSMIT_MODE from v$archive_dest WHERE TARGET='STANDBY';
DEST_NAME STATUS PROCESS ERROR TRANSMIT_MOD
-------------------- --------- ---------- ---------- ------------
LOG_ARCHIVE_DEST_2 VALID LGWR ASYNCHRONOUS
SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;
PROCESS STATUS THREAD# SEQUENCE# BLOCK# BLOCKS
--------- ------------ ---------- ---------- ---------- ----------
ARCH CLOSING 1 30 2048 48
ARCH CONNECTED 0 0 0 0
ARCH CLOSING 1 29 1 405
ARCH CLOSING 1 29 1 405
LNS WRITING 1 31 5718 1
SQL> select sequence#,applied from v$archived_log;
SEQUENCE# APPLIED
---------- ---------
26 YES
27 YES
28 YES
29 YES
30 YES
31 YES
6.6.16 总结
NAME ISDEFAULT SESMO SYSMOD VALUE
------------------------ ----- --------- ---------
db_name FALSE FALSE FALSE dave
db_unique_name FALSE FALSE FALSE dave_pd
log_archive_dest
fal_server
|
|