oracle DG:
英文全称dataguard
提供备份和灾难恢复
dg----必须要有两台数据库,一台主一台备,主备可以来回切换
dg功能
1.备份(硬件可以低于主库,软件可以不一致)
2.提供容灾(硬件必须不低于主库,软件路径版本必须一致)
3.读写分离(主库读写对外服务。备库只读)逻辑备库可以读,11g物理备库也可以读
4.可以做测试(快照备库可以读写,测试完了在将其转为物理备库,这时所做的测试操作全部丢失)
dg又分物理备库和逻辑备库(具体可以网上查询,不做详细介绍)
dg介绍
1.日志传输服务:定义主库日志通过什么方式,如何传递给备库
主库日志传递给备库时,使用什么进程去传递,通过lgwr进程传还是arc进程传,主库日志是否和备一致,主库日志和备是否可以有时间差
log_archive_config='dg_config(db_unique_name主send/nosend|receive/noreceive,db_unique_name备send/nosend|receive/noreceive)';
默认主库和备库send+receive即接受有传送
10g一个主库最多9个备库
11g一个主库最多30个备库
log_archive_dest_1='location='/'db_unique_name=pri'
log_archive_dest_2='service=service_name(默认闪回路径) <lgwr sync|arc async|delay 7200s延迟7200s传送|compress压缩归档文件传送>db_unique_name=std'
log_archive_dest_state_1=enable/disable
2.角色转换服务
switchover;自动转换,主库变备库,备库变主库,主库和备库都是正常的。(假如主库要升级,执行switchover将备库变成主库
关闭原来的主库,升级硬件,将原来的主库启动成备库,在执行switchover。)
failover :故障转换,主库不可用并且短时间无法恢复,这时需要failover切换,直接将备库做主库,原来的主库不在是dg中的成员,
必须重新搭建dg,如果使用的是dgbroker,这时原来的主库要成为备库必须重新实例化。
3.数据保护
a---最大保护模式:可以保证数据0丢失
开启最大保护模式时,当用户在主库进行操做,改操作记录到主库redo中,这时redo必须传递到备库,并且保证至少要有一个备库日志可用
该事务在主库才能完成。如果备库不可用,这时主库就会当机
v$database--protection_mode
b---最大可用性模式
处于最大可用性模式时,主库什么时候转日志,备库就什么时间接收
c---最大性能模式
保证数据库的性能,也保证数据0丢失,如果备库不可使用,主库转为最大可用模式,备库可用,恢复到最大性能模式
dg搭建的方式
1.操作系统命令方式(不做介绍)
2.rman的方式
duplicate克隆技术
3.oem(不做介绍)
搭建dg的前的准备
SID统一为up
主库:db_unique_name=pri 192.168.3.98
从库:db_unique_name=std 192.168.3.99
测试软件 vmware 10
测试环境 centos6.5
建议关闭selinux和iptables
环境变量:最好一致,写到bash_profile或者手动 source都可以
cat db
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=/u01/11g
export ORACLE_SID=up
exportPATH=$ORACLE_HOME/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin
cat asm
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=/u01/grid
export ORACLE_SID=+ASM
exportPATH=$ORACLE_HOME/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin
主库操作:(主库首先需要搭建好oracle库,不会的可以去看我的上一篇博客http://blog.csdn.net/freedompuge/article/details/45028961)
1.主库必须归档
启动到mount状态
alter databse archivelog开启归档
SQL> archive log list; ===》显示enabled表示开启
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 8
Next log sequence to archive 10
Current log sequence 10
2.强制日志记录
select force_logging from v$database;
alter database force logging;开启强制记录
3.网络配置
vim listener.ora
# listener.ora Network Configuration File:/u01/11g/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = up)
(ORACLE_HOME = /u01/11g)
(SID_NAME = up)
)
(SID_DESC =
(GLOBAL_DBNAME = pri)
(ORACLE_HOME = /u01/11g)
(SID_NAME = up)
)
(SID_DESC =
(GLOBAL_DBNAME = pri_DGMGRL) ---或者写pri_DGBROKER
(ORACLE_HOME = /u01/11g)
(SID_NAME = up)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.98)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/oracle
vim tnsname.ora-----tnsping ------如果不同可能是防火墙
# tnsnames.ora Network Configuration File:/u01/11g/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PRI =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.98)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri)
)
)
STD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.99)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = std)
)
)
EXTPROC_CONNECTION_DATA=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL =TPC)(KEY = EXTPROCO))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
4.附加日志打开(可做可不做,逻辑备库必做)
alter database {add|drop} supplemental logdata
5.备份
rman全备一次
backup full database include current controlfile for
standby
6.闪回功能(不打开就是物理备库)
alter database flashback off;
7.修改参数
alter system set db_unique_name=pri scope=spfile;
重启数据库,创建pfile
Create pfile=’/……’ from spfile
alter system switch logfile;
8.在备份一次数据库
rman----backup database 在备份一次数据库
9.增加备库日志(备库日志比主库日志多一个)
group#---v$standby_log;---查看备库日志组
alter database add standby logfile group 5 '/u01/......sredo01.log' size 50m;
.....
备库操作:
1.安装一台和主库一模一样的环境
只装软件不建库(这里不详细介绍安装软件了)
2.scp主库密码,参数文件,监听等,拷贝到相应的路径下
scp root@ip:xxxx /...
3.准备目录
grep / /…../init$ORACLE_SID.ora
根据显示的目录,创建路径
mkdir /u01/oracle/oradata/updb
/u01/oracle/fast_recovery_area/updb
/u01/oracle/admin/updb/{a,dp}dump -p
启动到nomount状态创建spfile---create spfile from pfile;
在到nomount状态修改unique_name,在重新启动到nomount
alter system set db_unique_name=std scope=spfile;
4.配置网络
vim listener.ora
# listener.ora Network Configuration File:/u01/11g/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = up)
(ORACLE_HOME = /u01/11g)
(SID_NAME = up)
)
(SID_DESC =
(GLOBAL_DBNAME = std)
(ORACLE_HOME = /u01/11g)
(SID_NAME = up)
)
(SID_DESC =
(GLOBAL_DBNAME = std_DGMGRL) ----std_DGBROKER
(ORACLE_HOME = /u01/11g)
(SID_NAME = up)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.99)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/oracle )
Vim tnsname.ora---与主库一样---防火墙关闭
# tnsnames.ora Network Configuration File:/u01/11g/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PRI =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.98)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri)
)
)
STD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.99)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = std)
)
)
EXTPROC_CONNECTION_DATA=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL =TPC)(KEY = EXTPROCO))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
之后在主库和从库执行 tnsping pri(std)看能否成功或者执行sqlplus sys/oracle@pri(std)
5.备库执行克隆
rman target sys/oracle@pri auxiliarysys/oracle@std
duplicate target database for standbynofilenamecheck from active database;
6.配置dgbroker
show parameter dg_broker_start---------true表示打开
alter system setdg_broker_start=true/false-----主库备库都打开
7.执行dgbroker配置dg
dgmgrl sys/oracle@pri---必须链接主库
CREATE CONFIGURATION dg_ps AS ----随便起名字,不要忘记就行
PRIMARY DATABASE IS pri ----主库名
CONNECT IDENTIFIER IS pri;
add databse std as connect identifier is stdmaintained as physical
show configuration
enable configuration
edit database pupdb set propertylogxptmode=sync
edit databse pupdb set propertystandbyfilemanagement=auto
8.测试主库和备库是否同步
alter system switch logfile;
select max(sequence#) from v$archived_log;
9.查看从库的日志文件
备库日志一般比主库多一个组
group#---v$standby_log;---查看备库日志组
alter database add standby logfile group11'/u01/......sredo01.log' size 50m;在主库创建(一般不需要做会自动创建)
alter database add standby logfile group12'/u01/......sredo02.log' size 50m;
alter database add standby logfile group13'/u01/......sredo03.log' size 50m;
alter database add standby logfile group14'/u01/......sredo04.log' size 50m;
alter system dg_broker_start=false--主备一起关
把备库启动到nomount在执行克隆----这种备库可以达到实时同步
10.在主库建一个表,在从库查看是否同步
create table test(id number);
11.主从切换
switchover to std;
注意事项:
1、 一开始使用了dgbroker配置dg,那么不管是在主库还是从库执行alter system set xxx=xxx scope=spfile;都不会记录到spfile里面
可以用dgmrl 里面的edit 修改参数
2、 show configuration 出现错误的时候
可以执行show database verbose std(pri)查看错误
需要注意的是在dgmgrl sys/oracle@pri和dgmgrl sys/oracle@std 两端看到的错误是不同的
如果看到Warning: ORA-16714: the value of property StandbyFileManagement isinconsistent with the database setting之类的错误
则修改edit database std set property StandbyFileManagement='auto';
3、 多使用help查看命令的使用方法
4、 下图是切换后的图,看到SUCCESS那么恭喜你DG搭建成功
DGMGRL> show configuration
Configuration - dg_ps
Protection Mode:MaxPerformance
Databases:
std - Primarydatabase
pri - Physicalstandby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS