创建环境:
Primary数据库
1, ip地址:192.168.1.111
2, 数据库sid:orcl
3, Db_unique_name:orclp
4, 数据库软件位置:/u01/oracle/oracle/product/10.2.0/db_1
5, 数据文件路径:/u01/oracle/oracle/product/10.2.0/oradata/orcl
6, 本地归档路径:/u01/oracle/oracle/product/10.2.0/archivelog
physical Standby数据库
1, ip地址:192.168.1.110
2, 数据库sid:orcl
3, Db_unique_name:orcls
4, 数据库软件位置:/u01/oracle/oracle/product/10.2.0/db_1
5, 数据文件路径:/u01/oracle/oracle/product/10.2.0/oradata/orcl
6, 本地归档路径:/u01/oracle/oracle/product/10.2.0/archivelog
1, 确认主数据库处于归档模式下
如果处于非归档模式可以将数据库启动到mount状态,然后通过alter database archive log;
2, 将数据库至于forcelogging状态
通过 alter database force logging转换为force logging状态
如果要取消alter database no force logging
目的:是为了防止用户通过nologging之类的操作跳过redo的生产,而无法传递到standby。
3, 配置初始化参数
根据oracle10g官方文档进行的参数设置,参数意义见最后的参考文档
参数说明:
Db_unique_name:名字可以随便写,目的是在dataguard中用于区分相同的实例名。
Log_archive_config:中的dg_config是用来指定dataguard中各个db_unique_name。
Log_archive_dest_1:用来存放归档的路径及存放在那台数据库中
Fal_server:用来表示当当前数据库为standby状态时,用来连接的primary库的网络服务名,可以有多个通过逗号隔开。
Fal_client:用来连接本地的网络服务名。
Db_file_name_convert:表示当添加数据文件时,传输到standby库时的路径转换
然后通过pfile创建spfile,因为spfile是二进制文件安全性更好,某些可以直接通过alter system命令直接进行修改,而不用重启数据库。
4, 创建standby数据库的控制文件
alter database create standby controlfile as'/u01/oracle/standby.ctl';
5, 对主数据库文件进行备份
因为我不采取rman进行备份,所以我直接关闭数据库,copy数据文件到standby数据库中。
这是我转载的一篇文章中关于linux之间的传输文件的方式
http://blog.csdn.net/xionglang7/article/details/7084919
我直接采用的scp 文件名(当前路径下)远端IP:存放的路径
如:scp -p example01.dbf sysaux01.dbf system01.dbf undotbs01.dbfusers01.dbf 192.168.1.110:/u01/oracle/oracle/product/10.2.0/oradata/
6, 配置监听和网络服务名
配置linstener.ora,如果network下没有该文件则直接创建好后将下面的内容添加上去
配置网络服务名:tnsnames.ora下添加如下的内容
千万不要写成tnsname.ora否则的话tnsping会报tns-03505
7, 创建密码文件,必须保证dataguard中sys的密码都一样
Orapwd file=/u01/oracle/oracle/product/10.2.0/db_1/dbs/PWDorclpassword=xionglang entires=10;
注意:linux下的密码文件格式为:oraPWDsid;windows下为PWDsid.ora
到此primary的主要工作就算做完了,不过应该注意开放监听端口1521,
在/etc/sysconfig下的iptables添加一句,开放1521到1523的端口
-A RH-Firewall-1-INPUT -m state --state NEW-m tcp -p tcp --dport 1520:1523 -j ACCEPT
然后重启防火墙 service iptables restart;
1, 创建相应的bdump,adump,cdump,udump文件
如果在windows下要进行创建实例的操作:Oradim –new –sid orcl
2, 创建监听及网络
创建监听:
创建服务名:
完成后通过tnsping orcl_p命令保证可以正常连接两个数据库。
3, 修改客户端的参数文件
其他的和primary数据库的基本是相同的,要注意修改控制文件的路径
4, 创建密码文件,保证与primary数据库的sys密码相同即可
5, 创建standby日志文件(在参数文件中以lgwr进行实时传输时,必须在standby数据库创建standby日志),将数据库启动到mount状态
6, 最后在主库中切换日志
Alter system switch logfile;
在standby库中通过查看是否传输到standby库中
Select sequence#,name,applied from v$archived_log
在standby数据库中对日志进行应用
Alter database recover managed standby database disconnectfrom session
取消应用
Alterdatabase recover managed standby database cancel;取消后才能打开数据库,但打开的数据库是只读模式的
7,总结因为我采取的是lgwr的方式的进行传输,并且采用的同步方式(sync),所以只要主库中的数据进行了lgwr写日志,就会有lnsn(lgwr network server)进程通过oracle net将日志条目从primary数据库中传到standby数据库,在有rfs(remote file server)进程将接收到的redo数据写入到standby redolog中(这就是为啥用lgwr方式传输必须要在standby中创建standby redolog),最后通过进行redo应用,有mrp进程读取归档文件将数据应用到standby数据库
1) 检查初始化参数文件,确认数据库对于不同角色的相应的初始化参数文件都进行了正确的配置
2) 检查即将成为primary的数据库是否有归档模式
3) 检查standby数据库的临时文件是否存在,并匹配primary数据库的临时文件
及为无损转换,通过手动或有计划的让其自动触发,工作量小。
1, 将primary库转换为standby数据库
1)查询转换的状态(应该为tostandby)
Select switchover_status from v$database;
如果为sessionactive表示用人连接数据库(如你以网络服务名的方式连接,最好查询下v$session)
2)启动switchover转换为standby角色
Alter database commit to switchover to physical standby;
3)关闭数据库启动到mount状态
2, 将standby数据库转换为primary数据库
1)检查转换状态(为toprimary)
Select switchover_status from v$database;
2)启动转换到primary数据库
Alter database commit to switchover to primary;
3)打开数据库进行验证
因为primary数据库故障或者短期内不能恢复,有可能丢失数据,并在切换后原来的primary数据库不在是data guard中的一部分
注意:在failover前应尽可能的将原primary数据库可用的redo都复制到standby数据库中
1) 查询standby数据库处于什么模式下,如果处于(maximum protection)则应转换为maximum performance
select PROTECTION_MODE from v$database; 默认的是maximumperformance
如果要转换可以用下面的语句
Alter database set standby database to maximize performance;
2) 在standby数据库中检查归档是否连续(没有返回行表示归档连续)
Select thread#,low_sequence#,high_sequence# fromv$archive_gap
如果有记录返回,则将primary数据库中的相应的记录拷贝到standby数据库
执行 alter database register physical logfile 'filespec1';
3) 检查归档是否完成
在primary数据库与standby数据库分别执行
Select distinct thread#,max(sequence#)over(partition by thread#) from v$archived_log;
THREAD# MAX(SEQUENCE#)OVER(PARTITIONBYTHREAD#)
---------- --------------------------------------
1 22
Select distinct thread#,max(sequence#)over(partition by thread#) from v$archived_log;
THREAD# MAX(SEQUENCE#)OVER(PARTITIONBYTHREAD#)
-----------------------------------------------
1 22
4) 启动failover
Alter databaserecover managed standby database finish force;
主要是停止rfs进行
5) 转换standby 数据库到primary数据库
Alter database commit to switchover to primary;
然后打开数据库即可
DB_NAME |
Specify an 8-character name. Use the same name for all standby databases. |
DB_UNIQUE_NAME |
Specify a unique name for each database. This name stays with the database and does not change, even if the primary and standby databases reverse roles. |
LOG_ARCHIVE_CONFIG |
Specify the DG_CONFIG attribute on this parameter to list the DB_UNIQUE_NAME of the primary and standby databases in the Data Guard configuration; this enables the dynamic addition of a standby database to a Data Guard configuration that has a Real Application Clusters primary database running in either maximum protection or maximum availability mode. By default, the LOG_ARCHIVE_CONFIG parameter enables the database to send and receive redo; after a role transition, you may need to specify these settings again using the SEND,NOSEND, RECEIVE, or NORECEIVE keywords. |
CONTROL_FILES |
Specify the path name for the control files on the primary database. Example 3-3 shows how to do this for two control files. It is recommended that a second copy of the control file is available so an instance can be easily restarted after copying the good control file to the location of the bad control file. |
LOG_ARCHIVE_DEST_n |
Specify where the redo data is to be archived on the primary and standby systems. InExample 3-3:
Note: If a flash recovery area was configured (with the DB_RECOVERY_FILE_DESTinitialization parameter) and you have not explicitly configured a local archiving destination with the LOCATION attribute, Data Guard automatically uses theLOG_ARCHIVE_DEST_10 initialization parameter as the default destination for local archiving. See Section 5.2.3 for more information. Also, see Chapter 14 for completeLOG_ARCHIVE_DEST_n information. |
LOG_ARCHIVE_DEST_STATE_n |
Specify ENABLE to allow redo transport services to transmit redo data to the specified destination. |
REMOTE_LOGIN_PASSWORDFILE |
Set the same password for SYS on both the primary and standby databases. The recommended setting is either EXCLUSIVE or SHARED. |
LOG_ARCHIVE_FORMAT |
Specify the format for the archived redo log files using a thread (%t), sequence number (%s), and resetlogs ID (%r). See Section 5.7.1 for another example. |
LOG_ARCHIVE_MAX_PROCESSES=integer |
Specify the maximum number (from 1 to 30) of archiver (ARCn) processes you want Oracle software to invoke initially. The default value is 4. See Section 5.3.1.2 for more information about ARCn processing. |
FAL_SERVER |
Specify the Oracle Net service name of the FAL server (typically this is the database running in the primary role). When the Chicago database is running in the standby role, it uses the Boston database as the FAL server from which to fetch (request) missing archived redo log files if Boston is unable to automatically send the missing log files. SeeSection 5.8. |
FAL_CLIENT |
Specify the Oracle Net service name of the Chicago database. The FAL server (Boston) copies missing archived redo log files to the Chicago standby database. See Section 5.8. |
DB_FILE_NAME_CONVERT |
Specify the path name and filename location of the primary database datafiles followed by the standby location. This parameter converts the path names of the primary database datafiles to the standby datafile path names. If the standby database is on the same system as the primary database or if the directory structure where the datafiles are located on the standby site is different from the primary site, then this parameter is required. Note that this parameter is used only to convert path names for physical standby databases. Multiple pairs of paths may be specified by this parameter. |
LOG_FILE_NAME_CONVERT |
Specify the location of the primary database online redo log files followed by the standby location. This parameter converts the path names of the primary database log files to the path names on the standby database. If the standby database is on the same system as the primary database or if the directory structure where the log files are located on the standby system is different from the primary system, then this parameter is required. Multiple pairs of paths may be specified by this parameter. |
STANDBY_FILE_MANAGEMENT |
Set to AUTO so when datafiles are added to or dropped from the primary database, corresponding changes are made automatically to the standby database. |