本文记录了在一台主机上实现部署Oracle 11g物理Active Data Guard的全过程,部署完毕后备库处于默认的最大性能模式。同时带大家一同体验一下Active Data Guard实时查询(Real-time query)特性。
操作系统版本信息:
- ora11g@secdb /home/oracle$ cat /etc/redhat-release
- Red Hat Enterprise Linux Server release 5.5 (Tikanga)
复制代码 Oracle数据库版本信息:
- sys@ora11g> select * from v$version;
- BANNER
- ----------------------------------------------------------------------
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- PL/SQL Release 11.2.0.1.0 - Production
- CORE 11.2.0.1.0 Production
- TNS for Linux: Version 11.2.0.1.0 - Production
- NLSRTL Version 11.2.0.1.0 - Production
复制代码
1.Oracle 11g Data Guard主库配置过程
1)确保主库处于FORCE LOGGING模式
调整方法如下:
(1)查看当前数据库是否处于FORCE LOGGING模式
- sys@ora11g> col force_logging for a15
- sys@ora11g> select force_logging from v$database;
- FORCE_LOGGING
- ---------------
- NO
复制代码
此处表明数据库运行在非FORCE LOGGING模式。
(2)调整数据库为FORCE LOGGING模式
- sys@ora11g> alter database force logging;
- Database altered.
复制代码
(3)再次查看当前数据库是否处于FORCE LOGGING模式
- sys@ora11g> select force_logging from v$database;
- FORCE_LOGGING
- ---------------
- YES
复制代码
OK,FORCE LOGGING模式调整完毕。
2)配置Redo传输认证
Data Guard使用Oracle Net会话在主库和备库之间传输redo数据和控制信息,因此需要基于SSL(Secure Sockets Layer )或者密码文件进行认证。当SSL认证无法满足时使用密码文件进行认证,因此需要确保所有备库的密码文件与主库保持一致。备库可以通过拷贝主库密码文件的方法完成。
3)配置主库用于接收Redo数据
此步骤是可选步骤,Oracle建议在配置主库的时候就预见到总有一天它会成为备库(例如进行主备库之间的switchover切换),要求当主库成为备库之后不需要做其他配置就可以顺畅地接收主库传过来的Redo数据。这也是Oracle最佳实践的一种体现。
(1)查看日志组日志成员大小
创建的Standby Redo Log大小要与主库的Redo大小保持一致。
- sys@ora11g> select group#, bytes from v$log;
- GROUP# BYTES
- ---------- ----------
- 1 52428800
- 2 52428800
- 3 52428800
复制代码
此时主库每组日志的日志成员大小都是50M。因此创建的Standby Redo Log大小也是50M。
(2)创建适当数量的Standby Redo Log组数
公式如下:
如果主库是单实例数据库:Standby Redo Log组数=主库日志组总数+1
如果住口是RAC数据库:Standby Redo Log组数=(所有节点中日志组数最大值 + 1) * RAC节点数
从上面日志组查询结果可见,此数据库是一个单实例的数据库,包含三组日志。因此Standby Redo Log组数=3+1=4。
需要创建四组Standby Redo Log日志。
(3)确认数据库参数MAXLOGFILES和MAXLOGMEMBERS不会限制Standby Redo Log创建
MAXLOGFILES和MAXLOGMEMBERS这两参数是在使用“CREATE DATABASE”语句创建数据库时做的限制,用于限制数据库日志文件的最大数量和日志组的最大数量。
如果在创建数据库时没有注意这个问题会导致Standby Redo Log无法创建的问题,解决方法只能是创新创建主库或者重新创建主库的控制文件。所以,一定要做好前期的规划。
(4)创建Standby Redo Log
- sys@ora11g> alter database add standby logfile ('/u01/app/oracle/oradata/ora11g/stdb_redo01.log') size 50m;
- Database altered.
- sys@ora11g> alter database add standby logfile ('/u01/app/oracle/oradata/ora11g/stdb_redo02.log') size 50m;
- Database altered.
- sys@ora11g> alter database add standby logfile ('/u01/app/oracle/oradata/ora11g/stdb_redo03.log') size 50m;
- Database altered.
- sys@ora11g> alter database add standby logfile ('/u01/app/oracle/oradata/ora11g/stdb_redo04.log') size 50m;
- Database altered.
复制代码
(5)验证查看Standby Redo Log创建结果
- sys@ora11g> select group#,thread#,sequence#,archived,status from v$standby_log;
- GROUP# THREAD# SEQUENCE# ARC STATUS
- ---------- ---------- ---------- --- ----------
- 4 0 0 YES UNASSIGNED
- 5 0 0 YES UNASSIGNED
- 6 0 0 YES UNASSIGNED
- 7 0 0 YES UNASSIGNED
复制代码
4)设置主库的参数文件
我这里的主库的实例名字是ora11g,备库的实例名约定为ora11gdg。
连接主库的Oracle网络服务名是ora11g,备库的网络服务名是ora11gdg。
(1)Oracle网络服务名配置信息如下
- ora11g@secdb /home/oracle$ vi $ORACLE_HOME/network/admin/tnsnames.ora
- ORA11G =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = secdb)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = ora11g)
- )
- )
- ORA11GDG =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = secdb)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = ora11gdg)
- )
- )
复制代码
(2)生成主库的pfile文件并编辑
- sys@ora11g> create pfile from spfile;
- File created.
- ora11g@secdb /home/oracle$ cd $ORACLE_HOME/dbs
- ora11g@secdb /u01/app/oracle/product/11.2.0/db_1/dbs$ ls -ltr
- total 36K
- -rw-r--r-- 1 oracle oinstall 2.8K May 15 2009 init.ora
- drwx------ 2 oracle oinstall 4.0K Mar 15 19:37 peshm_DBUA0_0/
- drwx------ 2 oracle oinstall 4.0K Mar 15 19:40 peshm_ora11g_0/
- -rw-rw---- 1 oracle oinstall 1.6K Mar 15 21:28 hc_DBUA0.dat
- -rw-r----- 1 oracle oinstall 24 Mar 15 21:32 lkORA11G
- -rw-rw---- 1 oracle oinstall 1.6K Mar 15 21:35 hc_ora11g.dat
- -rw-r----- 1 oracle oinstall 1.5K Mar 15 21:35 orapwora11g
- -rw-r----- 1 oracle oinstall 2.5K Mar 15 21:42 spfileora11g.ora
- -rw-r--r-- 1 oracle oinstall 924 Mar 15 21:45 initora11g.ora
- ora11g@secdb /oracle/ora11gR2/product/11.2.0/dbhome_1/dbs$ vi initora11g.ora
复制代码
(3)主库配置——当是主库角色时需要的参数
- DB_NAME=ora11g
- DB_UNIQUE_NAME=ora11g
- LOG_ARCHIVE_CONFIG='DG_CONFIG=(ora11g,ora11gdg)'
- control_files='/u01/app/oracle/oradata/ora11g/control01.ctl','/u01/app/oracle/oradata/ora11g/control02.ctl'
- LOG_ARCHIVE_DEST_1=
- 'LOCATION=/home/oracle/arch/ora11g/
- VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
- DB_UNIQUE_NAME=ora11g'
- LOG_ARCHIVE_DEST_2=
- 'SERVICE=ora11gdg ASYNC
- VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
- DB_UNIQUE_NAME=ora11gdg'
- LOG_ARCHIVE_DEST_STATE_1=ENABLE
- LOG_ARCHIVE_DEST_STATE_2=ENABLE
- REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
- LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
复制代码
(4)主库配置——当是备库角色时需要的参数
- FAL_CLIENT=ora11g
- FAL_SERVER=ora11gdg
- DB_FILE_NAME_CONVERT='ora11gdg','ora11g'
- LOG_FILE_NAME_CONVERT='ora11gdg','ora11g'
- STANDBY_FILE_MANAGEMENT=AUTO
复制代码
(5)创建所需要的目录
- ora11g@secdb /home/oracle$ mkdir -p /home/oracle/arch/ora11g
- ora11g@secdb /home/oracle$ mkdir -p /home/oracle/arch/ora11gdg
复制代码
5)数据库运行在归档模式
如果数据库为运行在归档模式下,按照如下步骤调整数据库为归档模式。
(1)查看是否为归档模式
- sys@ora11g> archive log list;
- Database log mode No Archive Mode
- Automatic archival Disabled
- Archive destination USE_DB_RECOVERY_FILE_DEST
- Oldest online log sequence 4
- Current log sequence 6
复制代码
结果显示“Database log mode”内容“No Archive Mode”表明数据库未运行在归档模式下。
(2)停止数据库并启动到mount状态
- sys@ora11g> shutdown immediate;
- Database closed.
- Database dismounted.
- ORACLE instance shut down.
- sys@ora11g> startup mount;
- ORACLE instance started.
- Total System Global Area 535662592 bytes
- Fixed Size 1337720 bytes
- Variable Size 402654856 bytes
- Database Buffers 125829120 bytes
- Redo Buffers 5840896 bytes
- Database mounted.
复制代码
(3)启用归档
- sys@ora11g> alter database archivelog;
- Database altered.
复制代码
(4)调整数据库为open状态
- sys@ora11g> alter database open;
- Database altered.
复制代码
2.Oracle 11g Data Guard物理备库创建过程
1)创建主库数据文件的备份
最常用的方法是使用RMAN工具完成,这样可以实现不停库的部署;还可以使用冷备完成。
因为这里实现的是主库和备库都在一台主机上,因此,这里使用冷备的方式生成数据文件的备份,并放到备库对应的目录下。
(1)关闭数据库
- sys@ora11g> shutdown immediate;
- Database closed.
- Database dismounted.
- ORACLE instance shut down.
复制代码
(2)主库数据文件的备份
- ora11g@secdb /home/oracle$ cd /u01/app/oracle/oradata/ora11g/
- ora11g@secdb /u01/app/oracle/oradata/ora11g$ ls -l
- total 1.7G
- -rw-r----- 1 oracle oinstall 9.4M Mar 15 21:47 control01.ctl
- -rw-r----- 1 oracle oinstall 9.4M Mar 15 21:47 control02.ctl
- -rw-r----- 1 oracle oinstall 51M Mar 15 21:46 redo01.log
- -rw-r----- 1 oracle oinstall 51M Mar 15 21:46 redo02.log
- -rw-r----- 1 oracle oinstall 51M Mar 15 21:47 redo03.log
- -rw-r----- 1 oracle oinstall 51M Mar 15 21:46 stdb_redo01.log
- -rw-r----- 1 oracle oinstall 51M Mar 15 21:46 stdb_redo02.log
- -rw-r----- 1 oracle oinstall 51M Mar 15 21:46 stdb_redo03.log
- -rw-r----- 1 oracle oinstall 51M Mar 15 21:46 stdb_redo04.log
- -rw-r----- 1 oracle oinstall 501M Mar 15 21:47 sysaux01.dbf
- -rw-r----- 1 oracle oinstall 681M Mar 15 21:47 system01.dbf
- -rw-r----- 1 oracle oinstall 30M Mar 15 21:39 temp01.dbf
- -rw-r----- 1 oracle oinstall 91M Mar 15 21:47 undotbs01.dbf
- -rw-r----- 1 oracle oinstall 5.1M Mar 15 21:47 users01.dbf
复制代码
这里使用tar方法生成数据文件的备份tar包,当然可以使用其他方法来完成,比如直接把数据文件拷贝到其他目录下。
- ora11g@secdb /u01/app/oracle/oradata/ora11g$ tar -cvf ora11g_cold_backup_datafiles.tar *.dbf
- sysaux01.dbf
- system01.dbf
- temp01.dbf
- undotbs01.dbf
- users01.dbf
- ora11g@secdb /u01/app/oracle/oradata/ora11g$ ls -l ora11g_cold_backup_datafiles.tar
- -rw-r--r-- 1 oracle oinstall 1.3G Mar 15 21:48 ora11g_cold_backup_datafiles.tar
复制代码
2)创建备库的控制文件
此时数据库处于关闭状态。
(1)创建备库ora11gdg控制文件存放的目录
- ora11g@secdb /home/oracle$ mkdir -p /u01/app/oracle/oradata/ora11gdg
复制代码
(2)生成主库spfile,以便在重启主库时使主库参数调整生效。
- sys@ora11g@> create spfile from pfile;
- File created.
复制代码
(3)启动主数据库到mount状态,创建备库的控制文件。
- sys@ora11g@> startup mount;
- ORACLE instance started.
- Total System Global Area 313860096 bytes
- Fixed Size 1336232 bytes
- Variable Size 239078488 bytes
- Database Buffers 67108864 bytes
- Redo Buffers 6336512 bytes
- Database mounted.
- sys@ora11g@> alter database create standby controlfile as '/u01/app/oracle/oradata/ora11gdg/control01.ctl';
- Database altered.
复制代码
拷贝生成备库的第二个控制文件。
- sys@ora11g@> ! cp /u01/app/oracle/oradata/ora11gdg/control01.ctl /u01/app/oracle/oradata/ora11gdg/control02.ctl
- sys@ora11g@> alter database open;
- Database altered.
复制代码
此时主库已经处于Open状态,可对外提供服务。
3)创建备库参数文件
根据主库的pfile文件进行调整。调整后的内容如下。
(1)拷贝主库参数文件生成备库pfile
- ora11g@secdb /home/oracle$ cd $ORACLE_HOME/dbs
- ora11g@secdb /oracle/ora11gR2/product/11.2.0/dbhome_1/dbs$ cp initora11g.ora initora11gdg.ora
复制代码
(2)调整备库pfile文件内容
- ora11g@secdb /oracle/ora11gR2/product/11.2.0/dbhome_1/dbs$ vi initora11gdg.ora
复制代码
(3)备库配置——当是备库角色时需要的参数
- DB_NAME=ora11g
- DB_UNIQUE_NAME=ora11gdg
- LOG_ARCHIVE_CONFIG='DG_CONFIG=(ora11g,ora11gdg)'
- control_files='/u01/app/oracle/oradata/ora11gdg/control01.ctl','/u01/app/oracle/oradata/ora11gdg/control02.ctl'
- FAL_CLIENT=ora11gdg
- FAL_SERVER=ora11g
- DB_FILE_NAME_CONVERT='ora11g','ora11gdg'
- LOG_FILE_NAME_CONVERT='ora11g','ora11gdg'
- STANDBY_FILE_MANAGEMENT=AUTO
- LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
复制代码
(4)备库配置——当是主库角色时需要的参数
- LOG_ARCHIVE_DEST_1=
- 'LOCATION=/home/oracle/arch/ora11gdg/
- VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
- DB_UNIQUE_NAME=ora11gdg'
- LOG_ARCHIVE_DEST_2=
- 'SERVICE=ora11g ASYNC
- VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
- DB_UNIQUE_NAME=ora11g'
- LOG_ARCHIVE_DEST_STATE_1=ENABLE
- LOG_ARCHIVE_DEST_STATE_2=ENABLE
- REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
复制代码
同时调整与路径相关的错误参数内容。同时创建确实的路径。
- $ mkdir -p /u01/app/oracle/admin/ora11gdg/adump
复制代码
4)拷贝备份文件到备库数据文件存放目录
把备份的tar包移动到ora11gdg存放数据文件目录中,解tar包生成备库的数据文件。
- ora11g@secdb /u01/app/oracle/product/11.2.0/db_1/dbs$ cd $ORACLE_BASE/oradata/ora11gdg
- ora11g@secdb /u01/app/oracle/oradata/ora11gdg$ mv ../ora11g/ora11g_cold_backup_datafiles.tar .
- ora11g@secdb /u01/app/oracle/oradata/ora11gdg$ tar -xvf ora11g_cold_backup_datafiles.tar
- sysaux01.dbf
- system01.dbf
- temp01.dbf
- undotbs01.dbf
- users01.dbf
- ora11g@secdb /u01/app/oracle/oradata/ora11gdg$ ls -l
- total 2.6G
- -rw-r----- 1 oracle oinstall 9.4M Mar 15 21:49 control01.ctl
- -rw-r----- 1 oracle oinstall 9.4M Mar 15 21:49 control02.ctl
- -rw-r--r-- 1 oracle oinstall 1.3G Mar 15 21:48 ora11g_cold_backup_datafiles.tar
- -rw-r----- 1 oracle oinstall 501M Mar 15 21:47 sysaux01.dbf
- -rw-r----- 1 oracle oinstall 681M Mar 15 21:47 system01.dbf
- -rw-r----- 1 oracle oinstall 30M Mar 15 21:39 temp01.dbf
- -rw-r----- 1 oracle oinstall 91M Mar 15 21:47 undotbs01.dbf
- -rw-r----- 1 oracle oinstall 5.1M Mar 15 21:47 users01.dbf
复制代码
5)备库环境设置
(1)生成备库的密码文件
由于是在一台主机上部署Data Guard,因此这里仅需拷贝主库的密码文件生成备库密码文件即可。
- ora11g@secdb /u01/app/oracle/oradata/ora11gdg$ cd $ORACLE_HOME/dbs
- ora11g@secdb /u01/app/oracle/product/11.2.0/db_1/dbs$ cp orapwora11g orapwora11gdg
复制代码
(2)验证网络服务名是否完整及正确
- ora11g@secdb /home/oracle$ cat $ORACLE_HOME/network/admin/tnsnames.ora
- ORA11G =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = secdb)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = ora11g)
- )
- )
- ORA11GDG =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = secdb)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = ora11gdg)
- )
- )
复制代码
(3)生成备库spfile
- ora11g@secdb /home/oracle$ export ORACLE_SID=ora11gdg
- ora11gdg@secdb /home/oracle$ sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 15 21:56:31 2012
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- Connected to an idle instance.
- sys@ora11gdg@> create spfile from pfile;
- File created.
复制代码 6)启动物理备库
(1)启动物理备库
- sys@ora11gdg@> startup mount;
- ORACLE instance started.
- Total System Global Area 313860096 bytes
- Fixed Size 1336232 bytes
- Variable Size 209718360 bytes
- Database Buffers 96468992 bytes
- Redo Buffers 6336512 bytes
- Database mounted.
复制代码
(2)创建standby redo log file用于接收主库传过来的日志
由于主库已经提前创建好了4组standby redo log file,备库会根据LOG_FILE_NAME_CONVERT参数转换后自动创建与之对应的standby redo log file日志组。因此此步骤可省略。
(3)备库创建创建在线日志
备库会自动创建与主库对应的Redo日志组。因此此步骤可省略。
(4)启动Redo Apply
- sys@ora11gdg@> alter database recover managed standby database using current logfile disconnect from session;
- Database altered.
复制代码
7)验证备库处于正常运行中
(1)查看已存在的归档日志文件
- sys@ora11gdg@> select sequence#, first_time, next_time from v$archived_log order by sequence#;
- SEQUENCE# FIRST_TIME NEXT_TIME
- ---------- ----------------- -----------------
- 6 20120315 21:40:46 20120315 21:49:23
- 7 20120315 21:49:23 20120315 21:49:26
- 8 20120315 21:49:26 20120315 21:59:37
复制代码
(2)主库切换一次日志
- ora11gdg@secdb /home/oracle$ export ORACLE_SID=ora11g
- ora11g@secdb /home/oracle$ sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 15 22:04:47 2012
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- sys@ora11g> alter system switch logfile;
- System altered.
复制代码
(3)验证备库是否收到归档日志
- ora11g@secdb /home/oracle$ export ORACLE_SID=ora11gdg
- ora11gdg@secdb /home/oracle$ sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 15 22:05:12 2012
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- sys@ora11gdg@> select sequence#, first_time, next_time from v$archived_log order by sequence#;
- SEQUENCE# FIRST_TIME NEXT_TIME
- ---------- ----------------- -----------------
- 6 20120315 21:40:46 20120315 21:49:23
- 7 20120315 21:49:23 20120315 21:49:26
- 8 20120315 21:49:26 20120315 21:59:37
- 9 20120315 21:59:37 20120315 22:04:51
复制代码
(4)验证接收到的Redo是否被应用到物理备库
- sys@ora11gdg@> select sequence#,applied from v$archived_log order by sequence#;
- SEQUENCE# APPLIED
- ---------- ---------
- 6 YES
- 7 YES
- 8 YES
- 9 YES
复制代码
Oracle 11g物理Data Guard到此创建完毕。
3.Oracle 11g Data Guard物理备库创建完毕后续任务
1)建议根据具体应用需求调整数据保护模式级别。
关于Dataguard三种保护模式内容请参见文章《【DataGuard】Oracle Dataguard三种保护模式特点总结》(http://space.itpub.net/519536/viewspace-573342)
2)建议开启数据库的闪回功能。
4.体验Active Data Guard实时查询(Real-time query)特性
以创建表空间、用户以及表为例体验一下Oracle 11g物理Active Data Guard实时查询(Real-time query)特性。
1.调整备库为“READ ONLY WITH APPLY”状态
调整备库为“READ ONLY WITH APPLY”状态,这体现的便是Oracle 11g物理Active Data Guard功能中的“Active”真实含义。
1)查看备库当前状态
- ora11gdg@secdb /home/oracle$ sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 16 11:54:52 2012
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- sys@ora11gdg@> select open_mode from v$database;
- OPEN_MODE
- --------------------
- MOUNTED
复制代码 此时备库处于MOUNT状态。
2)取消备库的自动恢复
- sys@ora11gdg@> alter database recover managed standby database cancel;
- Database altered.
复制代码
3)OPEN备库调整为“READ ONLY”状态
- sys@ora11gdg@> alter database open;
- Database altered.
- sys@ora11gdg@> select open_mode from v$database;
- OPEN_MODE
- --------------------
- READ ONLY
复制代码
4)在“READ ONLY”状态下进一步启动备库的恢复
- sys@ora11gdg@> alter database recover managed standby database using current logfile disconnect;
- Database altered.
复制代码
选项“USING CURRENT LOGFILE”的含义是当备库收到日志后,尽快完成恢复。
- sys@ora11gdg@> select open_mode from v$database;
- OPEN_MODE
- --------------------
- READ ONLY WITH APPLY
复制代码
状态“READ ONLY WITH APPLY”即表示此时备库处于Read Only状态的同时可以接受主库传过来的日志进行恢复,以便达到备库可以即时查看到主库变化的目的。
2.体验实时查询(Real-time query)特性
1)主库上创建表空间、用户以及表并初始化数据
(1)创建表空间并查看表空间创建结果和状态
- sys@ora11g> create tablespace secooler_tbs datafile '/u01/app/oracle/oradata/ora11g/secooler_tbs01.dbf' size 10m;
- Tablespace created.
- sys@ora11g> select * from v$tablespace where name = 'SECOOLER_TBS';
- TS# NAME INC BIG FLA ENC
- ---------- ------------------------------ --- --- --- ---
- 8 SECOOLER_TBS YES NO YES
- sys@ora11g> select ts#,status,bytes,name from v$datafile where ts# = 8;
- TS# STATUS BYTES NAME
- ---------- ------- ---------- ------------------------------
- 8 ONLINE 10485760 /u01/app/oracle/oradata/ora11g
- /secooler_tbs01.dbf
复制代码
(2)创建用户并授权
- sys@ora11g> create user secooler identified by secooler default tablespace secooler_tbs;
- User created.
- sys@ora11g> grant dba to secooler;
- Grant succeeded.
复制代码
(3)创建表并初始化数据
- sys@ora11g> conn secooler/secooler
- Connected.
- secooler@ora11g> create table t (x varchar2(8));
- Table created.
- secooler@ora11g> insert into t values ('Secooler');
- 1 row created.
- secooler@ora11g> commit;
- Commit complete.
- secooler@ora11g> select * from t;
- X
- --------
- Secooler
复制代码
2)此时观察ora11g实例的alert日志记录了如下信息
- Fri Mar 16 11:56:36 2012
- create tablespace secooler_tbs datafile '/u01/app/oracle/oradata/ora11g/secooler_tbs01.dbf' size 10m
- Fri Mar 16 11:56:48 2012
- Completed: create tablespace secooler_tbs datafile '/u01/app/oracle/oradata/ora11g/secooler_tbs01.dbf' size 10m
复制代码
3)几乎与此同时(1秒)备库ora11gdg实例的警告日志中记录了如下信息
- Fri Mar 16 11:56:37 2012
- Recovery created file /u01/app/oracle/oradata/ora11gdg/secooler_tbs01.dbf
- Successfully added datafile 5 to media recovery
- Datafile #5: '/u01/app/oracle/oradata/ora11gdg/secooler_tbs01.dbf'
复制代码
可见,备库已经接受到主库的这个变化,并把这个变化在备库应用完毕。
4)验证主库所创建表空间、用户以及表并初始化数据是否在备库应用成功
(1)查看备库表空间
- sys@ora11gdg> select * from v$tablespace where name = 'SECOOLER_TBS';
- TS# NAME INC BIG FLA ENC
- ---------- ------------------------------ --- --- --- ---
- 8 SECOOLER_TBS YES NO YES
- sys@ora11gdg> select ts#,status,bytes,name from v$datafile where ts# = 8;
- TS# STATUS BYTES NAME
- ---------- ------- ---------- ------------------------------
- 8 RECOVER 10485760 /u01/app/oracle/oradata/ora11g
- dg/secooler_tbs01.dbf
复制代码
创建成功,但是此时备库数据文件的状态是“RECOVER”。
(2)查看备库用户及数据是否存在
- sys@ora11gdg> conn secooler/secooler
- Connected.
- secooler@ora11g> set lines 80
- secooler@ora11g> desc t;
- Name Null? Type
- ------------------ -------- ----------------------------
- X VARCHAR2(8)
- secoolerdg@ora11g> select * from t;
- X
- --------
- Secooler
复制代码 主库上的变化已经即使的在备库上得到应用。
这便是Oracle 11g物理Active Data Guard实时查询(Real-time query)特性的体现。
5.小结
文章详细记录了在Oracle 11gR2环境上部署物理Data Guard的过程和注意事项,供大家参考。
在部署或者管理Oracle 11g Data Guard环境时需要时刻清醒的认识到你操作的对象是主库还是备库,防止由于混乱导致潜在故障发生。
阅读(1138) | 评论(0) | 转发(0) |