深抠参数sga_target

    在网上经常看见一些对sga_max_size和sga_target的对比、分析,总感觉很复杂,看了反而感觉头脑混沌、不分伯仲。

在此,我也抠一下sga,顿时感觉清爽许多。

先看定义:

SGA_MAX_SIZE specifies the maximum size of the SGA for the lifetime of the instance.

SGA_TARGET specifies the total size of all SGA components. If SGA_TARGET is specified, then the following memory pools are automatically sized:

  • Buffer cache (DB_CACHE_SIZE)

  • Shared pool (SHARED_POOL_SIZE)

  • Large pool (LARGE_POOL_SIZE)

  • Java pool (JAVA_POOL_SIZE)

If these automatically tuned memory pools are set to non-zero values, then those values are used as minimum levels by Automatic Shared Memory Management. You would set minimum values if an application component needs a minimum amount of memory to function properly.

The following pools are manually sized components and are not affected by Automatic Shared Memory Management:

  • Log buffer

  • Other buffer caches, such as KEEP, RECYCLE, and other block sizes

  • Streams pool

  • Fixed SGA and other internal allocations

The memory allocated to these pools is deducted from the total available for SGA_TARGET when Automatic Shared Memory Management computes the values of the automatically tuned memory pools.

由此可见:

        sga_max_size指定了实例一生中可以使用的sga的最大值。(也就是说实例只要不死,就只能用这么多内存。想增加?那不好意思,死一次吧,重启实例)

        sga_target指定了所有sga组件的总大小。其实也是sga的最大值,只不过不是一生中最大值,而是当前可使用的sga的最大值。因为sga_target是可以动态修改的,你随时可以调大调小,但是不可能超过sga_max_size,除非又死掉一次(重启))。

        也就是说当sga_target<sga_max_size的时候,是sga_target控制sga的大小。

        这也就解决了很多人对于sga_target设定大小的纠结,在我看来,很简单,sga_target 应该甚至必须等于sga_max_size,只有这样你所设定的内存大小才能被充分利用。

        人家官方文档写的很严谨,一切奥秘尽在lifetime一个单词而已。

另外,t欢迎大家对sga_targe的设定问题提出疑问,以免小生我被一叶障目啊

################################################################################################

下面佐证一下:

SQL> show sga

Total System Global Area  209715200 bytes
Fixed Size                  1218580 bytes
Variable Size             130025452 bytes
Database Buffers           71303168 bytes
Redo Buffers                7168000 bytes
SQL> show parameter sga;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
lock_sga                             boolean     FALSE
pre_page_sga                         boolean     FALSE
sga_max_size                         big integer 200M
sga_target                           big integer 200M
 
SQL> select sum(bytes) from v$sgastat;

SUM(BYTES)
----------
 209717864
SQL> select sum(bytes) ,pool from v$sgastat group by pool;  

SUM(BYTES) POOL
---------- ------------
  79689748
   4194304 java pool
 121639508 shared pool
   4194304 large pool

SQL> select * from v$sgastat where pool is null;  

POOL         NAME                            BYTES
------------ -------------------------- ----------
             fixed_sga                     1218580
             buffer_cache                 71303168
             log_buffer                    7168000

下面我把sga_target调成150M:

SQL> alter system set sga_target=150m;

系统已更改。

SQL> select sum(bytes) from v$sgastat;

SUM(BYTES)
----------
 159386216 SQL> select sum(bytes) ,pool from v$sgastat group by pool;   SUM(BYTES) POOL ---------- ------------   29358100    4194304 java pool  121639508 shared pool    4194304 large pool SQL> select * from v$sgastat where pool is null;   POOL         NAME                            BYTES ------------ -------------------------- ----------              fixed_sga                     1218580              buffer_cache                 20971520              log_buffer                    7168000

很明显buffer_cache跟着减少了50M,由原来的71303168减小为20971520。

根据引用\[1\],SGA_TARGET是Oracle数据库中的一个参数,用于指定系统全局区(SGA)的目标大小。如果在查询SGA_TARGET时遇到ORA-00821错误,表示指定的值太小,需要至少为5504M。要查询SGA_TARGET的值,可以通过查看Oracle安装目录下的参数文件来获取。参数文件的路径为$ORACLE_HOME/dbs,文件名格式为init+数据库实例名+.ora。可以使用命令"echo $ORACLE_HOME"来查看Oracle安装目录。如果参数文件丢失,可以参考Linux下Oracle数据库参数文件丢失解决方法。通过使用vim编辑器打开参数文件,可以查看其中的值。根据引用\[2\]和\[3\],可以使用ALTER SYSTEM SET语句来修改SGA_MAX_SIZE参数的值。例如,可以使用以下命令将SGA_MAX_SIZE设置为6442450944: ALTER SYSTEM SET sga_max_size = 6442450944 COMMENT='internally adjusted' SCOPE=SPFILE SID='INTOPAY'; 请注意,修改参数后需要重启数据库才能生效。 #### 引用[.reference_title] - *1* [Oracle 数据库修改配置文件sga_target参数的值,sga_target值太小导致数据库服务起不来问题解决,调大sga_...](https://blog.youkuaiyun.com/qq_38161040/article/details/118801809)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Oracle 11g sga_target 参数设置](https://blog.youkuaiyun.com/weixin_39643679/article/details/116418724)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

起个名字为啥那么难

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值