Home Database Mysql Tutorial 磁盘排序影响Oracle数据库性能的罪魁祸首

磁盘排序影响Oracle数据库性能的罪魁祸首

Jun 07, 2016 pm 03:15 PM
oracle Influence performance sort database disk

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 当建立同Oracle会话时,会在 服务器 内存 中划分出一个专门用来排序的区域,从而为会话提供排序空间。但是,这个排序空间毕竟有限,若记录数量超过这个排序空间的话,就需要进行磁盘排序。但是,我

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入

  当建立同Oracle会话时,会在服务器内存中划分出一个专门用来排序的区域,从而为会话提供排序空间。但是,这个排序空间毕竟有限,若记录数量超过这个排序空间的话,就需要进行磁盘排序。但是,我们都知道,磁盘排序的执行速度要比内存排序的执行速度慢1400倍。而且,磁盘排序会消耗临时表空间的资源,并且可能影响到正在进行的其他SQL排序,因为Oracle必须为临时表空间中的数据块分配缓冲池。而且,过多的磁盘排序会导致空闲缓冲等待,以及将执行其他任务的数据块从缓冲池中分页出去。对于数据库管理员来说,在内存中进行排序总是比磁盘排序更受欢迎。所以说,磁盘排序是影响Oracle数据库性能的罪魁祸首。

  在数据库优化的时候,我们应该想法设法降低数据库的磁盘排序。为此,笔者有如下建议。

  一、合理设置Sort_area_size参数

  虽然说Oracle10G以后的数据库会自动对内存进行管理。但是,在一些性能要求比较高或者排序频率比较高的数据库中,仍然有必要对一些影响内存分配的参数进行调整。其中,最重要的一个参数就是Sort_area_size。

  Oracle数据库会为所有的链接Oracle会话分配Sort_area_size这个参数。所以,对于拥有大量用户的数据库来说,如果增加这个参数的值,会让磁盘排序的几率明显降低,不过数据库也要为此付出这个代价,很容易导致内存过载。但是,如果这个参数的值设置的过低的话,又会导致过多的磁盘排序。

  所以,这个参数并不是越大越好。因为这个参数如果设置的过大的话,其带来的性能收益反而会降低。因为为了提高有限几个查询的速度,可能会浪费大量的内存。这无疑是我们数据库管理员不希望看到的。

  在实际工作中,我们往往需要在两者之间进行一个均衡。设置一个合理的参数,尽量让数据库减少磁盘排序的几率,同时也不能使得服务器内存过载。

  为此笔者有一个建议。数据库管理员应该每隔一段时间增加这个参数的值,并使用Statspack工具定时监控内存排序与磁盘排序的数据。在起初进行调整的时候最好每个小时查询一次。通过这些数据,我们就可以得到一个合理的参数值,在两这之间取得一个均衡。

  前期调整完成后,在后期仍然需要进行监控。因为后期随着企业应用的改变,这个参数仍然需要根据实际情况进行调整,以提高数据库的性能。

  二、尽量减少不必要的排序

  在某些情况下,尽管数据库管理员没有直接通过Order By等语句对数据库记录进行排序,可是Oracle数据库服务器仍然会对查询结果进行排序。因为这些语句需要起作用,必须要先对数据进行排序。所以,他们往往带有隐性的排序功能。

  我们在数据库维护或者前台应用程序设计的时候,要尽量的减少这种不必要的排序。如Distinct关键字,它的作用就是取消重复的记录。但是,要实现这个目的的话,则数据库必须要先对记录进行排序,然后才能够去除重复的记录内容。故在设计的时候,尽量要避免使用Distinct关键字。其实,笔者在工作中,经常会碰到这种情况,某些记录其实不存在重复记录,但是程序开发人员为了保障数据的准确性,就在SQL语句中加入了Distinct关键字,从而造成了不必要的排序。

  另外,在其他一些情况下,也会导致不必要的排序。如排序合并连接,也会导致不必要的排序。故无论何时,只要使用了排序合并连接,就会执行排序已连接关键值。故在数据库与应用程序设计的时候,要尽量避免排序合并连接。其实,在许多情况下,嵌套循环连接反而使更好的选择。因为这个嵌套循环连接,它更加有效而且不会导致不必要的排序以及不比要的全表扫描。

  其次,有时候缺失索引也会导致一些并不要的排序。

  故数据库管理员在平时的工作中,要尽量的减少这些不必要的排序,以让宝贵的内存资源交给更重要的任务来适用。

磁盘排序影响Oracle数据库性能的罪魁祸首

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

See all articles