准备:
1、修改主机名
primary host:ora2.cc.com ip:10.10.10.130
stdby host:ora3.cc.com ip:10.10.10.140
2、hosts文件互绑定
3、主库有完整的数据库,备库只有数据库软件(rdbms),不要建库
ora2.cc.com:--> rdbms instance+database
orcl orcl
ora3.cc.com:-->rdbms instance+database
orcl2 orcl
oranet (需提前在root下执行:xhost + 调取图形界面)
netmgr(create-->listener.ora
-->tnsnames.ora )
----------primary
$vim /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
TO_130=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora2.cc.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
to_140 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora3.cc.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
$ vim /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
SID_LIST_LISTENER = --------此段配置的为静态监听
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora2.cc.com)(PORT = 1521))
)
copy 一份listener,准备给备库使用,注意修改hostname,sid
cp -v /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora.140
copy 一份passwd,准备给备库使用,注意修改文件名
cp -v /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl2.140
$sqlplus / as sysdba
SQL> show parameter name -------检查name
NAME TYPE VALUE
------------------------------------ -----------
db_file_name_convert string
db_name string orcl
db_unique_name string orcl
global_names boolean FALSE
instance_name string orcl
lock_name_space string
log_file_name_convert string
service_names string orcl
SQL> select name from v$datafile; -----------检查文件
NAME
------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
SQL> select name from v$datafile;
SQL> select member from v$logfile;
SQL> select name from v$controlfile;
SQL> alter database add SUPPLEMENTAL LOG data;
SQL> alter system set service_names=orcl scope=spfile;
SQL> alter system set instance_name=orcl scope=spfile;
SQL> alter system set db_unique_name=orcl scope=spfile;
SQL> alter system set log_archive_config='dg_config=(orcl,orcl2)';
SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=orcl';
SQL> alter session set log_archive_dest_state_2=defer;
SQL> alter system set log_archive_dest_2='service=to_140 valid_for=(online_logfile,primary_role) db_unique_name=orcl2 ';
SQL> select name from v$datafile;
SQL> select member from v$logfile;
SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl/' scope=spfile;
SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl/' scope=spfile;
SQL> create pfile='/home/oracle/p.ora' from spfile;
复制pfile文件给备机用
$ cp -v p.ora s.ora
修改s.ora
$ diff p.ora s.ora
1,9d0
< orcl.__db_cache_size=125829120
< 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=167772160
< orcl.__sga_target=247463936
< orcl.__shared_io_pool_size=0
< orcl.__shared_pool_size=104857600
< orcl.__streams_pool_size=0
20c11
< *.db_unique_name='ORCL'
---
> *.db_unique_name='ORCL2'
22,23c13
< *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
< *.instance_name='ORCL'
---
> *.instance_name='ORCL2'
25,26c15,16
< *.log_archive_dest_1='location=/u01/app/oracle/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=orcl'
< *.log_archive_dest_2='service=to_140 valid_for=(online_logfile,primary_role) db_unique_name=orcl2 '
---
> *.log_archive_dest_1='location=/u01/app/oracle/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=orcl2'
> *.log_archive_dest_2='service=to_130 valid_for=(online_logfile,primary_role) db_unique_name=orcl '
修改服务器分发
SQL> alter system set dispatchers='';
System altered.
SQL> alter system set shared_servers=0;
System altered.
复制文件到备机
$ scp s.ora
[email protected]:/home/oracle
$ scp /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
[email protected]:/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
$ scp /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora.244
[email protected]:/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
$ scp /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl
[email protected]:/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl2
--------stdby
$ lsnrctl start
$ export ORACLE_SID=orcl2
$ cat s.ora
$ mkdir -pv /u01/app/oracle/admin/orcl/adump
$ mkdir -pv /u01/app/oracle/oradata/orcl/
$ mkdir -pv /u01/app/oracle/flash_recovery_area/orcl/
$ ls /u01/app/oracle/oradata/orcl/
$ ls /u01/app/oracle/flash_recovery_area
$ mkdir -pv /u01/app/oracle/archivelog
$ sqlplus / as sysdba
SQL> create spfile from pfile='/home/oracle/s.ora';
SQL> startup nomount
$ rman target sys/oracle@to_130 auxiliary sys/oracle@to_140
RMAN> duplicate target database for standby from active database nofilenamecheck;
Finished Duplicate Db at 25-APR-13 ---------------------状态成功
SQL> select status from v$instance;
STATUS
------------
MOUNTED
更改数据库为只读模式
SQL> alter database open read only;
Database altered.
SQL> alter database recover managed standby database disconnect from session; ------应用日志
Database altered.
SQL> select PROTECTION_MODE from v$database;
PROTECTION_MODE
--------------------
MAXIMUM PERFORMANCE ------------处于最大性能模式
其他2种模式为:最高可用------maximize availability
最大保护------maximize protection
SQL> alter database recover managed standby database cancel; 取消日志应用