- 浏览: 87078 次
- 性别:
- 来自: 北京
最新评论
One of the relatively newer features in Oracle concerns the moving of rows. Why would a row move and who or what controls that movement? Furthermore, by “move,” what exactly does move mean? Does a row move to another table, or is row movement constrained to the row’s container (i.e., a table)? An early use of row movement was highlighted in Oracle8i, and row movement then, as well as now, applied to moving rows in a partitioned table. With newer releases of the Oracle RDBMS, where else does row movement come into play, and are there any gotcha’s with respect to row movement operations?
This article looks at three common cases or situations where row movement needs to be enabled.
Partitioned Tables
As far back as Oracle 8.1.5 documentation, row movement applied to updatable partition keys. A list partition where the partition key is a specific value is a good example of this. Many partitioned table examples use regions, cities and states as list examples. What happens if you use a city as a partition key and an office in that city moves elsewhere? Or two offices in the same city (from different groups or business units within the same company) merge into one location? You could split the default partition and add the new location name. How would you move records from the old partitioned into the new one? Short of deleting from one partition and inserting same into a new one, wouldn’t it be easier to be able to perform a single update?
Let’s create a quick partitioned table example and see how moving a row works.
All of the cities are located in the Denver area (city ID of 282 in this example). Broomfield is further north of the Denver metro area and has been slated to become part of the Boulder area office group (using a city ID of 283). Let’s try and move it by updating the partition key value for that office.
Why didn’t the update work? The error message doesn’t come right out and say it, but the reason is that row movement is not enabled. How would you know this right off the bat? The reason why you would know this is due to the fact that row movement – by default – is not enabled. A simple alter table statement remedies the update problem.
Why did I disable the row movement? Well, tables are partitioned for a reason, and to help ensure data goes where it is supposed to, you should disallow inadvertent updates or row movements. Obviously, if your application requires those types of updates, this guideline wouldn’t necessarily apply to you.
Flashback
Being able to flashback DML operations has greatly reduced the frequency of how often you hear a DBA say, “Oops.” In the next example, I’ll delete a row, commit the operation, and try to recover the deleted record.
The error message in this case is much clearer as to the nature of the failed statement. I find it handy to keep the flashback syntax around in an easily (and quickly) identifiable location, and that is chiefly because I don’t use timestamps that much in my applications. Time is still somewhat of the essence and the quicker you can recover the table to a good state, the better.
If the table has row movement disabled, why is it you can drop the table and flashback the table to before the drop without row movement being enabled?
Chapter 15 in the Database Concepts guide states the following:
For Flashback Table to succeed, the system must retain enough undo information to satisfy the specified SCN or timestamp, and the integrity constraints specified on the tables cannot be violated. Also, row movement must be enabled.
The example above shows that “row movement must be enabled” is not entirely true.
Space Management
The third and final example of where row movement comes into play can be found in shrink operations. If you think about it, shrinking a table may entail moving data around within a table (handled internally by Oracle), so the idea of a row moving around makes sense. First, let’s get a record of the current ROWIDs for each office and then delete two rows.
Even in this small table, we should be able to reclaim some space, so let’s try shrinking the table.
Notice that the error number is different from the flashback example, but the message is pretty clear. We’ll alter the table and perform the shrink operation.
Now that the shrink has taken place, let’s examine the ROWIDs for the remaining two rows. Will the ROWIDs be the same or different?
Interestingly enough, the ROWIDs for the two remaining rows are different from their original IDs before the delete statement. You may have expected office_number 4’s ROWID to change, but not office_number 1’s, but it too changed location after the shrink.
The moral of the story here supports what the documentation says (in more than one place):
Before you use rowids in DML statements, they should be verified and guaranteed not to change. The intended rows should be locked so they cannot be deleted. Under some circumstances, requesting data with an invalid rowid could cause a statement to fail.
Using ROWIDs to perform DML on records can be wicked fast, and is virtually the fastest way to access a row. However, if there is any chance that someone else’s operation (and even yours) can alter the ROWIDs of a table, you can find yourself with lots of messy data. Further, a shrink operation (without the COMPACT option) can invalidate open cursors. That could spell trouble for an application.
In Closing
We looked at three major operations where row movement is required: partition key value change, flashback and space management. Enabling and disabling row movement is very simple to implement, and in most cases, has no unwanted side effects. Space management operations using the SHRINK option can have unintended consequences on other users and operations, and as we all know, good deeds (cleaning up space) should never go unpunished. Using row movement and understanding what takes place makes this feature an invaluable asset in your administration arsenal, and it is up to you to be careful so as not to be bitten by a changed ROWID.
This article looks at three common cases or situations where row movement needs to be enabled.
Partitioned Tables
As far back as Oracle 8.1.5 documentation, row movement applied to updatable partition keys. A list partition where the partition key is a specific value is a good example of this. Many partitioned table examples use regions, cities and states as list examples. What happens if you use a city as a partition key and an office in that city moves elsewhere? Or two offices in the same city (from different groups or business units within the same company) merge into one location? You could split the default partition and add the new location name. How would you move records from the old partitioned into the new one? Short of deleting from one partition and inserting same into a new one, wouldn’t it be easier to be able to perform a single update?
Let’s create a quick partitioned table example and see how moving a row works.
SQL> CREATE TABLE CITY_OFFICES 2 ( 3 OFFICE_NUMBER NUMBER NOT NULL, 4 CITY_ID VARCHAR2(12) NOT NULL, 5 OFFICE_NAME VARCHAR2(30) NOT NULL 6 ) 7 PARTITION BY LIST (CITY_ID) 8 ( 9 PARTITION P282 VALUES ('282'), 10 PARTITION P283 VALUES ('283'), 11 PARTITION P284 VALUES ('284')); Table created. SQL> SQL> INSERT INTO CITY_OFFICES VALUES (1,'282','DENVER'); 1 row created. SQL> INSERT INTO CITY_OFFICES VALUES (2,'282','DENVER TECH CTR'); 1 row created. SQL> INSERT INTO CITY_OFFICES VALUES (3,'282','DENVER WEST'); 1 row created. SQL> INSERT INTO CITY_OFFICES VALUES (4,'282','BROOMFIELD'); 1 row created. SQL> COMMIT; Commit complete.
All of the cities are located in the Denver area (city ID of 282 in this example). Broomfield is further north of the Denver metro area and has been slated to become part of the Boulder area office group (using a city ID of 283). Let’s try and move it by updating the partition key value for that office.
SQL> UPDATE CITY_OFFICES SET CITY_ID = '283' WHERE OFFICE_NUMBER = 4; UPDATE CITY_OFFICES SET CITY_ID = '283' WHERE OFFICE_NUMBER = 4 * ERROR at line 1: ORA-14402: updating partition key column would cause a partition change
Why didn’t the update work? The error message doesn’t come right out and say it, but the reason is that row movement is not enabled. How would you know this right off the bat? The reason why you would know this is due to the fact that row movement – by default – is not enabled. A simple alter table statement remedies the update problem.
SQL> ALTER TABLE CITY_OFFICES ENABLE ROW MOVEMENT; Table altered. SQL> UPDATE CITY_OFFICES SET CITY_ID = '283' WHERE OFFICE_NUMBER = 4; 1 row updated. SQL> COMMIT; Commit complete. SQL> ALTER TABLE CITY_OFFICES DISABLE ROW MOVEMENT; Table altered.
Why did I disable the row movement? Well, tables are partitioned for a reason, and to help ensure data goes where it is supposed to, you should disallow inadvertent updates or row movements. Obviously, if your application requires those types of updates, this guideline wouldn’t necessarily apply to you.
Flashback
Being able to flashback DML operations has greatly reduced the frequency of how often you hear a DBA say, “Oops.” In the next example, I’ll delete a row, commit the operation, and try to recover the deleted record.
SQL> DELETE FROM CITY_OFFICES WHERE OFFICE_NUMBER = 1; 1 row deleted. SQL> COMMIT; Commit complete. SQL> FLASHBACK TABLE CITY_OFFICES 2 TO TIMESTAMP (SYSTIMESTAMP - INTERVAL '05' minute); FLASHBACK TABLE CITY_OFFICES * ERROR at line 1: ORA-08189: cannot flashback the table because row movement is not enabled
The error message in this case is much clearer as to the nature of the failed statement. I find it handy to keep the flashback syntax around in an easily (and quickly) identifiable location, and that is chiefly because I don’t use timestamps that much in my applications. Time is still somewhat of the essence and the quicker you can recover the table to a good state, the better.
SQL> ALTER TABLE CITY_OFFICES ENABLE ROW MOVEMENT; Table altered. SQL> FLASHBACK TABLE CITY_OFFICES 2 TO TIMESTAMP (SYSTIMESTAMP - INTERVAL '05' minute); Flashback complete. SQL> SELECT * FROM CITY_OFFICES; OFFICE_NUMBER CITY_ID OFFICE_NAME ------------- ------------ ------------------------------ 1 282 DENVER 2 282 DENVER TECH CTR 3 282 DENVER WEST 4 283 BROOMFIELD
If the table has row movement disabled, why is it you can drop the table and flashback the table to before the drop without row movement being enabled?
SQL> ALTER TABLE CITY_OFFICES DISABLE ROW MOVEMENT; Table altered. SQL> DROP TABLE CITY_OFFICES; Table dropped. SQL> FLASHBACK TABLE CITY_OFFICES TO BEFORE DROP; Flashback complete.
Chapter 15 in the Database Concepts guide states the following:
For Flashback Table to succeed, the system must retain enough undo information to satisfy the specified SCN or timestamp, and the integrity constraints specified on the tables cannot be violated. Also, row movement must be enabled.
The example above shows that “row movement must be enabled” is not entirely true.
Space Management
The third and final example of where row movement comes into play can be found in shrink operations. If you think about it, shrinking a table may entail moving data around within a table (handled internally by Oracle), so the idea of a row moving around makes sense. First, let’s get a record of the current ROWIDs for each office and then delete two rows.
SQL> SELECT ROWID, OFFICE_NUMBER FROM CITY_OFFICES; ROWID OFFICE_NUMBER ------------------ ------------- AAANSfAAEAAAEAnAAA 1 AAANSfAAEAAAEAnAAD 2 AAANSfAAEAAAEAnAAE 3 AAANSgAAEAAAEAvAAA 4 SQL> DELETE FROM CITY_OFFICES WHERE OFFICE_NUMBER IN (2,3); 2 rows deleted. SQL> COMMIT; Commit complete.
Even in this small table, we should be able to reclaim some space, so let’s try shrinking the table.
SQL> ALTER TABLE CITY_OFFICES SHRINK SPACE; ALTER TABLE CITY_OFFICES SHRINK SPACE * ERROR at line 1: ORA-10636: ROW MOVEMENT is not enabled
Notice that the error number is different from the flashback example, but the message is pretty clear. We’ll alter the table and perform the shrink operation.
SQL> ALTER TABLE CITY_OFFICES ENABLE ROW MOVEMENT; Table altered. SQL> ALTER TABLE CITY_OFFICES SHRINK SPACE; Table altered.
Now that the shrink has taken place, let’s examine the ROWIDs for the remaining two rows. Will the ROWIDs be the same or different?
SQL> SELECT ROWID, OFFICE_NUMBER FROM CITY_OFFICES; ROWID OFFICE_NUMBER ------------------ ------------- AAANSfAAEAAAEAkAAA 1 AAANSgAAEAAAEAsAAA 4
Interestingly enough, the ROWIDs for the two remaining rows are different from their original IDs before the delete statement. You may have expected office_number 4’s ROWID to change, but not office_number 1’s, but it too changed location after the shrink.
The moral of the story here supports what the documentation says (in more than one place):
Before you use rowids in DML statements, they should be verified and guaranteed not to change. The intended rows should be locked so they cannot be deleted. Under some circumstances, requesting data with an invalid rowid could cause a statement to fail.
Using ROWIDs to perform DML on records can be wicked fast, and is virtually the fastest way to access a row. However, if there is any chance that someone else’s operation (and even yours) can alter the ROWIDs of a table, you can find yourself with lots of messy data. Further, a shrink operation (without the COMPACT option) can invalidate open cursors. That could spell trouble for an application.
In Closing
We looked at three major operations where row movement is required: partition key value change, flashback and space management. Enabling and disabling row movement is very simple to implement, and in most cases, has no unwanted side effects. Space management operations using the SHRINK option can have unintended consequences on other users and operations, and as we all know, good deeds (cleaning up space) should never go unpunished. Using row movement and understanding what takes place makes this feature an invaluable asset in your administration arsenal, and it is up to you to be careful so as not to be bitten by a changed ROWID.
发表评论
-
dbms_output can not put the zero
2011-08-25 09:29 792DECLARE V_INTA NUMBER ... -
what is the difference between object_id and data_object_id?
2011-08-24 09:17 983The object_id is the primary k ... -
oracle EXECUTE IMMEDIATE ora-00911
2011-08-14 10:15 1550I get an error when I try to ex ... -
Will the valid status of index impact dml operation?
2011-08-05 10:34 882DROP TABLE tab01; SELECT * FRO ... -
where can i find the job number of those jobs defined in dba_scheduler_jobs?
2011-08-01 10:41 877Question: Hello, could anybody ... -
Listener HPUX Error: 242: No route to host
2011-05-17 14:55 1016现象: 引用LSNRCTL> status Conne ... -
一进程阻塞问题解决
2011-05-12 16:38 4155同事反映,删除一条数据总是没有反应,请求协助解决. 问题非常 ... -
open database with ORA-00704 and ORA-39700
2011-05-06 16:13 29461,Error 1)alter.log Fri May ... -
oracle text index create and use
2011-05-06 13:41 1958一、Install Text Index 1,The ste ... -
offline datafile and offline tablespace
2011-05-04 11:43 25541)offline datafile OFFLINE Spe ... -
oracle three type of block size
2011-04-28 17:35 796Tools: 引用[oracle@node oracle]$ ... -
bbed一(安装)
2011-04-26 14:54 1545bbed ----------------------- bl ... -
Strategies for RAC inter-instance parallelized queries
2011-04-25 14:14 1171I recently had to sit down and ... -
Enable Row Movement in Partitioning and Overhead
2011-04-24 14:03 1594Question 1: Hi, I am partitio ... -
ORA-14402 updating partition key column
2011-04-23 19:48 6440做DBA几年来,经常遇到项目到了维护期总是修改表的结构,原因很 ... -
ORACLE DSI 介绍
2011-04-19 18:33 927DSI是Data Server Internals的缩写,是O ... -
Oracle / Buffer cache
2011-04-19 17:18 818引用8.7 Tuning the Operating Syst ...
相关推荐
ROW MOVEMENT 是 Oracle 中的一项特性,最初是在 8i 时引入的,旨在提高分区表的灵活性。这一特性默认是关闭的,需要在特定的场景下打开,例如使用 Flashback Table、Shrink Segment 和更新 Partition Key 等功能。 ...
alter table 表名 enable row movement; ``` 否则,可能会出现 ORA-08189 错误:“未启用行移动功能,不能闪回表。” 在恢复数据之后,需要关闭行移动功能: ```sql alter table 表名 disable row movement; ``` ...
## oracle恢复误删除的表数据 ** 查询某个时间节点的表数据 ```java select * from 表名 as of timestamp to_timestamp('2020-04-27 17:25:00','yyyy-mm-dd hh24:mi:ss') ``` 开启行移动功能 ```java alter table ...
ENABLE ROWMOVEMENT`语句启用,就可以执行回闪表操作。回闪表利用Oracle的撤销段(undo segment)存储的旧数据版本,通过回闪查询技术恢复表到指定时间点的状态。 在案例中,John面临的问题是由于年末批处理导致的...
其ROW MOVEMENT功能允许行在表内的移动,便于数据压缩和分区操作。 2. **自动内存管理**:11g引入了自动内存管理机制,系统能够自动调整SGA(System Global Area)和PGA(Program Global Area)的大小,以优化性能...
SQL> alter table emp enable row movement; SQL> flashback table dept to timestamp to_timestamp('2016-09-10 11:00:00','yyyy-mm-dd hh24:mi:ss'); 闪回表可能会失败,有可能有以下几种情况:违反了数据库约束...
ALTER TABLE 表名称 ENABLE ROW MOVEMENT; ``` 然后,使用`FLASHBACK TABLE`语句将表数据恢复到特定时间点: ```sql FLASHBACK TABLE person1 TO TIMESTAMP TO_TIMESTAMP('2017-08-22 09:00:00', 'yyyy-mm-dd hh24...
ENABLE ROW MOVEMENT`和`CTAS`(创建表作为选择)等方法,以减少锁定和提高性能。 这个实例展示了Oracle SQL在数据清洗和管理中的强大功能,特别是在处理重复数据时。了解如何有效地删除重复数据并保留最新信息...
ALTER TABLE 表名 ENABLE ROW MOVEMENT; FLASHBACK TABLE 表名 TO TIMESTAMP TO_TIMESTAMP('删除时间点', 'yyyy-mm-dd hh24:mi:ss'); ``` ##### 3.2 DROP误删除的恢复方法 **原理**:Oracle在执行DROP操作时,并不...
- **启用行移动**:执行`ALTER TABLE 表名 ENABLE ROW MOVEMENT;` - **闪回表**:执行`FLASHBACK TABLE 表名 TO TIMESTAMP TO_TIMESTAMP('删除时间点', 'yyyy-mm-dd hh24:mi:ss');` #### 三、Drop或Truncate误...
oracle 分区技术-大批量数据操作 大数据对象 (表, 索引)被分成小物理段 ...(row movement enabled) 分区可以存储在不同的表空间 分区可以有不同的物理存储参数 分区支持IOT表,对象表,LOB字段,varrays等
考虑使用ROW MOVEMENT、TABLE COMPRESSION等特性,根据实际需求平衡空间与性能。 5. **资源管理**:通过Oracle的调度工具如DBMS_JOB或DBMS_SCHEDULER,可以有效地安排资源的使用,避免高峰期的资源冲突。此外,使用...
alter table bwf_cond enable row movement; flashback table bwf_cond to timestamp to_timestamp('2018-04-27 16:00:00','yyyy-mm-ddhh24:mi:ss'); ``` 这将把`bwf_cond`表恢复到2018年4月27日16点的状态。 2...
ALTER TABLE table_name ENABLE ROW MOVEMENT; ``` 启用行移动后,当执行`ALTER TABLE SHRINK SPACE`时,Oracle会自动移动行到新的位置,从而重置高水位线。 - **收缩表空间**: ```sql ALTER TABLE table_...
这要求表必须启用 `row movement` 功能。 示例代码如下: ```sql SQL> alter table A enable row movement; SQL> flashback table A to timestamp 'YYYY-MM-DD HH24:MI:SS'; ``` #### Oracle Flashback Drop...
* 闪回操作(误删后台菜单):alter table PUB_QUERYMODELDEF enable row movement; flashback table PUB_QUERYMODELDEF to timestamp to_timestamp('20190307 16:20:20','yyyymmdd hh24:mi:ss'); alter table PUB_...
这个过程允许数据的动态移动(如果启用了row movement),并且分区可以分布在不同的表空间,具有不同的物理存储参数。分区支持多种数据类型,包括IOT表、对象表、LOB字段和varrays。 分区技术的主要优点在于性能...
使用此功能时,表必须具有ROW MOVEMENT属性,以确保可以移动表中的行。通过执行类似`FLASHBACK TABLE table_name TO TIMESTAMP 'YYYY-MM-DD HH24:MI:SS';`或`TO SCN scn_value;`的命令,可以恢复表至指定的时间点或...
- 表必须开启`ROW MOVEMENT`属性。 - `SYS`用户所拥有的对象不能被闪回。 - 闪回操作不能跨越DDL语句。 ### 1.2.3 闪回数据库 **数据库闪回**是Oracle 10g及以后版本的一个重要特性,它允许将整个数据库恢复到之前...
40. **ROW_MOVEMENT**: 行移动。 41. **GLOBAL_STATS**: 全局统计信息。 42. **USER_STATS**: 用户统计信息。 43. **DURATION**: 持续时间。 44. **SKIP_CORRUPT**: 是否跳过损坏的数据。 45. **MONITORING**: 监控...