业务需求,对日志表历史数据进行清理。历史表均很大,使用delete 操作删除90天前的数据。

第一部分:快速删除数据

  1. SQL> alter table CC.F_LOG parallel ;
  2. SQL>alter session enable parallel dml;
  3. SQL> delete FROM CC.F_LOG S WHERE S.CREATE_DATE>(SYSDATE-);
    执行计划确定并行

-----------------------------------------------
| Id | Operation |
-----------------------------------------------
| 0 | DELETE STATEMENT |
| 1 | PX COORDINATOR |
| 2 | PX SEND QC (RANDOM) |
| 3 | INDEX MAINTENANCE |
| 4 | PX RECEIVE |
| 5 | PX SEND RANGE |
| 6 | DELETE |
| 7 | BUFFER SORT |
| 8 | PX RECEIVE |
| 9 | PX SEND HASH (BLOCK ADDRESS)|
|* 10 | INDEX RANGE SCAN |
-----------------------------------------------

SQL> select INST_ID,sid,serial#,USERNAME,STATUS,MACHINE,SQL_ID,EVENT,(sysdate-LOGON_TIME)*86400 as "s",LAST_CALL_ET

from gv$session where status='ACTIVE' and username is not null;
INST_ID SID SERIAL# USERNAME STATUS MACHINE SQL_ID EVENT s LAST_CALL_ET
------- ------ ------- ------------------- --------------- -------------------- ------------------------------ ------- ------------
1 24   44857 SYS ACTIVE p01 6yn37jfu2y88k PX Deq Credit: send blkd 190 189
1 584  28067 SYS ACTIVE p01 2ymxxw3mapxd9 SQL*Net message from client 196 0
1 884  40483 SYS ACTIVE p01 6yn37jfu2y88k PX Deq: Table Q Normal 190 189
1 888   8663 SYS ACTIVE p01 6yn37jfu2y88k PX Deq: Execute Reply 3679 212
1 1157 9679  SYS ACTIVE p01 6yn37jfu2y88k PX Deq: Table Q Normal 190 189
1 1162 10801 SYS ACTIVE p01 6yn37jfu2y88k direct path write temp 190 189
1 1437 22187 SYS ACTIVE p01 6yn37jfu2y88k PX Deq Credit: send blkd 190 189
1 1728 17227 SYS ACTIVE p01 6yn37jfu2y88k PX Deq Credit: send blkd 190 189
1 1740 25759 SYS ACTIVE p01 6yn37jfu2y88k PX Deq: Table Q Normal 190 189
9 rows selected.

  1. 删除完毕还原并行1

SQL> alter table CC.F_LOG parallel 1;

第二部分:数据删除hang

  1. 删除数据后发现,数据库会话数量越来越多,且delete操作session event
  1. log file switch (archiving needed) 等待啥?需要等待日志切换归档完成? 为啥等待日志切换归档这么长时间? 观察alert
  1. SQL> select INST_ID,sid,serial#,USERNAME,STATUS,MACHINE,SQL_ID,EVENT,(sysdate-LOGON_TIME)* as "s",LAST_CALL_ET
    from gv$session where status='ACTIVE' and username is not null;
  2.  
  3. INST_ID SID SERIAL# USERNAME STATUS MACHINE SQL_ID EVENT
  4. ------- ------ ------- -------------- ---------- -------------------- -------------------- ------------------------------
  5. CXPT ACTIVE future-app1 fmmd0cjd0ghpf buffer busy waits
  6. ac ACTIVE pfmptom01.yutong.com 6d7v2nay5vm9n log file switch (archiving needed)
  7. ac ACTIVE pfmptom02.yutong.com 3dn60pvzrqz0g buffer busy waits
  8. CXPT ACTIVE future-app1 azakfbj8ss7f8 buffer busy waits
  9. ac ACTIVE pfmptom01.yutong.com 7nbhsah5kw0q2 log file switch (archiving needed)
  10. SYSTEM ACTIVE ZZYT\YT-P610764 1xz9mk73crhu8 log file switch (archiving needed)
  11. ac ACTIVE pfmptom02.yutong.com 3dn60pvzrqz0g buffer busy waits
  12. ac ACTIVE pfmptom01.yutong.com d8ats3n1vrm7t enq: US - contention
  13. ac ACTIVE pfmptom01.yutong.com 0jg5553p23hup enq: SQ - contention
  14. CXPT ACTIVE future-app2 azakfbj8ss7f8 enq: US - contention
  15. ac ACTIVE pfmptom02.yutong.com 3dn60pvzrqz0g buffer busy waits
  16. ac ACTIVE pfmptom01.yutong.com btgxyzwsc5sd1 enq: US - contention
  17. ac ACTIVE pfmpbak01 94cs4sv2zua0u log file switch (archiving needed)
  18. ac ACTIVE pfmptom02.yutong.com 3dn60pvzrqz0g buffer busy waits
  19. rows selected.
  20.  
  21. 观察ALERT日志,可以发现归档日志无法创建报错

Examine archive trace files for archiving errors
Current log# 8 seq# 41282 mem# 0: /oracle/oradata/fmpdb/redo08.log
Tue Aug 13 19:41:12 2019
ARC1: Encountered disk I/O error 19502
ARC1: Closing local archive destination LOG_ARCHIVE_DEST_1: '/oracle/archivelog/fmpdb_1_41278_961338832.log' (error 19502) (fmpdb)
ARC1: I/O error 19502 archiving log 4 to '/oracle/archivelog/fmpdb_1_41278_961338832.log'
ARCH: Archival stopped, error occurred. Will continue retrying
ORACLE Instance fmpdb - Archival Error
ORA-16038: log 4 sequence# 41278 cannot be archived
ORA-19502: write error on file "", block number (block size=)
ORA-00312: online log 4 thread 1: '/oracle/oradata/fmpdb/redo04.log'
Tue Aug 13 19:41:13 2019
ARCH: Archival stopped, error occurred. Will continue retrying
ORACLE Instance fmpdb - Archival Error
ORA-16014: log 4 sequence# 41278 not archived, no available destinations
ORA-00312: online log 4 thread 1: '/oracle/oradata/fmpdb/redo04.log'
Tue Aug 13 19:44:28 2019
minact-scn: useg scan erroring out with error e:12751
Tue Aug 13 19:46:14 2019
ARC1: Encountered disk I/O error 19502
ARC1: Closing local archive destination LOG_ARCHIVE_DEST_1: '/oracle/archivelog/fmpdb_1_41278_961338832.log' (error 19502) (fmpdb)
ARC1: I/O error 19502 archiving log 4 to '/oracle/archivelog/fmpdb_1_41278_961338832.log'
ARCH: Archival stopped, error occurred. Will continue retrying
ORACLE Instance fmpdb - Archival Error
ORA-16038: log 4 sequence# 41278 cannot be archived
ORA-19502: write error on file "", block number (block size=)
ORA-00312: online log 4 thread 1: '/oracle/oradata/fmpdb/redo04.log'
Tue Aug 13 19:46:14 2019
ARCH: Archival stopped, error occurred. Will continue retrying
ORACLE Instance fmpdb - Archival Error
ORA-16014: log 4 sequence# 41278 not archived, no available destinations
ORA-00312: online log 4 thread 1: '/oracle/oradata/fmpdb/redo04.log'
Tue Aug 13 19:49:35 2019
minact-scn: useg scan erroring out with error e:12751
Tue Aug 13 19:51:15 2019
ARC1: Encountered disk I/O error 19502
ARC1: Closing local archive destination LOG_ARCHIVE_DEST_1: '/oracle/ARC1: I/O error 19502 archiving log 4 to

'/oracle/archivelog/fmpdb_1_41278_961338832.log'
ARCH: Archival stopped, error occurred. Will continue retrying
ORACLE Instance fmpdb - Archival Error
ORA-16038: log 4 sequence# 41278 cannot be archived
ORA-19502: write error on file "", block number (block size=)
ORA-00312: online log 4 thread 1: '/oracle/oradata/fmpdb/redo04.log'
ARCH: Archival stopped, error occurred. Will continue retrying
ORACLE Instance fmpdb - Archival Error
ORA-16014: log 4 sequence# 41278 not archived, no available destinations
ORA-00312: online log 4 thread 1: '/oracle/oradata/fmpdb/redo04.log'

Tue Aug 13 19:56:16 2019
Archiver process freed from errors. No longer stopped
Tue Aug 13 19:56:18 2019
Archived Log entry 41273 added for thread 1 sequence 41278 ID 0x67cfc4e dest 1:
krse_arc_driver_core: Successful archiving of previously failed ORL
Tue Aug 13 19:56:18 2019
Thread 1 advanced to log sequence 41283 (LGWR switch)
Current log# 4 seq# 41283 mem# 0: /oracle/oradata/fmpdb/redo04.log
Tue Aug 13 19:56:18 2019
Some DDE async actions failed or were cancelled
Tue Aug 13 19:56:23 2019
Archived Log entry 41274 added for thread 1 sequence 41281 ID 0x67cfc4e dest 1:
Archived Log entry 41275 added for thread 1 sequence 41279 ID 0x67cfc4e dest 1:
Archived Log entry 41276 added for thread 1 sequence 41280 ID 0x67cfc4e dest 1:
Archived Log entry 41277 added for thread 1 sequence 41282 ID 0x67cfc4e dest 1:
Tue Aug 13 19:56:43 2019
Thread 1 advanced to log sequence 41284 (LGWR switch)
Current log# 5 seq# 41284 mem# 0: /oracle/oradata/fmpdb/redo05.log
Tue Aug 13 19:56:45 2019
Archived Log entry 41278 added for thread 1 sequence 41283 ID 0x67cfc4e dest 1:
Tue Aug 13 19:57:10 2019
Thread 1 cannot allocate new log, sequence 41285

操作手工删除归档日志后,快速执行脚本压缩备份归档日志删除已备份的归档日志释放空间。 delete操作恢复且执行完毕后,对数据库立即进行全备份。
[root@pfmpodb01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 297G 297G 0G 100% /

清理归档日志
[root@pfmpodb01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 297G 271G 12G 97% /

压缩备份归档日志后删除日志
backup format '/oracle/dbbak/archbak_%d_%s_%p_%T' archivelog all delete input;

[root@pfmpodb01 archivelog]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 297G 230G 52G 82% /

  1. Resolving Issues Where 'log file switch (archiving needed)' Waits Occur Because Log has not yet been Archived (文档 ID 1476444.1)
  2.  
  3. Problem Confirmation:
  4. The time spent actively in the local database is significant
  5. Only certain sessions, queries or jobs are experiencing slowness (not throughout the database)
  6. Waits for 'log file switch (archiving needed)' are a significant component of DB Time
  7. Free space in archive destination is less than redolog file size
  8. Waits for 'log file switch (archiving needed)'
  9. This wait event occurs when waiting for a log switch because the log we will be switching into has not been archived yet.
  10.  
  11. Reducing Waits
  12. Check the alert file to make sure that archiving has not stopped due to a failed archive write.
  13. To speed archiving, consider adding more archive processes or putting the archive files on striped disks.
  14. Check the archive log destination for space and make sure it is not full. If it is full, free up space.

delete删除数据造成归档日志增加,操作系统空间不足导致数据库hang住的更多相关文章

  1. Windows平台使用RMAN命令自动删除Oracle过期归档日志的方法

    自动删除Oracle过期归档日志的思路如下: 1.编写自动执行的bat脚本文件: 2.Windows设置定期执行计划 OracleArchLogClear.bat D:/Oracle/product/ ...

  2. 什么?还在用delete删除数据《死磕MySQL系列 九》

    系列文章 五.如何选择普通索引和唯一索引<死磕MySQL系列 五> 六.五分钟,让你明白MySQL是怎么选择索引<死磕MySQL系列 六> 七.字符串可以这样加索引,你知吗?& ...

  3. SQL中CRUD C——create 添加数据 R——read 读取数据 U——update 修改数据 D——delete 删除数据

    在SQL server中对数据库的操作: 删除表:drop table 表名修改表:alter table 表名 添加列add 列名 列类型alter table 表名 drop column 列名 ...

  4. MySQL不建议delete删除数据

    InnoDB存储架构 从这张图可以看到,InnoDB存储结构主要包括两部分:逻辑存储结构和物理存储结构. 逻辑上是由表空间tablespace -> 段segment或者inode -> ...

  5. Oracle闪回查询恢复delete删除数据

    Flashback query(闪回查询)原理 Oracle根据undo信息,利用undo数据,类似一致性读取方法,可以把表置于一个删除前的时间点(或SCN),从而将数据找回. Flashback q ...

  6. Influx Sql系列教程七:delete 删除数据

    前面介绍了使用insert实现新增和修改记录的使用姿势,接下来我们看一下另外一个简单的使用方式,如何删除数据 1. delete 语句 delete的官方语法如下 DELETE FROM <me ...

  7. 通过DataWorks数据集成归档日志服务数据至MaxCompute进行离线分析

    通过DataWorks归档日志服务数据至MaxCompute 官方指导文档:https://help.aliyun.com/document_detail/68322.html但是会遇到大家在分区上或 ...

  8. 配置闪回恢复区开启归档,未配置清理归档脚本,数据库hang住

    问题现象,测试环境执行SQL hang住 enmo:/home/oracle/worksh dg.sh SQL*Plus: Release Production on Mon May :: Copyr ...

  9. Mysql常用sql语句(24)- delete 删除数据

    测试必备的Mysql常用sql语句系列 https://www.cnblogs.com/poloyy/category/1683347.html 前言 delete 也属于DML语句(数据操纵语句) ...

随机推荐

  1. OpenResty之ngx.var.VARIABLE

    1. ngx.var.VARIABLE syntax: ngx.var.VAR_NAME context: set_by_lua*, rewrite_by_lua*, access_by_lua*, ...

  2. 3dmax联机分布式渲染方法技巧详解

      3dmax联机分布式渲染方法技巧详解 \测试环境:win7系统 3DMAX2009 Vray2.0 .首先要保证你的两台电脑能在局域网里互相访问如图: 其他电脑上也一样都能打开对方的电脑! 步! ...

  3. app 爬虫

    https://mp.weixin.qq.com/s/ClYYfpvylQGlYYHDFBuKpA 唯品会舆情监控系统 姚彬炎 唯技术 2月26日  

  4. OneDrive

    OneDrive https://onedrive.live.com

  5. 如何正确查看Linux机器内存使用情况

    如何正确查看Linux机器内存使用情况 背景 只要工作上涉及到Linux机器,基本上都会有这样一个需求,查看内存使用情况,但是怎么看才正确呢?之前使用的是top命令,一直存在一个误区. 为什么top命 ...

  6. 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_16-认证接口开发-Api接口定义

    4.3 认证服务 4.3.1 需求分析 认证服务需要实现的功能如下: 1.登录接口 前端post提交账号.密码等,用户身份校验通过,生成令牌,并将令牌存储到redis. 将令牌写入cookie. 2. ...

  7. [Scikit-learn] 1.1 Generalized Linear Models - from Linear Regression to L1&L2

    Introduction 一.Scikit-learning 广义线性模型 From: http://sklearn.lzjqsdd.com/modules/linear_model.html#ord ...

  8. win7下Excel2003/2010 同时打开多个独立窗口

    最近新买了本本,装了许多软件,由于许多苦逼的原因系统被我搞的乱乱的,不得已重装了几次,话说之前我用的都是台式机,用得蛮顺的,但是在重装系统之后发现自己装的Office 2003 在打开Excel 文档 ...

  9. 【Leetcode_easy】728. Self Dividing Numbers

    problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...

  10. OpenGL学习笔记 之三 (简单示例 太阳月亮地球)

    #include<glut.h> // 太阳.地球和月亮 // 假设每个月都是30天 // 一年12个月,共是360天 ;//day的变化:从0到359 void myDisplay(vo ...