首页 > 数据库 > Oracle > 11G dataguard RAC+单机
1. 在rac两个节点和单机都要修改hosts文件如下
10.17.1.71 trac1
192.168.1.1 trac1-priv
10.17.1.73 trac1-vip
10.17.1.72 trac2
192.168.1.2 trac2-priv
10.17.1.74 trac2-vip
10.17.1.60 trac-scan
10.17.1.76 css
2. 在rac两个节点与standby节点上修改tns文件,添加如下内容
primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.17.1.71)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.17.1.72)(PORT = 1521))
(LOAD_BALANCE =
yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = primary)
)
)
standby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.17.1.76)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = standby)
(INSTANCE_NAME
= trac) ------此处可选
)
)
3. 在rac两个节点上创建本地文件夹用来存储standby日志组
节点一
mkdir -p /oracle/oradata/trac
chmod -R 775 /oracle/oradata/
chown -R oracle:oinstall /oracle/oradata/
alter database add standby logfile thread 1 group 5
('/oracle/oradata/trac/redo05.log') size 50M;
alter database add standby logfile thread 1 group 6 ('/oracle/oradata/trac/redo06.log')
size 50M;
alter database add standby logfile thread 1 group 7
('/oracle/oradata/trac/redo07.log') size 50M;
节点二
mkdir -p /oracle/oradata/trac
chmod -R 775 /oracle/oradata/
chown -R oracle:oinstall /oracle/oradata/
alter database add standby logfile thread 2 group 8
('/oracle/oradata/trac/redo08.log') size 50M;
alter database add standby logfile thread 2 group 9
('/oracle/oradata/trac/redo09.log') size 50M;
alter database add standby logfile thread 2 group 10
('/oracle/oradata/trac/redo10.log') size 50M;
注:在主库端创建Standby日志组, Oracle建议Standby日志组至少要比联机日志组多一个, 这里我们创建6个,大小和redolog一致
看看刚建的Standby日志组, 还都是UNASSIGNE, 这是因为主库是Primary, 只有当切换成Standby角色时, Standby日志组才起作用
SQL> select group#,thread#,sequence#,archived,status from
v$standby_log;
GROUP# THREAD# SEQUENCE# ARC STATUS
---------- ---------- ----------
--- ----------
5 1 0 YES UNASSIGNED
6 1 0 YES UNASSIGNED
7 1 0 YES UNASSIGNED
8 2
0 YES UNASSIGNED
9 2 0 YES UNASSIGNED
10 2 0 YES UNASSIGNED
6 rows selected.
4. 修改启动文件
创建pfile并修改
Create pfile from spfile
然后在$ORACLE_HOME/dbs文件夹下找到pfile
节点一如下
trac2.__db_cache_size=587202560
trac1.__db_cache_size=553648128
trac2.__java_pool_size=16777216
trac1.__java_pool_size=16777216
trac2.__large_pool_size=33554432
trac1.__large_pool_size=33554432
trac2.__oracle_base='/oracle/app'#ORACLE_BASE
set from environment
trac1.__oracle_base='/oracle/app'#ORACLE_BASE
set from environment
trac2.__pga_aggregate_target=872415232
trac1.__pga_aggregate_target=872415232
trac2.__sga_target=1627389952
trac1.__sga_target=1627389952
trac2.__shared_io_pool_size=0
trac1.__shared_io_pool_size=0
trac2.__shared_pool_size=956301312
trac1.__shared_pool_size=872415232
trac2.__streams_pool_size=0
trac1.__streams_pool_size=0
*.archive_lag_target=0
*.audit_file_dest='/oracle/app/admin/trac/adump'
*.audit_trail='FALSE'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATADG/trac/controlfile/current.260.879016595'
*.db_block_size=8192
*.db_create_file_dest='+DATADG'
*.db_domain=''
trac1.db_keep_cache_size=117440512
*.db_name='trac'
*.diagnostic_dest='/oracle/app'
*.dispatchers='(PROTOCOL=TCP)
(SERVICE=tracXDB)'
trac1.instance_number=1
trac2.instance_number=2
*.job_queue_processes=1000
*.log_archive_dest_1='LOCATION=+archdg'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=2499805184
*.open_cursors=2000
*.processes=1500
*.remote_listener='trac-scan:1521'
*.remote_login_passwordfile='exclusive'
*.session_cached_cursors=500
*.sessions=1655
trac2.thread=2
trac1.thread=1
trac1.undo_tablespace='UNDOTBS1'
trac2.undo_tablespace='UNDOTBS2'
(此处是节点一和节点二在pfile后添加的内容)
*.DB_UNIQUE_NAME='primary'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'
*.log_archive_dest_1='LOCATION=+archdg
VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary'
*.LOG_ARCHIVE_DEST_2='SERVICE=standby
ARCH ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER='standby'
*.FAL_CLIENT='primary'
*.STANDBY_FILE_MANAGEMENT='AUTO'
#All_logfile>online log,standby redolog
使用新的pfile启动两个实例
startup pfile='/oracle/app/db_1/dbs/inittrac1.ora';
startup pfile='/oracle/app/db_1/dbs/inittrac2.ora';
create spfile from
pfile='/oracle/app/db_1/dbs/inittrac1.ora';
create spfile from
pfile='/oracle/app/db_1/dbs/inittrac2.ora';
standby节点pfile如下:
(自己手动vi的文件,目录可以自己定义,但要赋予权限)
此文件是根据节点一的pfile更改的,具体更改的地方可以对比看
*.archive_lag_target=0
*.audit_file_dest='/oracle/admin/trac/adump'
*.audit_trail='FALSE'
*.compatible='11.2.0.4.0'
*.control_files='/oracle/oradata/trac/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest='/oracle/oradata'
*.db_domain=''
*.db_name='trac'
*.diagnostic_dest='/oracle/app'
*.dispatchers='(PROTOCOL=TCP)
(SERVICE=tracXDB)'
*.job_queue_processes=1000
*.log_archive_dest_1='LOCATION=/oracle/oradata/archive'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=2000
*.processes=1500
*.remote_listener='10.17.1.76:1521'
*.remote_login_passwordfile='exclusive'
*.session_cached_cursors=500
*.sessions=1655
undo_tablespace='UNDOTBS1'
*.DB_UNIQUE_NAME='standby'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'
*.log_archive_dest_1='LOCATION=/oracle/oradata/archive
VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'
*.LOG_ARCHIVE_DEST_2='SERVICE=primary
ARCH ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=primary'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER='primary'
*.FAL_CLIENT='standby'
*.STANDBY_FILE_MANAGEMENT='AUTO'
5. 在standby机建立OFA目录
mkdir -p /oracle/admin/trac/adump
mkdir -p /oracle/admin/trac/bdump
mkdir -p /oracle/admin/trac/cdump
mkdir -p /oracle/admin/trac/dpdump
mkdir -p /oracle/admin/trac/pfile
mkdir -p /oracle/admin/trac/udump
mkdir -p
/oracle/db_1/cfgtoollogs/dbca/trac
mkdir -p /oracle/oradata/trac
mkdir -p /oracle/oradata/archive
chmod -R 775 /oracle
chown -R oracle:oinstall /oracle
6. 复制主库某一节点的密码文件到standby节点$ORACLE_HOME/dbs目录下,并重命名该密码文件,并且赋予相应的属主和权限
scp oracle@10.17.1.71:/oracle/app/db_1/dbs/orapwtrac1
/oracle/app/db_1/dbs/
mv orapwtrac1 orapwtrac
chmod 775 orapwtrac
7. 备份主库并进入force logging
alter
database force logging;
备份数据库
Rman target /
run {
backup
format '/oracle/%U_backup.bus'
database;
}
备份控制文件
run {
allocate channel c1 device type disk format
'/oracle/CON_%U';
backup current controlfile for standby;
}
将备份文件传到备机(我默认开启的4通道,所以有四个文件)
[oracle@css dbs]$ scp
oracle@10.17.1.71:/oracle/t* /oracle/
oracle@10.17.1.71's password:
tmqbv6ap_1_1_backup.bus 100% 1842MB 40.9MB/s
00:45
tnqbv6ap_1_1_backup.bus 100% 657MB
7.4MB/s 01:29 toqbv6aq_1_1_backup.bus 100% 9832KB 9.6MB/s
00:01 tpqbv6aq_1_1_backup.bus 100% 174MB
9.1MB/s 00:19
[oracle@css dbs]$ scp
oracle@10.17.1.71:/oracle/C* /oracle/
oracle@10.17.1.71's password:
CON_trqbv6gg_1_1 100% 29MB
28.6MB/s 00:01
8. 恢复数据库
将备库使用standby.ora启动到nomount状态
SQL> startup
pfile='/oracle/app/db_1/dbs/standby.ora' nomount;
ORACLE instance started.
Total System Global Area 446832640 bytes
Fixed Size 2253984 bytes
Variable Size 385878880 bytes
Database Buffers 50331648 bytes
Redo Buffers 8368128 bytes
SQL> create spfile from
pfile='/oracle/app/db_1/dbs/standby.ora';
File created.
恢复控制文件
RMAN> restore controlfile from
'/oracle/CON_trqbv6gg_1_1';
Starting restore at 13-JUL-15
using target database control file
instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=572 device
type=DISK
channel ORA_DISK_1: restoring
control file
channel ORA_DISK_1: restore
complete, elapsed time: 00:00:01
output file
name=/oracle/oradata/trac/control01.ctl
Finished restore at 13-JUL-15
Rman备份信息如下(摘自主库的rman备份信息)
File LV Type Ckp SCN Ckp Time
Name
---- -- ---- ---------- --------- ----
3 Full 12156309 13-JUL-15
+DATADG/trac/datafile/undotbs1.258.879016513
6 Full 12156309 13-JUL-15
+DATADG/trac/datafile/undotbs2.265.879016805
4 Full 12156311 13-JUL-15
+DATADG/trac/datafile/users.259.879016513
5 Full 12156311 13-JUL-15
+DATADG/trac/datafile/example.264.879016611
1 Full 12156307 13-JUL-15
+DATADG/trac/datafile/system.256.879016513
7 Full 12156307 13-JUL-15 +DATADG/trac/datafile/xuhch.dbf
2 Full 12156305 13-JUL-15
+DATADG/trac/datafile/sysaux.257.879016513
恢复数据库(因为备机是本地管理数据文件,所以需要rename)
[oracle@css ~]$ rman target /
Recovery Manager: Release
11.2.0.4.0 - Production on Tue Jul 14 09:58:37 2015
Copyright (c) 1982, 2011, Oracle
and/or its affiliates. All rights
reserved.
connected to target database: TRAC
(DBID=308437330, not open)
RMAN> run{
2> set newname for datafile 1
to '/oracle/oradata/trac/system01.dbf';
3> set newname for datafile 2
to '/oracle/oradata/trac/sysaux01.dbf';
4> set newname for datafile 3
to '/oracle/oradata/trac/undotbs01.dbf';
5> set newname for datafile 4
to '/oracle/oradata/trac/users01.dbf';
6> set newname for datafile 5
to '/oracle/oradata/trac/example01.dbf';
7> set newname for datafile 6
to '/oracle/oradata/trac/undotbs02.dbf';
8> set newname for datafile 7
to '/oracle/oradata/trac/xuhch.dbf';
9> restore database;
10> switch datafile all;
11> }
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 14-JUL-15
using target database control file
instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1143
device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=1713
device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=7 device
type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=576 device
type=DISK
channel ORA_DISK_1: starting
datafile backup set restore
channel ORA_DISK_1: specifying
datafile(s) to restore from backup set
channel ORA_DISK_1: restoring
datafile 00003 to /oracle/oradata/trac/undotbs01.dbf
channel ORA_DISK_1: restoring
datafile 00006 to /oracle/oradata/trac/undotbs02.dbf
channel ORA_DISK_1: reading from
backup piece /oracle/toqbv6aq_1_1_backup.bus
channel ORA_DISK_2: starting
datafile backup set restore
channel ORA_DISK_2: specifying
datafile(s) to restore from backup set
channel ORA_DISK_2: restoring
datafile 00004 to /oracle/oradata/trac/users01.dbf
channel ORA_DISK_2: restoring
datafile 00005 to /oracle/oradata/trac/example01.dbf
channel ORA_DISK_2: reading from
backup piece /oracle/tpqbv6aq_1_1_backup.bus
channel ORA_DISK_3: starting
datafile backup set restore
channel ORA_DISK_3: specifying
datafile(s) to restore from backup set
channel ORA_DISK_3: restoring
datafile 00001 to /oracle/oradata/trac/system01.dbf
channel ORA_DISK_3: restoring
datafile 00007 to /oracle/oradata/trac/xuhch.dbf
channel ORA_DISK_3: reading from
backup piece /oracle/tnqbv6ap_1_1_backup.bus
channel ORA_DISK_4: starting
datafile backup set restore
channel ORA_DISK_4: specifying
datafile(s) to restore from backup set
channel ORA_DISK_4: restoring
datafile 00002 to /oracle/oradata/trac/sysaux01.dbf
channel ORA_DISK_4: reading from
backup piece /oracle/tmqbv6ap_1_1_backup.bus
channel ORA_DISK_1: piece
handle=/oracle/toqbv6aq_1_1_backup.bus tag=TAG20150713T173105
channel ORA_DISK_1: restored
backup piece 1
channel ORA_DISK_1: restore
complete, elapsed time: 00:02:00
channel ORA_DISK_2: piece
handle=/oracle/tpqbv6aq_1_1_backup.bus tag=TAG20150713T173105
channel ORA_DISK_2: restored
backup piece 1
channel ORA_DISK_2: restore complete,
elapsed time: 00:02:03
channel ORA_DISK_3: piece
handle=/oracle/tnqbv6ap_1_1_backup.bus tag=TAG20150713T173105
channel ORA_DISK_3: restored
backup piece 1
channel ORA_DISK_3: restore
complete, elapsed time: 00:03:23
channel ORA_DISK_4: piece handle=/oracle/tmqbv6ap_1_1_backup.bus
tag=TAG20150713T173105
channel ORA_DISK_4: restored
backup piece 1
channel ORA_DISK_4: restore
complete, elapsed time: 00:03:53
Finished restore at 14-JUL-15
datafile 1 switched to datafile
copy
input datafile copy RECID=9
STAMP=885031391 file name=/oracle/oradata/trac/system01.dbf
datafile 2 switched to datafile
copy
input datafile copy RECID=10
STAMP=885031391 file name=/oracle/oradata/trac/sysaux01.dbf
datafile 3 switched to datafile
copy
input datafile copy RECID=11
STAMP=885031391 file name=/oracle/oradata/trac/undotbs01.dbf
datafile 4 switched to datafile
copy
input datafile copy RECID=12
STAMP=885031391 file name=/oracle/oradata/trac/users01.dbf
datafile 5 switched to datafile
copy
input datafile copy RECID=13
STAMP=885031391 file name=/oracle/oradata/trac/example01.dbf
datafile 6 switched to datafile
copy
input datafile copy RECID=14
STAMP=885031391 file name=/oracle/oradata/trac/undotbs02.dbf
datafile 7 switched to datafile
copy
input datafile copy RECID=15 STAMP=885031391 file
name=/oracle/oradata/trac/xuhch.dbf
9. 将备库进入恢复模式
alter database recover managed standby database using
current logfile disconnect from session;
10. 进行测试
alter
system switch logfile;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28719622/viewspace-1732544/ ,如需转载,请注明出处,否则将追究法律责任。