ORACLE 11G 搭建DATAGUARD步骤
1 安装环境
在主机1上安装数据库软件,并建监听和实例,在主机2上安装数据库软件,并建监听,但不建实例。 操作系统 主机名 IP 主机1 redhat6.1 64位 dg1 192.168.132.3 主机2 redhat6.1 64位 db2 192.168.132.4 oracle 11.2.0.1.0 /oracle/app/oracle/ $ORACLE_BASE/product/11.2.0/db_1 数据库软件版本 oracle 11.2.0.1.0 ORACLE_BASE ORACLE_HOME /oracle/app/oracle/ $ORACLE_BASE/product/11.2.0/db_1 ORACLE_SID 闪回区 归档
dbtest 4G 开启 2 主数据库配置
2.1
设置数据库强制归档
sqlplus / as sysdba
SQL> ALTER DATABASE FORCE LOGGING; SQL> select force_logging from v$database; FOR --- YES
2.2 添加STANDBY日志文件
SQL>alter database add standby logfile group 4 ('/oradata/dbtest/redo04.log') size 50m;
SQL>alter database add standby logfile group 5 ('/oradata/dbtest/redo05.log') size 50m;
SQL>alter database add standby logfile group 6 ('/oradata/dbtest/redo06.log') size 50m;
SQL>alter database add standby logfile group 7 ('/oradata/dbtest/redo07.log') size 50m;
SQL> select * from v$logfile order by 1;
2.3 修改参数文件
2.3.1 生成pfile
SQL>create pfile from spfile; SQL>shutdown immediate;
2.3.2 修改pfile
vi $ORACLE_HOME/dbs/initdbtest.ora 在最后添加如下内容: *.db_unique_name=dbtest1 *.fal_server='dbtest2' *.fal_client='dbtest1'
*.standby_file_management=auto
*.db_file_name_convert='/oradata/dbtest/','/oradata/dbtest/'
*.log_file_name_convert='/oradata/dbtest/','/oradata/dbtest/' *.log_archive_config='dg_config=(dbtest1,dbtest2)' *.log_archive_dest_2='service=dbtest2
LGWR
SYNC
AFFIRM
valid_for=(online_logfiles,primary_role) db_unique_name=dbtest2'
*.log_archive_dest_state_2='ENABLE'
2.3.3 生成spfile
SQL> shutdown immediate
[oracle@dbserver01 ~]$ cd $ORACLE_HOME/dbs
[oracle@dbserver01 dbs]$ mv spfilejkfwdb.ora spfilejkfwdb.ora.bak SQL> startup nomount SQL> create spfile from pfile; File created.
SQL> show parameter uniq SQL> shutdown immediate; SQL> startup
SQL> show parameter spfile
2.4 修改监听配置文件
2.5 修改TNS配置文件
[oracle@dg1 admin]$ cat tnsnames.ora #
tnsnames.ora
Network
Configuration
File:
/oracle/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DBTEST = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.3)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dbtest1) ) ) DBTEST1 = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.3)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dbtest1) ) ) DBTEST2 = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.4)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dbtest2) ) )
EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC2)) )
(CONNECT_DATA =
(SID = PLSExtProc) (PRESENTATION = RO) ) )
2.6 重启监听服务
lsnrctl stop lsnrctl start
2.7 配置最大可用模式
SQL> alter database set standby database to maximize availability; Database altered. SQL> exit
2.8 备份数据库
[oracle@dg1 admin]$ rman target / RMAN> backup database plus archivelog; RMAN> backup current controlfile for standby; RMAN> exit
备份完成后会在闪回区生产备份文件
3 备数据库配置
3.1
建立相应的文件目录
包括dump文件目录,闪回区,数据文件目录,可以通过 show parameter dest命令查看
mkdir -p /oracle/app/oracle/admin/dbtest/adump mkdir -p /oracle/app/oracle/admin/dbtest/dpdump
mkdir -p /oracle/app/oracle/diag/rdbms/dbtest1/dbtest/trace mkdir -p /oracle/app/oracle/diag/rdbms/dbtest1/dbtest/cdump mkdir -p /oracle/app/oracle/flash_recovery_area