Asynchronous Global Index

RDBMS 19.23

-- 参考文档:

https://docs.oracle.com/database/121/VLDBG/GUID-087B87A6-959A-40C6-82AF-36E401FD089B.htm#VLDBG14107 -- 异步GIDX简介

https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_3001.htm#CIHCAAGD -- update [global] index

How To Update Both Global and Local Indexes when Moving Table Partition? (Doc ID 795854.1) -- 更新global索引和local索引 参考

How to Drop/Truncate Multiple Partitions in Oracle 12C (Doc ID 1482264.1) -- Index maintenance

Global Index Maintenance (GIDX) on Partitioned Tables not Running Asynchronously in 12c+ (Doc ID 2404701.1) -- 条件

https://oracle-base.com/articles/12c/asynchronous-global-index-maintenance-for-drop-and-truncate-partition-12cr1#:\~:text=When combined with the UPDATE INDEXES clause the,types%2C domain indexes or those owned by SYS.

异步GIDX简介:

Asynchronous Global Index Maintenance for Dropping and Truncating Partitions

The partition maintenance operations DROP PARTITION and TRUNCATE PARTITION are optimized by making the index maintenance for metadata only.

Asynchronous global index maintenance for DROP and TRUNCATE is performed by default; however, the UPDATE INDEXES clause is still required for backward compatibility.

The following list summarizes the limitations of asynchronous global index maintenance:

  • Only performed on heap tables

  • No support for tables with object types

  • No support for tables with domain indexes

  • Not performed for the user SYS

Maintenance operations on indexes can be performed with the automatic scheduler job SYS.PMO_DEFERRED_GIDX_MAINT_JOB to clean up all global indexes. This job is scheduled to run at 2:00 A.M. on a daily basis by default. You can run this job at any time using DBMS_SCHEDULER.RUN_JOB if you want to proactively clean up the indexes. You can also modify the job to run with a different schedule based on your specific requirements. However, Oracle recommends that you do not drop the job.

You can also force cleanup of an index needing maintenance using one of the following options:

  • DBMS_PART.CLEANUP_GIDX - This PL/SQL procedure gathers the list of global indexes in the system that may require cleanup and runs the operations necessary to restore the indexes to a clean state.

  • ALTER INDEX REBUILD [PARTITION] -- This SQL statement rebuilds the entire index or index partition as is done in releases previous to Oracle Database 12c Release 1 (12.1). The resulting index (partition) does not contain any stale entries.

  • ALTER INDEX [PARTITION] COALESCE CLEANUP -- This SQL statement cleans up any orphaned entries in index blocks.

异步GIDX的条件:

There are a few situations under which asynchronous GIDX will not run:

There is a domain index on the table (unsupported for async index maintenance)

The #_of_table_segments_truncated * #_of_global_index_partitions is > 125000 (reference unpublished Bug 19017670].

The DBA has set the hidden parameter "_fast_index_maintenance" = FALSE to disable asynchronous GIDX maintenance (not recommended).

-- 查看隐含参数: _fast_index_maintenance 为true

复制代码
SYS@cdbtest SQL> select a.ksppinm name,b.ksppstvl value,a.ksppdesc description     
  from x$ksppi a,x$ksppcv b
 where a.inst_id = USERENV ('Instance')
   and b.inst_id = USERENV ('Instance')
   and a.indx = b.indx
and upper(a.ksppinm) LIKE upper('%_fast_index_maintenance%')
   order by name  2    3    4    5    6    7  
  8  ;

NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
DESCRIPTION
--------------------------------------------------------------------------------
_fast_index_maintenance
TRUE
fast global index maintenance during PMOPs


SYS@cdbtest SQL>  

-- 查看MO_DEFERRED_GIDX_MAINT_SCHED,修改为每天8点开始运行,默认为凌晨两点开始运行(方便测试,晚上要关闭测试机)

复制代码
begin
dbms_scheduler.set_attribute (
name => 'SYS.PMO_DEFERRED_GIDX_MAINT_SCHED',
attribute => 'REPEAT_INTERVAL',
value => 'FREQ=DAILY; BYHOUR=8; BYMINUTE=0; BYSECOND=0'
);
end;
/ 

-- 查看修改后的结果

复制代码
SYS@cdbtest SQL>  select start_date,last_start_date,next_run_date from dba_scheduler_jobs where job_name='PMO_DEFERRED_GIDX_MAINT_JOB';

START_DATE
---------------------------------------------------------------------------
LAST_START_DATE
---------------------------------------------------------------------------
NEXT_RUN_DATE
---------------------------------------------------------------------------
03-JUL-24 08.00.00.882192 AM PST8PDT
01-JUL-24 04.41.01.939138 PM PST8PDT
03-JUL-24 08.00.00.882192 AM PST8PDT


SYS@cdbtest SQL> 

-- 创建测试用的分区表和索引

复制代码
CREATE TABLE mytesttable
(deptno number, secondcol varchar2(80))
PARTITION BY RANGE (deptno)
(
PARTITION p1 VALUES LESS THAN (100001),
PARTITION p2 VALUES LESS THAN (250001),
PARTITION p3 VALUES LESS THAN (350001),
PARTITION p4 VALUES LESS THAN (450001),
PARTITION p5 VALUES LESS THAN (550001)
);

-- insert rows
begin
for i in 1..550000 loop
insert into mytesttable values (i, rpad('x',80,'x'));
end loop;
commit;
end;
/
/
/

-- create global index
create index deptno_idx on mytesttable (deptno) global;

-- truncate或者drop掉一个分区,这里使用update index,而不是使用update global index。 不要使用update global index,不然达不到测试效果

两者的区别:

The following is a sample to verify that 'UPDATE INDEXES' will update both global and local index during partition move.

复制代码
ALTER TABLE mytesttable TRUNCATE PARTITIONS p2,p3 update indexes;
ALTER TABLE mytesttable TRUNCATE PARTITIONS p1 update indexes;
--alter table mytesttable drop partition p3 update global indexes;

-- 查看是否有orphaned_entries,orphaned_entries=yes,即达到测试目的

复制代码
SYS@cdbtest SQL> select table_name,
index_name,
status,
orphaned_entries
from dba_indexes
where orphaned_entries='YES';  2    3    4    5    6  

TABLE_NAME
--------------------------------------------------------------------------------
INDEX_NAME
--------------------------------------------------------------------------------
STATUS   ORP
-------- ---
MYTESTTABLE
DEPTNO_IDX
VALID    YES


SYS@cdbtest SQL> 

-- 查看MO_DEFERRED_GIDX_MAINT_SCHED是否运行。这里设置了8:00开始运行,但是实际运行是下午4点多(这个地方比较奇怪,以为设置为8点就8点准时运行,实际上看,是在下午空闲时间运行了)

复制代码
SYS@cdbtest SQL> select start_date,last_start_date,next_run_date from dba_scheduler_jobs where job_name='PMO_DEFERRED_GIDX_MAINT_JOB';

START_DATE
---------------------------------------------------------------------------
LAST_START_DATE
---------------------------------------------------------------------------
NEXT_RUN_DATE
---------------------------------------------------------------------------
03-JUL-24 08.00.00.882192 AM PST8PDT
01-JUL-24 04.41.01.939138 PM PST8PDT
03-JUL-24 08.00.00.882192 AM PST8PDT


SYS@cdbtest SQL> 

SYS@cdbtest SQL> select start_date,last_start_date,next_run_date from dba_scheduler_jobs where job_name='PMO_DEFERRED_GIDX_MAINT_JOB';

START_DATE
---------------------------------------------------------------------------
LAST_START_DATE
---------------------------------------------------------------------------
NEXT_RUN_DATE
---------------------------------------------------------------------------
03-JUL-24 08.00.00.882192 AM PST8PDT
03-JUL-24 04.36.32.500768 PM PST8PDT
04-JUL-24 08.00.00.021273 AM PST8PDT


SYS@cdbtest SQL>

-- 运行完毕后,再次查看,是否还有orphaned_entries,已经没有orphaned_entries了

复制代码
SYS@cdbtest SQL>  select table_name,
index_name,
status,
orphaned_entries
from dba_indexes
where orphaned_entries='YES';  2    3    4    5    6

no rows selected

SYS@cdbtest SQL>

END

相关推荐
JH307310 小时前
第七篇:Buffer Pool 与 InnoDB 其他组件的协作
java·数据库·mysql·oracle
数据库生产实战10 小时前
解析Oracle 19C中并行INSERT SELECT的工作原理
数据库·oracle
itachi-uchiha19 小时前
安装Oracle Database 23ai Free
数据库·oracle
代码程序猿RIP21 小时前
【SQLite 库】sqlite3_open_v2
jvm·oracle·sqlite
菜鸟plus+1 天前
Java 定时任务
数据库·oracle
潘潘潘潘潘潘潘潘潘潘潘潘1 天前
【MySQL】库与表的基础操作
数据库·mysql·oracle
一只小bit1 天前
MySQL 库的操作:从创建配置到备份恢复
服务器·数据库·mysql·oracle
养生技术人1 天前
Oracle OCP认证考试题目详解082系列第57题
运维·数据库·sql·oracle·开闭原则
养生技术人2 天前
Oracle OCP认证考试题目详解082系列第53题
数据库·sql·oracle·database·开闭原则·ocp
养生技术人2 天前
Oracle OCP认证考试题目详解082系列第48题
运维·数据库·sql·oracle·database·开闭原则·ocp