数据库
首页 > 数据库> > Oracle Dataguard配置(二)Dataguard配置

Oracle Dataguard配置(二)Dataguard配置

作者:互联网

        上一篇时候,我们已经安装好了一台DB,接下来开始做DG配置,

DB参数规划

HOSTNAME

IP

DB_NAME

DB_UNIQUE_NAME

INSTANCE_NAME

SERVICE_NAME

mydb01

192.168.110.138

orcl

dbprimary

orcl

orcl

mydb02

192.168.110.139

orcl

dbstandby

orcl

orcl

文件物理路径

文件类别主库备库

datafile

/data/oracle/oradata/orcl/

/data/oracle/oradata/orcl/

controlfile

/data/oracle/oradata/orcl/

/data/oracle/oradata/orcl/

archivelog

/data/oracle/oradata/archive/

/data/oracle/oradata/archive/

(一)、主备库上分别配置监听和tns.ora

配置lisenter.ora,內容如下:
   dbprimary的listener.ora (/data/oracle/product/11.2.0/db_1/network/admin目录下):
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = orcl)
      (ORACLE_HOME = /data/oracle/product/11.2.0/db_1)
      (GLOBAL_DBNAME = orcl)
    )
  )
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = mydb01)(PORT = 1521))
    )
  )


   dbstandby的listener.ora:
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = ZZKPHMDB)
      (ORACLE_HOME = /data/oracle/product/11.2.0/db_1)
      (GLOBAL_DBNAME = orcl)
    )
  )
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = mydb02)(PORT = 1521))
    )
  )


  dbprimary和dbstandby上的tnsnames.ora是一样的
# Generated by Oracle configuration tools.

dbprimary =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = mydb01)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
dbstandby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = mydb02)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

(二)、检查配置主备库是否正确
 
 备库上执行:oracle>sqlplus sys/oracle@dbprimary as sysdba
 主库上执行:oracle>sqlplus sys/oracle@dbstandby as sysdba

能连上说明主备库可以互通。

(三)、主库上增加standby_log

配置Standby Redo Log。创建组数至少要比主库的online redo log组数多一个。主库增加group 5,6,7;因为会把主库的oradata覆盖掉备库的oradata目录,所以暂时不增加备库的standby_log。查看standby_log:select * from v$standby_log,查看log文件:select * from v$logfile; 过会儿把主库的文件复制到备库后,再在备库上shutdown->startup mount->创建group 8.
alter database add standby logfile group 5 ('/data/oracle/oradata/orcl/redo05.log') size 50m;
alter database add standby logfile group 6 ('/data/oracle/oradata/orcl/redo06.log') size 50m;
alter database add standby logfile group 7 ('/data/oracle/oradata/orcl/redo07.log') size 50m;

4.、dbprimary上配置
1. oracle>mkdir /data/oracle/oradata/archive
2. cd /data/oracle/product/11.2.0/db_1/dbs
   oracle>orapwd file=orapworcl password=oracle entries=4 产生密码文件,也要复制到备库
3. oracle>sqlplus sys as sysdba
 sql>create pfile from spfile; 在/data/oracle/product/11.2.0/db_1/dbs/下生成initorcl.ora
 在initorcl.ora文件后面增加内容:
*.DB_UNIQUE_NAME='dbprimary'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(dbprimary, dbstandby)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/data/oracle/oradata/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dbprimary'
*.LOG_ARCHIVE_DEST_2='SERVICE=dbstandby LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dbstandby'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'
*.LOG_ARCHIVE_MAX_PROCESSES=5
*.FAL_SERVER='dbstandby'
*.FAL_CLIENT='dbprimary'
*.STANDBY_FILE_MANAGEMENT='AUTO'

4. 
 sql>shutdown immediate;
 sql>create spfile from pfile;
 sql>startup mount;
 sql>alter database archivelog;
 sql>alter database open;
 sql>archive log list; 查看是否处于log模式,如果不是执行如下命令
 sql>alter database force logging; 改变为logging模式
 sql>alter database create standby controlfile as '/data/oracle/oradata/orcl/standby01.ctl'; 创建dbstandby上的控制文件
 sql>shutdown immediate;#关闭主库准备打包复制文件
 
5. 把/data/oracle/oradata打包传到dbstandby服务器, 把 /data/oracle/product/11.2.0/db_1/dbs/orapworcl也传过去。复制资料时候主库是关闭状态,待备库配置完成,并启动后,主库再开启。
oracle>cd /data/oracle/
oracle>tar czvf oradata.tar oradata #打包:
oracle>scp /data/oracle/oradata.tar mydb02:/data/app/oracle/
oracle>scp /data/oracle/product/11.2.0/db_1/dbs/orapworcl mydb02:/data/oracle/product/11.2.0/db_1/dbs/


(四)、dbstandby上配置
1. oracle>sqlplus sys as sysdba
   sql>shutdown immediate;
2. oracle>cd /data/app/oracle
   oracle>rm -rf oradata
   把刚才传过来的包解压
   oracle>tar zxvf oradata.tar
   oracle>cd oradata/orcl/
   oracle>cp standby01.ctl standby02.ctl
   oracle>cp standby01.ctl standby03.ctl
3. sql>create pfile from spfile
   修改initorcl.ora
*.control_files='/data/oracle/oradata/orcl/standby01.ctl','/data/oracle/oradata/orcl/standby02.ctl','/data/oracle/oradata/orcl/standby03.ctl'
*.DB_UNIQUE_NAME='dbstandby'
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(dbprimary, dbstandby)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/data/oracle/oradata/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dbstandby'
*.LOG_ARCHIVE_DEST_2='SERVICE=dbprimary LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dbprimary'
*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'
*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'
*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'
*.LOG_ARCHIVE_MAX_PROCESSES=5
*.FAL_SERVER='dbprimary'
*.FAL_CLIENT='dbstandby'
*.STANDBY_FILE_MANAGEMENT='AUTO'    
    
4.创建group 8 

sql>startup mount;

sql>alter database add standby logfile group 8 ('/data/oracle/oradata/orcl/redo08.log') size 50m;

/data/oracle/oradata/orcl/下多出一个redo08.log文件。
5. 启动到recover mange模式
   sql> shutdown immediate;
   sql>create spfile from pfile;
   sql>startup nomount;
   sql>alter database mount standby database;
   sql>alter database recover managed standby database disconnect from session;  启动到recover mange模式

(五)、启动主库

    oracle>lsnrctl stop 
    oracle>lsnrctl start
    sql>shutdown immediate;    
    sql>startup;  

(六)、验证归档日志是否同步到备库

查看目录/data/oracle/oradata/archive/是否与主库一致。

执行sql>alter system switch logfile;看备库上是否会新增一个归档日志。

此时,备库是无法用plsql连线的,需要将备库切换到read only

(七)、切换备库到read only
 startup mount;
 alter database open read only;
 alter database recover managed standby database using current logfile disconnect from session;

再用plsql就可以连线,只是备库无法修改数据。创建一个表空间,备库中同步新增一个表空间。

(八)、重启测试,主库自动启动,备库需要手动切换到read only

 sqlplus sys as sysdba 
 shutdown immediate;
 startup mount;
 alter database open read only;
 alter database recover managed standby database using current logfile disconnect from session; 
 alter database recover managed standby database cancel;

 alter database recover managed standby database using current logfile disconnect from session; 

至此,从安装oracle到datagard的配置过程就结束了,希望对你有所帮助。如有问题可以评论探讨,互相学习。

标签:database,配置,oracle,orcl,oradata,Dataguard,sql,Oracle,data
来源: https://blog.csdn.net/haofangkiller/article/details/120394129