Oracle

到目前為止,中斷 ALTER INDEX COALESCE CLEANUP 是否會失去工作?

  • April 21, 2020

在 Oracle 12c (12.1) 中,我們有一個帶有間隔分區的巨大分區表。除了本地索引,上面還有兩個全域索引。使用 UPDATE INDEXES 子句刪除舊分區有助於全域索引保持有效。

第二天晚上,稱為非同步全域索引維護後台作業的功能啟動了一個 ALTER INDEX xxx COALESCE CLEANUP 命令,該命令執行了幾天,並從已刪除分區的孤立條目中清除全域索引。

不幸的是,我們需要在這個表上創建另一個具有不同參數的索引,但是由於後台作業導致的共享 DML 鎖 (Row-X (SX)) 導致資源繁忙錯誤,這是不可能的。由於我們需要部署一個新版本,我們肯定需要另一個索引上的 DDL。對我來說,這看起來很奇怪, alter index … coalesce cleanup 不允許並行創建另一個索引。為什麼要有關係?

**問題:**如果我們殺死會話,過去2天的工作會失去,工作需要從頭重新開始嗎?

出於明顯的原因(懶惰),我使用範例從這篇文章中創建表和索引:

https://richardfoote.wordpress.com/2013/08/02/12c-asynchronous-global-index-maintenance-part-i-where-are-we-now/

create table muse (id number, code number, name varchar2(30)) partition by range (id) (partition muse1 values less than (1000001), partition muse2 values less than (2000001), partition muse3 values less than (maxvalue));
insert into muse with g as (select * from dual connect by level <= 1000) select rownum, mod(rownum,100000), 'DAVID BOWIE' from g,g,g where rownum <=  3000000;
commit;
create index muse_id_i on muse(id);
create index muse_code_i on muse(code) global partition by range(code)(partition code_p1 values less than (50000), partition code_p2 values less than (maxvalue));
exec dbms_stats.gather_table_stats(ownname=>user, tabname=>'MUSE', cascade=>true, estimate_percent=>null, method_opt=>'FOR ALL COLUMNS SIZE 1');

接下來刪除一個分區:

SQL> alter table muse drop partition muse1 update global indexes;

Table altered.

然後分析索引:

SQL> analyze index muse_id_i validate structure;

Index analyzed.

SQL> select name, lf_rows, del_lf_rows from index_stats;

NAME                              LF_ROWS DEL_LF_ROWS
------------------------------ ---------- -----------
MUSE_ID_I                         3000000     1000000

孤立條目在此處顯示為已刪除條目。

我的補充來了。手動啟動coalesce cleanup,然後在幾秒鐘後中斷它(Ctrl-C),然後再次分析索引:

SQL> alter index muse_id_i coalesce cleanup;
^C
alter index muse_id_i coalesce cleanup
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation



SQL> SQL> analyze index muse_id_i validate structure;

Index analyzed.

SQL> select name, lf_rows, del_lf_rows from index_stats;

NAME                              LF_ROWS DEL_LF_ROWS
------------------------------ ---------- -----------
MUSE_ID_I                         2723063      723063

如您所見,即使中斷命令,一些條目也已被清除。現在再做一次:

SQL> alter index muse_id_i coalesce cleanup;
^Calter index muse_id_i coalesce cleanup
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation



SQL> analyze index muse_id_i validate structure;

Index analyzed.

SQL> select name, lf_rows, del_lf_rows from index_stats;

NAME                              LF_ROWS DEL_LF_ROWS
------------------------------ ---------- -----------
MUSE_ID_I                         2532434      532434

接下來創建一個索引,然後繼續:

SQL> create index muse_name_i on muse(name) local;

Index created.

SQL> alter index muse_id_i coalesce cleanup;
^C
alter index muse_id_i coalesce cleanup
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation

SQL> SQL> analyze index muse_id_i validate structure;

Index analyzed.

SQL> select name, lf_rows, del_lf_rows from index_stats;

NAME                              LF_ROWS DEL_LF_ROWS
------------------------------ ---------- -----------
MUSE_ID_I                         2151894      151894

最後:

SQL> alter index muse_id_i coalesce cleanup;

Index altered.

SQL> analyze index muse_id_i validate structure;

Index analyzed.

SQL> select name, lf_rows, del_lf_rows from index_stats;

NAME                              LF_ROWS DEL_LF_ROWS
------------------------------ ---------- -----------
MUSE_ID_I                         2000000           0

SQL>

所以不,進步並沒有失去。

引用自:https://dba.stackexchange.com/questions/265489