上一篇文章介绍了Data Guard 12cR2中3个特性,本篇文章将继续介绍部分新特性。
| Using DBCA to Create a Data Guard Standby
在12c之前创建物理备库的方法有:
1.使用RMAN备份恢复方法;
2.在11g时可以选择duplicate方式创建物理备库;通过这种方式直接在线从主库搭建起物理备库。
到12cR2后,Oracle又提供更简单的方式来创建物理备库,就是本篇文章介绍的方式:即使用DBCA方式直接建立物理备库。这个功能再次简化了创建备库的复杂度。
通过DBCA提供的参数createDuplicateDB,我们可以很容易的搭建一个物理备库。其具体语法如下:
dbca -createDuplicateDB -gdbName global_database_name -primaryDBConnectionString easy_connect_string_to_primary -sid database_system_identifier [-createAsStandby [-dbUniqueName db_unique_name_for_standby]] [-customScripts scripts_list] [-datafileDestination data_files_directory] [-initParams initialization_parameters [-initParamsEscapeChar initialization_parameters_escape_character]] [-useWalletForDBCredentials {true | false} -dbCredentialsWalletPassword wallet_account_password -dbCredentialsWalletLocation wallet_files_directory]
虽然通过DBCA能非常简单的创建一个物理备库,但是要使用这个功能,必须满足以下条件:
主库必须是单机环境,非RAC数据库;
主库必须是非CDB环境;
在12c里非常重要的新特性之一就是多租户环境,但是该特性不支持CDB环境的数据库,同时主库也不能是RAC环境。如果不满足以上条件,在使用DBCA创建备库的时候,会提示如下错误:
主库是CDB环境,错误如下: [FATAL] [DBT-16057] Specified primary database is a container database (CDB). CAUSE: Duplicate database operation is supported only for non container databases. 主库是RAC数据库,错误如下: [FATAL] [DBT-16056] Specified primary database is not a Single Instance (SI) database. CAUSE: Duplicate database operation is supported only for SI databases.
也就说通过DBCA搭建出来的备库也是一个单机非CDB的备库,如果你想要搭建一个为RAC的备库,则需要手动转换或者使用Oracle Enterprise Manager Cloud Control来将备库转换为RAC数据库。
接下来将演示如何使用DBCA来创建一个物理备库。假定主备环境如下:
同时假设主备库已经具备如下环境:
1.主库是单机并且使用ASM;
2.主库已经开启了归档模式;
3.密码文件和SPFILE都存储在ASM中;
4.备库同样使用ASM存储数据,且备库端环境已经具备;
创建步骤如下:
1.在主库开启Force Logging
[oracle@dbpri]$ sqlplus / as sysdba SQL> alter database force logging; Database altered. SQL>
2.主库创建Standby Redo logs
查看Redo log的大小:
[oracle@dbpri]$ sqlplus / as sysdba SQL> select thread#,group#,bytes/1024/1024 SIZE _MB, status from v$log; THREAD# GROUP# SIZE_MB STATUS ---------- ---------- -------------- ---------------- 1 1 100 CURRENT 1 2 100 INACTIVE 1 3 100 INACTIVE 1 4 100 INACTIVE 1 5 100 INACTIVE 1 6 100 INACTIVE
创建Standby redo logs:
[oracle@dbpri]$ sqlplus / as sysdba SQL> alter database add standby logfile thread 1 group 7 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 8 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 9 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 10 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 11 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 12 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 13 ('+DATADG') size 100M; Database altered. SQL>
当在主库创建好 Standby redo logs 后,备库也会自动创建。
3.创建网络服务名
主库tnsnames.ora
ordbpri = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL= TCP)(HOST=dbpri)(PORT=1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ordbpri) ) ) ordbstd = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL = TCP)(HOST=dbstd) (PORT=1521)))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ordbstd) ) ) ordbpri_local_listener = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL = TCP)(HOST=dbpri)(PORT=1521) ) ) )
备库tnsnames.ora
ordbpri = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL= TCP)(HOST=dbpri)(PORT=1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ordbpri) ) ) ordbstd = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL = TCP)(HOST=dbstd) (PORT=1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ordbstd) ) ) ordbstd_local_listener = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL = TCP)(HOST=dbstd)(PORT=1521) ) ) )
4.在备库执行DBCA
[oracle@dbstd ~]$ dbca -silent -createDuplicateDB -gdbName ordbpri -sid ordbstd -sysPassword oracle -primaryDBConnectionString dbpri:1521/ordbpri -createAsStandby -dbUniqueName ordbstd –initParams db_create_file_dest=+DATADG, db_create_online_log_dest_1=+DATADG,local_listener=”ordbstd_local_listener” 输出如下: Enter SYS user password: Listener config step 33% complete Auxiliary instance creation 66% complete RMAN duplicate 100% complete Look at the log file " /u01/app/oracle/product/12.2.0/dbhome_1/cfgtoollogs/dbca/ordbpri/ordbpri.log" for further details.
注:也可以使用自定义脚本,当备库完成创建后,执行定制脚本。
5.在备库完成环境配置
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=+DATADG VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ordbstd' scope=spfile; SQL> alter system set db_file_name_convert='+DATADG/ordbpri','+DATADG/ordbstd' scope=spfile; SQL> alter system set log_file_name_convert='+DATADG/ordbpri','+DATADG/ordbstd' scope=spfile; SQL> alter system set standby_file_management=auto scope=spfile; SQL> alter system set remote_listener=' dbstd:1521' scope=spfile; SQL> shutdown immediate SQL> startup SQL> alter system register;
注:在12c,可以尝试使用DG Broker来进行Data Guard的管理和维护。
6.备库创建密码文件和SPFILE到ASM
[grid@dbstd ~]$ export ORACLE_SID=+ASM1 [grid@dbstd ~]$ export ORACLE_HOME=/u01/app/12.2.0.1/grid [grid@dbstd ~]$ export PATH=$ORACLE_HOME/bin:$PATH [grid@dbstd]$asmcmd –p ASMCMD [+] > mkdir DATADG /ORDBSTD/PASSWORD ASMCMD[+]>pwcopy /u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/orapwordbstd +DATADG/ORDBSTD/PASSWORD/pwordbstd [oracle@dbstd]$ rm /u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/orapwordbstd [oracle@dbstd ~]$ export ORACLE_HOME=/u01/app/12.2.0.1/dbhome_1 [oracle@dbstd ~]$ export ORACLE_SID=ordbstd [oracle@dbstd ~]$ export PATH=$ORACLE_HOME/bin:$PATH [oracle@dbstd]$ sqlplus / as sysdba SQL> create pfile='/tmp/pfilestd.ora' from spfile; SQL> create spfile='+DATADG/ORDBSTD/spfileordbstd.ora' from pfile='/tmp/pfilestd.ora'; [oracle@dbstd]$ rm /u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/spfileordbstd.ora
7.备库创建PFILE并且关闭备库。
[oracle@dbstd]$echo “spfile='+DATADG/ORDBSTD/spfileordbstd.ora'” > /u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/initordbstd.ora [oracle@dbstd] sqlplus / as sysdba SQL> shutdown immediate SQL>exit
8.将备库注册到Oracle Restart及启动备库。
[oracle@dbstd]$ srvctl add database -db ordbstd -oraclehome /u01/app/oracle/product/12.2.0.1/dbhome_1 -dbtype Single -instance ordbstd -node dbstd -dbname ordbpri -diskgroup DATADG -role physical_standby -spfile '+DATADG/ORDBSTD/spfileordbstd.ora' -pwfile '+DATADG/ORDBSTD/PASSWORD/pwordbstd' [oracle@dbstd]$ srvctl start database -db ordbstd
至此,完成了DBCA从单实例主库到创建单实例备库。
| 作者简介
杨波,沃趣科技数据库技术专家
主要参与公司产品实施、测试、维护以及优化。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。