Oracle用户环境变量配置:
ORACLE_BASE=/orcl/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
ORACLE_SID=orcl
export ORACLE_BASE ORACLE_HOME ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH
export PATH
export NLS_LANG=american_america.AL32UTF8
主库:
1. 将primary数据库设置为force logging模式
select force_logging from v$database;
alter database force logging;
2. 创建密码文件(如果没有)
orapwd file=$ORACLE_HOME/dbs/orapworcl password=syspassword entries=30;
3. 将主库至于归档模式
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
4. disabled selinux
cat /etc/selinux/config | grep 'SELINUX'
5. 配置standby redo log
select GROUP#,BYTES/1024/1024 size_M,STATUS,ARCHIVED from v$log; # 查询当前日志组大小
alter database add standby logfile group 4 ('/orcl/app/oracle/oradata/orcl/standbyrd01.log') size 200M;
alter database add standby logfile group 5 ('/orcl/app/oracle/oradata/orcl/standbyrd02.log') size 200M;
alter database add standby logfile group 6 ('/orcl/app/oracle/oradata/orcl/standbyrd03.log') size 200M;
alter database add standby logfile group 7 ('/orcl/app/oracle/oradata/orcl/standbyrd04.log') size 200M;
alter database drop standby logfile group 4; # 删除
select group#,thread#,sequence#,archived,status from v$standby_log; # 验证
alter database create standby controlfile as '/orcl/app/oracle/oradata/orcl/orcldg01.ctl';
create pfile from spfile;
vi $ORACLE_HOME/dbs/initorcl.ora(添加以下内容)
*.log_file_name_convert='/orcl/app/oracle/oradata/orcl/','/orcl/app/oracle/oradata/orcl/'
*.db_unique_name='orcl1'
*.fal_client='orcl1'
*.fal_server='orcldg'
*.log_archive_config='DG_CONFIG=(orcl1,orcldg)'
*.log_archive_dest_1='LOCATION=/orcl/app/oracle/oradata/orcl/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl1'
*.log_archive_dest_2='SERVICE=orcldg LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLES) DB_UNIQUE_NAME=orcldg'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.standby_file_management='AUTO'
*.remote_login_passwordfile='EXCLUSIVE'
*.log_archive_format=%t_%s_%r.arc
create spfile from pfile='initorcl.ora'
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Nginx01)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
)
)
ADR_BASE_LISTENER=/orcl/app/oracle
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Nginx01)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCLDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Nginx01-dg)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldg)
)
)
10. shutdown immediate
11. 传输控制文件、初始化参数文件、监听文件、密码文件到备机
cd /orcl/app/oracle/product/12.2.0/db_1/network/admin
scp listener.ora Nginx01-dg:/orcl/app/oracle/product/12.2.0/db_1/network/admin
scp tnsnames.ora Nginx01-dg:/orcl/app/oracle/product/12.2.0/db_1/network/admin
scp sqlnet.ora Nginx01-dg:/orcl/app/oracle/product/12.2.0/db_1/network/admin
cd /orcl/app/oracle/oradata/orcl
scp orcldg01.ctl Nginx01-dg:/orcl/app/oracle/oradata/orcl/
cd /orcl/app/oracle/product/12.2.0/db_1/dbs
scp initorcl.ora Nginx01-dg:/orcl/app/oracle/product/12.2.0/db_1/dbs/initorcl.ora
scp orapworcl Nginx01-dg:/orcl/app/oracle/product/12.2.0/db_1/dbs/orapworcl
12. 在主库上RMAN备份恢复到standby:
1. 主库启动到mount状态,备库启动到nomount状态
2. rman target sys/abcd1234@orcl auxiliary sys/abcd1234@orcldg
3. duplicate target database for standby nofilenamecheck from active database; # 主备机目录一致使用nofilenamecheck参数
备库:
1. disabled selinux
cat /etc/selinux/config | grep 'SELINUX'
2. 创建目录
mkdir -p /orcl/app/oracle/oradata/orcl/
mkdir -p /orcl/app/oracle/admin/orcl/adump
3. 修改主库传过来的初始化参数文件initorcl.ora文件
*.control_files='/orcl/app/oracle/oradata/orcl/orcldg01.ctl','/orcl/app/oracle/oradata/orcl/orcldg02.ctl'
*.log_file_name_convert='/orcl/app/oracle/oradata/orcl/','/orcl/app/oracle/oradata/orcl/'
*.db_unique_name='orcldg'
*.fal_client='orcldg'
*.fal_server='orcl1'
*.log_archive_config='DG_CONFIG=(orcl1,ALL_ROLES) DB_UNIQUE_NAME=orcldg'
*.log_archive_dest_2='SERVICE=orcl1 LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLES) DB_UNIQUE_NAME=orcl1'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.standby_file_management='AUTO'
*.log_archive_format=%t_%s_%r.arc
*.remote_login_passwordfile='EXCLUSIVE
4. listener.ora和tnsnames.ora文件不用做任何修改
5. 启动(rman备份恢复完成后)
alter database mount standby database;
alter database open read only;
alter database recover managed standby database disconnect from session;
alter database set standby database to maximize availability;
6. 查询验证
select switchover_status,open_mode,database_role,db_unique_name,protection_mode,protection_level from v$database;
select SEQUENCE#,FIRST_TIME,NEXT_TIME,APPLIED from v$archived_log order by 1;
select max(sequence#) from v$log;
7. 关机
alter database recover managed standby database cancel;
shutdown immediate;
原文链接:https://www.f2er.com/oracle/206426.html