最近一直通过rebuild online 做索引碎片整理,因表均为分区表,大部分为本地索引及分区索引,有的表涉及上千个索引分区,于是我就用脚本放在后台执行了。这种情况正常运行了一个月。
突然今天巡检执行日志的时候,索引IDX_T1_ID 的其它分区重建只需要10min左右,但 IDX_T1_ID rebuild partition SYS_P3592 分区从凌晨4:29开始到中午12点都还没有结果,意识到执行不正常,查看了下索引涉及到的数据有数据正常入表,数据也可查询,目前看不影响此表的dml操作。
然后咨询开发有个定时任务4:30发起,差不多有80w左右的数据入表,查看程序日志此任务也一直没有执行结束。庆幸的是此任务仅是备份表数据功能。
SQL> alter index IDX_T1_ID rebuild partition SYS_P3592 online tablespace two_ind_dat;
alter index IDX_T1_ID rebuild partition SYS_P3592 online tablespace two_ind_dat
*
ERROR at line 1:
ORA-08106: cannot create journal table TWO.SYS_JOURNAL_407292
select object_name,created,status From dba_objects where object_name like 'SYS_JOURNAL_%'
Wed Dec 04 12:33:39 2024
online index (re)build cleanup: objn=407292 maxretry=2000 forever=0
Wed Dec 04 12:37:19 2024
opiodr aborting process unknown ospid (125308) as a result of ORA-28
Wed Dec 04 12:48:26 2024
SQL> drop index IDX_T1_ID ;
drop index IDX_T1_ID
*
ERROR at line 1:
ORA-08104: this index object 407292 is being online built or rebuilt
-- 清理全部异常数据
declare
isClean boolean;
begin
isClean := FALSE;
while isClean=FALSE loop
isClean := dbms_repair.online_index_clean(dbms_repair.all_index_id,dbms_repair.lock_wait);
dbms_lock.sleep(2);
end loop;
exception
when others then
RAISE;
end;
/
-- 指定OBJECT_ID 清理
SQL> DECLARE
2 RetVal BOOLEAN;
3 OBJECT_ID BINARY_INTEGER;
4 WAIT_FOR_LOCK BINARY_INTEGER;
5 BEGIN
6 OBJECT_ID := 407292;
7 WAIT_FOR_LOCK := NULL;
8 RetVal := SYS.DBMS_REPAIR.ONLINE_INDEX_CLEAN ();
9 COMMIT;
10 END;
11 /
DECLARE
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
ORA-06512: at "SYS.DBMS_REPAIR", line 475
ORA-06512: at line 8
Wed Dec 04 16:56:09 2024
online index (re)build cleanup: objn=369888 maxretry=2000 forever=0
online index (re)build cleanup: objn=369888 maxretry=2000 forever=0
online index (re)build cleanup: objn=369888 maxretry=2000 forever=0
online index (re)build cleanup: objn=369888 maxretry=2000 forever=0
Wed Dec 04 16:56:28 2024
online index (re)build cleanup: objn=369888 maxretry=2000 forever=0
Wed Dec 04 16:57:16 2024
online index (re)build cleanup: objn=369888 maxretry=2000 forever=0
online index (re)build cleanup: objn=369888 maxretry=2000 forever=0
create table t1 (
id VARCHAR2(11) not null,
create_date TIMESTAMP(6) not null
);
create index IDX_T1_ID on t1 (id);
create table t1 (
id VARCHAR2(11) not null,
create_date TIMESTAMP(6) not null
)
PARTITION BY RANGE(create_date)INTERVAL(numtoyminterval(1,'month'))
(PARTITION part202401 VALUES LESS THAN(TO_DATE('20240201','yyyymmdd')),
PARTITION part202402 VALUES LESS THAN(TO_DATE('20240301','yyyymmdd'))
);
11:47:21 SQL> select count(*) from t1 partition(SYS_P1741);
COUNT(*)
----------
44551512
11:48:05 SQL> create index IDX_T1_ID on t1 (id);
Index created.
12:36:05 SQL> set autotrace trace
12:36:13 SQL> select * from t1 where id ='1';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 2209018382
----------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 3 (0)| 00:00:01 | | |
| 1 | TABLE ACCESS BY GLOBAL INDEX ROWID| T1 | 1 | 20 | 3 (0)| 00:00:01 | ROWID | ROWID |
|* 2 | INDEX RANGE SCAN | IDX_T1_ID | 1 | | 3 (0)| 00:00:01 | | |
----------------------------------------------------------------------------------------------------------------
12:37:20 SQL> alter table t1 truncate partition (SYS_P1741);
Table truncated.
12:37:30 SQL> col OBJECT_NAME for a50
12:37:38 SQL> set line 800
12:37:43 SQL> select object_name,status from user_objects where object_name='IDX_T1_ID';
OBJECT_NAME STATUS
-------------------------------------------------- -------
IDX_T1_ID VALID
12:38:25 SQL> set autotrace trace
12:38:34 SQL> select * from t1 where id ='1';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 589593414
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE ALL| | 1 | 20 | 2 (0)| 00:00:01 | 1 |1048575|
|* 2 | TABLE ACCESS FULL | T1 | 1 | 20 | 2 (0)| 00:00:01 | 1 |1048575|
--------------------------------------------------------------------------------------------
13:06:40 SQL> select status from user_indexes where index_name='IDX_T1_ID';
STATUS
--------
UNUSABLE
注:以下结果是被验证N次后,Rebuild Online 和 Insert 执行1小时以上再Kill会话,才会偶尔出现。
15:20:04 SQL> select * from t1 where id='1';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 589593414
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE ALL| | 1 | 20 | 2 (0)| 00:00:01 | 1 |1048575|
|* 2 | TABLE ACCESS FULL | T1 | 1 | 20 | 2 (0)| 00:00:01 | 1 |1048575|
--------------------------------------------------------------------------------------------
15:26:06 SQL> alter index IDX_T1_ID rebuild;
Index altered.
15:33:49 SQL> select * from t1 where id='1';
no rows selected
Elapsed: 00:00:24.82
Execution Plan
----------------------------------------------------------
Plan hash value: 589593414
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 2 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE ALL| | 1 | 20 | 2 (0)| 00:00:01 | 1 |1048575|
|* 2 | TABLE ACCESS FULL | T1 | 1 | 20 | 2 (0)| 00:00:01 | 1 |1048575|
--------------------------------------------------------------------------------------------
15:34:19 SQL> exec dbms_stats.gather_table_stats(ownname=>'SYS',tabname=> 'T1');
PL/SQL procedure successfully completed.
Elapsed: 00:01:51.92
16:08:04 SQL> select * from t1 where id='1';
no rows selected
Elapsed: 00:00:22.27
Execution Plan
----------------------------------------------------------
Plan hash value: 2209018382
----------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 183 | 4209 | 27 (0)| 00:00:01 | | |
| 1 | TABLE ACCESS BY GLOBAL INDEX ROWID| T1 | 183 | 4209 | 27 (0)| 00:00:01 | ROWID | ROWID |
|* 2 | INDEX RANGE SCAN | IDX_T1_ID | 183 | | 4 (0)| 00:00:01 | | |
----------------------------------------------------------------------------------------------------------------
SELECT A.tablespace_name tablespace,
D.mb_total,
SUM(A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total - SUM(A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM v$sort_segment A,
(SELECT B.name, C.block_size, SUM(C.bytes) / 1024 / 1024 mb_total
FROM v$tablespace B, v$tempfile C
WHERE B.ts# = C.ts#
GROUP BY B.name, C.block_size) D
WHERE A.tablespace_name = D.name
GROUP by A.tablespace_name, D.mb_total;
col opname format a32
col target format a32
col perwork format a12
set linesize 1200
select sid
,opname
,target
,sofar
,totalwork
,trunc(sofar/totalwork*100,2)||'%' as perwork
from v$session_longops where sofar!=totalwork and sid=132;
SID OPNAME TARGET SOFAR TOTALWORK PERWORK
---------- --------------------- ------------------ ---------- ---------- --------
827 Index Fast Full Scan IDX_T1_ID 27914 157907 17.67%
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。