linux 5.8 + oracle11gr2
服务器配置、关联包检查、环境配置、安装包解压缩、安装数据库软件
主备环境配置相同
PATH=$PATH:$HOME/bin
ORACLE_BASE=/u01/app
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1/
ORACLE_SID=primary
#NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8" #第三段和数据库端字符集一致
PATH=$ORACLE_HOME/bin:$PATH
#DISPLAY=192.168.16.85:0.0
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH DISPLAY
export LANG=en_US
export PATH
主备 /etc/hosts
192.168.16.165 rha.orc1.com
192.168.16.166 rha.orc2.com
主机
安装数据库软件
//设置数据库为 force logging 模式
SQL> alter database force logging;
//设置数据库为归档模式
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6
//确定数据库相关 name 参数值
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string primary
db_unique_name string primary
global_names boolean FALSE
instance_name string orcl
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string primary
//创建standby数据库控制文件
SQL> alter database create standby controlfile as '/u01/standby/standby.ctl';
//创建primary数据库客户端初始化参数文件,并做修改;以pfile重启,创建spfile
SQL> create pfile from spfile;
DB_UNIQUE_NAME=primary
LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'
LOG_ARCHIVE_DEST_1='LOCATION=/u01/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary'
LOG_ARCHIVE_DEST_2='SERVICE=standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
#----------角色转换-------不能有中文---
FAL_SERVER=primary
FAL_CLIENT=standby
#DB_FILE_NAME_CONVERT='/u01/app/oradata/primary','/u01/app/oradata/standby'
#LOG_FILE_NAME_CONVERT='/u01/app/oradata/primary','/u01/app/oradata/standby'
STANDBY_FILE_MANAGEMENT=AUTO
SQL> shutdown immediate
SQL> startup pfile=...
//拷贝 控制文件、密码文件 到备机指定位置
//配置监听、tnsnames.ora
备机
//创建 /u01/app 下日志目录
[oracle@rha app]$ mkdir -p /u01/app/oradata/primary
[oracle@rha app]$ mkdir -p /u01/app/admin/primary/adump
[oracle@rha app]$ mkdir -p /u01/app/admin/primary/dpdump
[oracle@rha app]$ mkdir -p /u01/app/admin/primary/pfile
[oracle@rha app]$ mkdir -p /u01/app/fast_recovery_area/primary
//修改 初始化参数文件 /u01/app/product/11.2.0/db_1/dbs/initorcl.ora
DB_UNIQUE_NAME=standby
LOG_ARCHIVE_CONFIG='DG_CONFIG=(primary,standby)'
DB_FILE_NAME_CONVERT='/u01/app/oradata/primary','/u01/app/oradata/standby'
LOG_FILE_NAME_CONVERT='/u01/app/oradata/primary','/u01/app/oradata/standby'
LOG_ARCHIVE_FORMAT=%s_%t_%r.log
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_1='LOCATION=/u01/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'
#--------
LOG_ARCHIVE_DEST_2='SERVICE=primary LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'
LOG_ARCHIVE_DEST_STATE_2=ENABLE
FAL_SERVER=primary
FAL_CLIENT=standby
STANDBY_FILE_MANAGEMENT=AUTO
//创建spfile ,启动到 mount状态
SQL> create spfile from pfile;
SQL> startup nomount;
主机
//RMAN
$ rman target sys/oracle@primary auxiliary sys/oracle@standby
RMAN> duplicate target database for standby nofilenamecheck from active database;
//创建主库备份日志文件
SQL> alter database add standby logfile '/u01/app/oradata/primary/std_redo01.log' size 50m;
alter database add standby logfile '/u01/app/oradata/primary/std_redo02.log' size 50m;
alter database add standby logfile '/u01/app/oradata/primary/std_redo03.log' size 50m;
备机
SQL> startup mount
//创建主库备份日志文件
SQL> alter database add standby logfile '/u01/app/oradata/primary/std_redo01.log' size 50m;
alter database add standby logfile '/u01/app/oradata/primary/std_redo02.log' size 50m;
alter database add standby logfile '/u01/app/oradata/primary/std_redo03.log' size 50m;
//启动redo应用
SQL> alter database recover managed standby database disconnect from session;
//暂停redo应用
SQL> alter database recover managed standby database cancel;
查看同步情况,若查出归档日志数量相同,则同步正常
select open_mode,database_role,controlfile_type from v$database;
select thread#, max(sequence#) from v$log group by thread#;
主机
SQL> show parameter instance_name
SQL> alter system swi?tch logfile;
SQL> select max(sequence#) from v$archived_log;
备机
SQL> show parameter instance_name
SQL> select max(sequence#) from v$archived_log;
关闭备库,应先暂停redo应用
SQL> alter database recover managed standby database cancel;
SQL> shutdown immediate
启动 redo 应用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
启动实时应用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
这个命令指示备库开始使用备用日志文件进行恢复。它也告诉备库命令完成后回到命令行界面
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
此时只是暂时 redo 应用,并不是停止 Standby 数据库,standby 仍会保持接收只不过不会再应用
接收到的归档,直到你再次启动 redo 应用为止
参考文档:http://www.5ienet.com/note/html/dg/index.shtml
http://blog.itpub.net/23890223/viewspace-772125/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29143715/viewspace-1467746/,如需转载,请注明出处,否则将追究法律责任。