Oracle12C chance FROM pga

SGA and PGA Introduction

1 sga Composition: 2b4p1s (memory)
Database Buffer Cache: including default the pool, Keep the pool, Recycle the pool;
the redo log Buffer
Share the pool: including Library Cache, Dictionary Cache
Large the pool
Java the pool
STREAMS the pool
size of this partial area of the fixed sga few MB

2.pga composition:
. 1) Stack Space (SQL Work area): Sort area (sort area), hash area (configured hash table), bitmap merge area (area index)
2) UGA zone: (private sql area major proportion) :
      2.1) persistent area: bind variable storage, and data type of information cursor
      2.2) run-time area: query execution state information, X $ KSMUP

each session execute sql assigned to a private sql area Oracle, the region also stores a very important address information is used to point to shared sql area stored in the library cache,
which holds the SQl execution plan. Oracle recommends that the program development process as much as possible the use of bind variable purpose is to reduce hard parse,
Direct means understanding is that we try to reuse the SQL execution plan of the library cache, which can reduce competition share pool latch bolt and library cache latch and so on.
Which bind variable from there to do? In fact, already mentioned above, it is that there is a permanent memory area in the private sql area in this region was only just released under the cursor is closed.
Finally, here to understand it is that free memory is permanent memory, or the memory will not run back to the anti OS, but gave the anti-UGA

Official Document Location 

  • Books → Concepts → Part V Oracle Instance Architecture → 14 Memory Architecture → 14.2 Overview of the User Global Area
  • Books → Concepts → Part V Oracle Instance Architecture → 14 Memory Architecture → 14.3 Overview of the Program Global Area (PGA)

 

PGA Overview

PGA is specific to an operating system process or thread memory area, and not on the system and other processes or threads share. Since the PGA is process-specific, so it will never be allocated in the SGA. PGA is a heap of memory required to contain a dedicated or shared server process session variables. The server process allocates memory structures in the PGA when needed.

PGA is like a temporary clerical work surfaces used. In this analogy, the clerk is a server process for the customer (client process) services. Clerk clean up a portion of the mesa, the use of the work space to store more information about customer requirements, and customer requested folder is sorted, then let out a workspace at the completion of the work.

The following figure shows an example of a shared server is not configured for the PGA (the set of all PGA). You can use an initialization parameter setting examples PGA target maximum size. If necessary, it can be increased as needed to the respective PGA the target size.

Figure 2: Examples of PGA

 

Note:
daemon also assign their own PGA. The focus of this discussion is limited to the server process PGA.
See Also:

  • "Summary of Memory Management Methods"

1 PGA of contents

PGA is further subdivided into a plurality of different regions, each with a different purpose.

The figure below shows the contents of a PGA dedicated server session may be included. Not all of the PGA area under any circumstances are present.

Figure 3: PGA content

1.1 Private SQL 区

Private SQL area holds information about a parsed SQL statements, and other information specific to the session.

When the server process executes SQL or PL / SQL code, the process uses its private SQL area to store the bind variable values, status information query execution, and query execution work area.

Do not confuse the UGA in private SQL area, and shared SQL area in the SGA stored execution plan. Many private SQL area in the same or a different session, may point to a single execution plan in the SGA. For example, running in a session "SELECT * FROM sales" 20 times, and run in a different session in the same query 10 times, but they can share the same execution plan. Each run of the private SQL area is not shared, and therefore may contain different values ​​and data.

A cursor is a name or a handle to a specific private SQL area. As shown below, you can move the cursor as a pointer to the server state information from the client. SQL cursors are closely related to the private area, the two terms are sometimes used interchangeably.

Figure 4: Cursor

Private SQL area is divided into the following areas:

  • run-time area
    This area contains the query execution status information. For example, run-time area tracks the number of rows retrieved so far in the full table scan.
    Oracle database will create run-time area, as a first step in the implementation of the request. For DML statements, run-time area which is released when the SQL statement is closed.
  • persistent area
    This area contains bind variable's value. Bind variables when executing SQL statements at run time to provide values in SQL statements. Only when the cursor is closed, persistent regions were released.

The client process responsible for managing private SQL area. Although the number of client processes that can be allocated private SQL area is limited by the initialization parameter OPEN_CURSORS, but the allocation and deallocation of private SQL area depends on the application.

While most users rely on automatic cursor handling mechanism database utilities, but still an Oracle database programming interface provides developers with more control over the cursor. In general, applications should close all open cursors and no longer in use, to release the lasting region, minimizing memory requirements and user applications.

See Also:

  • "Shared SQL Areas"
  • "Oracle Database Development Guide" and "Oracle Database PL / SQL Language Reference" to learn how to use cursors

 

1.2 SQL Work 区

The workspace is the PGA is memory intensive operations allocated private memory area. 

For example, a sorting operation to sort the sort area using a set of rows. Likewise, hash join operation input data to the left, and to create a hash table using the hash area, and bitmap merge operation is used to combine the bitmap merge area retrieved from the plurality of scanned bitmap index data .

The following example shows the employees and departments table appearances join query plan.

SQL> SELECT * 
  2  FROM   employees e JOIN departments d 
  3  ON     e.department_id=d.department_id 
  4  ORDER BY last_name;
--------------------------------------------------------------------------------
| Id| Operation           | Name        | Rows  | Bytes | Cost (%CPU)| Time    |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT    |             |   106 |  9328 |    7  (29)| 00:00:01 |
| 1 |  SORT ORDER BY      |             |   106 |  9328 |    7  (29)| 00:00:01 |
|*2 |   HASH JOIN         |             |   106 |  9328 |    6  (17)| 00:00:01 |
| 3 |    TABLE ACCESS FULL| DEPARTMENTS |    27 |   540 |    2   (0)| 00:00:01 |
| 4 |    TABLE ACCESS FULL| EMPLOYEES   |   107 |  7276 |    3   (0)| 00:00:01 |
--------------------------------------------------------------------------------

Full table scan track progress in Example 1, run-time region. Performing a hash join this session hash region to match the two rows in the table. The sorting operations in the ORDER BY sorting zone.

If the amount is too large to be the operator of data processing can not be completed in the SQL Work area, the Oracle database will enter data into smaller pieces. Thus, the database to deal with some piece of data in memory, while the remaining data is written to a temporary disk storage, pending subsequent processing.

When you enable automatic PGA memory management, database automatically optimize the size of the work area. You can also manually control and optimize the size of the work area. For more information, see "Memory Management".

In general, larger work area can significantly improve Caozuoxingneng, but this is more memory consumption for the price. Ideally, the size of the work area sufficient to accommodate its associated SQL assignment operator input data and auxiliary memory structures. Otherwise, the response time will increase, because part of the input data must be cached to disk. In extreme cases, if the size of the workspace compared to the size of the input data appears too small, the database must buy and sell these pieces of data back and forth several times, greatly increasing the response time.

See Also:

  • "Oracle Database Administrator's Guide" to learn how to use automatic PGA management
  • "Oracle Database Performance Tuning Guide" to learn how to adjust the PGA memory

2 in a PGA mode dedicated and shared server

PGA memory allocation depends on the database is to use a dedicated or shared server connections.

Table 1 shows the differences.

 

Memory area Private server Shared Server
Nature of the conversation memory private shared
Location persistent area PGA SGA
Position DML / run-time region DDL statements PGA SGA

Memory allocation table the differences between dedicated and shared server 14-1

See Also:

 

    • "Oracle Database Administrator's Guide" for how to configure a shared database server

 

UGA Overview

UGA is allocated for the session variable session memory, such as login information and other information required database session. In fact, UGA stores the session state.

Figure 1 depicts the UGA

Figure 1: User Global Area (the UGA)

If a session PL / SQL package is loaded into memory, the state in the packet containing the UGA, i.e. all packets is a value set at a particular time variables stored. When the subpackages change the value of a variable, the package will change state. By default, the survival package variables during the session is unique and persistent.

OLAP 页面缓冲池也存储在 UGA 中。该池管理相当于数据块的 OLAP 数据页。页缓冲池在启动一个 OLAP 会话时分配,并在该会话结束时释放。每当用户查询一个多维对象(如立方体)时,就会自动打开一个 OLAP 会话。

该 UGA 必须在数据库会话的整个存活期间是可用的。 由于这个原因, 当使用共享服务器的连接时,UGA 不能存储在 PGA 中,因为 PGA 是特定于单个进程的。因此,当使用共享服务器的连接时,UGA 被存储在 SGA 中,以使任何共享服务器进程都能访问它。在使用专用服务器的连接时, UGA 存储在 PGA 中。

 

pga和uga比较

uga:user global area ,是会话含义的内存区 为了保证数据可以被会话访问到,所以mts模式属于sga中的大池,专有模式属于pga,属于用户的内存区。
    uga保存当前会话相关的信息,比如会话登录信息、pl/sql包的参数信息,绑定变量的值。

pga:program global area,是操作系统含义上的内存区,
    可以理解为操作系统在一个进程启动时,为他分配的内存空间
    查询使用 show pga;

 

sga和pga比较

sga:共享数据块,所有进程可以访问,数据并发访问
    涉及lock,latch,锁定和队列
    是数据库最主要优化区域,一些重要的指标:data buffer hit,library hit(hard/soft parse),hot blocks
pga:为专有进程服务,进程间无法数据共享,数据独占
    无需锁定机制
    性能优化只需要考虑它的大小。

Guess you like

Origin www.cnblogs.com/caibird2005/p/11278649.html