zoukankan      html  css  js  c++  java
  • PGA和UGA内存的使用情况

    引用thomas kyte的PGA和UGA的统计内存的使用情况,用排序区不同的大小来查看pga、UGA、物理读取不同内存使用

    会话1:创建测试表和测试不同排序大小

    create table t as select * from all_objects;
    exec dbms_stats.gather_table_stats( user, 'T' );
    创建测试表

    创建run_query脚本:用于控制内存参数排序区(sort_area_size)的大小和表的排序

    connect glltabspace/oracle
    set serveroutput off
    set echo on
    column sid new_val SID
    select sid from v$mystat where rownum = 1;
    alter session set workarea_size_policy=manual;
    alter session set sort_area_size = &1;
    prompt run @reset_stat &SID and @watch_stat in another session here!
    pause
    set termout off
    select * from t order by 1, 2, 3, 4;
    set termout on
    prompt run @watch_stat in another session here!
    pause
    run_query

    会话2:查看会话1中不同排序大小,得到PGAUGA、物理读取的情况。

    reset_stat脚本:记录PGAUGA、物理读取使用情况和与之前相比差值

    create table sess_stats
    ( name varchar2(64), value number, diff number );
    
    variable sid number
    exec :sid := &1
    reset_stat

    watch_stat脚本:统计PGAUGA、物理读取使用情况,并写入reset_stat脚本创建的表

    merge into sess_stats
    using
    (
    select a.name, b.value
      from v$statname a, v$sesstat b
     where a.statistic# = b.statistic#
       and b.sid = :sid
       and (a.name like '%ga %'
            or a.name like '%direct temp%')
    ) curr_stats
    on (sess_stats.name = curr_stats.name)
    when matched then
      update set diff = curr_stats.value - sess_stats.value,
                 value = curr_stats.value
    when not matched then
      insert ( name, value, diff )
      values
      ( curr_stats.name, curr_stats.value, null )
    /
    
    select name,
           case when name like '%ga %'
                then round(value/1024,0)
                else value
            end kbytes_writes,
           case when name like '%ga %'
                then round(diff /1024,0)
                else value
            end diff_kbytes_writes
      from sess_stats
     order by name;
    
    watch_stat

    设置排序区为64KB(65536),查看PGA,UGA

    ###########################################################
    ###     
    设置排序区为64KB(65536),查看PGA,UGA
             ###
    ###########################################################
    #会话1:
    glltabspace@GULL>  @run_query 65536
    已连接。
    glltabspace@GULL> column sid new_val SID
    glltabspace@GULL> select sid from v$mystat where rownum = 1;
    
           SID
    ----------
             1
    
    glltabspace@GULL> alter session set workarea_size_policy=manual;
    
    会话已更改。
    
    glltabspace@GULL> alter session set sort_area_size = &1;
    原值    1: alter session set sort_area_size = &1
    新值    1: alter session set sort_area_size = 65536
    
    会话已更改。
    
    glltabspace@GULL> prompt run @reset_stat &SID and @watch_stat in another session here!
    run @reset_stat          1 and @watch_stat in another session here!
    glltabspace@GULL> pause
    
    
    
    
    #新建一个会话,为会话2,在表还未排序时,查看初始的PGAUGA
    #@reset_stat 1 ,1是会话1中的SID
    glltabspace@GULL> @reset_stat 1
    
    表已创建。
    
    
    PL/SQL 过程已成功完成。
    
    glltabspace@GULL> @watch_stat
    
    6 行已合并。
    
    
    NAME                                                             KBYTES_WRITES DIFF_KBYTES_WRITES
    ---------------------------------------------------------------- ------------- ------------------
    physical reads direct temporary tablespace                                   0                  0
    physical writes direct temporary tablespace                                  0                  0
    session pga memory                                                        1185
    session pga memory max                                                    1185
    session uga memory                                                         370
    session uga memory max                                                     434
    
    已选择6行。
    
    #此时说明:现在的会话使用uga=370kb,最大值434kb,PGA=1185KB,最大值1185kb
    
    
    #会话1:按回车,继续执行表的排序
    glltabspace@GULL> set termout off
    glltabspace@GULL> prompt run @watch_stat in another session here!
    run @watch_stat in another session here!
    glltabspace@GULL> pause
    
    
    
    
    #会话2:
    glltabspace@GULL> @watch_stat
    
    6 行已合并。
    
    
    NAME                                                             KBYTES_WRITES DIFF_KBYTES_WRITES
    ---------------------------------------------------------------- ------------- ------------------
    physical reads direct temporary tablespace                                3181               3181
    physical writes direct temporary tablespace                               3181               3181
    session pga memory                                                         993               -192
    session pga memory max                                                    1249                 64
    session uga memory                                                         498                128
    session uga memory max                                                     562                128
    
    已选择6行。
    
    #说明:临时表空间的读取、写入比较大
    pga:993KB,最大值1249kb
    uga:498kb,最大值562kb
    
    排序区为64kb

    设置排序区为1MB(1048576)查看PGA,UGA

    NAME                                                             KBYTES_WRITES DIFF_KBYTES_WRITES
    ---------------------------------------------------------------- ------------- ------------------
    physical reads direct temporary tablespace                                1064               1064
    physical writes direct temporary tablespace                               1064               1064
    session pga memory                                                         801                  0
    session pga memory max                                                    2209                  0
    session uga memory                                                         370                  0
    session uga memory max                                                    1344                  0
    
    已选择6行。
    
    排序区1MB

    发现此时的临时表空间的I/O次数有所下降

    设置排序区为1G(1073741820)查看PGA,UGA

    NAME                                                             KBYTES_WRITES DIFF_KBYTES_WRITES
    ---------------------------------------------------------------- ------------- ------------------
    physical reads direct temporary tablespace                                   0                  0
    physical writes direct temporary tablespace                                  0                  0
    session pga memory                                                         737                  0
    session pga memory max                                                   10849              10112
    session uga memory                                                         306                  0
    session uga memory max                                                   10282               9977
    排序区1G

    当排序区为1g,实际的uga的大小使用10mb,此时的临时表空间I/O数为0,说明排序区的内存不是一开始就分配,需要多少分配多少,但不会超过sort_area_size的大小

  • 相关阅读:
    指针和引用作为函数参数传递
    cv::Mat.type()
    Matlab 双目标定工具箱
    invalid conversion from `const void*' to `void*'
    error: 'vector' is not a member of cv
    单例模式与静态成员
    RGBD SLAM V2 +Ubuntu 16.04+ROS KINETIC配置及运行
    EntityFrameworkCore + MySQL 主从复制应用读写分离
    Docker 搭建 MySQL8.0 主从复制环境
    Asp.Net Core 项目中使用 Serilog 输出日志到 Elasticsearch
  • 原文地址:https://www.cnblogs.com/gull/p/5496507.html
Copyright © 2011-2022 走看看