首页 > 其他 > 详细

数据卫士

时间:2015-06-11 02:17:36      阅读:279      评论:0      收藏:0      [点我收藏+]
 

对于数据卫士,您可以在物理备用和逻辑备用之间进行选择。让我们先来看一下两者 有哪些不同!我将首先演示物理备用,随后转换至逻辑备用(数据库也由此命名):

[oracle@uhesse1 ~]$ dgmgrl sys/oracle@prima

DGMGRL for Linux: Version 11.2.0.1.0 - 64bit Production

Copyright (c) 2000, 2009, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.

Connected.

DGMGRL> show configuration;

Configuration - myconf

  Protection Mode: MaxPerformance

  Databases:

    prima - Primary database

    logst - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:

SUCCESS

到目前为止,logst仍然是物理备用。被称为物理备用的原因是,primalogst的数据文件在物理上是相同的。我甚至可以从一个还原至另一个:

DGMGRL> edit database logst set state=apply-off;

Succeeded.

DGMGRL> exit

[oracle@uhesse1 ~]$ sqlplus sys/oracle@prima as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 20 11:43:07 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

SYS@prima > select name from v$datafile where file#=4;

NAME

--------------------------------------------------

/u01/app/oracle/oradata/prima/users01.dbf

SYS@prima > alter database datafile 4 offline;

Database altered.

现在,我从备用服务器uhesse2中将数据文件复制到主服务器uhesse1,有不同的方法可以做到这一点,但scp是一个:

SYS@logst > select name from v$datafile where file#=4;

NAME

--------------------------------------------------

/u01/app/oracle/oradata/logst/users01.dbf

SYS@logst > exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

[oracle@uhesse2 ~]$ scp /u01/app/oracle/oradata/logst/users01.dbf uhesse1:/u01/app/oracle/oradata/prima/users01.dbf

The authenticity of host ‘uhesse1 (192.168.56.10)‘ can‘t be established.

RSA key fingerprint is e9:e7:5b:8b:b2:33:42:26:89:03:54:0c:16:0d:98:57.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘uhesse1,192.168.56.10‘ (RSA) to the list of known hosts.

oracle@uhesse1‘s password:

users01.dbf                                                                                               100% 5128KB   5.0MB/s   00:00   

[oracle@uhesse2 ~]$

当我尝试将数据文件在prima上再次上线时,看起来就像我想从备份中将其恢复:

SYS@prima > alter database datafile 4 online;

alter database datafile 4 online

*

ERROR at line 1:

ORA-01113: file 4 needs media recovery

ORA-01110: data file 4: ‘/u01/app/oracle/oradata/prima/users01.dbf‘

SYS@prima > recover datafile 4;

Media recovery complete.

SYS@prima > alter database datafile 4 online;

Database altered.

在此处的两个站点中,数据文件和归档的日志文件在物理上都是相同的,只有控制文 件是不同的。 v$database(比如v$datafile)从控制文件获取其内容:

SYS@prima > select name,dbid,database_role from v$database;

NAME                                                                   DBID DATABASE_ROLE

-------------------------------------------------- ---------- ----------------

PRIMA                                                           2012613220 PRIMARY

SYS@prima > connect sys/oracle@logst as sysdba

Connected.

SYS@logst > select name,dbid,database_role from v$database;

NAME                                                                   DBID DATABASE_ROLE

-------------------------------------------------- ---------- ----------------

PRIMA                                                           2012613220 PHYSICAL STANDBY

现在,我要将其转换至逻辑备用:

DGMGRL> edit database logst set state=apply-off;

Succeeded.

DGMGRL> exit

[oracle@uhesse1 ~]$ sqlplus sys/oracle@prima as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 20 17:29:16 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

SYS@prima > exec dbms_logstdby.build

PL/SQL procedure successfully completed.

SYS@prima > connect sys/oracle@logst as sysdba

Connected.

SYS@logst > alter database recover to logical standby logst;

Database altered.

SYS@logst > shutdown immediate

ORA-01507: database not mounted

ORACLE instance shut down.

SYS@logst > startup mount

ORACLE instance started.

Total System Global Area  521936896 bytes

Fixed Size                         2214936 bytes

Variable Size                    314573800 bytes

Database Buffers      201326592 bytes

Redo Buffers                       3821568 bytes

Database mounted.

SYS@logst > alter database open resetlogs;

Database altered.

SYS@logst > select name,dbid,database_role from v$database;

NAME                                                                   DBID DATABASE_ROLE

-------------------------------------------------- ---------- ----------------

LOGST                                                           3156487356 LOGICAL STANDBY

SYS@logst > exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

[oracle@uhesse1 ~]$ dgmgrl sys/oracle@prima

DGMGRL for Linux: Version 11.2.0.1.0 - 64bit Production

Copyright (c) 2000, 2009, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.

Connected.

DGMGRL> remove database logst;

Removed database "logst" from the configuration

DGMGRL> add database logst as connect identifier is logst;

Database "logst" added

DGMGRL> enable database logst;

Enabled.

DGMGRL> show configuration;

Configuration - myconf

  Protection Mode: MaxPerformance

  Databases:

    prima - Primary database

    logst - Logical standby database

Fast-Start Failover: DISABLED

Configuration Status:

SUCCESS

一处重要的改变是, DBID和名称现已不同于上面看到的主数据库。数据文件在物理上也不再是相同的:

DGMGRL> edit database logst set state=apply-off;

Succeeded.

DGMGRL> exit

[oracle@uhesse1 ~]$ sqlplus sys/oracle@prima as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 20 17:38:56 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

SYS@prima > alter database datafile 4 offline;

Database altered.

SYS@prima > select name from v$datafile where file#=4;

NAME

--------------------------------------------------

/u01/app/oracle/oradata/prima/users01.dbf

SYS@prima > host cp /u01/app/oracle/oradata/prima/users01.dbf /u01/app/oracle/oradata/prima/users01.old

我复制原始文件的原 因是,我知道从logst恢复将不起作用。为了证明我的观点:

[oracle@uhesse2 ~]$ scp /u01/app/oracle/oradata/logst/users01.dbf uhesse1:/u01/app/oracle/oradata/prima/users01.dbf

oracle@uhesse1‘s password:

users01.dbf                                                                                   100% 5128KB   5.0MB/s   00:00   

SYS@prima > alter database datafile 4 online;

alter database datafile 4 online

*

ERROR at line 1:

ORA-01122: database file 4 failed verification check

ORA-01110: data file 4: ‘/u01/app/oracle/oradata/prima/users01.dbf‘

ORA-01206: file is not part of this database - wrong database id

没错,logst现在是一个自主数据库,它只是偶然地使用与prima(几乎)相同的DML。它在Oracle数据块方面已不再与prima相同。对于logst来说,来自于primarowids已不再有意义:

DGMGRL> edit database logst set state=apply-on;

Succeeded.

SYS@prima > insert into scott.dept values (50,‘TEST‘,‘TEST‘);

insert into scott.dept values (50,‘TEST‘,‘TEST‘)

                  *

ERROR at line 1:

ORA-00376: file 4 cannot be read at this time

ORA-01110: data file 4: ‘/u01/app/oracle/oradata/prima/users01.dbf‘

SYS@prima > host cp /u01/app/oracle/oradata/prima/users01.old /u01/app/oracle/oradata/prima/users01.dbf

SYS@prima > alter database datafile 4 online;

alter database datafile 4 online

*

ERROR at line 1:

ORA-01113: file 4 needs media recovery

ORA-01110: data file 4: ‘/u01/app/oracle/oradata/prima/users01.dbf‘

SYS@prima > recover datafile 4;

Media recovery complete.

SYS@prima > alter database datafile 4 online;

Database altered.

SYS@prima > insert into scott.dept values (50,‘TEST‘,‘TEST‘);

1 row created.

SYS@prima > commit;

Commit complete.

SYS@prima > select rowid,dept.* from scott.dept where deptno=50;

ROWID                      DEPTNO DNAME      LOC

------------------ ---------- -------------- -------------

AAADS8AAEAAAACNAAE     50 TEST               TEST

这就是我们通常记录在重做日志条目中的rowid,在我们进行“Redo Apply”(“恢复数据库”的另一种术语)时,该rowid足以在主数据库上以及一个物理备用上对该行进行检索。但这个rowidlogst上是不同的:

SYS@logst > connect sys/oracle@logst as sysdba

Connected.

SYS@logst > select rowid,dept.* from scott.dept where deptno=50;

ROWID DEPTNO DNAME LOC

------------------ ---------- -------------- -------------

AAADS8AAEAAAACOAAA 50 TEST TEST

这就是为什么我们需要将附加信息(补充日志数据)放入主数据库的重做日志条 目中。这将帮助SQL Apply机制对该行进行检索:

bubuko.com,布布扣

逻辑备用架构

补充日志数据应至少额外包括上图中的主键。在没有主键的情况下,修改行的每 一列将被写入重做日志。 这将影响主数据库的性能逻辑备用的另一个严重缺点是,SQL Apply机制并不支持每个数据类型和每个在主数据库上的操作。然而,不支持的数据类型数量随着版本的升级正在逐渐减少。

 

数据卫士

原文:http://blog.itpub.net/12798004/viewspace-1692815/

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!