过程和Duplicate复制数据库并创建物理StandBy类似,只是不需要重启数据库。

目的:创建standby,不重启源数据库

1设定环境如下:

Primary数据库

IP 172.17.22.16
SID orcl

Standby数据库

IP 172.17.22.17
SID orcl_standby

设置提示,以区分操作的位置

primary数据库

set SQLPROMPT Primary>

standby数据库

set SQLPROMPT StandBy>

1、Primary端设置 归档模式

确保primary数据库运行在归档模式

Primary>archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 5
Current log sequence 7
Primary>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
Primary>startup mount
ORACLE instance started. Total System Global Area 3290345472 bytes
Fixed Size 2217832 bytes
Variable Size 1795164312 bytes
Database Buffers 1476395008 bytes
Redo Buffers 16568320 bytes
Database mounted.
Primary>alter database archivelog; Database altered. Primary>alter database open; Database altered. Primary>archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7
Primary>

2、Primary端开启强制日志

Primary>select force_logging from v$database;

FOR
---
NO Primary>alter database force logging; Database altered.

关于FORCE LOGGING

想必大家知道有一些DDL语句可以通过指定NOLOGGING子句的方式避免写redo log(目的是提高速度,某些时候确实有效),指定数据库为FORCE LOGGING模式后,数据库将会记录除临时表空间或临时回滚段外所有的操作而忽略类似NOLOGGING之类的指定参数。如果在执行force logging时有nologging之类的语句在执行,则force logging会等待直到这类语句全部执行。FORCE LOGGING是做为固定参数保存在控制文件中,因此其不受重启之类操作的影响(只执行一次即可),如果想取消,可以通过alter database no force logging语句关闭强制记录。

3、standby端创建相关目录

为了和Primary库保存相同的结构,我们需要在Standby数据库建立相同的目录,首先查询现有Primary数据库的相关目录

Primary>col name for a30
Primary>col value for a100
Primary>select name ,value from v$parameter where name in ('audit_file_dest','background_dump_dest','control_files','core_dump_dest','user_dump_dest') ORDER BY name ASC; NAME VALUE
------------------------------ ---------------------------------------------------------------------------------------------audit_file_dest /usr/oracle/app/admin/orcl/adump
background_dump_dest /usr/oracle/app/diag/rdbms/orcl/orcl/trace
control_files /usr/oracle/app/oradata/orcl/control01.ctl, /usr/oracle/app/flash_recovery_area/orcl/control02.ctl
core_dump_dest /usr/oracle/app/diag/rdbms/orcl/orcl/cdump
user_dump_dest /usr/oracle/app/diag/rdbms/orcl/orcl/trace

在standby数据库服务器创建如下的目录:

[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/admin/orcl_standby/adump
[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/diag/rdbms/orcl_standby/orcl_standby/trace
[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/oradata/orcl_standby
[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/flash_recovery_area/orcl_standby
[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/diag/rdbms/orcl_standby/orcl_standby/

3、创建辅助实例密钥文件

方法一: 直接从Primary数据库复制密钥文件过来      (如果ORACLE_SID不同 需要改名)

[oracle@oracledb dbs]$ scp orapworcl 172.17.22.17:/usr/oracle/standby/app/product/11.2.0/dbhome_1/dbs
oracle@172.17.22.17's password:
orapworcl 100% 1536 1.5KB/s 00:00
[oracle@oracledb dbs]$

改名

[oracle@oracledb dbs]$ mv orapworcl  orapworcl_standby

方法二: orapwd生成

orapwd FILE=/usr/oracle/standby/app/product/11.2.0/dbhome_1/dbs/orapworcl password=wangshengzhuang entries=30;

4、修改primary端初始化参数,

需要配置如下的参数,参数说明如下

1、与主库角色相关的初始化参数说明:

DB_NAME

注意保持同一个DataGuard环境中所有数据库DB_NAME相同

DB_UNIQUE_NAME

为每一个数据库指定一个唯一的名称,以标示同一个dataguard环境中不同的数据库。

LOG_ARCHIVE_CONFIG

该参数通过DG_CONFIG属性罗列同一个Data Guard中所有DB_UNIQUE_NAME(含主库db及备库db),以逗号分隔。

例如:LOG_ARCHIVE_CONFIG='DB_CONFIG=(orcl,orcl2)'

LOG_ARCHIVE_DEST_n

归档文件的生成路径。该参数非常重要,dataguard就是通过这里的设置传输日志的。

LOG_ARCHIVE_DEST_STATE_n

指定参数值为ENABLE,标示对应的LOG_ARCHIVE_DEST_n参数是否有效。

REMOTE_LOGIN_PASSWORDFILE

推荐设置参数值为EXCLUSIVE或者SHARED,注意保证相同Data Guard配置中所有db服务器sys密码相同。如果不同日志传输会失败。数据库默认是EXCLUSIVE,一般不用修改。

LOG_ARCHIVE_FORMAT

指定归档文件格式。一般也不用修改,保持默认即可

2、以下参数为备库角色相关的参数,建议在主库的初始化参数中也进行设置,这样在主备库角色相互转换后不需要做修改dataguard也能正常运行。

FAL_SERVER

指定备库到主数据库的连接服务名,FAL_SERVER = orcl2日志所在服务器。

FAL_CLIENT

指定主库到备库的连接服务名,FAL_CLIENT = orcl日志接收客户端。

STANDBY_FILE_MANAGEMENT

如果主库的数据文件发生修改(如新建,重命名等)则按照本参数的设置在备库中做相应修改。设为AUTO表示自动管理。设为MANUAL表示需要手工管理。

例如:STANDBY_FILE_MANAGEMENT=AUTO

在Primary端根据spfile生成pfile,并备份

Primary>create pfile from spfile;

File created.

查询Primary库的db_unique_name,(默认和db_name相同)

Primary>show parameter db_unique_name;

NAME                     TYPE            VALUE
------------------------------------ ---------------------- ------------------------------
db_unique_name string orcl

修改spfile参数值

-------为了不重启,沿用上面的db_unique_name
--alter system set DB_UNIQUE_NAME=orcl scope=spfile ----这里的orcl和orcl_standby为别为主库和备库的db_unique_name
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcl_standby)' scope=spfile -----这里的service为主库连接到备库的服务名,后面会在tnsnames.ora文件中配置 valid_for参数说明这个归档日志目的地在本数据库为主库的角色下才需要把online_logfile传输到备库去。arch async NOAFFIRM说明的是同步的方式,这个同步的方式有三种方式,最大保护,最大性能,最大可用。每个方式有不同的设置,具体见后面说明
alter system set LOG_ARCHIVE_DEST_2='SERVICE=tns_standby ARCH ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_standby'
----- 暂时不启用日志传送
alter system set LOG_ARCHIVE_DEST_STATE_2=DEFER ------以下修改的是作为备库角色需要的参数,为了方便以后主备库切换,建议在主库中也配置作为备库角色的相关参数。
alter system set FAL_SERVER=tns_standby
alter system set FAL_CLIENT=tns_primary
alter system set STANDBY_FILE_MANAGEMENT=AUTO
alter system set  DB_FILE_NAME_CONVERT='/usr/oracle/standby/app/oradata/orcl_standby/','/usr/oracle/app/oradata/orcl/' scope=spfile;
alter system set LOG_FILE_NAME_CONVERT='/usr/oracle/standby/app/oradata/orcl_standby/','/usr/oracle/app/oradata/orcl/' scope=spfile;

生成standby端的pfile

在Primary端根据spfile重新生成pfile,用以启动standby数据库

Primary>create pfile from spfile;

File created.

复制生成的initorcl.ora到standby的$ORACLE_HOME/dbs目录下,并改名(因为实例名不同)

[oracle@oracledb dbs]$ pwd
/usr/oracle/app/product/11.2.0/dbhome_1/dbs
[oracle@oracledb dbs]$ scp initorcl.ora 172.17.22.17:/usr/oracle/standby/app/product/11.2.0/dbhome_1/dbs
The authenticity of host '172.17.22.17 (172.17.22.17)' can't be established.
RSA key fingerprint is 72:28:f5:f9:9c:f8:49:23:48:6d:9d:d4:0e:0c:89:71.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.22.17' (RSA) to the list of known hosts.
oracle@172.17.22.17's password:
initorcl.ora 100% 1291 1.3KB/s 00:00
[oracle@oracledb dbs]$

改名

[oracle@oracledb dbs]$ mv initorcl.ora  initorcl_standby.ora

修改standbyd端的initorcl_standby.ora文件,内容如下

------这里的实例名要由orcl改为orcl_standby
orcl_standby.__db_cache_size=1476395008
orcl_standby.__java_pool_size=16777216
orcl_standby.__large_pool_size=16777216
orcl_standby.__oracle_base='/usr/oracle/app'#ORACLE_BASE set from environment
orcl_standby.__pga_aggregate_target=1325400064
orcl_standby.__sga_target=1979711488
orcl_standby.__shared_io_pool_size=0
orcl_standby.__shared_pool_size=436207616
orcl_standby.__streams_pool_size=0
*.audit_file_dest='/usr/oracle/standby/app/admin/orcl_standby/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/usr/oracle/standby/app/oradata/orcl_standby/control01.ctl','/usr/oracle/standby/app/flash_recovery_area/orcl_standby/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/usr/oracle/standby/app/flash_recovery_area'
*.db_recovery_file_dest_size=4070572032
*.diagnostic_dest='/usr/oracle/standby/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.memory_target=3299868672
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1' *.DB_UNIQUE_NAME=orcl_standby
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcl_standby)'
*.LOG_ARCHIVE_DEST_2='SERVICE=tns_primary ARCH ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
------路径转换

*.DB_FILE_NAME_CONVERT= '/usr/oracle/app/oradata/orcl/','/usr/oracle/standby/app/oradata/orcl_standby/'
   *.LOG_FILE_NAME_CONVERT='/usr/oracle/app/oradata/orcl/','/usr/oracle/standby/app/oradata/orcl_standby/'

*.FAL_SERVER=tns_primary 
*.FAL_CLIENT=tns_standby
*.STANDBY_FILE_MANAGEMENT=AUTO

通过复制的pfile创建Standby数据库的spfile

StandBy> create spfile from pfile;

File created.

启动到nomount环境

SQL> startup nomount
ORACLE instance started. Total System Global Area 3290345472 bytes
Fixed Size 2217832 bytes
Variable Size 1795164312 bytes
Database Buffers 1476395008 bytes
Redo Buffers 16568320 bytes

5、配置监听服务

Primary端监听(应该已经存在,大多数情况下不用重新配置)

# listener.ora Network Configuration File: /usr/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools. LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.22.16)(PORT = 1521))
)
) ADR_BASE_LISTENER = /usr/oracle/app

StandBy端监听(配置了静态监听 服务名GLOBAL_DBNAME = StandBy)

# listener.ora Network Configuration File: /usr/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools. SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = StandBy)
(ORACLE_HOME =/usr/oracle/standby/app/product/11.2.0/dbhome_1)
(SID_NAME = orcl_standby)
)
) LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.22.17)(PORT = 1521))
)
) ADR_BASE_LISTENER = /usr/oracle/app

启动standby端监听

[oracle@oracledb admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 23-DEC-2015 15:48:15

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Starting /usr/oracle/standby/app/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /usr/oracle/standby/app/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /usr/oracle/standby/app/diag/tnslsnr/oracledb/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.17.22.17)(PORT=1521))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 23-DEC-2015 15:48:16
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /usr/oracle/standby/app/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /usr/oracle/standby/app/diag/tnslsnr/oracledb/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.17.22.17)(PORT=1521)))
Services Summary...
Service "StandBy" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

6、配置网络服务名,并测试互通性

Primary端和StandBy端都要进行如下配置:

tns_primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.22.16)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
) tns_standby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.22.17)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME =StandBy )
)
)

***********************************************************************************************

SERVICE_NAME 的值参考lsnrctl的输出,确保用sqlplus工具或者navicact工具能够连接SERVICE_NAME

因为fal_server 会使用服务名,如果配置不正确,这归档日志无法正常发送

***********************************************************************************************

在primary端和standby端都进行测试(为了角色切换)

[oracle@oracledb admin]$ tnsping tns_primary

[oracle@oracledb admin]$ tnsping tns_standby

7、duplicate standby

rman连接两个数据库

[oracle@oracledb admin]$ rman target sys/wangshengzhuang@tns_primary auxiliary sys/wangshengzhuang@tns_standby

Recovery Manager: Release 11.2.0.1.0 - Production on Wed Dec 23 16:11:51 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1426832466)
connected to auxiliary database: ORCL (not mounted)

开始复制

RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;

Starting Duplicate Db at 23-DEC-15
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
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 12/23/2015 16:13:38
RMAN-05541: no archived logs found in target database

primary端切换下日志,quit重新执行rman duplicate即可

[oracle@oracledb ~]$ rman target sys/wangshengzhuang@tns_primary auxiliary sys/wangshengzhuang@tns_standby 

Recovery Manager: Release 11.2.0.1.0 - Production on Wed Dec 30 16:56:13 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1426832466)
connected to auxiliary database: ORCL (not mounted) RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK; Starting Duplicate Db at 30-DEC-15
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 contents of Memory Script:
{
backup as copy reuse
targetfile '/usr/oracle/app/product/11.2.0/dbhome_1/dbs/orapworcl' auxiliary format
'/usr/oracle/standby/app/product/11.2.0/dbhome_1/dbs/orapworcl_standby' ;
}
executing Memory Script Starting backup at 30-DEC-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 device type=DISK
Finished backup at 30-DEC-15 contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '/usr/oracle/standby/app/oradata/orcl_standby/control01.ctl';
restore clone controlfile to '/usr/oracle/standby/app/flash_recovery_area/orcl_standby/control02.ctl' from
'/usr/oracle/standby/app/oradata/orcl_standby/control01.ctl';
}
executing Memory Script Starting backup at 30-DEC-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/usr/oracle/app/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f tag=TAG20151230T165618 RECID=4 STAMP=899830578
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 30-DEC-15 Starting restore at 30-DEC-15
using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 30-DEC-15 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
"/usr/oracle/standby/app/oradata/orcl_standby/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/usr/oracle/standby/app/oradata/orcl_standby/system01.dbf";
set newname for datafile 2 to
"/usr/oracle/standby/app/oradata/orcl_standby/sysaux01.dbf";
set newname for datafile 3 to
"/usr/oracle/standby/app/oradata/orcl_standby/undotbs01.dbf";
set newname for datafile 4 to
"/usr/oracle/standby/app/oradata/orcl_standby/users01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/usr/oracle/standby/app/oradata/orcl_standby/system01.dbf" datafile
2 auxiliary format
"/usr/oracle/standby/app/oradata/orcl_standby/sysaux01.dbf" datafile
3 auxiliary format
"/usr/oracle/standby/app/oradata/orcl_standby/undotbs01.dbf" datafile
4 auxiliary format
"/usr/oracle/standby/app/oradata/orcl_standby/users01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /usr/oracle/standby/app/oradata/orcl_standby/temp01.dbf in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 30-DEC-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/usr/oracle/app/oradata/orcl/system01.dbf
output file name=/usr/oracle/standby/app/oradata/orcl_standby/system01.dbf tag=TAG20151230T165625
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/usr/oracle/app/oradata/orcl/sysaux01.dbf
output file name=/usr/oracle/standby/app/oradata/orcl_standby/sysaux01.dbf tag=TAG20151230T165625
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:16
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/usr/oracle/app/oradata/orcl/undotbs01.dbf
output file name=/usr/oracle/standby/app/oradata/orcl_standby/undotbs01.dbf tag=TAG20151230T165625
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/usr/oracle/app/oradata/orcl/users01.dbf
output file name=/usr/oracle/standby/app/oradata/orcl_standby/users01.dbf tag=TAG20151230T165625
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 30-DEC-15 sql statement: alter system archive log current contents of Memory Script:
{
backup as copy reuse
archivelog like "/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2015_12_30/o1_mf_1_8_c8772wkh_.arc" auxiliary format
"/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_%u_.arc" ;
catalog clone recovery area;
switch clone datafile all;
}
executing Memory Script Starting backup at 30-DEC-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=8 RECID=2 STAMP=899830620
output file name=/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 30-DEC-15 searching for all files in the recovery area List of Files Unknown to the Database
=====================================
File Name: /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc
cataloging files...
cataloging done List of Cataloged Files
=======================
File Name: /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=899830621 file name=/usr/oracle/standby/app/oradata/orcl_standby/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=5 STAMP=899830621 file name=/usr/oracle/standby/app/oradata/orcl_standby/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=899830621 file name=/usr/oracle/standby/app/oradata/orcl_standby/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=899830621 file name=/usr/oracle/standby/app/oradata/orcl_standby/users01.dbf contents of Memory Script:
{
set until scn 1027736;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script executing command: SET until clause Starting recover at 30-DEC-15
using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 8 is already on disk as file /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc
archived log file name=/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc thread=1 sequence=8
media recovery complete, elapsed time: 00:00:00
Finished recover at 30-DEC-15
Finished Duplicate Db at 30-DEC-15

8、启用日志传送

Primary>show parameter LOG_ARCHIVE_DEST_STATE_2

NAME                     TYPE            VALUE
------------------------------------ ---------------------- ------------------------------
log_archive_dest_state_2 string DEFER
log_archive_dest_state_20 string enable
log_archive_dest_state_21 string enable
log_archive_dest_state_22 string enable
log_archive_dest_state_23 string enable
log_archive_dest_state_24 string enable
log_archive_dest_state_25 string enable
log_archive_dest_state_26 string enable
log_archive_dest_state_27 string enable
log_archive_dest_state_28 string enable
log_archive_dest_state_29 string enable
Primary>alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE; System altered.

8、验证结果

查询primary数据库角色

Primary>select database_role from v$database;

DATABASE_ROLE
--------------------------------
PRIMARY

查询standby数据库角色

StandBy>select database_role from v$database;

DATABASE_ROLE
--------------------------------
PHYSICAL STANDBY StandBy>

primary端插入一条数据

Primary> INSERT INTO "SCOTT"."DEPT" ("DEPTNO", "DNAME", "LOC") VALUES ('12', 'OPERATIONS', 'OPERATIONS');

1 row created.

Primary>commit;

Commit complete.

Primary>alter system switch logfile;

System altered.

standby端:启动redo应用、暂停redo应用 打开数据库,查询数据是否被同步过来了

StandBy>alter database recover managed standby database disconnect from session;

Database altered.

StandBy>alter database recover managed standby database cancel;

Database altered.

StandBy>alter database open;

Database altered.

StandBy>select open_mode from v$database;

OPEN_MODE
----------------------------------------
READ ONLY StandBy>

见证奇迹的时刻:

StandBy>select * from scott.dept;

    DEPTNO DNAME            LOC
---------- ---------------------------- --------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
12 OPERATIONS OPERATIONS

9、启用实时应用redo

添加redo log

首先查询当前redo log的大小、位置

Primary>col group# for 9
Primary>col status for a10
Primary>col type for a10
Primary>col member for a50;
Primary>col is_rec for a10
Primary>select * from v$logfile; GROUP# STATUS TYPE MEMBER IS_REC
------ ---------- ---------- -------------------------------------------------- ------
3 ONLINE /usr/oracle/app/oradata/orcl/redo03.log NO
2 ONLINE /usr/oracle/app/oradata/orcl/redo02.log NO
1 ONLINE /usr/oracle/app/oradata/orcl/redo01.log NO Primary>select * from v$log; GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARCHIV STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME
------ ---------- ---------- ---------- ---------- ---------- ------ ---------- ------------- ------------ ------------ ------------
1 1 10 52428800 512 1 NO CURRENT 1029234 23-DEC-15 2.8147E+14
2 1 8 52428800 512 1 YES INACTIVE 1028340 23-DEC-15 1028421 23-DEC-15
3 1 9 52428800 512 1 YES INACTIVE 1028421 23-DEC-15 1029234 23-DEC-15

standby redo log的文件大小与primary数据库online redo log文件大小相同。

standby redo log的组数最好比主库online redo log多。

当前主库有三组、每组1个member、大小为50M, 我们在备库增加四组,每组1个member,大小为50M

StandBy>ALTER DATABASE ADD STANDBY  LOGFILE GROUP 4('/usr/oracle/standby/app/oradata/orcl_standby/stbyredolog4a.log') SIZE  50 M;

Database altered.

StandBy>ALTER DATABASE ADD STANDBY LOGFILE GROUP 5('/usr/oracle/standby/app/oradata/orcl_standby/stbyredolog5a.log') SIZE  50 M;

Database altered.

StandBy>ALTER DATABASE ADD STANDBY LOGFILE GROUP 6('/usr/oracle/standby/app/oradata/orcl_standby/stbyredolog6a.log') SIZE  50 M;

Database altered.

StandBy>ALTER DATABASE ADD STANDBY LOGFILE GROUP 7('/usr/oracle/standby/app/oradata/orcl_standby/stbyredolog7a.log') SIZE  50 M;

Database altered.

查询备库当前的日志

Standby>select group#, type, member from v$logfile;

GROUP# TYPE      MEMBER
----------------------------------------------------------------------------------------------------------------------------- 3 ONLINE /usr/oracle/standby/app/oradata/orcl_standby/redo03.log
2 ONLINE /usr/oracle/standby/app/oradata/orcl_standby/redo02.log
1 ONLINE /usr/oracle/standby/app/oradata/orcl_standby/redo01.log
4 STANDBY /usr/oracle/standby/app/oradata/orcl_standby/stbyredolog4a.log
5 STANDBY /usr/oracle/standby/app/oradata/orcl_standby/stbyredolog5a.log
6 STANDBY /usr/oracle/standby/app/oradata/orcl_standby/stbyredolog6a.log
7 STANDBY /usr/oracle/standby/app/oradata/orcl_standby/stbyredolog7a.log

为了switchover,我们在主库也增加4组standby redo log

Primary>ALTER DATABASE ADD STANDBY   LOGFILE GROUP 4('/usr/oracle/app/oradata/orcl/stbyredolog4a.log') SIZE  50 M;

Database altered.

Primary>ALTER DATABASE ADD STANDBY   LOGFILE GROUP 5('/usr/oracle/app/oradata/orcl/stbyredolog5a.log') SIZE  50 M;

Database altered.

Primary>ALTER DATABASE ADD STANDBY   LOGFILE GROUP 6('/usr/oracle/app/oradata/orcl/stbyredolog6a.log') SIZE  50 M;

Database altered.

Primary>ALTER DATABASE ADD STANDBY   LOGFILE GROUP 7('/usr/oracle/app/oradata/orcl/stbyredolog7a.log') SIZE  50 M;

Database altered.

查看结果:

Primary>select * from v$logfile;

GROUP# STATUS      TYPE         MEMBER                        IS_REC
------ ---------- ---------- -------------------------------------------------- ------
3 ONLINE /usr/oracle/app/oradata/orcl/redo03.log NO
2 ONLINE /usr/oracle/app/oradata/orcl/redo02.log NO
1 ONLINE /usr/oracle/app/oradata/orcl/redo01.log NO
4 STANDBY /usr/oracle/app/oradata/orcl/stbyredolog4a.log NO
5 STANDBY /usr/oracle/app/oradata/orcl/stbyredolog5a.log NO
6 STANDBY /usr/oracle/app/oradata/orcl/stbyredolog6a.log NO
7 STANDBY /usr/oracle/app/oradata/orcl/stbyredolog7a.log NO 7 rows selected.
 

更改primary和standby端的log_archive_dest_2、

更改Primary端的log_archive_dest_2

Primary>alter system set log_archive_dest_2='SERVICE=tns_standby LGWR ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_standby';

System altered.

更改standby端的log_archive_dest_2

Standby>alter system set log_archive_dest_2='SERVICE=tns_primary LGWR ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl';

System altered.

启用实时StandBy端redo应用

StandBy>alter database recover managed standby database using current logfile  disconnect from session;

验证:

首先在Primay端插入一条数据:

Primary>select * from scott.dept;

    DEPTNO DNAME            LOC
---------- ---------------------------- --------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
12 OPERATIONS OPERATIONS Primary>INSERT INTO "SCOTT"."DEPT" ("DEPTNO", "DNAME", "LOC") VALUES ('13', 'OPERATIONS', 'OPERATIONS'); 1 row created. Primary>commit; Commit complete.

standby端查看

StandBy>select * from scott.dept;
DEPTNO DNAME LOC
---------- ---------------------------- --------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
12 OPERATIONS OPERATIONS
13 OPERATIONS OPERATIONS 6 rows selected.

10、switchover

备库暂停 redo应用

StandBy>alter database recover managed standby database cancel;

Database altered.

查询主库是否支持switchover操作

Primary> select switchover_status from v$database;

SWITCHOVER_STATUS
----------------------------------------
TO STANDBY

查询备库是否支持switchover操作

StandBy> select switchover_status from v$database;

SWITCHOVER_STATUS
----------------------------------------
NOT ALLOWED

not allowed是因为主库还未变切换为standby

switchover,primary切换为物理standby,切换后查看数据库角色、打开模式、

Primary>alter database commit to switchover to physical standby;

Database altered.

Primary>shutdown immediate;
ORA-01507: database not mounted ORACLE instance shut down.
Primary>startup
ORACLE instance started. Total System Global Area 3290345472 bytes
Fixed Size 2217832 bytes
Variable Size 1795164312 bytes
Database Buffers 1476395008 bytes
Redo Buffers 16568320 bytes
Database mounted.
Database opened.
Primary>select open_mode from v$database; OPEN_MODE
----------------------------------------
READ ONLY Primary>select database_role from v$database; DATABASE_ROLE
--------------------------------
PHYSICAL STANDBY Primary>

如果报错ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected,关闭活动的连接即可

Primary>alter database commit to switchover to physical standby;
alter database commit to switchover to physical standby
*
ERROR at line 1:
ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected

物理standby切换为primary

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
----------------------------------------
SWITCHOVER PENDING

如果是SWITCHOVER PENDING,说明当前standby数据库没有启动redo应用,重新执行下面的命令即可

alter database recover managed standby database using current logfile  disconnect from session;

如果是session active 说明当前有用户连接到StandBy数据库,建议先断开这些连接,或者先关闭数据库,启动到mount状态(出现上面那个状态是你用sqlplus连接着主库,启动到mount状态就正常啦 )

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started. Total System Global Area 3290345472 bytes
Fixed Size 2217832 bytes
Variable Size 1795164312 bytes
Database Buffers 1476395008 bytes
Redo Buffers 16568320 bytes
Database mounted.
SQL> select switchover_status from v$database; SWITCHOVER_STATUS
----------------------------------------
TO PRIMARY

切换

StandBy>select switchover_status from v$database;

SWITCHOVER_STATUS
----------------------------------------
TO PRIMARY StandBy> alter database commit to switchover to primary; Database altered. StandBy>alter database open; Database altered. StandBy>select open_mode from v$database; OPEN_MODE
----------------------------------------
READ WRITE StandBy>select database_role from v$database; DATABASE_ROLE
--------------------------------
PRIMARY StandBy>

测试同上(插入删除),这里只进行简单测试

现在的Primay切换日志

SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
14 SQL> alter system switch logfile; System altered.

在现在的standby查询

SYS@orcl>select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
15

常用查询

1、查询进程的活动状态

select process,client_process,sequence#,status from v$managed_standby;

2、查询redo应用进度

select dest_name,archived_thread#,archived_seq#,applied_thread#,applied_seq#,db_unique_name from v$archive_dest_status where status ='VALID';

3、查询归档文件路径及创建信息

select name,creator,sequence#,applied,completion_time from v$archived_log;

4、查询归档历史

select first_time,first_change#,next_change#,sequence# from v$log_history;

select thread#,sequence#,applied from v$archived_log;

5、参看数据库的基本信息

select database_role,db_unique_name,open_mode,protection_mode,protection_level,switchover_status from v$database;

6、查询redo应用及redo传输服务的活动状态

select database_role,db_unique_name,open_mode,protection_mode,protection_level,switchover_status from v$database;

7、检查应用模式

StandBy>select recovery_mode from v$archive_dest_status where dest_id=2;

RECOVERY_MODE
----------------------------------------------
IDLE

取值

idle

managed:

managed real_time_apply:

8、在主库上执行只主要是查看日志归档目的地是否可用,如果远程归档目录不可用则error会显示错误信息

Primary>select dest_name,status,error from v$archive_dest;

DEST_NAME          STATUS     ERROR
------------------------- ---------- ----------------------------------------------------------------------------------------------------
LOG_ARCHIVE_DEST_1 VALID
LOG_ARCHIVE_DEST_2 VALID
LOG_ARCHIVE_DEST_3 INACTIVE
LOG_ARCHIVE_DEST_4 INACTIVE
LOG_ARCHIVE_DEST_5 INACTIVE
LOG_ARCHIVE_DEST_6 INACTIVE
LOG_ARCHIVE_DEST_7 INACTIVE
LOG_ARCHIVE_DEST_8 INACTIVE
LOG_ARCHIVE_DEST_9 INACTIVE
LOG_ARCHIVE_DEST_10 INACTIVE
LOG_ARCHIVE_DEST_11 INACTIVE
LOG_ARCHIVE_DEST_12 INACTIVE
LOG_ARCHIVE_DEST_13 INACTIVE
LOG_ARCHIVE_DEST_14 INACTIVE
LOG_ARCHIVE_DEST_15 INACTIVE
LOG_ARCHIVE_DEST_16 INACTIVE
LOG_ARCHIVE_DEST_17 INACTIVE
LOG_ARCHIVE_DEST_18 INACTIVE
LOG_ARCHIVE_DEST_19 INACTIVE
LOG_ARCHIVE_DEST_20 INACTIVE
LOG_ARCHIVE_DEST_21 INACTIVE
LOG_ARCHIVE_DEST_22 INACTIVE
LOG_ARCHIVE_DEST_23 INACTIVE
LOG_ARCHIVE_DEST_24 INACTIVE
LOG_ARCHIVE_DEST_25 INACTIVE
LOG_ARCHIVE_DEST_26 INACTIVE
LOG_ARCHIVE_DEST_27 INACTIVE
LOG_ARCHIVE_DEST_28 INACTIVE
LOG_ARCHIVE_DEST_29 INACTIVE
LOG_ARCHIVE_DEST_30 INACTIVE
LOG_ARCHIVE_DEST_31 INACTIVE
STANDBY_ARCHIVE_DEST VALID 32 rows selected.

9、查询归档日志的应用情况。主备库上查询结果不同,在主库上对于每个归档文件会有两条记录。

Standby>select name,SEQUENCE#,APPLIED from v$archived_log order by sequence#;

NAME                                                                    SEQUENCE# APPLIED
---------------------------------------------------------------------------------------------------------------------------------- ---------- ------------------
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc 8 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_9_c878jl2c_.arc 9 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_10_c878jl5h_.arc 10 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_11_c878jl92_.arc 11 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_12_c878zoqm_.arc 12 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_13_c87902oc_.arc 13 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_14_c879bdmq_.arc 14 YES
tns_primary 14 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_15_c879ty73_.arc 15 YES
tns_primary 15 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_16_c879yfv8_.arc 16 YES
tns_primary 16 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_17_c87bj8s9_.arc 17 YES
tns_primary 17 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_18_c87bmfnc_.arc 18 YES
tns_primary 18 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_19_c87kfnfc_.arc 19 YES
tns_primary 19 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_20_c87kozrv_.arc 20 YES
tns_primary 20 NO
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_21_c87kq3v1_.arc 21 YES
tns_primary 21 NO
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_22_c87kqj88_.arc 22 YES
tns_primary 22 NO
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_23_c87m0kpm_.arc 23 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_24_c87mch18_.arc 24 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_25_c87mn8sw_.arc 25 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_26_c87po9r6_.arc 26 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_27_c87pwj5t_.arc 27 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_28_c87px4hz_.arc 28 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_29_c87pzfbv_.arc 29 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_30_c87pzr9s_.arc 30 YES
/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_31_c87pzsk7_.arc 31 YES 33 rows selected. Standby>

10、查询dataguard状态信息

Standby>select message_num,message from v$dataguard_status;

MESSAGE_NUM MESSAGE
----------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 ARC0: Archival started
2 ARC1: Archival started
3 ARC2: Archival started
4 ARC1: Becoming the 'no FAL' ARCH
5 ARC2: Becoming the heartbeat ARCH
6 ARC3: Archival started
7 RFS[1]: Assigned to RFS process 5881
8 RFS[1]: Identified database type as 'physical standby': Client is ARCH pid 9099
9 RFS[2]: Assigned to RFS process 5892
10 RFS[2]: Identified database type as 'physical standby': Client is ARCH pid 9099
11 RFS[3]: Assigned to RFS process 5897
12 RFS[3]: Identified database type as 'physical standby': Client is ARCH pid 9101
13 Attempt to start background Managed Standby Recovery process
14 MRP0: Background Managed Standby Recovery process started
15 Managed Standby Recovery not using Real Time Apply
16 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_25_c87mn8sw_.arc
17 Media Recovery Waiting for thread 1 sequence 26
18 RFS[4]: Assigned to RFS process 5906
19 RFS[4]: Identified database type as 'physical standby': Client is ARCH pid 9099
20 RFS[5]: Assigned to RFS process 5911
21 RFS[5]: Identified database type as 'physical standby': Client is ARCH pid 9099
22 RFS[6]: Assigned to RFS process 5918
23 RFS[6]: Identified database type as 'physical standby': Client is ARCH pid 9099
24 RFS[7]: Assigned to RFS process 5925
25 RFS[7]: Identified database type as 'physical standby': Client is ARCH pid 9099
26 RFS[8]: Assigned to RFS process 5932
27 RFS[8]: Identified database type as 'physical standby': Client is ARCH pid 9099
28 RFS[9]: Assigned to RFS process 5938
29 RFS[9]: Identified database type as 'physical standby': Client is ARCH pid 9099
30 RFS[10]: Assigned to RFS process 5945
31 RFS[10]: Identified database type as 'physical standby': Client is ARCH pid 9099
32 RFS[11]: Assigned to RFS process 5952
33 RFS[11]: Identified database type as 'physical standby': Client is ARCH pid 9099
34 RFS[12]: Assigned to RFS process 5959
35 RFS[12]: Identified database type as 'physical standby': Client is ARCH pid 9099
36 RFS[13]: Assigned to RFS process 5970
37 RFS[13]: Identified database type as 'physical standby': Client is ARCH pid 9099
38 RFS[14]: Assigned to RFS process 5976
39 RFS[14]: Identified database type as 'physical standby': Client is ARCH pid 9099
40 RFS[15]: Assigned to RFS process 5984
41 RFS[15]: Identified database type as 'physical standby': Client is ARCH pid 9099
42 RFS[16]: Assigned to RFS process 5991
43 RFS[16]: Identified database type as 'physical standby': Client is ARCH pid 9099
44 RFS[17]: Assigned to RFS process 6006
45 RFS[17]: Identified database type as 'physical standby': Client is ARCH pid 9099
46 RFS[18]: Assigned to RFS process 6018
47 RFS[18]: Identified database type as 'physical standby': Client is ARCH pid 9099
48 RFS[19]: Assigned to RFS process 6024
49 RFS[19]: Identified database type as 'physical standby': Client is ARCH pid 9099
50 RFS[20]: Assigned to RFS process 6035
51 RFS[20]: Identified database type as 'physical standby': Client is ARCH pid 9099
52 RFS[21]: Assigned to RFS process 6047
53 RFS[21]: Identified database type as 'physical standby': Client is ARCH pid 9099
54 RFS[22]: Assigned to RFS process 6059
55 RFS[22]: Identified database type as 'physical standby': Client is ARCH pid 9099
56 RFS[23]: Assigned to RFS process 6070
57 RFS[23]: Identified database type as 'physical standby': Client is ARCH pid 9099
58 RFS[24]: Assigned to RFS process 6076
59 RFS[24]: Identified database type as 'physical standby': Client is ARCH pid 9099
60 RFS[25]: Assigned to RFS process 6082
61 RFS[25]: Identified database type as 'physical standby': Client is ARCH pid 9099
62 RFS[26]: Assigned to RFS process 6090
63 RFS[26]: Identified database type as 'physical standby': Client is ARCH pid 9099
64 RFS[27]: Assigned to RFS process 6097
65 RFS[27]: Identified database type as 'physical standby': Client is ARCH pid 9099
66 RFS[28]: Assigned to RFS process 6104
67 RFS[28]: Identified database type as 'physical standby': Client is ARCH pid 9099
68 RFS[29]: Assigned to RFS process 6110
69 RFS[29]: Identified database type as 'physical standby': Client is ARCH pid 9099
70 RFS[30]: Assigned to RFS process 6116
71 RFS[30]: Identified database type as 'physical standby': Client is ARCH pid 9099
72 RFS[31]: Assigned to RFS process 6123
73 RFS[31]: Identified database type as 'physical standby': Client is ARCH pid 9099
74 RFS[32]: Assigned to RFS process 6133
75 RFS[32]: Identified database type as 'physical standby': Client is ARCH pid 9099
76 RFS[33]: Assigned to RFS process 6144
77 RFS[33]: Identified database type as 'physical standby': Client is ARCH pid 9099
78 RFS[34]: Assigned to RFS process 6161
79 RFS[34]: Identified database type as 'physical standby': Client is ARCH pid 9099
80 RFS[35]: Assigned to RFS process 6167
81 RFS[35]: Identified database type as 'physical standby': Client is ARCH pid 9099
82 RFS[36]: Assigned to RFS process 6174
83 RFS[36]: Identified database type as 'physical standby': Client is ARCH pid 9099
84 RFS[37]: Assigned to RFS process 6181
85 RFS[37]: Identified database type as 'physical standby': Client is ARCH pid 9099
86 RFS[38]: Assigned to RFS process 6188
87 RFS[38]: Identified database type as 'physical standby': Client is ARCH pid 9099
88 RFS[39]: Assigned to RFS process 6201
89 RFS[39]: Identified database type as 'physical standby': Client is ARCH pid 9099
90 RFS[40]: Assigned to RFS process 6207
91 RFS[40]: Identified database type as 'physical standby': Client is ARCH pid 9099
92 RFS[41]: Assigned to RFS process 6214
93 RFS[41]: Identified database type as 'physical standby': Client is ARCH pid 9099
94 RFS[42]: Assigned to RFS process 6221
95 RFS[42]: Identified database type as 'physical standby': Client is ARCH pid 9099
96 RFS[43]: Assigned to RFS process 6232
97 RFS[43]: Identified database type as 'physical standby': Client is ARCH pid 9099
98 RFS[44]: Assigned to RFS process 6238
99 RFS[44]: Identified database type as 'physical standby': Client is ARCH pid 9099
100 RFS[45]: Assigned to RFS process 6244
101 RFS[45]: Identified database type as 'physical standby': Client is ARCH pid 9099
102 MRP0: Background Media Recovery cancelled with status 16037
103 MRP0: Background Media Recovery process shutdown
104 Managed Standby Recovery Canceled
105 RFS[46]: Assigned to RFS process 6253
106 RFS[46]: Identified database type as 'physical standby': Client is ARCH pid 9099
107 RFS[47]: Assigned to RFS process 6263
108 RFS[47]: Identified database type as 'physical standby': Client is ARCH pid 9099
109 RFS[48]: Assigned to RFS process 6270
110 RFS[48]: Identified database type as 'physical standby': Client is ARCH pid 9099
111 RFS[49]: Assigned to RFS process 6276
112 RFS[49]: Identified database type as 'physical standby': Client is ARCH pid 9099
113 RFS[50]: Assigned to RFS process 6284
114 RFS[50]: Identified database type as 'physical standby': Client is ARCH pid 9099
115 RFS[51]: Assigned to RFS process 6295
116 RFS[51]: Identified database type as 'physical standby': Client is ARCH pid 9099
117 RFS[52]: Assigned to RFS process 6301
118 RFS[52]: Identified database type as 'physical standby': Client is ARCH pid 9099
119 RFS[53]: Assigned to RFS process 6312
120 RFS[53]: Identified database type as 'physical standby': Client is ARCH pid 9099
121 RFS[54]: Assigned to RFS process 6320
122 RFS[54]: Identified database type as 'physical standby': Client is ARCH pid 9099
123 RFS[55]: Assigned to RFS process 6325
124 RFS[55]: Identified database type as 'physical standby': Client is ARCH pid 9099
125 RFS[56]: Assigned to RFS process 6332
126 RFS[56]: Identified database type as 'physical standby': Client is LGWR ASYNC pid 10167
127 Primary database is in MAXIMUM PERFORMANCE mode
128 ARC0: Beginning to archive thread 1 sequence 26 (1039145-1040585)
129 RFS[57]: Assigned to RFS process 6334
130 RFS[57]: Identified database type as 'physical standby': Client is LGWR ASYNC pid 10167
131 ARC0: Completed archiving thread 1 sequence 26 (0-0)
132 Primary database is in MAXIMUM PERFORMANCE mode
133 RFS[58]: Assigned to RFS process 6339
134 RFS[58]: Identified database type as 'physical standby': Client is ARCH pid 9099
135 RFS[59]: Assigned to RFS process 6356
136 RFS[59]: Identified database type as 'physical standby': Client is ARCH pid 9099
137 Attempt to start background Managed Standby Recovery process
138 MRP0: Background Managed Standby Recovery process started
139 Managed Standby Recovery starting Real Time Apply
140 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_26_c87po9r6_.arc
141 Media Recovery Waiting for thread 1 sequence 27 (in transit)
142 RFS[60]: Assigned to RFS process 6364
143 RFS[60]: Identified database type as 'physical standby': Client is ARCH pid 9099
144 MRP0: Background Media Recovery cancelled with status 16037
145 Managed Standby Recovery not using Real Time Apply
146 MRP0: Background Media Recovery process shutdown
147 Managed Standby Recovery Canceled
148 RFS[61]: Assigned to RFS process 6373
149 RFS[61]: Identified database type as 'physical standby': Client is ARCH pid 9099
150 ARC1: Beginning to archive thread 1 sequence 27 (1040585-1040839)
151 ARC1: Completed archiving thread 1 sequence 27 (0-0)
152 RFS[62]: Assigned to RFS process 6378
153 RFS[62]: Identified database type as 'physical standby': Client is ARCH pid 9099
154 RFS[63]: Assigned to RFS process 6382
155 RFS[63]: Identified database type as 'physical standby': Client is Foreground pid 9102
156 ARC3: Beginning to archive thread 1 sequence 28 (1040839-1040863)
157 ARC3: Completed archiving thread 1 sequence 28 (0-0)
158 RFS[64]: Assigned to RFS process 6386
159 RFS[64]: Identified database type as 'physical standby': Client is ARCH pid 9099
160 RFS[65]: Assigned to RFS process 6393
161 RFS[65]: Identified database type as 'physical standby': Client is ARCH pid 9095
162 ARC0: Beginning to archive thread 1 sequence 29 (1040863-1040945)
163 ARC0: Completed archiving thread 1 sequence 29 (0-0)
164 RFS[66]: Assigned to RFS process 6395
165 RFS[66]: Identified database type as 'physical standby': Client is ARCH pid 9099
166 RFS[67]: Assigned to RFS process 6400
167 RFS[67]: Identified database type as 'physical standby': Client is Foreground pid 9102
168 ARC1: Beginning to archive thread 1 sequence 30 (1040945-1040959)
169 ARC1: Completed archiving thread 1 sequence 30 (0-0)
170 RFS[68]: Assigned to RFS process 6404
171 RFS[68]: Identified database type as 'physical standby': Client is Foreground pid 9102
172 RFS[69]: Assigned to RFS process 6406
173 RFS[69]: Identified database type as 'physical standby': Client is Foreground pid 9102
174 Attempt to start background Managed Standby Recovery process
175 MRP0: Background Managed Standby Recovery process started
176 Managed Standby Recovery starting Real Time Apply
177 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_27_c87pwj5t_.arc
178 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_28_c87px4hz_.arc
179 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_29_c87pzfbv_.arc
180 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_30_c87pzr9s_.arc
181 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_31_c87pzsk7_.arc
182 Resetting standby activation ID 1427590416 (0x55174d10)
183 MRP0: Media Recovery Complete: End-Of-REDO
184 MRP0: Background Media Recovery process shutdown
185 ALTER DATABASE SWITCHOVER TO PRIMARY
186 ARC0: Becoming the 'no SRL' ARCH
187 ARC0: Becoming the 'no SRL' ARCH
188 ARC1: Becoming the 'no SRL' ARCH 188 rows selected.

11、查看是否有日志缺失

Standby>select * from v$archive_gap;

no rows selected

主备库的起停和维护

Dataguard关闭(先关主库再关备库)

Dataguard开启(先开备库再开主库)

Failover切换方法

(1)判断主数据库确实出现严重的硬件故障或其他原因导致主数据库无法启动。

(2)在物理备用数据库上检查是否有archive redo log gaps

Standby>SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

no rows selected

如果有则消除archive redo log gaps

从主数据库上或其他备份的地方把没有传到物理备用数据库的archive redo log传到物理备用数据库上,并注册到物理备用数据库的controlfile中。

SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'archive redo log文件名称';

重复2,3步骤直到V$ARCHIVE_GAP视图无记录存在。

(3)查看归档文件是否完整

主库备库分别执行下面语句,取得各个线程已经归档的文件最大的序号,如果最大序号不同,则必须将多出的序号对应的归档文件复制到待转换的standby服务器(也有可能primary库已经无法打开了)

SQL> select distinct  thread#, max(sequence#)  over  (partition by  thread#) from v$archived_log;

   THREAD#   MAX(SEQUENCE#)OVER(PARTITIONBYTHREAD#)
---------- --------------------------------------
1 84 SQL> select max(sequence#) from v$archived_log; MAX(SEQUENCE#)
--------------
84

(4)在物理备用数据库上发起failover操作

SQL > ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;

(5)把物理备用数据库转化成主用角色

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

(6)把新的主用数据库重新启动

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP;

(7)对新的主用数据库做全备份.

Duplicate复制数据库并创建物理StandBy(spfile+不同实例名+不同路径)的更多相关文章

  1. Duplicate复制数据库并创建物理StandBy(spfile+不同实例名)

    过程和Duplicate复制数据库并创建物理StandBy类似,只是不需要重启数据库. 目的:创建standby,不重启源数据库 1设定环境如下: Primary数据库 IP 172.17.22.16 ...

  2. Duplicate复制数据库并创建物理StandBy(spfile版本)

    过程和Duplicate复制数据库并创建物理StandBy类似,只是不需要重启数据库. 目的:创建standby,不重启源数据库 1设定环境如下: Primary数据库 IP 172.17.22.16 ...

  3. Duplicate复制数据库并创建物理StandBy(pfile版本)

    1设定环境如下: Primary数据库 IP 172.17.22.16 SID orcl Standby数据库 IP 172.17.22.17 SID orcl 设置提示,以区分操作的位置 prima ...

  4. 11g 使用rman duplicate复制数据库,创建辅助实例

    一,创建所需目录 1)创建审计文件目录 PROD1@dbrac1 /dsg/oracle11$ cd $ORACLE_BASE/admin PROD1@dbrac1 /u01/app/oracle/a ...

  5. 使用RMAN DUPLICATE...FROM ACTIVE DATABASE创建物理standby database

    Applies to: Oracle Server - Enterprise Edition - Version 11.1.0.6 to 11.2.0.4 [Release 11.1 to 11.2] ...

  6. 11g使用非duplicate方式创建物理standby要注意的问题总结

    在上篇博文中,使用了duplicate方式来创建物理standby http://blog.csdn.net/aaron8219/article/details/38434579 今天来说说在11g中 ...

  7. Oracle 11gR2 使用RMAN Duplicate复制数据库

    Oracle 11gR2 使用RMAN Duplicate复制数据库     前言:     上周刚做完一个项目,用户要求RAC的数据库可以自己主动备份到另外一个单节点上,单节点可以正常拿起来就能用. ...

  8. Oracle 11gR2使用RMAN duplicate复制数据库

    11g的RMAN duplicate 个人感觉比10g的先进了很多,10g需在rman备份的基础上进行复制,使用RMAN duplicate创建一个数据完全相同但DBID不同的数据库.而11g的RMA ...

  9. Oracle Data Guard 创建物理Standby数据库

    创建物理备库 机器名                    a1                    a2                    IP:                    192 ...

随机推荐

  1. MVC开发中的常见错误-05-无法将类型“System.Data.Entity.Infrastructure.DbQuery<BBFJ.OA.Model.RoleInfo>”转换为“System.Collections.Generic.List<BBFJ.OA.Model.RoleInfo>”

    List<RoleInfo> roleInfoList = (List<RoleInfo>)ViewBag.AllRoles; 错误原因很明确了 ViewBag.AllRole ...

  2. Ext.js入门:TreePanel(九)

    一:最简单的树 二:通过TreeNode自定义静态树 三:用TreeLoader加载数据生成树 四:解决IE下非正常加载节点问题 五:使用TreeNodeUI 六:带有checkbox的树 七:编辑树 ...

  3. ELK - MAC环境搭建

    ELK - MAC环境搭建 本文旨在记录elasticsearch.logstash.kibana在mac下的安装与启动. 写在前面 ELK的官方文档对与它们的使用方法已经讲的非常清楚了,这里只对相关 ...

  4. POJ 2010 Moo University - Financial Aid (优先队列)

    题意:从C头奶牛中招收N(奇数)头.它们分别得分score_i,需要资助学费aid_i.希望新生所需资助不超过F,同时得分中位数最高.求此中位数. 思路: 先将奶牛排序,考虑每个奶牛作为中位数时,比它 ...

  5. 手动卸载Office2010

    手动卸载Office2010视频 http://v.youku.com/v_show/id_XNTE3MTMwNDUy.html 其中遇到Application Data文件夹打不开 http://z ...

  6. 练习|Django-单表

    结构目录 页面展示: 1创建Django,创建app01 在modules.py添加 class Book(models.Model): id=models.AutoField(primary_key ...

  7. mac电脑对ntfs格式硬盘进行写操作(简单说就是向ntfs硬盘拷贝东西)

    使用mac电脑的童鞋应该都会遇到一个问题: 对ntfs格式的优盘或硬盘(移动硬盘默认ntfs)只能读不能写,也就是只能拷贝出数据,却没法拷贝数据到移动硬盘中. 下面是参考自网上的一种方法,无需第三方软 ...

  8. Linux学习之Vim/Vi使用(十三)

    Linux学习之Vim/Vi使用 Vim/Vi简介 Vim/Vi工作模式 Vim/Vi基本使用 Vim/Vi应用技巧 Vim/Vi简介 Vim/Vi是一个功能强大的全屏幕文本编辑器,是Linux/UN ...

  9. MacBook快速入门

    入职新美大,全面进入Mac工作环境,果断"撸起袖子加油干","浪起来,逼格提起来".顺道提一嘴,这边的兄弟们的干劲是真心足,作为一名老兵痞,必须要虚心向身边NX ...

  10. SQL EXCEPT INTERSECT

    EXCEPT是指在第一个集合中存在,但是不存在于第二个集合中的数据. INTERSECT是指在两个集合中都存在的数据. )) go )) go insert into t1 ,'t1' union a ...