ip: 192.168.12.210
db_name: orcl
db_unique_name: orcl
数据库版本: oracle 11g R2 32
操作系统: centos 6.2 (查询命令cat/etc/redhat-release)
ip: 192.168.12.211
db_name: orcl
db_unique_name: orcl2
数据库版本: oracle 11g R2 32
操作系统: centos 6.2 (查询命令cat/etc/redhat-release)
alter database force logging
查询是否设置成功:
SQL> select force_logging from v$database;
FOR
---
YES
shutdown immediateàstartup mountàalter database archivelogàalter database open
查询是否设置成功:
archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/oradata/orcl2/standbylog
Oldest online log sequence 20
Next log sequence to archive 0
Current log sequence 21
LISTENER1 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =oracleTest211.domain)(PORT = 1521))
)
)
ADR_BASE_LISTENER1 = /u01/app/oracle
(这种模式主要是能在nomount模式中以服务名的方式连接数据库)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME =/u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL =TCP)(HOST = oracleTest210.domain)(PORT = 1521))
)
)
)
vi /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/sqlnet.ora
SQLNET.AUTHENTICATION_SERVICES = (ALL)
说明:
none : 表示关闭操作系统认证,只能密码认证
all : 用于linux或unix平台,本机操作系统认证,异机使用密码文件认证
nts : 用于windows平台
alter system set remote_login_passwordfile= exclusive
说明:
none : 不使用密码文件认证
exclusive :要密码文件认证,自己独占使用(默认值)
shared :要密码文件认证,不同实例dba用户可以共享密码文件
说明:这里使用sql 语句修改的方式避免静态文件修改可能的误输入
alter system set db_unique_name='orcl' scope=spfile;
alter system setlog_archive_config='DG_CONFIG=(orcl,orcl2)';
alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/orcl/archvalid_for=(all_logfiles,primary_role) db_unique_name=orcl';
alter system set log_archive_dest_2='SERVICE=orcl2 lgwr sync valid_for=(online_logfile,primary_role) db_unique_name=orcl2';
alter system setlog_archive_dest_3='LOCATION=/u01/app/oracle/oradata/orcl/standbylogvalid_for=(standby_logfile,standby_role) db_unique_name=orcl' scope=spfile;
--其实可以不要log_archive_dest_3的配置,直接将log_archive_dest_1中的primary_role改为all_role也可以
--等同于设置STANDBY_ARCHIVE_DEST
alter system setlog_archive_dest_1='LOCATION=/u01/app/oracle/oradata/orcl/archvalid_for=(all_logfiles,all_role) db_unique_name=orcl';
alter system set db_file_name_convert='orcl2','orcl'scope=spfile;
--表示当本机变成standby时将primary的路径中的字符串“orcl2”替换成“orcl”
alter system set log_file_name_convert='orcl2','orcl'scope=spfile;
alter system set fal_client='orcl';
alter system set fal_server='orcl2';
alter system set standby_file_management=auto;
alter database add standby logfile group 4 '/u01/app/oracle/oradata/orcl/standby04.log' size 50M;
alter database add standby logfile group 5 '/u01/app/oracle/oradata/orcl/standby05.log' size 50M;
alter database add standby logfile group 6 '/u01/app/oracle/oradata/orcl/standby06.log' size 50M;
alter database add standby logfile group 7 '/u01/app/oracle/oradata/orcl/standby07.log' size 50M;
createpfile='$ORACLE_HOME/dbs/initorclnew.ora' from spfile;
orapwd file='$ORACLE_HOME/dbs/orapworcl'password=abc123 entries=5 force=y;
查询密码文件中的用户
select * from v$pwfile_users;
scp initorclnew.oraorapworcl [email protected]:$ORACLE_HOME/dbs/
mv initorclnew.ora initorcl2.ora
mv orapworcl orapworcl2
mkdir/u01/app/oracle/oradata/orcl2/
mkdir /u01/app/oracle/oradata/orcl2/arch
mkdir /u01/app/oracle/oradata/orcl2/standbylog
vi initorcl2.ora
orcl.__db_cache_size=167772160
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASEset from environment
orcl.__pga_aggregate_target=201326592
orcl.__sga_target=293601280
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=109051904
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/orcl2/control01.ctl','/u01/app/oracle/oradata/orcl2/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4039114752
*.db_unique_name='orcl2'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP)(SERVICE=orclXDB)'
*.fal_client='orcl2'
*.fal_server='orcl'
*.log_archive_config='DG_CONFIG=(orcl,orcl2)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/orcl2/archvalid_for=(all_logfiles,primary_role) db_unique_name=orcl2'
*.log_archive_dest_2='SERVICE=orcl lgwr syncvalid_for=(online_logfile,primary_role) db_unique_name=orcl'
*.log_archive_dest_3='LOCATION=/u01/app/oracle/oradata/orcl2/standbylogvalid_for=(standby_logfile,standby_role) db_unique_name=orcl2'
*.memory_target=492830720
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.db_file_name_convert='orcl','orcl2'
*.log_file_name_convert='orcl','orcl2'
rman target sys/abc123@orcl auxiliary sys/abc123@orcl2
duplicate target database for standby nofilenamecheck from activedatabase;
alter database create standby controlfile as '/u01/control01.ctl';
scp /u01/control01.ctl [email protected]:/u01/app/oracle/oradata/orcl2/
shutdown immediate
scp redo* standby0* system01.dbf undotbs01.dbf sysaux01.dbftemp01.dbf users01.dbf [email protected]:/u01/app/oracle/oradata/orcl2
primary startupàstandby startup standby 执行:
alter database recover managed standby database using current logfile disconnect from session;
sision;
select status from v$standby_log;
主备库都要运行
alter database set standby database to maximize availability;
查询当前状态
select switchover_status,open_mode,database_role,db_unique_name,protection_mode,
protection_level from v$database
将备库shutdown后,主库的PROTECTION_LEVEL将变为RESYNCHRONIZATION
主库:create sequence seq_test
create table test(id int)
insert into test values(seq_test.nextval)
commit;
备库:select * from test;
我的博客:www.fanmeng.net.cn