Skip to Main Content
  • Questions
  • How "ONLINE" is an "alter table move ONLINE" in 12.2 and beyond?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, John.

Asked: April 02, 2020 - 1:38 pm UTC

Last updated: March 18, 2024 - 3:53 am UTC

Version: 12.2.0.1

Viewed 10K+ times! This question is

You Asked

Good Morning,

It seems like Oracle has made some significant improvements to the "alter table move ONLINE" command in 12.2. For a basic heap table that is made up of varchar, char and number data types with a few b-tree indexes, it seems like we can now perform a table move while still allowing the application to perform a select, update, delete or insert on the table! In other words, if the table move takes 10 minutes, an application can execute DML operations, and it will not receive any errors. Please confirm that this is the case so that I will make sure not to cause an application issue the next time I run this command. It will also be nice to know how Oracle accomplished lowering the HWM with "alter table move online", but wasn't able to do it with the "SHRINK SPACE" command.

BTW: I noticed that the indexes are also maintained and remain "VALID" before, during and after the move operation.

I don't see why I would ever use "SHRINK SPACE" anymore since the operation is intrusive during the lowering of the HWM. Also, as an added annoyance, we have "enable row movement" on the table.

P.S. I am now aware of the restriction when using the "alter table move ONLINE" command which are listed here: https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/ALTER-TABLE.html#GUID-552E7373-BF93-477D-9DA3-B2C9386F2877

Thank you,

John

and Chris said...

ALTER TABLE ... MOVE ONLINE is non-blocking DDL. Which means that yes, you can run DML against the table while the move completes.

Though if there is any uncommitted DML on the table, this DDL statement is itself blocked until the transaction itself completes.

Though as you've noted, this has a few restrictions:

Restrictions on Moving Tables Online

Moving tables online is subject to the following restrictions:

* You cannot combine this clause with any other clause in the same statement.

* You cannot specify this clause for a partitioned index-organized table.

* You cannot specify this clause if a domain index is defined on the table.

* Parallel DML and direct path INSERT operations require an exclusive lock on the table. Therefore, these operations are not supported concurrently with an ongoing online table MOVE, due to conflicting locks.

* You cannot specify this clause for index-organized tables that contain any LOB, VARRAY, Oracle-supplied type, or user-defined object type columns.


A major difference between MOVE and SHRINK is MOVE is out-of-line. So you need enough space to store two copies of the table. This is not the case with SHRINK.

For more discussion on the differences between these, see: https://asktom.oracle.com/pls/apex/f?p=100:11:::NO:RP:P11_QUESTION_ID:9527343800346989243

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

John Cantu, April 02, 2020 - 4:13 pm UTC

That's perfect, Chris.

Since you bring up other methods, I don't think I will ever use DMBS_REDEFINITION again to lower HWM since I can use "alter table move online" now. I'm assuming that DBMS_REDEFINITION also requires about twice the space to complete, right?
Connor McDonald
April 03, 2020 - 2:31 am UTC

WIth almost any "move" style operation, we rarely move *in place*, so there will always be requirement for additional space temporarily.

'coalese' is an exception

MOVE ONLINE

oj, October 31, 2022 - 12:41 pm UTC

With this restriction for MOVE ONLINE;

* You cannot combine this clause with any other clause in the same statement.

Does that mean you can't perform MOVE ONLINE PARALLEL ? (but if the TABLE PARALLEL ATTIBUTE is set, does it circumvent this restriction as you don't need the PARALLEL clause then?)

If PARALLEL is a no go with MOVE ONLINE, that certainly could be a case for going back to SHRINK (bearing in mind the differences/restrictions that's been explained already)
Chris Saxon
October 31, 2022 - 4:19 pm UTC

You can MOVE ONLINE PARALLEL; verify this by querying v$px_process (or similar views) when running the alter table statement. Ensure parallel DDL is enabled for the session!

MOVE ONLINE with multiple LOBs

Tom, March 12, 2024 - 5:05 pm UTC

I am trying to figure out best way to get the table with multiple LOB columns moved to new tablespaces. here is my test SQL

alter table DA000032.test2 move tablespace TESTTBS1
lob(X1) store as (tablespace LOB_TBS1)
lob(X2) store as (tablespace LOB_TBS1)
ONLINE
;

when I do the move, I have DML (UPDATES) running in 2 other windows. one window starts before the DDL MOVE command is entered, the second window is started after the MOVE command is entered. the MOVE does not complete until both windows are committed/rolled back.

My thought was that they would get executed in order, quiesce the DML as needed to move the table and LOB segments.
is this to do with the LOB segments? it is not ONLINE, if the command will not execute while DML is running?


Connor McDonald
March 18, 2024 - 3:53 am UTC

We need a "quiet point" at both start and end of the process.

For example, I did this in isolation:

SQL> create table t (
  2    x int primary key,
  3    c clob );

Table created.

SQL>
SQL>
SQL> insert into t
  2  select rownum, rpad('x',32000,'x')
  3  from dual
  4  connect by level <= 3000;

3000 rows created.

SQL> commit;

Commit complete.

SQL>
SQL> set timing on
SQL> alter table t move lob(c) store as ( tablespace users ) online;

Table altered.

Elapsed: 00:00:05.65


So I need 5 seconds to move the data.

Then I did the following tests:

Session 1: delete from t where x= 1;
Session 2: alter table move; (which waits)

When I committed session 1, session 2 returned AFTER 5 seconds, thus the move operation had not done any work until session 1 committed.

Then I flipped it

Session 1: alter table move; (starts)
Session 2: delete from t where x= 1;

Session 1 never returns, but when I commit session 2, session 1 'instantly' completes, ie, most of the work was done.

We need a moment of no txn activity to commence and complete the operation.

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.