Rely constraint and ROWID Tips

本文详细阐述了如何在逻辑备份数据库中使用行标识符进行表恢复,解释了行标识符在主数据库和Oracle实例之间的不一致性,并介绍了辅助日志机制在逻辑备份数据库中的应用。此外,文章还提供了在没有主键或唯一索引的表上解决问题的方法,包括定义禁用的主键约束,以及辅助日志对恢复过程的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Relying on Unique Identification of Rows in Data Guard Tables

In the physical standby database, the recovery is achieved using the rowid of segments. Since a logical standby database is not structurally exact as the primary database, the rowid between the primary and the Oracle instance will not be the same. For a logical standby database, the SQL apply service must use some other mechanism to uniquely identify a row in tables.

Usually, the primary key and non-null unique indexes are the best available data structure that can be used to identify a row in a table. In general, it is good practice for a database design to have a primary key or unique index on tables; however, this may not always be the case in any database.

Although having a primary key or unique index on tables will assist in recovery on a logical standby site, it is not an absolute requirement for logical Oracle instance setup. The SQL apply service can use other scalar columns from the tables to determine the uniqueness of rows.

Normally, when a row is updated in a database, its old and new values, along with the rowid, are written in the redo log. The redo log does not contain any information about the primary key or unique key for that row. Since a logical standby database depends on such an identifier to uniquely identify a row, Oracle introduced a Supplemental Logging mechanism for logical standby databases.

ROWID and supplemental logging

When the supplemental logging is active on a database, the redo logs contain other columns from tables to uniquely identify a row. If the table has a primary key or unique index defined, the only columns involved in the primary key or unique index will be registered in the redo logs along with the actual column(s) that has changed.

If the table does not have any primary keys or unique index defined, Oracle will write all scalar columns from the table to identify the row. This may significantly increase the size of redo logs and will impact the log apply services on the logical standby site.

One way to resolve this issue is to define a disabled primary key RELY constraint on those tables that do not have a primary key/unique index defined. Creating a disabled primary key will not add any extra overhead in maintaining the primary key on the primary database, yet it will minimize the information required in redo logs for logical Oracle instance recovery.

WARNING – Before creating the Primary Key RELY constraint, it is vital that the DBA understand the application data very well. Alternatively, the application developers can help with constraints definitions.

Putting a database in Supplemental Logging mode is a requirement for a logical standby database.  Even if all the tables in the database have a primary key defined, supplemental logging will have to be activated so that the primary key columns will be written to the redo logs along with the updated columns.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值