大表delete刪數(shù)據(jù)導(dǎo)致數(shù)據(jù)庫(kù)異常解決
一、問題描述
早上正在上班路上,群里客戶說(shuō),有一張24G的大表,delete刪了26小時(shí)還沒有跑完,目前進(jìn)程還在跑讓幫忙處理下,停止當(dāng)前進(jìn)程,并保留對(duì)應(yīng)條件的數(shù)據(jù),多余數(shù)據(jù)刪掉。
二、查看數(shù)據(jù)庫(kù)情況
1.未開歸檔
2.UNDO表空間爆滿
三、提出方案
1.經(jīng)過溝通,該表為測(cè)試數(shù)據(jù)表,目前沒有在使用;
于是打算rename該表,通過ctas的方式去將需要的數(shù)據(jù)撈出來(lái),重建索引和相關(guān)約束。
2.存在一個(gè)問題:delete進(jìn)程已經(jīng)執(zhí)行了26小時(shí),如果kill進(jìn)程,必然會(huì)導(dǎo)致undo回滾,回滾默認(rèn)開啟并行會(huì)導(dǎo)致數(shù)據(jù)庫(kù)和系統(tǒng)負(fù)載很高,于是需要提前處理下,設(shè)置參數(shù)_fast_start_parallel_rollback_關(guān)掉UNDO并行。
--查看回滾參數(shù)設(shè)置,是否是默認(rèn)并行 SQL> show parameter fast_start_parallel_rollback NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ fast_start_parallel_rollback string LOW --LOW 代表 開啟CPU*2并行 --設(shè)置spfile取消并行 SQL> alter system set fast_start_parallel_rollback=false; System altered.
四、執(zhí)行過程
1.備份保留 表創(chuàng)建語(yǔ)句。
2.記錄當(dāng)前無(wú)效對(duì)象。
SELECT d.OWNER ,d.OBJECT_NAME ,d.OBJECT_TYPE ,d.status FROM dba_objects d WHERE d.status = 'INVALID' AND d.owner = '**';
3.查看delete進(jìn)程pid,系統(tǒng)級(jí)kill掉。
--查詢SID, SERIAL# select s.SQL_TEXT, se.SID, se.SERIAL# from v$session se, v$sql s where s.sql_id = se.SQL_ID and username = '**' and status = 'ACTIVE' and s.SQL_TEXT like '%delete * from *****%'; --數(shù)據(jù)庫(kù)級(jí)kill進(jìn)程 alter system kill session '2953,31083';
報(bào)錯(cuò)
ERROR at line 1:
ORA-00031: session marked for kill
--系統(tǒng)級(jí) kill進(jìn)程
select spid, osuser, s.program
from v$session s,v$process p
where s.paddr=p.addr and s.sid=2953;
kill -9 105257
4.觀察undo回滾情況
--查看等待事件 select inst_id,event,count(*) from gv$session a where a.status='ACTIVE' and not (a.type = 'BACKGROUND' and a.state='WAITING' and a.wait_class='Idle') group by inst_id,event order by a.inst_id,count(*) desc; --------------------------------------------------- 1 wait for a undo record 61 1 resmgr:cpu quantum 29 1 enq: RO - fast object reuse 22 1 enq: CR - block range reuse ckpt 20 1 free buffer waits 17 --查看當(dāng)前數(shù)據(jù)回滾情況 alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; select usn, state, undoblockstotal "Total", undoblocksdone "Done", undoblockstotal - undoblocksdone "ToDo", decode(cputime, 0, 'unknown', sysdate + (((undoblockstotal - undoblocksdone) / (undoblocksdone / cputime)) / 86400)) "Estimated time to complete" from v$fast_start_transactions where state = 'RECOVERING'; --------------------------------------------------- 83 RECOVERING 9026713 455 9026258 26-4月 -21
5.觀察系統(tǒng)負(fù)載,IO負(fù)載,內(nèi)存使用情況
6.等待回滾完成,持續(xù)時(shí)間較久。
7.回滾成功后,rename 原表。
rename table to table_20210410;
8.CTAS將需要的數(shù)據(jù)撈到新表(原來(lái)的表名)中。
create table USER.TABLE nologging parallel 8 tablespace TBS as select /*+parallel(TABLE,'8')*/ * from USER.TABLE_20210410 where *** like '******%'; --取消并行 alter table USER.TABLE noparallel; --開啟logging alter table USER.TABLE logging;
9.rename索引,并重建索引。
alter index USER.INDEX1 rename to INDEX1_20210410; --重建索引 create index USER.INDEX1 on USER.TABLE (***) tablespace TBS parallel 8; --取消并行 alter index USER.INDEX1 noparallel;
10.創(chuàng)建約束,授權(quán)。
11.比對(duì)無(wú)效對(duì)象,數(shù)據(jù)是否一致
12.drop掉rename的表。
drop table USER.TABLE_20210410 cascade;
以上就是大表delete刪數(shù)據(jù)導(dǎo)致數(shù)據(jù)庫(kù)異常解決的詳細(xì)內(nèi)容,更多關(guān)于delete刪數(shù)據(jù)數(shù)據(jù)庫(kù)異常的資料請(qǐng)關(guān)注本站其它相關(guān)文章!
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。