oracle之PGA相关的sql

2021/11/3 2:09:53

本文主要是介绍oracle之PGA相关的sql,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

在上篇文章中初步介绍了关于pga的基础知识,阅读了其他很多关于pga的内容,今天总结一些关于pga的sql和其他知识。

在网上找了相关资料整理而来,可能有点乱,先码上后再整理下。

 

 

https://blog.csdn.net/haiross/article/details/18053099   ---PGA_AGGREGATE_TARGET参数的理解

手动设置会话的sort_area_size,查看该会话的

alter session set sort_area_size =1024000;
select * from v$parameter where name like '%area%'  ;(有DBA权限这样才能看到,普通用户目前还没找到方法验证这个参数是否修改成功)

1.PGA_AGGREGATE_TARGET-此参数用来指定所有session总计可以使用最大PGA内存。这个参数可以被动态的更改,取值范围从10M -- (4096G-1 )bytes。动态就是不用重启数据库,alter system set PGA_AGGREGATE_TARGET=4096m ;
2。WORKAREA_SIZE_POLICY-此参数用于开关PGA内存自动管理功能,该参数有两个选项:AUTO 和 MANUAL,当设置为AUTO时,数据库使用Oracle9i以来提供的自动PGA管理功能,当设置为MANUAL时,则仍然使用Oracle9i前手工管理的方式。

 

SELECT x.ksppinm NAME, y.ksppstvl/1024/1024 VALUE, x.ksppdesc describ
FROM SYS.x$ksppi x, SYS.x$ksppcv y
WHERE x.inst_id = USERENV ('Instance')
AND y.inst_id = USERENV ('Instance')
AND x.indx = y.indx
AND x.ksppinm LIKE '%pga_max%';    ----查看隐形参数,一个会话最大的pga大小。不能瞎调。alter system set '_pga_max_size' = 2048M;

SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
FROM SYS.x$ksppi x, SYS.x$ksppcv y
WHERE x.inst_id = USERENV ('Instance')
AND y.inst_id = USERENV ('Instance')
AND x.indx = y.indx
AND x.ksppinm LIKE '%smm%'   ;-----其他参数

 

 

SELECT * FROM V$PGASTAT;

NAME                                                                  VALUE UNIT
---------------------------------------------------------------- ---------- ------------
aggregate PGA target parameter                                    536870912 bytes    --当前PGA_AGGREGATE_TARGET的值
aggregate PGA auto target                                         477379584 bytes    --当前可用于自动分配了的PGA大小,应该比PGA_AGGREGATE_TARGET 小
global memory bound                                                26843136 bytes    --自动模式下工作区域的最大大小,Oracle根据工作负载自动调整。
total PGA inuse                                                     6448128 bytes
total PGA allocated                                                11598848 bytes    --PGA的最大分配
maximum PGA allocated                                             166175744 bytes
total freeable PGA memory                                            393216 bytes    --PGA的最大空闲大小
PGA memory freed back to OS                                        69074944 bytes
total PGA used for auto workareas                                         0 bytes    --PGA分配给auto workareas的大小
maximum PGA used for auto workareas                                 1049600 bytes
total PGA used for manual workareas                                       0 bytes
maximum PGA used for manual workareas                                530432 bytes
over allocation count                                                  1118    --实例启动后,发生的分配次数,如果这个值大于0,就要考虑增加pga的值
bytes processed                                                   114895872 bytes
extra bytes read/written                                            4608000 bytes
cache hit percentage                                                  96.14 percent    --命中率

 

 

 

引言:1、在处理SQL语句时的第一步就是要创建运行时区域[SQL工作区域(SQL Work Area)],SQL语句执行完毕就释放该区域。
 
2、WORKAREA_ADDRESS(这个字段在V$SQL_WORKAREA_ACTIVE和V$SQL_WORKAREA
中都有),表示Address of the work area handle,也就是说,它是SQL工作区域这个对象的句柄(相当于是该对象在oracle系统级别上的一个标识符(identity),类似,一个人,在中国范围内,有一个唯一的区别于别人的身份证号。也类似锁是对象的中介一样。是一种表示地址的句柄)的值。Each SQL statement stored in the shared pool has one or more childcursors that are listed in theV$SQL view.V$SQL_WORKAREA lists all work areas needed by these child cursors。这句话说明,一个SQL语句(即父游标)的每个子游标(即执行计划等)对应都有一个自己的SQL工作区域这种对象。
  句柄,首先,它是在某一类对象范围内标识其中一个对象的句柄。比如,这里的在oracle系统级别上的SQL工作区域这种对象。当一个SQL语句(即父游标)以某种执行计划(即该SQL语句的某子游标)来进行执行时,oracle系统会为该子游标对应的SQL工作区域这个对象分配一块内存空间(内存区域)。当该SQL语句执行完毕后,oracle系统就释放这一块内存空间。也就说,每一次,该SQL语句(即父游标)以该执行计划(即该子游标)来进行执行,则oracle系统都会为该子游标对应的SQL工作区域这个对象分配一块内存空间(内存区域)。这样,每次oracle系统给该SQL工作区域这个对象分配的那块内存空间的地址应该都不会一样,但是,SQL工作区域这个对象的句柄值始终不变。这样做的好处,是每个进程分工明确,即执行SQL语句的服务器进程每次要用一块内存空间(即SQL工作区域)时,它就直接通过SQL工作区域这个对象的句柄来找到该SQL工作区域这个对象(用前判断下是否已有空间分配给该对象即可)并使用它即可,而服务器进程不用去先为该对象分配一块内存空间(内存区域)。这个给SQL工作区域对象分配一块内存空间(内存区域)的工作就交由oracle系统中专门负责给各类对象分配一块内存空间(内存区域)的进程来做即可。
 
操作系统的句柄也是这个机制原理,就是一个进程明确分工的机制:
进 程a只想使用一块内存空间,不想自己分配该内存空间。所以进程b来做分配内存空间这个工作,并将该内存空间的地址与一个句柄(变量)的值关联起来。这样,进程a就可以用句柄了,它感觉用句柄好像用指针的感觉。当进程b来做释放该内存空间这个工作后,就会将该内存空间的地址与该句柄(变量)的值间的关联(这个关联信息也要存放在某个变量或内存空间上的)撤销掉。

这里说的对象(如,类的一个对象),其实质就是指一块内存空间。
对象的理解:
1、第一种理解,对象就是一块内存空间,进程通过句柄变量找到该内存空间。
2、第二种理解,创建一个对象就是在内存的程序区或其他什么区上创建一个用于描述该对象叫什么名字和它的句柄是多少(即保存对象名字和其句柄值)的内存结构,多个这种内存结构构成一张某个软件(里的各个进程)可以使用的对象清单。创建一个对象时,可能会没有马上给该对象分配内存空间(这种内存空间在内存的什么区上,忘了)。


注释:

一个SQL语句的每一个子游标都对应有自己的一个SQL工作区对象,该SQL工作区对象是该子游标第一次运行时创建,而后,无论是否给SQL工作区对象动态分配(或是撤销)内存,SQL工作区对象这个对象还是始终存在的。
  “SQL工作区对象”不同于“SQL工作区”这个概念,即前者是一个对象,后者是单纯的一块内存空间。当系统给SQL工作区对象动态分配一块内存空间时,这片内存空间就称为空间,就称为SQL工作区。SQL工作区SQL工作区。


一个SQL语句的每一个子游标都对应有自己的一个SQL工作区对象,而optimal尺寸和onepass尺寸是SQL工作区对象的属性。只要该SQL语句内容不变,则它的子游标对应的SQL工作区的属性optimal尺寸和onepass尺寸的值也不变。
oracle系统根据optimizer statistics(指的就是work area profile)估算出optimal尺寸和onepass尺寸,而期望尺寸以optimal尺寸和onepass尺寸依据,根据一定规则计算得到。


参考:oracle系统根据optimizer statistics(指的就是work area profile)估算出optimal尺寸和onepass尺寸


正文:


一、V$SQL_WORKAREA
它描述的对象是SQL工作区(
WORKAREA_ADDRESS
RAW(4 | 8)
Address of the work area handle. This is the primary key for the view.
)。
它是一个非实时的视图,该视图里的一部分字段(即TOTAL_EXECUTIONS、OPTIMAL_EXECUTIONS、ONEPASS_EXECUTIONS、MULTIPASSES_EXECUTIONS)的值是一个累计值,也就是说,一个SQL语句(即父游标)的每个子游标(即执行计划等)对应都有一个自己的SQL工作区域这种对象,该SQL语句每运行一次后,这部分字段对应产生的新值累加到这部分字段原来的值上,便是得到了该SQL语句这次运行后V$SQL_WORKAREA里这部分字段的值。
它是实例系统级别的,即显示数据库上SGA里当前在共享池上存在着的子游标对应的SQL工作区从创建开始到目前的一些累计值。
 
You can use thisview to find out answers to the following questions:
·        What are the top 10 work areasthat require the most cache area?
·        For work areas allocated in AUTOmode, what percentage of work areas are running using maximum memory?
 
 
字段说明:
ESTIMATED_OPTIMAL_SIZE    NUMBER
Estimatedsize (in bytes) required by this work area to execute the operation completelyin memory (optimal execution).
Derived from either optimizer statistics or previousexecutions.
译文:该值是根据优化器的统计信息计算所得的结果或是直接等于上一次该SQL工作区对应的sql语句运行时ESTIMATED_OPTIMAL_SIZE字段的值。
那我们不禁要问上一次的ESTIMATED_OPTIMAL_SIZE字段的值从哪里而得?必然的,上一次的ESTIMATED_OPTIMAL_SIZE字段的值最终归结还是来自根据优化器的统计信息计算所得的结果。
ESTIMATED_ONEPASS_SIZE           NUMBER
Estimatedsize (in bytes) required by this work area to execute the operation in a singlepass. Derived from either optimizer statistics or previousexecutions.
 
TOTAL_EXECUTIONS=OPTIMAL_EXECUTIONS+ONEPASS_EXECUTIONS+MULTIPASSES_EXECUTIONS






 
二、V$SQL_WORKAREA_ACTIVE
它是一个实时视图,它描述的对象是SQL工作区

WORKAREA_ADDRESS
RAW(4 | 8)
Address of the work area handle. This is the primary key for the view.
),它是实例系统级别的,即显示数据库上当前时刻正在运行的那些SQL工作区。
You can use thisview to answer the following:
·        What are the top 10 largestwork areas currently allocated in the system?
·        What percentage of memory isover-allocated (EXPECTED_SIZE<ACTUAL_MEM_USED)and under-allocated (EXPECTED_SIZE>ACTUAL_MEM_USED)?
·        What are the active work areasusing more memory than what is expected by the memory manager?
·        What are the active work areasthat have spilled to disk?
 
字段说明:
WORK_AREA_SIZE    NUMBER
 
Maximumsize (in bytes) of the work area as it is currently used by the operation
译文:WORK_AREA_SIZE是当前这个操作正在使用本SQL工作区域时,本SQL工作区域的可以占用的空间大小的最大值。
EXPECTED_SIZE NUMBER
Expectedsize (in bytes) for this work area. EXPECTED_SIZE is set on behalf of theoperationby the memory manager. Memory(指的是ACTUAL_MEM_USED) can be over-allocated when WORK_AREA_SIZE has a higher value thanEXPECTED_SIZE. This can occur when the operation using this work area takes along time to resize it.
译文:EXPECTED_SIZE即本SQL工作区域的期望尺寸。这个期望尺寸是PGA自动管理机制中的本地内存管理器(local memory manager)这个进程设置的,这个期望尺寸是该进程所认为的本次操作所要用到的(实际)SQL工作区域的内存空间大小。如果WORK_AREA_SIZE 的值大于EXPECTED_SIZE的值,那么本SQL工作区域的实际大小(ACTUAL_MEM_USED)就可能会over-allocated。所谓over-allocated,就是发生EXPECTED_SIZE<ACTUAL_MEM_USED这种情况。over-allocated这种情况可能会发生在如下时候:当一个使用本SQL工作区域的操作运行了很长一段时间时,就会将本SQL工作区域的实际大小(ACTUAL_MEM_USED)改得大些。
ACTUAL_MEM_USED NUMBER
Amountof PGA memory (in bytes) currently allocated on behalf of this work area. Thisvalue should range between 0 and WORK_AREA_SIZE.
 
WORK_AREA_SIZE、EXPECTED_SIZE、ACTUAL_MEM_USED这三个参数间的关系:
 
1、0    <ACTUAL_MEM_USED<WORK_AREA_SIZE。
2、ACTUAL_MEM_USED和WORK_AREA_SIZE这两个参数可以大于,也可以小于EXPECTED_SIZE。
当EXPECTED_SIZE < ACTUAL_MEM_USED 时,称为over-allocated ;
当EXPECTED_SIZE > ACTUAL_MEM_USED 时,称为under-allocated。
 
SEGRFNO#   NUMBER
Relative filenumber within the tablespace(此句说明了相对文件号的含义,即它是在一个表空间范围内的对属于该表空间的数据文件的一个编号)for the temporary segment created on behalf of thiswork area. This column is NULL if this work area has not (yet) spilled to disk.


注释:V$SQL_WORKAREA_ACTIVE和V$SQL_WORKAREA两个视图的联系--
V$SQL_WORKAREA_ACTIVE表示一个SQL工作区实际运行时的一些实际值,而V$SQL_WORKAREA表示该SQL工作区一些属性的理论值。

三、V$SQL_WORKAREA_HISTOGRAM
This view shows the number of workareas executed with optimal memory size, one-pass memory size, and multi-passmemory sizesince instance startup.
Example 7-4 Querying V$SQL_WORKAREA_HISTOGRAM: Non-empty Buckets
Consider a sort operation that requires 3 MB of memory torun optimally (cached). Statistics about the work area used by this sort areplaced in the bucket defined byLOW_OPTIMAL_SIZE = 2097152 (2 MB)andHIGH_OPTIMAL_SIZE = 4194303 (4 MB minus 1 byte), because 3 MBfalls within that range of optimal sizes.
参考:http://docs.oracle.com/cd/E11882_01/server.112/e41573/memory.htm#PFGRF94359
 
 
V$SQL_WORKAREA_HISTOGRAM displays the cumulative work area execution statistics(cumulated since instance startup) for different work area groups.The work areas are split into 33 groups based on their optimal memory requirementswith the requirements increasing in powers of two. Thatis, work areas whose optimal requirement varies from 0 KB to 1 KB, 1 KB to 2KB, 2 KB to 4 KB, ... and 2 TB to 4 TB.
参考:
http://docs.oracle.com/cd/E11882_01/server.112/e40402/dynviews_3063.htm#REFRN30258
有上述可知,
它描述的对象是SQL工作区(LOW_OPTIMAL_SIZE and HIGH_OPTIMAL_SIZE表示SQL工作区处于optimal mode 运行时的memory 大小处于上述的范围).
它是一个非实时的视图, 记录自从数据库实例启动以来到目前为止有过的SQL工作区的相关信息。
它是实例系统级别的,即显示数据库上自从数据库实例启动以来到目前为止有过的SQL工作区的相关信息的一些累计值。
 

四、V$PGASTAT
它是一个数据库实例级别视图,其中有些字段是实时值字段,有些则是累积值字段。它的字段(带total的字段)值一般是数据库当前各个进程的属性之和。
This view gives instance-level statistics on the PGA memory usageand the automatic PGA memory manager.
0、aggregate PGA target parameter: This is the current valueof the initialization parameterPGA_AGGREGATE_TARGET.
参数total PGA allocated和PGA_AGGREGATE_TARGET是一对对应值,即前者表示一个数据库实例上的当前所有进程对应的pga之和的实际值,后者表示一个数据库实例上的当前所有进程对应的pga之和可以达到的最大值(理论值)。
 
1、aggregate PGA auto target: This gives the amount of PGA memory Oracle Database can use forwork areas running in automatic mode. This amount is dynamically derived fromthe value of the parameterPGA_AGGREGATE_TARGET andthecurrent work area workload.
当前SQL work area的负载影响aggregate PGA auto target的值,反过来,aggregate PGA auto target之后又影响下一次调整时SQLwork area的大小。
 
aggregatePGA auto target,表示一个数据库实例上的(当前)所有进程对应的pga里可调整的内存空间(即SQLwork area)之和(可以到达)的最大值。当然,它是预期值(目标值)类型的参数,所以实际情况下,一个数据库实例上的所有进程对应的pga里可调整的内存空间(即SQLwork area)之和可以超过该最大值的。
注释:这里的work area包括SQL的工作区和PL/SQL的工作区。

workarea
A private allocation of PGA memory used formemory-intensive operations.
http://docs.oracle.com/cd/E11882_01/server.112/e40540/glossary.htm#CNCPT2135
SQL Work Areas
A work area is a private allocation of PGA memory used formemory-intensive operations.
http://docs.oracle.com/cd/E11882_01/server.112/e40540/memory.htm#CNCPT1242
也就是说,work area是一种内存分配的空间(A private allocation),而SQL Work Areas
是work area中的一种(A work area)。

 
2、参数命名规则的含义
凡是参数名里带有aggregate或者total的,表示“聚合,所有的”意思,如PGA_AGGREGATE_TARGET,表示一个数据库实例上的各个进程自己的pga大小之和。
aggregatePGA auto target,表示一个数据库实例上的所有进程对应的pga里可调整的内存空间(即SQLwork area)之和的最大值。再例如,aggregate PGA auto target、total PGAallocated、total PGA used for auto workareas。
 
其中,total还表示该参数当前的实际的值之和。
 
 
凡是参数名里带有target的,表示一个预期值(目标值),或说参考值,不一定要等于它,可以小于,也可以大于它,但最好不要大它太多。这些参数都是oracle系统处于(pga)自动调整模式时自动调整算法机制计算出的建议值。
 
凡是参数名里带有auto的,表示oracle系统处于(pga)自动调整模式时会用到的参数,手动模式时不用的。
或者oracle官方文档的参数解释里,带有in AUTO mode,说明该参数也是用于(pga)自动调整模式时的参数。如,
aggregatePGA auto target: This gives the amount of PGAmemory Oracle Database can use for work areas runningin automatic mode.
globalmemory bound: This gives the maximum size of awork area executedinAUTO mode.
 
total PGA used for auto workareas: This indicates how much PGA memory is currently consumedby work areas runningunder automaticmemory management mode.
3、  globalmemory bound:
This gives the maximum size of a work area executed in AUTO mode.
This value is continuously adjusted by Oracle Database toreflect the current state of the work area workload.
The global memory bound generally decreases when the numberof active work areas is increasing in the system.
As a rule of thumb, the value of the global bound shouldnot decrease to less than one megabyte. If it does, then the value ofPGA_AGGREGATE_TARGET should probably be increased.
该参数表示一个数据库实例上每个pga(内存空间)里SQL work area那块区域的最大值。但是,实际上,有时某个pga区域的内存大小是可以超过该最大值。
 
4、total PGAallocated: (实时值)
 This gives the currentamount of PGA memoryallocated by the instance. Oracle Database tries to keep this number less than thevalue ofPGA_AGGREGATE_TARGET. However, it is possible for the PGA allocated toexceed that value by a small percentage andfor a short period, when the work area workload is increasing very rapidly orwhen the initialization parameter PGA_AGGREGATE_TARGET is set to a too small value.
该参数表示一个数据库实例上的实际上当前所有进程对应的pga的内存空间之和。
 
参数total PGA allocated和PGA_AGGREGATE_TARGET是一对对应值,即前者表示一个数据库实例上的当前所有进程对应的pga之和的实际值,后者表示一个数据库实例上的当前所有进程对应的pga之和可以达到的最大值(理论值)。
 
 
注释:
英文中PGA memory如果没有带修饰语的话,表示的就是整个pga内存空间的大小,如下是有带修饰语的:
aggregate PGA auto target: This gives the amount of PGA memoryOracle Database can use for work areas runningin automatic mode.
译文:Pga内存空间中用于SQL work area的那块区域。
total PGA used for auto workareas: This indicates how muchPGA memoryis currently consumed by work areas runningunder automatic memory management mode.
译文:Pga内存空间中用于SQL work area的那块区域。
 
5、total PGA used for auto workareas:(实时值)
 This indicates how much PGA memory is currently consumed by work areasrunning under automatic memory management mode. This number can be used todetermine how much memory is consumed byotherconsumersofthe PGA memory(for example, PL/SQL or Java):
PGA other = totalPGA allocated - total PGA used for auto workareas(用于SQL的内存空间)
该参数表示一个数据库实例上的当前所有进程对应的pga里可调整的内存空间(其他还包括PL/SQL or Java的work area)之一的SQLwork area之和的。
参数total PGA used for auto workareas和aggregate PGA auto target是一对对应值,即前者表示一个数据库实例上的当前所有进程对应的pga里可调整的内存空间(即SQLwork area)之和的实际值,后者表示一个数据库实例上的当前所有进程对应的pga里可调整的内存空间(即SQLwork area)之和可以到达的最大值(理论值)。
注释:
这里说的PL/SQL or Java,指的是客户端使用的是一段PL/SQL脚本,提交给服务端,或是客户端使用Java语言的一段代码,提交给服务端。不是我们平时提交SQL语句。此时,服务器进程上的已经分配的pga空间里划一块空间给这两种使用。即三种在pga上有各个的空间使用。
参考:http://docs.oracle.com/cd/B19306_01/server.102/b14220/sqlplsql.htm#i7579
24 SQL, PL/SQL, and JavaV$PROCESS_MEMORY
categories
   Categoryname. Categories include "SQL", "PL/SQL", "OLAP" and"JAVA". Special categories are "Freeable" and"Other".Freeablememory has been allocated to the process by the operating system, but has notbeen allocated to a category. "Other" memory has beenallocated to a category, but not to one ofthe named categories("SQL","PL/SQL", "OLAP" and "JAVA",即other是另一种未知名的categories?).
ALLOCATED
   Bytes of PGA memory allocated by the processfor the category. For the "Freeable" category, it is the amount of free PGA memoryeligible to bereleased tothe operating system.
USED
Bytes of PGA memory used by theprocess for the category. For"Freeable", the value is zero. For "Other", the value isNULL for performance reasons.???
 
 
7.5.1.2.3 V$PROCESS_MEMORYThis view displays dynamic PGA memory usage by namedcomponent categories for each Oracle process. This view will contain up to sixrows for each Oracle process, one row for:
·        Each named component category: Java, PL/SQL,OLAP, and SQL.
·        Freeable: memory that has beenallocated to the process by the operating system, but not to a specificcategory.
·        Other: memory that has beenallocated to a category, but not to one of the named categories.
You can use the columns CATEGORY, ALLOCATED,USED, andMAX_ALLOCATED to dynamically monitor thePGA memory usage of Oracle processes for each of the six categories.
(即six rows分别指Java, PL/SQL, OLAP, and SQL、Freeable、Other)
 
The UGA consists of a small fixed area containing a few atomicvariables, small data structures and pointers. The rest of the UGA is a heap.Most of the UGA heap is for private SQL andPL/SQL areas. So yes, package variables and bind variable arethere (although the bind meta-data is in the SGA) but sort areas, row sourcebuffers, and runtime state data are also major space consumers.
http://www.orafaq.com/maillist/oracle-l/2003/11/11/0789.htm
 
 
5、 total freeable PGA memory:
 This indicates howmuch allocated PGA memory which canbe freed.
Number of bytes of PGA memory in all processes that could be freed backto the operating system.
注释1:
这里的freed不是空闲的意思,而是释放的意思。
PGA memoryfreed back to OS:
Number of bytes of PGA memory freed back to theoperating system, cumulatedsinceinstance startup.
注释2:
一个进程在视图V$PROCESS_MEMORY上各个字段CATEGORY值对应的ALLOCATED值之和,等于该进程在视图V$PROCESS上字段PGA_ALLOC_MEM值。同理,一个进程在视图V$PROCESS_MEMORY上各个字段CATEGORY值对应的USED值之和,等于该进程在视图V$PROCESS上字段PGA_USED_MEM值。
 
一个进程在视图V$PROCESS_MEMORY上字段CATEGORY值为Freeable对应的ALLOCATED值,等于该进程在视图V$PROCESS上字段PGA_FREEABLE_MEM
值。
 
刚开始以为视图V$PROCESS 中PGA_ALLOC_MEM字段减去 PGA_USED_MEM 字段  所得的差值就是等于PGA_FREEABLE_MEM字段的值。但是实际上,发现不是这样,看到自己电脑上的显示的 V$PROCESS结果里,PGA_FREEABLE_MEM字段的值都是为0,而PGA_ALLOC_MEM字段减去 PGA_USED_MEM 字段  所得的差值都不是0。因为内存空间的分配和使用这两个概念是软件设计中常用的管理内存空间的手段。例如,创建一个表时,会分配以一个区段大小为单位的整数倍的空间给该表,而当向表中添加数据时(也就是使用该表时),则是按一个oracle数据块的空间大小为单位来使用,即按数据块大小来添加数据的。再如,window下用的记事本文件都是先分配一定大小(假设为A)的空间,如果使用该记事本文件的大小超过了该分配的空间,则又会再分配一定大小(也为A)的空间给该记事本文件。如下图所示:
图示里大小:69字节表示该记事本文件已经使用了的空间大小,而占用空间:4096字节则表示操作系统给该记事本文件分配的空间大小。那么视图V$PROCESS 中的PGA_FREEABLE_MEM字段表示什么呢?我们可以从对V$PROCESS_MEMORY中字段CATEGORY的解释中得知:Category name. Categoriesinclude "SQL", "PL/SQL", "OLAP" and"JAVA". Special categories are "Freeable" and"Other". Freeable memory has been allocated to theprocess by the operating system, but has not been allocated to a category."Other" memory has been allocated to a category, but not to one ofthe named categories.从上面的解释中可以发现,pga上内存空间可以分成包括Freeable在内的六种类型。比如,会话执行sql语句时pga上就会有一块SQL类型的区域,执行PL/SQL存储过程时pga上就会有一块PL/SQL类型的区域。包括Freeable在内的每一个CATEGORY都有自己的ALLOCATED和USED属性。只是还不知道在什么情况下一个进程对应的pga里的Freeable是不为0。 
 
6、  total PGA inuse
Indicates how much PGA memory is currently consumed bywork areas. This number can be used to determine how much memory is consumed byother consumers of the PGA memory (for example, PL/SQL or Java).
Oracle官方文档写错了,实际上该参数是pga分配后当前正在使用的部分,值等于V$PROCESS  PGA_USED_MEM的总和。
 
 
五、V$PROCESS_MEMORY
该视图为数据库实例级别上的实时视图,它描述的对象是各个进程对应的pga上分成六种类型的区域。
categories
   Categoryname. Categories include "SQL", "PL/SQL", "OLAP" and"JAVA". Special categories are "Freeable" and"Other".Freeablememory has been allocated to the process by the operating system, but has notbeen allocated to a category. "Other" memory has beenallocated to a category, but not to one ofthe named categories("SQL","PL/SQL", "OLAP" and "JAVA",即other是另一种未知名的categories?).
ALLOCATED
   Bytes of PGA memory allocated by the processfor the category. For the "Freeable" category, it is the amount of free PGA memoryeligible to bereleased tothe operating system.
USED
Bytes of PGA memory used by theprocess for the category. For"Freeable", the value is zero. For "Other", the value isNULL for performance reasons.???
 
 
V$PROCESS_MEMORYThis view displays dynamic PGA memory usage by namedcomponent categories for each Oracle process. This view will contain up to sixrows for each Oracle process, one row for:
·        Each named component category: Java, PL/SQL,OLAP, and SQL.
·        Freeable: memory that has beenallocated to the process by the operating system, but not to a specificcategory.
·        Other: memory that has beenallocated to a category, but not to one of the named categories.
You can use the columns CATEGORY, ALLOCATED,USED, andMAX_ALLOCATED to dynamically monitor thePGA memory usage of Oracle processes for each of the six categories.
注释:
1、six rows分别指Java, PL/SQL, OLAP, and SQL、Freeable、Other。
 
 
2、从V$PROCESS_MEMORY中字段CATEGORY上可以看出pga上内存空间分别用于什么用途,即pga上内存空间可以分成包括Freeable在内的六种类型。

附加

1、认识视图的角度:
它的内容是实时更新吗(确切地说,哪些字段是实时更新的当前值,哪些是累计值)?它是实例系统级别,还是会话级别范围?它描述的对象是谁?

2、除了dba_\user_\all_开头的视图里所看到的对象结果会因在不同用户下运行而不同外,其他视图不是当前会话级别视图,一般看到的都是一样的结果,即数据库级别上的所有对象。

版权声明:本文为CSDN博主「haiross」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/haiross/article/details/19122909



这篇关于oracle之PGA相关的sql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程