Oracle 11g新特性触发Direct Path Read 等待事件案例
最近单位的一台生产数据库出现性能问题,同事处理后给我分享了这个案例。 在这里我整理一下分享给各位同学
数据库环境:
Oracle 11.2.0.3单实例,操作系统是Windows Server 2008 R2。
故障现象:
数据库访问缓慢,I/O使用率达到100%
故障分析:
1. DB Time高,数据库压力大。将近60分钟的采样时间内DB Time高达6983.24。
2. 物理读(Physical read)和逻辑读(Logical read)的数量级相同。看来这么大的物理读就是I/O达到100%的原因。
3. SGA区的Buffer Nowait 100%,看起来和大量的物理读有些矛盾。
4. 前台等待事件排在第一位的是直接路径读direct path read, 占据整个DB Time的85.97%。直接路径读的特点是不经过SGA的缓冲区,直接从存储获取数据。
5. 从TOP SQL上可以看到最耗时的sql语句都是在等待I/O,并且这些I/O来自同一张大表CX_BAS_CUS_CON_SUMUP。系统产生的逻辑读、物理读、直接路径读都来自于这张大表。问题找到了!通过执行计划看到了访问这张大表的sql执行计划是全表扫,该表大小为488M。
最终结论:
在Oracle 11g中有一个新特性,,为了保护已经缓存在buffer cache的数据,当出现全表扫的查询时会判断该表的大小。如果该表过大,则使用直接路径读(Direct Path Read)来获取数据。避免大量冷数据对Buffer Cache的冲击。此次问题的原因就是因为这个新特性。大量的并发查询CX_BAS_CUS_CON_SUMUP,并且执行计划都是采用了全表扫,满足了11g的这个新特性,通过直接路径读的方式绕过SGA从存储上获取数据。由于没有SGA的缓存,每一次查询都需要从存储读取产生了大量的物理读,最终导致I/O 100%。由于处理速度慢,CPU又产生了大量的等待队列,所以DB Time也非常高。
新特性中如何判断全表扫的大小呢?
下面看一个隐含参数:_small_table_threshold
该参数默认为Buffer Cache的2%,如果表大于5倍_small_table_threshold就触发该特性。
可以通过设置10949事件屏蔽这个特性
alter session set events '10949 trace name context forever, level 1';
解决方案:
应用团队确认了该表的数据,删除了大量的历史数据,使得全表扫后远低于_small_table_threshold x 5后的数值。再次执行该sql语句就可以缓存在buffer cache中了,物理读和I/O负载全部恢复到合理的范围。
由于不让修改应用程序,我们无法优化该SQL。所以该问题没有从根本上解决。当数据量增大到阈值,问题会卷土重来。
最后感谢我的同事分享这个案例给我
全文完
本文永久更新链接地址:

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

SQL commands in MySQL can be divided into categories such as DDL, DML, DQL, DCL, etc., and are used to create, modify, delete databases and tables, insert, update, delete data, and perform complex query operations. 1. Basic usage includes CREATETABLE creation table, INSERTINTO insert data, and SELECT query data. 2. Advanced usage involves JOIN for table joins, subqueries and GROUPBY for data aggregation. 3. Common errors such as syntax errors, data type mismatch and permission problems can be debugged through syntax checking, data type conversion and permission management. 4. Performance optimization suggestions include using indexes, avoiding full table scanning, optimizing JOIN operations and using transactions to ensure data consistency.

InnoDB achieves atomicity through undolog, consistency and isolation through locking mechanism and MVCC, and persistence through redolog. 1) Atomicity: Use undolog to record the original data to ensure that the transaction can be rolled back. 2) Consistency: Ensure the data consistency through row-level locking and MVCC. 3) Isolation: Supports multiple isolation levels, and REPEATABLEREAD is used by default. 4) Persistence: Use redolog to record modifications to ensure that data is saved for a long time.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool