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

相关推荐
BullSmall6 小时前
PostgreSQL 14 pg_dumpall 完整备份指南
数据库·postgresql·oracle
宇宙第一小趴菜11 小时前
三、Oracle 核心原理
数据库·oracle
龙仔72511 小时前
SQL Server OS_Core 数据库全自动备份【完整笔记·可直接复用】
数据库·笔记·oracle
Cloud云卷云舒1 天前
云卷云舒:从Oracle/MySQL迁移到HaishanDB:迁移评估工具核心技术拆解
mysql·oracle·ai-native·haishandb·信创数据库替换
段一凡-华北理工大学1 天前
向量数据库实战:选型、调优与落地~系列文章12:文本分块策略实战:chunk_size 怎么选?重叠多少?
开发语言·数据库·后端·oracle·rust·工业智能体·高炉智能化
oradh1 天前
Oracle XTTS实现跨版本迁移和升级(Oracle 11g单库升级至19C RAC集群)
数据库·oracle·11g升级19c·xtts跨版本迁移和升级
会编程的土豆1 天前
数据库范式
数据库·oracle
—Miss. Z—1 天前
计算机二级MySQL——简单应用题(存储过程&存储函数)
数据库·oracle·php
NineData2 天前
Oracle 卡住时先看阻塞源,ChatDBA 会先把锁链路理出来
数据库·oracle·ninedata·锁故障·锁等待·chatdba·锁阻塞
踏月的造梦星球2 天前
达梦数据库执行计划与性能分析入门:EXPLAIN、AUTOTRACE 与 ET
服务器·数据库·oracle