主库已安装好数据库,备库只安装好oracle软件
环境如下:
项目列表 | primary库 | standby库 |
操作系统: | rhel6.3 | rhel6.3 |
oracle软件版本: | oracle 11.2.0.3 | oracle 11.2.0.3 |
IP地址: | 172.17.61.115 | 172.17.61.131 |
db_unique_name | db115 | db131 |
oracle_sid,db_name | orcl | orcl |
在一个dg环境中,db_name,oracle_sid必须是一样的,db_unique_name用来区别dg环境中的不同库。
1.确认主库的监听是开着的
[ogg@qht115 u01]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 20-SEP-2018 09:36:38
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.17.61.115)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 05-SEP-2018 08:44:23
Uptime 15 days 0 hr. 52 min. 14 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11203/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/qht115/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.17.61.115)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 2 handler(s) for this service...
The command completed successfully
2.主库确保开启归档模式
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 23
Next log sequence to archive 28
Current log sequence 28
3.打开force_logging
SQL> select FORCE_LOGGING from v$database;
FOR
---
YES
如果为NO,则需要执行alter database force logging;
4.主库创建密码文件
[oracle@qht115 dbs]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=sys entries=30
5.配置主库的tnsnames.ora
[oracle@qht115 admin]$ cat tnsnames.ora
db115 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.61.115)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
db131 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.61.131)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
6.修改主库的参数文件
生成pfile
SQL> create pfile='/u01/app/oracle/product/11203/dbs/initorcl.ora' from spfile;
修改参数文件如下:
[oracle@qht115 dbs]$ cat initorcl.ora
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
*.aq_tm_processes=0
*.compatible='11.2.0'
*.control_files='/u01/oradata/orcl/control01.ctl','/u01/oradata/orcl/control02.ctl','/u01/oradata/orcl/control03.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_cache_size=1610612736
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orcl'
*.db_recovery_file_dest_size=21474836480
*.db_recovery_file_dest='/u01/app/oracle/admin/orcl/flash_recovery_area'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.java_pool_size=134217728
*.job_queue_processes=10
*.large_pool_size=218103808
*.open_cursors=300
*.pga_aggregate_target=524288000
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_manager_plan=''
*.sessions=335
*.shared_pool_size=536870912
*.streams_pool_size=67108864
*.undo_management='AUTO'
*.undo_retention=900
*.undo_tablespace='UNDOTBS1'
--增加以下部分
#*.DB_FILE_NAME_CONVERT='/u01/oradata/orcl/','/u01/oradata/orcl/'
--主备使用了不同的文件路径时,需要设置此参数。当主库切换或发生故障后转移到备用数据库时,将路径进行转换后写入控制文件。由于主备路径相同,所以可不设置些参数。
#*.LOG_FILE_NAME_CONVERT='/u01/oradata/orcl/','/u01/oradata/orcl/'
--同db_file_name_convert,指明主数据库和备用数据库联机重做日志文件转换关系,由于主备路径相同,所以可不设置些参数。
*.DB_UNIQUE_NAME='db115'
--DB_UNIQUE_NAME指定同一个dg环境中的不同数据库
*.fal_client='db115' --当需要主从切换时,db115设为备库,这个值对应tnsname.ora的设置
*.fal_server='db131' --当需要主从切换时,db131设为主库,这个值对应tnsname.ora的设置
*.log_archive_config='DG_CONFIG=(db115,db131)' --定义DG中所有有效的DB_UNIQUE_NAME名字的列表,主从的设置相同
*.log_archive_dest_1='LOCATION=/u01/app/oracle/admin/orcl/flash_recovery_area/ORCL/archivelog LGWR VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=db115'
--归档日志的存放位置,LOCATION为存放在本地,LGWR意为之传输redo日志,VALID_FOR=(ALL_LOGFILES,ALL_ROLES)定义所有类型的日志文件和不论主库备库角色一律传递归档到此目录
*.log_archive_dest_2='SERVICE=db131 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db131'
--第2个归档日志存放的位置,SERIVCE是用于指定备用数据库的TNSNAMES描述符
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.standby_file_management='AUTO'
--该参数只在当前库为备库时生效,提前设置以便需要进行主备角色切换时使用。建议将其值设置为AUTO,这样当主库添加或删除数据文件时,会自动在备库上完成相应的更改。
7.备库的准备工作
[oracle@qht131 ~]$ cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11203
ORACLE_SID=orcl
LD_LIBRARY_PATH=$ORACLE_HOME/lib
PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH PATH
[oracle@qht131 ~]$ mkdir -p /u01/oradata/orcl
[oracle@qht131 dbs]$ mkdir -p /u01/app/oracle/admin/orcl/flash_recovery_area/ORCL/archivelog/ORCL
orcl.__db_cache_size=88080384
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=104857600
orcl.__sga_target=314572800
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=205520896
orcl.__streams_pool_size=4194304
#*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
#*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/oradata/orcl/control01.ctl','/u01/oradata/orcl/control02.ctl','/u01/oradata/orcl/control03.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/admin/orcl/flash_recovery_area'
*.db_recovery_file_dest_size=4322230272
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
#*.filesystemio_options='ASYNCH'
*.open_cursors=300
#*.optimizer_capture_sql_plan_baselines=FALSE
*.pga_aggregate_target=103809024
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=312475648
*.undo_tablespace='UNDOTBS1'
*.DB_FILE_NAME_CONVERT='/u01/oradata/orcl/','/u01/oradata/orcl/'
*.LOG_FILE_NAME_CONVERT='/u01/oradata/orcl/','/u01/oradata/orcl/'
*.DB_UNIQUE_NAME='db131'
*.fal_client='db131'
*.fal_server='db115'
*.log_archive_config='DG_CONFIG=(db131,db115)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/admin/orcl/flash_recovery_area/ORCL/archivelog LGWR VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=db131'
*.log_archive_dest_2='SERVICE=db115 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db115'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.standby_file_management='AUTO'
[oracle@qht131 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/u01/network/admin/listener.ora
# Generated by Oracle configuration tools.
INBOUND_CONNECT_TIMEOUT_LISTENER=0
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11203)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11203)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11203)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.61.131)(PORT = 1521))
)
[oracle@qht131 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10201/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
db115 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.61.115)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
db131 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.61.131)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
复制密码文件
[oracle@qht115 dbs]$ scp orapworcl 172.17.61.131:/u01/app/oracle/product/11203/dbs
[oracle@qht131 admin]$ lsnrctl start
8.主库和备库都生成spfile
主库:
SQL> shutdown immediate;
SQL> startup nomount pfile='/u01/app/oracle/product/11203/dbs/initorcl.ora'
SQL> create spfile from pfile='/u01/app/oracle/product/11203/dbs/initorcl.ora'
SQL> startup force
备库需要启到到nomount:
SQL> startup nomount pfile='/u01/app/oracle/product/11203/dbs/initorcl.ora'
SQL> create spfile from pfile='/u01/app/oracle/product/11203/dbs/initorcl.ora'
SQL> shutdown immediate;
SQL> startup nomount
9.备份主库
先在主库和备库都建立一个RMAN备份和恢复的目录
[oracle@qht115 ~]$ mkdir -p /u01/rman
[oracle@qht131 ~]$ mkdir -p /u01/rman
主库开始执行备份,注意自动备份控制文件
RMAN> configure controlfile autobackup on;
RMAN> configure controlfile autobackup format for device type disk to '/u01/rman/con%F';
RMAN> backup device type disk format '/u01/rman/%U' database plus archivelog;
9.将所有备份文件复制到备库。这个必须得做,否则在第10步进行恢复的时候会提示找不到文件。
[oracle@qht115 rman]$ scp * 172.17.61.131:/u01/rman
10.在主库执行复制操作
注意:如果target 和 Auxiliary库的目录结构相同,在复制的时候记得加上nofilenamecheck参数,不然会报如下错误:
RMAN-05001: auxiliary file name /u01/oradata/orcl/users01.dbf conflicts with a file used by the target database
如果目录不同,在pfile里加如下2个参数进行转换: db_file_name_convert , log_file_name_convert.
[oracle@qht115 rman]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Mon Oct 8 12:17:42 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1166343071)
RMAN> connect auxiliary sys/sys@db131
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby nofilenamecheck;
Starting Duplicate Db at 08-OCT-18
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
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=19 device type=DISK
contents of Memory Script:
{
restore clone standby controlfile;
}
executing Memory Script
Starting restore at 08-OCT-18
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/rman/conc-1166343071-20181008-00
channel ORA_AUX_DISK_1: piece handle=/u01/rman/conc-1166343071-20181008-00 tag=TAG20181008T115944
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/oradata/orcl/control01.ctl
output file name=/u01/oradata/orcl/control02.ctl
output file name=/u01/oradata/orcl/control03.ctl
Finished restore at 08-OCT-18
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/oradata/orcl/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/oradata/orcl/system01.dbf";
set newname for datafile 2 to
"/u01/oradata/orcl/undotbs01.dbf";
set newname for datafile 3 to
"/u01/oradata/orcl/sysaux01.dbf";
set newname for datafile 4 to
"/u01/oradata/orcl/users01.dbf";
set newname for datafile 5 to
"/u01/oradata/orcl/qhtdata01.dbf";
set newname for datafile 6 to
"/u01/oradata/orcl/l5mspace01.dbf";
set newname for datafile 7 to
"/u01/oradata/orcl/clt_stats01.dbf";
set newname for datafile 8 to
"/u01/oradata/orcl/tbs_tspitr1_01.dbf";
set newname for datafile 9 to
"/u01/oradata/orcl/mtrxspace01.dbf";
set newname for datafile 10 to
"/u01/oradata/orcl/magspace01.dbf";
set newname for datafile 11 to
"/u01/oradata/orcl/tbs_tspitr2_01.dbf";
set newname for datafile 14 to
"/u01/oradata/orcl/mtrxspace02.dbf";
set newname for datafile 15 to
"/u01/oradata/orcl/ogg01.dbf";
restore
clone database
;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/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
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
executing command: SET NEWNAME
Starting restore at 08-OCT-18
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/oradata/orcl/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/oradata/orcl/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/oradata/orcl/clt_stats01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/oradata/orcl/tbs_tspitr1_01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/oradata/orcl/mtrxspace01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/oradata/orcl/magspace01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00014 to /u01/oradata/orcl/mtrxspace02.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/rman/f4tf568h_1_1
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00001 to /u01/oradata/orcl/system01.dbf
channel ORA_AUX_DISK_2: restoring datafile 00003 to /u01/oradata/orcl/sysaux01.dbf
channel ORA_AUX_DISK_2: restoring datafile 00005 to /u01/oradata/orcl/qhtdata01.dbf
channel ORA_AUX_DISK_2: restoring datafile 00006 to /u01/oradata/orcl/l5mspace01.dbf
channel ORA_AUX_DISK_2: restoring datafile 00011 to /u01/oradata/orcl/tbs_tspitr2_01.dbf
channel ORA_AUX_DISK_2: restoring datafile 00015 to /u01/oradata/orcl/ogg01.dbf
channel ORA_AUX_DISK_2: reading from backup piece /u01/rman/f5tf568h_1_1
channel ORA_AUX_DISK_1: piece handle=/u01/rman/f4tf568h_1_1 tag=TAG20181008T115704
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:04:20
channel ORA_AUX_DISK_2: piece handle=/u01/rman/f5tf568h_1_1 tag=TAG20181008T115704
channel ORA_AUX_DISK_2: restored backup piece 1
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:04:50
Finished restore at 08-OCT-18
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=27 STAMP=988975874 file name=/u01/oradata/orcl/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=28 STAMP=988975874 file name=/u01/oradata/orcl/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=29 STAMP=988975874 file name=/u01/oradata/orcl/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=30 STAMP=988975874 file name=/u01/oradata/orcl/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=31 STAMP=988975874 file name=/u01/oradata/orcl/qhtdata01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=32 STAMP=988975874 file name=/u01/oradata/orcl/l5mspace01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=33 STAMP=988975874 file name=/u01/oradata/orcl/clt_stats01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=34 STAMP=988975874 file name=/u01/oradata/orcl/tbs_tspitr1_01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=35 STAMP=988975874 file name=/u01/oradata/orcl/mtrxspace01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=36 STAMP=988975874 file name=/u01/oradata/orcl/magspace01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=37 STAMP=988975874 file name=/u01/oradata/orcl/tbs_tspitr2_01.dbf
datafile 14 switched to datafile copy
input datafile copy RECID=38 STAMP=988975874 file name=/u01/oradata/orcl/mtrxspace02.dbf
datafile 15 switched to datafile copy
input datafile copy RECID=39 STAMP=988975874 file name=/u01/oradata/orcl/ogg01.dbf
Finished Duplicate Db at 08-OCT-18
11.备库查看状态,打开备库的恢复模式:
SQL> select database_role, open_mode from v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
71 RFS 08-OCT-18 08-OCT-18 NO
72 RFS 08-OCT-18 08-OCT-18 NO
73 RFS 08-OCT-18 08-OCT-18 NO
//查看备库的日志同步情况,可见编号为71,72,73的日志还没有得到应用,确保日志都应用了,在主库上也执行一遍同样的语句,联动检查同步情况(检查主库日志是否都已经同步到最新序列号,检查备库所有日志是否得到应用,即APPLIED字段值为“YES”,当该字段值为“IN-MEMORY”时意正在写入内存并同步中,当字段值为“NO”时意为日志还未得到同步)。
12.备库增加standby logfile
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database add standby logfile '/u01/oradata/orcl/redo01_dg.log' size 512m;
Database altered.
SQL> alter database add standby logfile '/u01/oradata/orcl/redo02_dg.log' size 512m;
Database altered.
SQL> alter database add standby logfile '/u01/oradata/orcl/redo03_dg.log' size 512m;
Database altered.
SQL> alter database add standby logfile '/u01/oradata/orcl/redo04_dg.log' size 512m;
Database altered.
SQL> alter database add standby logfile '/u01/oradata/orcl/redo05_dg.log' size 512m;
Database altered.
SQL> alter database add standby logfile '/u01/oradata/orcl/redo06_dg.log' size 512m;
Database altered.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
13.备库增加standby log
增加standby log之前需要先暂停redo日志,否则会出错:
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo01_dg' size 512m;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo01_dg' size 512m
*
ERROR at line 1:
ORA-01156: recovery or flashback in progress may need access to files
standbylog的组数和在线日志的组数应该一样多
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo01_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo02_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo03_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo04_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo05_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo06_dg' size 512m;
Database altered.
14,同样的在主库上也增加standby log
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo01_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo02_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo03_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo04_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo05_dg' size 512m;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/oradata/orcl/redo06_dg' size 512m;
Database altered.
15.检查备库的日志是否接收和应用
备库开启日志同步:
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
71 RFS 08-OCT-18 08-OCT-18 YES
72 RFS 08-OCT-18 08-OCT-18 YES
73 RFS 08-OCT-18 08-OCT-18 YES
主库执行一次switch logfile:
SQL> alter system switch logfile;
System altered.
再次检查备库的日志状态:
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
71 RFS 08-OCT-18 08-OCT-18 YES
72 RFS 08-OCT-18 08-OCT-18 YES
73 RFS 08-OCT-18 08-OCT-18 YES
74 RFS 08-OCT-18 08-OCT-18 NO
已将74#新产生的log同步过来,不过applied还是“NO",说明还没有应用,过段时间系统会自动应用,稍后再检查一次:
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
71 RFS 08-OCT-18 08-OCT-18 YES
72 RFS 08-OCT-18 08-OCT-18 YES
73 RFS 08-OCT-18 08-OCT-18 YES
74 RFS 08-OCT-18 08-OCT-18 YES
再次检查时74#的applied状态已由"NO"改为"YES"
16.暂停standby log的应用时,主库的日志还是会传送到备库,只是不应用而已,待alter database recover managed standby database disconnect from session后会应用applied为”no"的日志:
备库暂停standby log应用:
SQL> alter database recover managed standby database cancel;
Database altered.
主库切换一次log
SQL> alter system switch logfile;
System altered.
备库已接收到刚刚的log,applied状态为"no"
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
71 RFS 08-OCT-18 08-OCT-18 YES
72 RFS 08-OCT-18 08-OCT-18 YES
73 RFS 08-OCT-18 08-OCT-18 YES
74 RFS 08-OCT-18 08-OCT-18 YES
75 RFS 08-OCT-18 08-OCT-18 NO
待恢复standby log后,会应用applied为"no"的日志,applied的状态”NO“→”IN-MEMORY“→”YES“
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
71 RFS 08-OCT-18 08-OCT-18 YES
72 RFS 08-OCT-18 08-OCT-18 YES
73 RFS 08-OCT-18 08-OCT-18 YES
74 RFS 08-OCT-18 08-OCT-18 YES
75 RFS 08-OCT-18 08-OCT-18 YES
17.备库的read only模式
备库可以承担一些查询的工作,分流主库的压力,这时就需要将备库以read only的模式打开
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open read only;
Database altered.
主库执行一些操作后做一次switch
SQL> conn l5m/l5m
Connected.
SQL> create table t_test as select * from dba_tables;
Table created.
SQL> conn / as sysdba
Connected.
SQL> alter system switch logfile;
System altered.
这时备库是read only的是不会应用主库的操作,新传过来的log的applied状态为“NO”
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
71 RFS 08-OCT-18 08-OCT-18 YES
72 RFS 08-OCT-18 08-OCT-18 YES
73 RFS 08-OCT-18 08-OCT-18 YES
74 RFS 08-OCT-18 08-OCT-18 YES
75 RFS 08-OCT-18 08-OCT-18 YES
76 RFS 08-OCT-18 08-OCT-18 NO
6 rows selected.
主库刚刚新建立的表并没有applied到备库:
SQL> select * from l5m.t_test;
select * from l5m.t_test
*
ERROR at line 1:
ORA-00942: table or view does not exist
重新开启standby log后,数据已同步过来了。
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
71 RFS 08-OCT-18 08-OCT-18 YES
72 RFS 08-OCT-18 08-OCT-18 YES
73 RFS 08-OCT-18 08-OCT-18 YES
74 RFS 08-OCT-18 08-OCT-18 YES
75 RFS 08-OCT-18 08-OCT-18 YES
76 RFS 08-OCT-18 08-OCT-18 YES
6 rows selected.
SQL> select count(*) from l5m.t_test;
COUNT(*)
----------
3446
11g 可以使用active standby,实现日志应用和查询同时进行。即Real-Time Apply + Real-Time Query.
这个功能后期会测试。