centOS7.3下搭建oracle11g 11.2.0.4 ADG部署

预先准备的环境:

两台主机,操作系统centOS7.3

[email protected][/root]#cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

两台上面都部署好了oracle11.2.0.4的oracle软件。

两台ip分布:

主库:172.16.22.110

备库:172.16.23.111

实例规划:

主库实例名/库名:scc/scc

备库实例名/库名:tcc/tcc

主库需要建库完成,库名和实例名满足如上说明。

备库只需要安装oracle11.2.0.4软件完成即可。

一、监听和tns配置

主库监听配置

vi $ORACLE_HOME/network/admin/listener.ora

LISTENER =
        (DESCRIPTION_LIST =
                (DESCRIPTION =
                        (ADDRESS_LIST =
                        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.110)(PORT = 1521))
                )
        )
)
SID_LIST_LISTENER =
(SID_LIST =
        (SID_DESC =
                (GLOBAL_DBNAME = scc)
                (ORACLE_HOME = /oracle11/product/112)
                (SID_NAME = scc)
        )
)

主库tns配置

vi $ORACLE_HOME/network/admin/tnsnames.ora

scc =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.110)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = scc)
    )
  )

从库配置监听

vi $ORACLE_HOME/network/admin/listener.ora

LISTENER =
        (DESCRIPTION_LIST =
                (DESCRIPTION =
                        (ADDRESS_LIST =
                        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.111)(PORT = 1521))
                )
        )
)


SID_LIST_LISTENER =
(SID_LIST =
        (SID_DESC =
                (GLOBAL_DBNAME = tcc)
                (ORACLE_HOME = /oracle11/product/112)
                (SID_NAME = tcc)
        )
)

从库配置tns

vi $ORACLE_HOME/network/admin/tnsnames.ora

tcc =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.111)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = tcc)
    )
  )

sqlplus登陆主库

export ORACLE_SID=scc

sqlplus / as sysdba

主库开启强制日志模式

SQL> alter database force logging;

Database altered.

主库开归档

SQL> archive log list ;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     16
Current log sequence           18
SQL> shutdow immediate 
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount ;
ORACLE instance started.

Total System Global Area 2471931904 bytes
Fixed Size                  2255752 bytes
Variable Size             553649272 bytes
Database Buffers         1895825408 bytes
Redo Buffers               20201472 bytes
SQL> alter database mount ;

Database altered.


SQL> alter database archivelog ;

Database altered.

查看主库日志,添加备用日志

SQL> select group#, member from v$logfile;

    GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
         1
/oracle11/oradata/scc/redo01.log

         2
/oracle11/oradata/scc/redo02.log

         3
/oracle11/oradata/scc/redo03.log

添加备用日志:

alter database add standby logfile 
'/oracle11/oradata/scc/redo04.log' size 50M ;

alter database add standby logfile 
'/oracle11/oradata/scc/redo05.log' size 50M ;

alter database add standby logfile 
'/oracle11/oradata/scc/redo06.log' size 50M ;

alter database add standby logfile 
'/oracle11/oradata/scc/redo07.log' size 50M ;

查看当前使用的spfile

SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /oracle11/product/112/dbs/spfi
                                                 lescc.ora

通过当前使用spfile创建新的pfile

SQL> create pfile from spfile ;

File created.

创建的pfile默认在$ORACLE_HOME/dbs目录下

oracle11@scc[/oracle11/product/112/dbs]$ll
-rw-r--r--. 1 oracle11 dba  937 Aug  4 14:26 initscc.ora

修改主库新创建的pfile

oracle11@scc[/oracle11/product/112/dbs]$cat initscc.ora
scc.__db_cache_size=1895825408
scc.__java_pool_size=16777216
scc.__large_pool_size=16777216
scc.__oracle_base='/oracle11'#ORACLE_BASE set from environment
scc.__pga_aggregate_target=838860800
scc.__sga_target=2483027968
scc.__shared_io_pool_size=0
scc.__shared_pool_size=520093696
scc.__streams_pool_size=0
*.audit_file_dest='/oracle11/admin/scc/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/oracle11/oradata/scc/control01.ctl','/oracle11/fast_recovery_area/scc/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='scc'
*.db_recovery_file_dest='/oracle11/fast_recovery_area'
*.db_recovery_file_dest_size=5218762752
*.diagnostic_dest='/oracle11'
*.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.110)(PORT = 1521))'
*.open_cursors=300
*.pga_aggregate_target=823132160
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=335
*.sga_target=2470445056
*.undo_tablespace='UNDOTBS1'



##add by wufan 20180804 14:43
#DB_NAME=scc
DB_UNIQUE_NAME=scc
LOG_ARCHIVE_CONFIG='DG_CONFIG=(scc,tcc)'
LOG_ARCHIVE_DEST_1=
 'LOCATION=/oracle11/fast_recovery_area/archive
  VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
  DB_UNIQUE_NAME=scc'
LOG_ARCHIVE_DEST_2=
 'SERVICE=tcc ASYNC
  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
  DB_UNIQUE_NAME=tcc'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
#REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=4
DB_FILE_NAME_CONVERT='tcc','scc'
LOG_FILE_NAME_CONVERT='tcc','scc'
STANDBY_FILE_MANAGEMENT=AUTO

文件中上多行空行之上的部分是本来就有的,不需要动。我们需要修改是添加空行下面的部分。

下面有注释掉的两行DB_NAME和REMOTE_LOGIN_PASSWORDFILE两项,是因为上面有,所以注释了,如果上面没有,就需要放开注释。

修改完成后保存退出。

下面就需要根据新修改的pfile文件重启scc主库。

停库

SQL> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

起库到nomount阶段

SQL> startup nomount pfile=/oracle11/product/112/dbs/initscc.ora
ORACLE instance started.

Total System Global Area 2471931904 bytes
Fixed Size                  2255752 bytes
Variable Size             553649272 bytes
Database Buffers         1895825408 bytes
Redo Buffers               20201472 bytes
SQL> select instance_name,status from v$instance ;

INSTANCE_NAME    STATUS
---------------- ------------
scc              STARTED

SQL> 

根据新的pfile文件创建新的spfile文件

SQL> create spfile from pfile ;

File created.

SQL> 

新建的spfile也会在默认的$ORACLE_HOME/dbs/spfiletcc.ora下面

oracle11@scc[/oracle11/product/112/dbs]$ll
-rw-r-----. 1 oracle11 dba 4608 Aug  4 14:47 spfilescc.ora

再次停库然后重启,此时使用默认的spfile文件

SQL> shutdown immediate ; 
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> 

SQL> startup
ORACLE instance started.

Total System Global Area 2471931904 bytes
Fixed Size                  2255752 bytes
Variable Size             553649272 bytes
Database Buffers         1895825408 bytes
Redo Buffers               20201472 bytes
Database mounted.
Database opened.
SQL> show parameter pfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /oracle11/product/112/dbs/spfi
                                                 lescc.ora
SQL> 

下面就需要把主库的$ORACLE_HOME/dbs/inittcc.ora和$ORACLE_HOME/dbs/orapwtcc两个文件scp到备库上对应的目录上去

oracle11@scc[/oracle11/product/112/dbs]$scp initscc.ora [email protected]:/oracle11/product/112/dbs/inittcc.ora
The authenticity of host '172.16.22.111 (172.16.22.111)' can't be established.
ECDSA key fingerprint is 01:5f:2b:19:ae:61:5b:5e:6b:9f:7e:2e:5a:03:65:4d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.22.111' (ECDSA) to the list of known hosts.
[email protected]'s password: 
initscc.ora                                                                                       100% 1533     1.5KB/s   00:00    
oracle11@scc[/oracle11/product/112/dbs]$scp orapwscc [email protected]:/oracle11/product/112/dbs/orapwtcc
[email protected]'s password: 
orapwscc                                                                                          100% 1536     1.5KB/s   00:00    
oracle11@scc[/oracle11/product/112/dbs]$

下面要做的工作,是通过主库scp过来的初始化参数文件和密码文件能把库启动到nomount阶段

备库上修改$ORACLE_HOME/dbs/inittcc.ora

vi $ORACLE_HOME/dbs/inittcc.ora

在控制模式下进行如下操作:

1、把scc都改成scc_tmp;

2、把tcc都改成scc;

3、把scc_tmp改成tcc

4、在把DB_NAME这项改回SCC

命令使用如下:

将文件中所有的scc替换成scc_tmp:

:%s/scc/scc_tmp/g

将文件中所有的tcc换成scc:

:%s/tcc/scc/g

将文件中所有的scc_tmp换成tcc:

:%s/scc_tmp/tcc/g

注意:

主备库的pfile参数文件中DB_NAME一项都要是相同的,都是SCC。也就是主库名。

备库初始化参数文件如下:

[email protected][/oracle11/product/112/dbs]$cat inittcc.ora
tcc.__db_cache_size=1895825408
tcc.__java_pool_size=16777216
tcc.__large_pool_size=16777216
tcc.__oracle_base='/oracle11'#ORACLE_BASE set from environment
tcc.__pga_aggregate_target=838860800
tcc.__sga_target=2483027968
tcc.__shared_io_pool_size=0
tcc.__shared_pool_size=520093696
tcc.__streams_pool_size=0
*.audit_file_dest='/oracle11/admin/tcc/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/oracle11/oradata/tcc/control01.ctl','/oracle11/fast_recovery_area/tcc/control02.ctl'
*.db_block_size=8192
*.db_domain=''
#*.db_name='scc'
*.db_recovery_file_dest='/oracle11/fast_recovery_area'
*.db_recovery_file_dest_size=5218762752
*.diagnostic_dest='/oracle11'
*.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.110)(PORT = 1521))'
*.open_cursors=300
*.pga_aggregate_target=823132160
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=335
*.sga_target=2470445056
*.undo_tablespace='UNDOTBS1'



##add by wufan 20180804 14:43
DB_NAME=scc
DB_UNIQUE_NAME=tcc
LOG_ARCHIVE_CONFIG='DG_CONFIG=(tcc,scc)'
LOG_ARCHIVE_DEST_1=
 'LOCATION=/oracle11/fast_recovery_area/archive
  VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
  DB_UNIQUE_NAME=tcc'
LOG_ARCHIVE_DEST_2=
 'SERVICE=scc ASYNC
  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
  DB_UNIQUE_NAME=scc'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
#REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=4
DB_FILE_NAME_CONVERT='scc','tcc'
LOG_FILE_NAME_CONVERT='scc','tcc'
STANDBY_FILE_MANAGEMENT=AUTO

此时初始化参数文件有了,就可以把备库起到nomount阶段了

备库

export ORACLE_SID=tcc

[email protected][/oracle11/product/112/dbs]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sat Aug 4 23:28:36 2018

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile=/oracle11/product/112/dbs/inittcc.ora
ORACLE instance started.

Total System Global Area 2471931904 bytes
Fixed Size                  2255752 bytes
Variable Size             553649272 bytes
Database Buffers         1895825408 bytes
Redo Buffers               20201472 bytes
SQL> 

配置备库的tns,把主库的tns加进去

备库

vi $ORACLE_HOME/network/admin/tnsnames.ora

添加:

scc =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.110)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = scc)
    )
  )

测试tns是否通

[email protected][/oracle11/product/112/network/admin]$tnsping scc

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 04-AUG-2018 23:07:51

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.110)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = scc)))
OK (0 msec)

配置主库的tns,把备库的tns加进去

主库

vi $ORACLE_HOME/network/admin/tnsnames.ora

添加:

tcc =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.111)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = tcc)
    )
  )

同上使用tnsping tcc测试连通性。

下面起备库监听

备库

[email protected][/oracle11/product/112/network/admin]$lsnrctl start LISTENER_TCC

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 09-AUG-2018 00:24:58

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

Starting /oracle11/product/112/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /oracle11/product/112/network/admin/listener.ora
Log messages written to /oracle11/diag/tnslsnr/CentOS7/listener_tcc/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.16.22.111)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.22.111)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_TCC
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                09-AUG-2018 00:24:58
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle11/product/112/network/admin/listener.ora
Listener Log File         /oracle11/diag/tnslsnr/CentOS7/listener_tcc/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.16.22.111)(PORT=1521)))
The listener supports no services
The command completed successfully
[email protected][/oracle11/product/112/network/admin]$

如果出现了图中这种情况:

The listener supports no services

表示实例未注册到监听中去,提供下面三种解决办法:

1、listener.ora配置文件中:

SID_LIST_LISTENER =
(SID_LIST =
        (SID_DESC =
                (GLOBAL_DBNAME = scc)
                (ORACLE_HOME = /oracle11/product/112)
                (SID_NAME = scc)
        )
)

如果没有飘红的两项,加上。

2、可以直接sqlplus登陆,手工注册

[email protected][/oracle11/product/112/network/admin]$export ORACLE_SID=tcc
[email protected][/oracle11/product/112/network/admin]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 9 00:29:07 2018

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> alter system register ;

System altered.

SQL> 

上面两步都需要重启监听。

3、如果还不行,那就是我这种情况,改监听名,改成默认的

listener.ora配置:

LISTENER =
        (DESCRIPTION_LIST =
                (DESCRIPTION =
                        (ADDRESS_LIST =
                        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.110)(PORT = 1521))
                )
        )
)

把这个监听名称改成默认的名称,我现在为了重现这个问题特意改成了LISTENER_TCC

LISTENER_TCC =
        (DESCRIPTION_LIST =
                (DESCRIPTION =
                        (ADDRESS_LIST =
                        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.110)(PORT = 1521))
                )
        )
)

我把他改回来:

[email protected][/oracle11/product/112/network/admin]$cat listener.ora 
LISTENER =
        (DESCRIPTION_LIST =
                (DESCRIPTION =
                        (ADDRESS_LIST =
                        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.22.111)(PORT = 1521))
                )
        )
)
SID_LIST_LISTENER =
(SID_LIST =
        (SID_DESC =
                (GLOBAL_DBNAME = tcc)
                (ORACLE_HOME = /oracle11/product/112)
                (SID_NAME = tcc)
        )
)

然后在重启监听:

[email protected][/oracle11/product/112/network/admin]$lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 09-AUG-2018 00:33:26

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.22.111)(PORT=1521)))
The command completed successfully
[email protected][/oracle11/product/112/network/admin]$lsnrctl start 

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 09-AUG-2018 00:33:33

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

Starting /oracle11/product/112/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /oracle11/product/112/network/admin/listener.ora
Log messages written to /oracle11/diag/tnslsnr/CentOS7/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.16.22.111)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.22.111)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                09-AUG-2018 00:33:33
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle11/product/112/network/admin/listener.ora
Listener Log File         /oracle11/diag/tnslsnr/CentOS7/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.16.22.111)(PORT=1521)))
Services Summary...
Service "tcc" has 1 instance(s).
  Instance "tcc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[email protected][/oracle11/product/112/network/admin]$

解决了。

下面就可以进行rman连接了

主库

11gR2:

rman target / auxiliary sys/ztesoft@tcc

12cR2

rman target sys/oracle auxiliary sys/ztesoft@tcc

11g和12c连接本地库的时候,11g不要求提供用户,但是12c昨天测试提示了要求用户名,这个看情况吧,如果要求提供加上就是了。

oracle11@scc[/oracle11/product/112/network/admin]$rman target / auxiliary sys/ztesoft@tcc

Recovery Manager: Release 11.2.0.4.0 - Production on Sat Aug 4 15:30:03 2018

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

connected to target database: SCC (DBID=2571255956)
connected to auxiliary database: SCC (not mounted)

RMAN> duplicate target database for standby from active database;

Starting Duplicate Db at 04-AUG-18
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=10 device type=DISK

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/oracle11/product/112/dbs/orapwscc' auxiliary format 
 '/oracle11/product/112/dbs/orapwtcc'   ;
}
executing Memory Script

Starting backup at 04-AUG-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=256 device type=DISK
Finished backup at 04-AUG-18

contents of Memory Script:
{
   backup as copy current controlfile for standby auxiliary format  '/oracle11/oradata/tcc/control01.ctl';
   restore clone controlfile to  '/oracle11/fast_recovery_area/tcc/control02.ctl' from 
 '/oracle11/oradata/tcc/control01.ctl';
}
executing Memory Script

Starting backup at 04-AUG-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/oracle11/product/112/dbs/snapcf_scc.f tag=TAG20180804T153057 RECID=1 STAMP=983287857
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 04-AUG-18

Starting restore at 04-AUG-18
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 04-AUG-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 
 "/oracle11/oradata/tcc/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to 
 "/oracle11/oradata/tcc/system01.dbf";
   set newname for datafile  2 to 
 "/oracle11/oradata/tcc/sysaux01.dbf";
   set newname for datafile  3 to 
 "/oracle11/oradata/tcc/undotbs01.dbf";
   set newname for datafile  4 to 
 "/oracle11/oradata/tcc/users01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format 
 "/oracle11/oradata/tcc/system01.dbf"   datafile 
 2 auxiliary format 
 "/oracle11/oradata/tcc/sysaux01.dbf"   datafile 
 3 auxiliary format 
 "/oracle11/oradata/tcc/undotbs01.dbf"   datafile 
 4 auxiliary format 
 "/oracle11/oradata/tcc/users01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /oracle11/oradata/tcc/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 04-AUG-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/oracle11/oradata/scc/system01.dbf
output file name=/oracle11/oradata/tcc/system01.dbf tag=TAG20180804T153105
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/oracle11/oradata/scc/sysaux01.dbf
output file name=/oracle11/oradata/tcc/sysaux01.dbf tag=TAG20180804T153105
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/oracle11/oradata/scc/undotbs01.dbf
output file name=/oracle11/oradata/tcc/undotbs01.dbf tag=TAG20180804T153105
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=/oracle11/oradata/scc/users01.dbf
output file name=/oracle11/oradata/tcc/users01.dbf tag=TAG20180804T153105
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 04-AUG-18

sql statement: alter system archive log current

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=983316838 file name=/oracle11/oradata/tcc/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=983316838 file name=/oracle11/oradata/tcc/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=983316838 file name=/oracle11/oradata/tcc/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=983316838 file name=/oracle11/oradata/tcc/users01.dbf
Finished Duplicate Db at 04-AUG-18

RMAN> 

复制完成后可以查看备库状态 处于MOUNT,角色是物理备库:

SQL> select database_role, open_mode from v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED

SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> 

此时主库状态,处于OPEN,可读写,默认为最大性能模式:

SQL> select database_role, open_mode from v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PRIMARY          READ WRITE

SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> select PROTECTION_MODE from v$database;

PROTECTION_MODE
--------------------
MAXIMUM PERFORMANCE

SQL>

切换ADG

备库上执行

export ORACLE_SID=tcc

sqlplus / as sysdba

SQL> recover managed standby database using current logfile disconnect from session;
Media recovery complete.
SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter database open;

Database altered.

SQL> select database_role, open_mode from v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY

SQL>

其中disconnect from session表示后台执行,类似于shell的&。可以看出现在备库处于READ ONLY状态,不再是处于MOUNT不可使用的状态,即现在可以执行只读操作了。

SQL> recover managed standby database using current logfile disconnect from session;
Media recovery complete.
SQL> select database_role, open_mode from v$database;

DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY

SQL>

此时数据库状态时READ ONLY WITH APPLY,即只读且实时应用日志,通常所说的ADG,Active Data Guard。

READ ONLY WITH APPLY表示备库处于READ ONLY状态的同时可以接收主库传过来的日志文件并进行恢复,以便备库可以即时查看到主库的变化。

此时adg已经搭建完成了,可以测试一下效果。

主库:

oracle11@scc[/oracle11/product/112/dbs]$export ORACLE_SID=scc
oracle11@scc[/oracle11/product/112/dbs]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Aug 8 16:41:26 2018

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create table wufan(name varchar2(20),passwd varchar2(30));

Table created.

SQL> insert into wufan values('wufan','123456');

1 row created.

SQL> commit;

Commit complete.

SQL> 

备库可以直接去查看下表和数据是否过去了

备库

[email protected][/oracle11/product/112/network/admin]$export ORACLE_SID=tcc
[email protected][/oracle11/product/112/network/admin]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 9 00:44:58 2018

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> desc wufan 
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 NAME                                               VARCHAR2(20)
 PASSWD                                             VARCHAR2(30)

SQL> select * from wufan ;

NAME                 PASSWD
-------------------- ------------------------------
wufan                123456

SQL> 

看到表和数据已经过来了。

其它一些实验

1、切换SNAPSHOT DATABASE

SNAPSHOT的原理是基于闪回数据原理,此时备库是可读写状态,可以用这种真实的生产环境进行一些无法在测试环境做的实验。使用完后,可以执行命令退回,SNAPSHOT期间对备库做的所有变更都会还原:

备库

执行:

SQL> alter database recover managed standby database cancel;

SQL> alter database convert to snapshot standby;

测试完成后,在执行:

SQL> alter database convert to physical standby;

SQL> alter database recover managed standby database disconnect;

即可取消中间操作的变化。

7.切换主库日志

通过主库手工切换日志,来看看备库是否实时接收应用了日志,可以看出此时备库的最新日志SEQUENCE#是15号:

SYS@BEIJING> alter system archive log current; 
System altered.

SYS@BEIJING> select sequence#, first_time, next_time from v$archived_log order by sequence#;
 SEQUENCE# FIRST_TIME         NEXT_TIME
---------- ------------------ ------------------
        13 29-JUL-16          29-JUL-16
        13 29-JUL-16          29-JUL-16
        14 29-JUL-16          29-JUL-16
        14 29-JUL-16          29-JUL-16
        15 29-JUL-16          29-JUL-16
        15 29-JUL-16          29-JUL-16

此时查看备库,已经应用15号日志:

SQL> select sequence#, first_time, next_time from v$archived_log order by sequence#;
 SEQUENCE# FIRST_TIME      NEXT_TIME
---------- -------------- ------------------
        12 29-JUL-16       29-JUL-16
        13 29-JUL-16       29-JUL-16
        14 29-JUL-16       29-JUL-16
        15 29-JUL-16       29-JUL-16

8.设置归档日志删除策略

可以设置主库的归档日志应用至备库后再删除的策略,一方面保证了归档日志传输接收,另一方面可以有效控制归档日志文件的产生量大小。默认是没有任何删除策略:

[oracle@bill02 BEIJING]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jul 29 10:10:55 2016Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: BEIJING (DBID=882855131)

RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name BEIJING are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # defaultCONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0.4/dbs/snapcf_BEIJING.f'; # default

执行:

RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
new RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
new RMAN configuration parameters are successfully stored

再次查看:

RMAN> show all;

RMAN configuration parameters for database with db_unique_name BEIJING are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0.4/dbs/snapcf_BEIJING.f'; # default

 

你可能感兴趣的:(oracle)