Will moving a table/partition to a different tablespace interrupt queries accessing said table/partition?

梦想的初衷 提交于 2019-12-08 03:54:50

问题


As the title says: will moving (without renaming) a table/partition while it's being accessed have negative consequences on any queries accessing it?

For example, say there's a long-running SELECT COUNT(*) FROM some_table.
If I were to ALTER TABLE some_table MOVE TABLESPACE some_other_tablespace, would the SELECT fail?
Would it complete, but have incorrect results? Maybe something else entirely?

The only info I could find was that moving the table to a different tablespace would require rebuilding the indices under certain circumstances, but none made mention of what happens to any active queries.


回答1:


It might fail with ORA-08103: object no longer exists.

In Oracle, readers and writers do not block each other. Which means DML and queries will not interfere with each other, excluding a few weird cases like running out of UNDO space. But moving a tablespace, or any type of ALTER or other DDL statement, is not a normal write. The multiversion concurrency control model breaks down when you run DDL, at least for the involved objects, and weird things start to happen.

Testing a large move is difficult, but you can reproduce these errors by looping through a lot of small alters and queries. In case you think this is only a theoretical issue, I have seen these errors occur in real-life, on a production database.

Warning: infinite loops below since I can't predict how long it will take to reproduce this error. But it usually only takes me tens of seconds.

--Create sample table.
drop table test1 purge;
create table test1(a number, b number)
partition by list(a) (partition p1 values(1), partition p2 values(2))
nologging tablespace users;

--Session 1
begin
  loop
    execute immediate '
      insert /*+ append */ into test1 select mod(level,2)+1, level
      from dual connect by level <= 100000';
    commit;
    execute immediate 'alter table test1 move partition p1 tablespace users';
  end loop;
end;
/       

--Session 2: Read from moved partition
declare
  v_count number;
begin
  loop
    select count(*) into v_count from test1 where a = 1;
  end loop;
end;
/

--Session 3: Read from unmoved partition
declare
  v_count number;
begin
  loop
    select count(*) into v_count from test1 where a = 2;
  end loop;
end;
/

Session 2 will eventually die with:

ORA-08103: object no longer exists
ORA-06512: at line 6

Session 3 will not fail, it is not querying an altered partition. Each partition has its own segment, and is a separate object that can potentially "no longer exist".




回答2:


A partition move WILL cause DML to fail if it is accessing the parition.

I just proved it :-/.

I was doing a large delete and tried to move a partition (alter table move partition).
The error I received was: ORA-12801: error signaled in parallel query server P004ORA-08103: object no longer exists



来源:https://stackoverflow.com/questions/15531881/will-moving-a-table-partition-to-a-different-tablespace-interrupt-queries-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!