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

相关推荐
隔窗听雨眠3 天前
Oracle19c集群补丁实战手册
oracle·数据库补丁·opatchauto
杨凯凡6 天前
IT日报|2026-11-19:Oracle Java 紧急补丁、Optimizely 供应链攻击、GitHub 安全评估升级
java·oracle·github
OxYGC7 天前
[Web3] 智能合约 13: 项目实战⑤ DappLink Oracle
oracle·web3·智能合约
Lucifer三思而后行8 天前
Oracle RAC 启动失败,DBA 如何一步步定位问题?
oracle·rac
tianyuanwo9 天前
NocoDB 系统手册:PostgreSQL 主机资产管理的界面层实施方案
数据库·postgresql·oracle
隔窗听雨眠12 天前
Oracle日志体系分层结构与故障定位路径
数据库·oracle·故障排查
曲径海盗13 天前
Try-Except怎么用,3个追问解答在自动化下的应用
java·jvm·oracle
爱吃奥利奥_wen16 天前
SQL Server 基础语法详解:从建库建表到约束与增删改查
服务器·数据库·oracle
x_SpiderMan16 天前
搭建Oracle RAC 集群
数据库·oracle
测试界的小码农16 天前
【图数据库实战进阶(03):Neo4j 图数据建模实战——节点、关系与属性应该怎么设计?】
数据库·oracle·neo4j