设置主库的db_unique_name,默认是设好的,如果没有设则使用以下命令设置
SQL>alter system set db_unique_name = 'bdcadb' scope = spfile;
设好后需要重启生效
主库设置其他初始化参数
mkdir -p /u02/stdlog/bdcadb
alter system set log_archive_config = 'DG_CONFIG=(bdcadb,bdcadg)';
alter system set log_archive_dest_2= 'LOCATION=/u02/stdlog/bdcadb VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=bdcadb';
alter system set log_archive_dest_3= 'SERVICE=bdcadg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=bdcadg';
alter system set fal_server=bdcadg';
alter system set fal_client = 'bdcadb';
先临时关闭archived_log的传输
alter system set log_archive_dest_state_3 = defer;
2. 物理DG上的设置
在/etc/hosts中添加主库的hostname
# vi /etc/hosts --添加
#public
192.168.1.196 bdcadb.99bill.com bdcadb
192.168.1.197 bdcadg.99bill.com bdcadg
物理DG添加tnsnames
$ cd $ORACLE_HOME/network/admin
$ vi tnsnames.ora
BDCADB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.151)(PORT = 1530))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bdcataf.99bill.com)
)
)
物理DG上手工创建相关目录
mkdir -p /u02/app/oracle/admin/bdcadb/adump
mkdir -p /u02/archive/bdcadb
mkdir -p /u02/oradata/bdcadb
mkdir -p /u02/stdlog/bdcadb
创建物理DG的初始化参数
$ jdb
$ cd /home/oracle
$ vi initbdcadb.ora
bdcadb.__db_cache_size=45365592064
bdcadb.__java_pool_size=805306368
bdcadb.__large_pool_size=939524096
bdcadb.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
bdcadb.__pga_aggregate_target=12884901888
bdcadb.__sga_target=51539607552
bdcadb.__shared_io_pool_size=0
bdcadb.__shared_pool_size=4160749568
bdcadb.__streams_pool_size=0
*._gc_policy_time=0
*._serial_direct_read='NEVER'
*.audit_file_dest='/u02/app/oracle/admin/bdcadb/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_files='/u02/oradata/bdcadb/bdcadb/control01.ctl','/u02/oradata/bdcadb/bdcadb/control02.ctl','/u02/oradata/bdcadb/bdcadb/control03.ctl'
*.db_block_size=8192
*.db_domain='99bill.com'
*.db_file_multiblock_read_count=16
*.db_file_name_convert='bdcadb','bdcadb'
*.db_files=2048
*.db_name='bdcadb'
*.db_unique_name='bdcadg'
*.db_writer_processes=4
*.diagnostic_dest='/u02/app/oracle'
*.event='28401 TRACE NAME CONTEXT FOREVER, LEVEL 1'
*.fal_client='bdcadg'
*.fal_server='bdcadb'
*.lock_sga=TRUE
*.log_archive_config='DG_CONFIG=(bdcadg,bdcadb)'
*.log_archive_dest_1='location=/u02/archive/bdcadb VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=bdcadb'
*.log_archive_dest_2='SERVICE=BDCADB LGWR ASYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=bdcadb'
*.log_archive_dest_3='LOCATION=/u02/stdlog/bdcadb VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=bdcadg'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_max_processes=6
*.log_file_name_convert='bdcadb','bdcadb'
*.memory_target=0
*.nls_date_format='yyyy-mm-dd hh24:mi:ss'
*.open_cursors=1000
*.optimizer_index_caching=90
*.optimizer_index_cost_adj=15
*.pga_aggregate_target=12884901888
*.processes=4000
*.remote_login_passwordfile='EXCLUSIVE'
*.sec_case_sensitive_logon=FALSE
*.service_names='bdcadb.99bill.com','bdcataf.99bill.com'
*.sessions=4405
*.sga_max_size=51539607552
*.sga_target=51539607552
*.standby_file_management='AUTO'
*.undo_retention=86400
*.undo_tablespace='UNDOTBS1'
*.utl_file_dir='/tmp''
启动数据库到nomount状态并生成spfile
$ jdb
$ sqlplus / as sysdba
startup nomount pfile='/home/oracle/initbdcadb.ora'
create spfile='/u02/oradata/bdcadb/spfilebdcadb.ora' from pfile='/home/oracle/initbdcadb.ora';
shutdown immediate
3. 传输主库的密码文件到备库
Oracle 11g的备库密码通过orapwd命令生成会出现问题,必须从主库上传输一份,并且logdb2的密码文件也必须从logdb1拷贝过来,保证两节点主库和备库三个密码文件是同一个文件
4. 进行数据库的duplicate
将备库打开到nomount状态,主库执行:
$ rman target sys/oracle@bdcadb auxiliary sys/oracle@logdg ;
$RMAN>run{
duplicate target database for standby from active database nofilenamecheck;
}
5. 主库和备库添加standby log
添加standby log公式:(每线程的日志组数+1)×最大线程数
alter database add standby logfile group 5 ('/u02/oradata/bdcadb/standby05_1.log','/u02/oradata/bdcadb/standby05_2.log') size 536870912;
alter database add standby logfile group 6 ('/u02/oradata/bdcadb/standby06_1.log','/u02/oradata/bdcadb/standby06_2.log') size 536870912;
alter database add standby logfile group 7 ('/u02/oradata/bdcadb/standby07_1.log','/u02/oradata/bdcadb/standby07_2.log') size 536870912;
alter database add standby logfile group 8 ('/u02/oradata/bdcadb/standby08_1.log','/u02/oradata/bdcadb/standby08_2.log') size 536870912;
alter database add standby logfile group 9 ('/u02/oradata/bdcadb/standby09_1.log','/u02/oradata/bdcadb/standby09_2.log') size 536870912;
6. 物理DG启动到apply状态
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
Oracle 11gR2可以启动到READ ONLY模式进行APPLY
alter database open;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
7. 开启supplement
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE) COLUMNS;
8. 主库开启向物理DG传输log
alter system set log_archive_dest_state_3 = enable;