How to Improve Oracle Performance

Source: Internet
Author: User
How to Improve Oracle Performance

How to Improve Oracle Performance

How to Improve Oracle Performance

1. Set the appropriate SGA

Some people often complain that the server hardware is good, but Oracle is very slow. It is likely that the memory allocation is unreasonable. (1) Suppose the memory is 512 MB, which is usually a small application. It is recommended that the SGA of Oracle be approximately 240 M, of which: The Shared Pool (SHARED_POOL_SIZE) can be set to 60 M to 80 M, depending on the actual number of users, queries, etc. The data block buffer can be roughly allocated 120 M-150 M. In 8i, DB_BLOCK_BUFFERS needs to be set, and DB_BLOCK_BUFFER * DB_BLOCK_SIZE is equal to the data block buffer size. You can use db_cache_size to directly allocate the data buffer in 9i.

(2) If the memory is 1 GB, the SGA of Oracle can allocate 500 M: The Shared Pool is allocated 150 M to 400 M, and the data buffer is allocated M to M.

(3) The memory is 2 GB, And the SGA can allocate 1.2 GB, the sharing pool is between 500 mb and MB, and the rest is allocated to the data block buffer.

(4) 2 GB memory or above: it is enough to share a pool of MB to MB, and it does not help much. (Biti_rainy has a special note) the data buffer is as large as possible, but you must pay attention to two problems: first, you need to leave enough memory for the operating system and other applications, and second, for a 32-bit operating system, Oracle's SGA has a limit of GB. Some 32-bit operating systems can break through this restriction. For more information about the method, see the masterpiece of Biti.

2. Analyze tables and indexes, and change the optimization mode

The default optimization mode of Oracle is CHOOSE. In this case, if the table is not analyzed, full table scan is often used for queries without indexing. This usually results in too many disk I/O, resulting in slow query. If the execution plan stability is not used, analyze both the table and index, which may directly increase the query speed. The analysis TABLE command can use analyze table to ANALYZE indexes. You can use the analyze index Command. For tables with less than 1 million, you can analyze the entire table. For large tables, you can analyze them by percentage, but the percentage cannot be too low. Otherwise, the statistical information generated may be inaccurate. You can use the LAST_ANALYZED column of DBA_TABLES to check whether the table has been analyzed or analyzed. You can use the LAST_ANALYZED column of DBA_INDEXES for indexing.

The following example shows the speed comparison before and after analysis. (The table CASE_GA_AJZLZ contains about 0.35 million data and has a primary key.) Enable the automatic query execution plan function in SQLPLUS. (Run RDBMSADMINutlxplan. SQL for the first time to create the PLAN_TABLE table)

  
SQL> SET AUTOTRACE ON
SQL> SET TIMING ON

  
You can use set autotrace on to view the statement execution plan and set timing on to view the statement running time.

  
SQL> select count (*) from CASE_GA_AJZLZ;
COUNT (*)
----------
346639
  
Used time: 00: 00: 21.38
  
Execution Plan
0 select statement Optimizer = CHOOSE
1 0 SORT (AGGREGATE)
2 1 table access (FULL) OF 'case _ ga_ajzlz'
........................
Note that table access (FULL) in the preceding analysis indicates that the statement performs a full table scan. In addition, the query takes 21.38 seconds. The table has not been analyzed yet. Next we will analyze the table:

  
SQL> analyze table CASE_GA_AJZLZ compute statistics;

  
The table has been analyzed. Used time: 00: 05: 357.63. Then query:

  
SQL> select count (*) from CASE_GA_AJZLZ;
COUNT (*)
----------
346639
  
Used time: 00: 00: 00.71
  
Execution Plan
 
0 select statement Optimizer = FIRST_ROWS (Cost = 351 Card = 1)
1 0 SORT (AGGREGATE)
2 1 INDEX (fast full scan) OF 'pk _ ajzlz' (UNIQUE) (Cost = 351
Card = 346351)
..............................

  
Please note that this time only takes 0.71 seconds! This is due to INDEX (fast full scan ). Through the analysis table, the PK_AJZLZ index is used for queries. the disk I/O is greatly reduced and the speed is greatly improved! The following practical statements can be used:
  
Used to generate and analyze all tables and indexes of a user. Assume that the user is GAXZUSR:

  
SQL> set pagesize 0
SQL> spool d: analyze_tables. SQL;
SQL> select 'analyze table' | owner | '.' | table_name |'
Compute statistics; 'from dba_tables where owner = 'gaxzusr ';
SQL> spool off
SQL> spool d: analyze_indexes. SQL;
SQL> select 'analyze Index' | owner | '.' | index_name |'
Compute statistics; 'from dba_indexes where owner = 'gaxzusr ';
SQL> spool off
SQL> @ d: analyze_tables. SQL
SQL> @ d: analyze_indexes. SQL

  
Explanation: The preceding statements generate two SQL files to analyze all GAXZUSR tables and indexes respectively. If you need to analyze the table by percentage, you can modify the script. Through the above steps, we have completed the analysis of tables and indexes, and can test the speed improvement. We recommend that you run the preceding statements on a regular basis, especially when a large amount of data is updated.

Of course, you can use dbms_stats to analyze tables and indexes, which is more convenient. But I still get used to the above method, because the success or failure will be prompted directly.

In addition, we can modify the optimization mode. The value of optimizer_mode can be RULE, CHOOSE, FIRST_ROWS, and ALL_ROWS. For the OLTP system, you can change it to FIRST_ROWS to request the query to return results as soon as possible. In this way, the query performance can be improved even if no analysis is required. However, the analysis of tables and indexes helps to find the most appropriate execution plan.

3. Set cursor_sharing = FORCE or SIMILAR

This method is only available at the beginning of 8i, which is not supported by oracle805. By setting this parameter, You can forcibly share explain plans with different words. For example, the following two statements can be shared:

  
SQL> SELECT * FROM MYTABLE WHERE NAME = 'Tom'
SQL> SELECT * FROM MYTABLE WHERE NAME = 'turner'

  
This method can greatly reduce the problem of low buffer utilization and avoid re-interpretation of statements. This function can solve the performance degradation caused by hard parsing to a large extent. You may decide whether to change this parameter to FORCE based on the actual situation of the system. This parameter is exact by default. Note that ORACLE must be patched before modification. Otherwise, oracle will occupy 100% of the CPU and cannot be used. For ORACLE9i, you can set it to SIMILAR, which combines the advantages of FORCE and EXACT. However, please use this function with caution. This parameter may also have a huge negative impact!

4. Store frequently used small tables and indexes in the data cache KEEP pool

The Data Reading speed on the memory is much faster than that on the hard disk,

The data read speed in the memory is 14000 times that of the hard disk! If the resources are rich, it is better to give the tables frequently used for full table scanning to the dingtalk memory. You can simply use alter table tablename CACHE. After ORACLE8i, you can use alter table table STORAGE (BUFFER_POOL KEEP ). In general, you can consider placing the tables within 200 data blocks in the keep pool, depending on the memory size and other factors. You can use the access. SQL and access_report. SQL provided in this article to find out which tables or indexes meet the conditions. These two scripts are written by the famous Oracle expert Burleson. You can also adjust the scripts based on your actual situation. You can use alter index indexname STORAGE (BUFFER_POOL KEEP) to pin indexes in the KEEP pool.

Prepare the table in the KEEP pool. DB_KEEP_CACHE_SIZE must be set for ORACLE9i, and buffer_pool_keep must be set for 8i. In 8i, you also need to modify db_block_lru_latches. The default value of this parameter is 1, and buffer_pool_keep cannot be used. This parameter should be less than 2*3 * CPU, but must be greater than 1 to set DB_KEEP_CACHE_BUFFER. Buffer_pool_keep is allocated from db_block_buffers, so it must be smaller than db_block_buffers. After these parameters are set, you can pin common objects to the memory permanently.

5. Set optimizer_max_permutations

For multi-table join queries, if cost-based optimization (CBO) is adopted, ORACLE calculates many running solutions,
  
Select the optimal solution. This parameter is used to set the optimal solution for oracle. If the value is too large, it takes a long time to calculate the optimal solution. The default values of Oracle805 and 8i are 2000. We recommend that you change the value of 8. The default value of 9i is 2000.

6. Adjust sorting Parameters

(1) SORT_AREA_SIZE: the default SORT_AREA_SIZE used for sorting is 32 K, which is usually a little small and can be set to 1 M (1048576 ). This parameter cannot be set to an excessively large value because the same sort memory is allocated for each connection.

(2) SORT_MULTIBLOCK_READ_COUNT: increasing this parameter can improve the sorting performance of the temporary tablespace. The default value is 2. You can change it to 32 to compare the changes in the sorting query time. Note that the maximum value of this parameter is related to the platform.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.