重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
# update indexes更新所有索引,global 或者local,而当使用update indexes更新global index时,不能指定子句, # update global indexes只能用于global indexes TEST@czhpdb1 > alter table test_part drop partition p2 update indexes; Table altered. # 可以看到索引并没有失效,但是NUM_ROWS并未发生改变,也就是索引并未被实时更新 TEST@czhpdb1 > select table_name,index_name,status,num_rows from user_indexes where table_name='TEST_PART'; TABLE_NAME INDEX_NAME STATUS NUM_ROWS ---------------------------------------- -------------------- ---------- ---------------------------------------- TEST_PART IDX_TEST_PART VALID 5001 # 可以看到产生了延迟GLOBAL INDEX MAINTAINE的定时任务,默认凌晨两点开始自动执行维护global index col job_name for a50 col LAST_START_DATE for a40 col NEXT_RUN_DATE for a40 select JOB_NAME,LAST_START_DATE,NEXT_RUN_DATE from DBA_SCHEDULER_JOBS where JOB_NAME='PMO_DEFERRED_GIDX_MAINT_JOB'; JOB_NAME LAST_START_DATE NEXT_RUN_DATE -------------------------------------------------- ---------------------------------------- ---------------------------------------- PMO_DEFERRED_GIDX_MAINT_JOB 06-JAN-20 03.06.37.673278 AM PST8PDT 07-JAN-20 02.00.00.679539 AM PST8PDT # user_indexes视图orphaned_entries字段标识global index是否包含索引延迟维护的过期条目 TEST@czhpdb1 > select table_name,index_name,status,num_rows,orphaned_entries from user_indexes where table_name='TEST_PART'; TABLE_NAME INDEX_NAME STATUS NUM_ROWS ORPHANED_ ---------------------------------------- -------------------- ---------- ---------------------------------------- --------- TEST_PART IDX_TEST_PART VALID 5001 YES
如果需要,也可以通过如下四种办法手工维护延迟维护global index。
创新互联建站是一家集网站建设,博罗企业网站建设,博罗品牌网站建设,网站定制,博罗网站建设报价,网络营销,网络优化,博罗网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
方法1:DBMS_PART.CLEANUP_GIDX
# 通过调用系统包DBMS_PART.CLEANUP_GIDX col job_name for a50 col LAST_START_DATE for a40 col NEXT_RUN_DATE for a40 select JOB_NAME,LAST_START_DATE,NEXT_RUN_DATE from DBA_SCHEDULER_JOBS where JOB_NAME='PMO_DEFERRED_GIDX_MAINT_JOB'; JOB_NAME LAST_START_DATE NEXT_RUN_DATE -------------------------------------------------- ---------------------------------------- ---------------------------------------- PMO_DEFERRED_GIDX_MAINT_JOB 06-JAN-20 03.06.37.673278 AM PST8PDT 07-JAN-20 02.00.00.679539 AM PST8PDT SYS@czh29c > exec DBMS_PART.CLEANUP_GIDX('TEST','TEST_PART'); PL/SQL procedure successfully completed. TEST@czhpdb1 > select table_name,index_name,status,num_rows,orphaned_entries from user_indexes where table_name='TEST_PART'; TABLE_NAME INDEX_NAME STATUS NUM_ROWS ORPHANED_ ---------------------------------------- -------------------- ---------- ---------------------------------------- --------- TEST_PART IDX_TEST_PART VALID 5001 NO
方法2:dbms_scheduler.run_job
# 使用sys连接数据库时,一定要注意切换pdb,只有切换到正确的pdb,才能正确的执行调度定时任务完成相应维护操作 SYS@czh29c > alter session set container=czhpdb1; Session altered. SYS@czh29c > show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------------------------------------- ------------------------------ ---------- ---------- 3 CZHPDB1 READ WRITE NO # 查询DBA_SCHEDULER_JOBS,查看调度任务 SYS@czh29c > col job_name for a50 SYS@czh29c > col LAST_START_DATE for a40 SYS@czh29c > col NEXT_RUN_DATE for a40 SYS@czh29c > select JOB_NAME,LAST_START_DATE,NEXT_RUN_DATE from DBA_SCHEDULER_JOBS where JOB_NAME='PMO_DEFERRED_GIDX_MAINT_JOB'; JOB_NAME LAST_START_DATE NEXT_RUN_DATE -------------------------------------------------- ---------------------------------------- ---------------------------------------- PMO_DEFERRED_GIDX_MAINT_JOB 06-JAN-20 03.06.37.606301 AM PST8PDT 07-JAN-20 02.00.00.609298 AM PST8PDT # 手工执行调度任务 SYS@czh29c > exec dbms_scheduler.run_job('PMO_DEFERRED_GIDX_MAINT_JOB'); PL/SQL procedure successfully completed. # 查看global index状态,已经被维护 TEST@czhpdb1 > select table_name,index_name,status,num_rows,orphaned_entries from user_indexes where table_name='TEST_PART'; TABLE_NAME INDEX_NAME STATUS NUM_ROWS ORPHANED_ ---------------------------------------- -------------------- ---------- ---------------------------------------- --------- TEST_PART IDX_TEST_PART VALID 5001 NO
方法3:重建索引
# 可以rebuild启用并行parallel,rebuild完毕之后,使用alter index no paralle,关闭并行度 TEST@czhpdb1 > alter index idx_test_part rebuild online; Index altered. TEST@czhpdb1 > select table_name,index_name,status,num_rows,orphaned_entries from user_indexes where table_name='TEST_PART'; TABLE_NAME INDEX_NAME STATUS NUM_ROWS ORPHANED_ ---------------------------------------- -------------------- ---------- ---------------------------------------- --------- TEST_PART IDX_TEST_PART VALID 10003 NO
方法四:coalesce cleanup
# COALESCE # Specify this clause to merge the contents of index partition blocks where possible # to free blocks for reuse. # CLEANUP # Specify CLEANUP to remove orphaned index entries for records that were previously # dropped or truncated by a table partition maintenance operation. # To determine whether an index partition contains orphaned index entries, you can # query the ORPHANED_ENTRIES column of the USER_, DBA_, ALL_PART_INDEXES # data dictionary views. Refer to Oracle Database Reference for more information TEST@czhpdb1 > alter index idx_test_part coalesce cleanup; Index altered. TEST@czhpdb1 > select table_name,index_name,status,num_rows,orphaned_entries from user_indexes where table_name='TEST_PART'; TABLE_NAME INDEX_NAME STATUS NUM_ROWS ORPHANED_ ---------------------------------------- -------------------- ---------- ---------------------------------------- --------- TEST_PART IDX_TEST_PART VALID 10003 NO