ORACLE ASMM与AMM的下结论

 

前者安全之XSS

转载请表明出处:unclekeith:
前者安全之XSS

概念比较介绍

XSS定义

XSS, 即为(Cross Site Scripting), 中文名为跨站脚本,
是发出在对象用户的浏览器范围上的,当渲染DOM树的历程成发生了不在预期内执行的JS代码时,就暴发了XSS攻击。

跨站脚本的显要不在‘跨站’上,而介于‘脚本’上。半数以上XSS攻击的首要方法是置于一段远程或者第三方域上的JS代码。实际上是在目的网站的效能域下执行了那段js代码。

 

XSS攻击格局

反射型 XSS

反射型XSS,也叫非持久型XSS,是指暴发请求时,XSS代码出现在伸手URL中,作为参数提交到服务器,服务器解析并响应。响应结果中包蕴XSS代码,最终浏览器解析并施行。

从概念上得以见到,反射型XSS代码是首先出现在URL中的,然后急需服务端解析,最后亟待浏览器解析之后XSS代码才可以攻击。

举一个小栗子。

使用express起一个web服务器,然后设置一下伸手接口。通过ajax的GET请求将参数发往服务器,服务器解析成json后响应。将回到的数据解析后显获得页面上。(没有对回到的数量开展解码和过滤等操作。)

html
<textarea name="txt" id="txt" cols="80" rows="10">
<button type="button" id="test">测试</button>

js
var test = document.querySelector('#test')
test.addEventListener('click', function () {
  var url = `/test?test=${txt.value}`   // 1. 发送一个GET请求
  var xhr = new XMLHttpRequest()
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) {
      if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
        // 3. 客户端解析JSON,并执行
        var str = JSON.parse(xhr.responseText).test
        var node = `${str}`
        document.body.insertAdjacentHTML('beforeend', node)
      } else {
        console.log('error', xhr.responseText)
      }
    }
  }
  xhr.open('GET', url, true)
  xhr.send(null)
}, false)

express
var express = require('express');
var router = express.Router();

router.get('/test', function (req, res, next) {
 // 2. 服务端解析成JSON后响应
  res.json({
    test: req.query.test
  })
})

当今我们通过给textarea添加一段有攻击目的的img标签,

<img src="null" onerror='alert(document.cookie)' />

实在的页面时如此的。
图片 1
ok现在,大家点击<测试>按钮,一个XSS攻击就时有爆发了。下边图片中是获得了本地的部分cookie消息
图片 2
实际上,大家只是模仿攻击,通过alert获取到了民用的cookie消息。然则倘借使黑客来说,他们会注入一段第三方的js代码,然后将获取到的cookie音讯存到他们的服务器上。那样的话黑客们就有机会获得大家的身价申明做一些非法的业务了。

如上,存在的一些难题,首要在于没有对用户输入的音信举行过滤,同时没有去除掉DOM节点中留存的有的有危机的轩然大波和一部分有损伤的DOM节点。

存储型 XSS
存储型XSS,也叫持久型XSS,主要是将XSS代码发送到服务器(不管是数据库、内存如故文件系统等。),然后在下次央浼页面的时候就不用带上XSS代码了。

最杰出的就是留言板XSS。用户提交了一条包含XSS代码的留言到数据库。当对象用户查询留言时,那个留言的情节会从服务器解析之后加载出来。浏览器发现有XSS代码,就作为正常的HTML和JS解析执行。XSS攻击就爆发了。
DOM XSS
DOM XSS攻击不一致于反射型XSS和存储型XSS,DOM
XSS代码不需求服务器端的分析响应的直接参预,而是经过浏览器端的DOM解析。那全然是客户端的事体。

DOM
XSS代码的攻击暴发的也许在于我们编辑JS代码造成的。大家领略eval语句有一个效应是将一段字符串转换为实在的JS语句,因而在JS中利用eval是很凶险的工作,简单造成XSS攻击。幸免使用eval语句。

如以下代码

test.addEventListener('click', function () {
  var node = window.eval(txt.value)
  window.alert(node)
}, false)

txt中的代码如下
<img src='null' onerror='alert(123)' />

如上通过eval语句就招致了XSS攻击。

深信有些人会对ORACLE当中的AMM(Automatic
Memory Management)与ASMM(Automatic Shared Memory
Management)有些迷惑或歪曲,不清楚两者的异同,本文种从多少个方面来总括一下两岸的异同。如有不足或疏漏之处,敬请指正!

XSS危害

  1. 通过document.cookie盗取cookie
  2. 利用js或css破坏页面正常的布局与体制
  3. 流量威胁(通过走访某段具有window.location.href定位到其余页面)
  4. Dos攻击:利用合理的客户端请求来据为己有过多的服务器资源,从而使合法用户不能获取服务器响应。
  5. 行使iframe、frame、XMLHttpRequest或上述Flash等艺术,以(被口诛笔伐)用户的身份实施一些管制动作,或举办一些相似的如发腾讯网、加好友、发私信等操作。
  6. 运用可被攻击的域受到其他域信任的性状,以受依赖来源的身价呼吁一些平日不容许的操作,如举行不当的投票活动。

 

XSS防御

从上述的反射型和DOM
XSS攻击可以看看,我们不可以长相的将用户输入的数量直接存到服务器,要求对数据举办部分拍卖。以上的代码出现的一些标题如下

  1. 从然则滤危险的DOM节点。如享有实践脚本能力的script,
    具有显示广告和色情图片的img, 具有改变样式的link, style,
    具有内嵌页面的iframe, frame等元素节点。
  2. 平素不过滤危险的质量节点。如事件, style, src, href等
  3. 没有对cookie设置httpOnly。

一经将以上三点都在渲染进程中过滤,那么出现的XSS攻击的几率也就小很多。

缓解情势如下

对cookie的保护

  1. 对主要的cookie设置httpOnly,
    避免客户端通过document.cookie读取cookie。服务端可以安装此字段。

对用户输入数据的拍卖

  1. 编码:无法对用户输入的内容都维持原样,对用户输入的数目举行字符实体编码。对于字符实体的概念可以参考小说尾部给出的参阅链接。
  2. 解码:原样突显内容的时候必须解码,不然突显不到情节了。
  3. 过滤:把输入的局地不合规的东西都过滤掉,从而有限帮忙安全性。如移除用户上传的DOM属性,如onerror,移除用户上传的Style节点,iframe,
    script节点等。

通过一个事例讲解一下怎么处理用户输入的数码。

心想事成原理如下:

  1. 留存一个parse函数,对输入的数量进行拍卖,重临处理将来的数目
  2. 对输入的数额(如DOM节点)进行解码(使用第三方库 he.js)
  3. 过滤掉一部分要素有损害的要素节点与特性节点。如script标签,onerror事件等。(使用第三方库HTMLParser.js)

<script src='/javascripts/htmlparse.js'></script>
<script src='/javascripts/he.js'></script>
// 第三方库资源在文章底部给出

// parse函数实现如下

function parse (str) {
      // str假如为某个DOM字符串
      // 1. result为处理之后的DOM节点
      let result = ''
      // 2. 解码
      let decode = he.unescape(str, {
          strict: true
      })
      HTMLParser(decode, {
          start (tag, attrs, unary) {
              // 3. 过滤常见危险的标签
              if (tag === 'script' || tag === 'img' || tag === 'link' || tag === 'style' || tag === 'iframe' || tag === 'frame') return
              result += `<${tag}`
              for (let i = 0; i < attrs.length; i++) {
                  let name = (attrs[i].name).toLowerCase()
                  let value = attrs[i].escaped
                  // 3. 过滤掉危险的style属性和js事件
                  if (name === 'style' || name === 'href' || name === 'src' || ~name.indexOf('on')) continue
                  result += ` ${name}=${value}`
              }
              result += `${unary ? ' /' : ''} >`
          },
          chars (text) {
              result += text
          },
          comment (text) {
              result += `<!-- ${text} -->`
          },
          end (tag) {
              result += `</${tag}>`
          }
      })
      return result
  }

故而,有了以上的parse函数之后,就足以避免半数以上的xss攻击了。

test.addEventListener('click', function () {
  // ... 省略部分代码
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) {
      if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
        // 3. 客户端解析JSON,并执行
        // test按钮的点击事件中唯一的变化就是使用parse对服务端返回的数据进行了解码和过滤的处理。
        var str = parse(JSON.parse(xhr.responseText).test)
        // 通过parse解析之后返回的数据就是安全的DOM字符串
        var node = `${str}`
        document.body.insertAdjacentHTML('beforeend', node)
      }
    }
  }
  // ... 省略部分代码
}, false)

那就是说,栗子说完了。

稍加总计一下

  1. 倘使在DOM解析进程成出现不在预期内的更动(JS代码执行或样式多量变化时),就可能暴发XSS攻击
  2. XSS分为反射型XSS,存储型XSS和DOM XSS
  3. 反射型XSS是在将XSS代码放在URL中,将参数提交到服务器。服务器解析后响应,在响应结果中存在XSS代码,最后通过浏览器解析执行。
  4. 存储型XSS是将XSS代码存储到服务端(数据库、内存、文件系统等),在下次呼吁同一个页面时就不需求带上XSS代码了,而是从服务器读取。
  5. DOM XSS的暴发重大是在JS中动用eval造成的,所以理应防止拔取eval语句。
  6. XSS危机有偷盗用户cookie,通过JS或CSS改变样式,DDos造成健康用户不可以获得服务器响应。
  7. XSS代码的防备重大通过对数码解码,再过滤掉危险标签、属性和事件等。

参考资源

  1. 《WEB前端黑客技术揭秘》
  2. 浅谈XSS攻击的这一个事(附常用绕过姿势)
  3. XSS实战:我是何等拿下你的百度账号
  4. HTMLParser
  5. he
  6. Web安全-XSS

从ORACLE揭橥的本子历史(时间轴)来看,ORACLE的内存管理的大体历程如下:

 

ORACLE  9i 
    
PGA自动管理,SGA手动管理

ORACLE
10g      PGA自动管理,SGA自动管理(ASMM,自动共享内存管理)

ORACLE
11g      PGA,SGA统一机动管理(AMM,自动内存管理)

ORACLE
12c      跟11g同等,没有变化

 

 

官方文档的牵线资料如下:

 

·        
Oracle
9i

 

·        
Beginning
with Oracle9i, the dynamic SGA infrastructure allowed for the sizing of
the Buffer Cache, Shared Pool and the Large Pool without having to shut
down the database. Key features being:

o   Dynamic
Memory resizing

o   DB_CACHE_SIZE
instead of DB_BLOCK_BUFFERS

o   DB_nK_CACHE_SIZE
for multiple block sizes

o   PGA_AGGREGATE_TARGET
Introduction of Automatic PGA Memory management

 

·        
Oracle
Database 10g

 

·        
Automatic
Shared Memory Management (ASMM) was introduced in 10g. You enable the
automatic shared memory management feature by setting the SGA_TARGET
parameter to a non-zero value.

 

·        
Oracle
Database 11g

 

·        
Automatic
Memory Management is being introduced in 11g. This enables automatic
tuning of PGA and SGA with use of two new parameters named
MEMORY_MAX_TARGET and MEMORY_TARGET

·        
Oracle
Database 12c

           
Automatic Memory Management keeps the same behaviour as in 11g.

 

 

自动共享内存管理(Automatic
Shared Memory Management ASMM)是ORACLE
10g初始引入的的新技巧,ASMM用来贯彻SGA的全自动管理。。当启用自动共享内存管理后,不再需求为各类内存组件设定值,当然假诺你设置SGA_TARGET的同时,设置了db_cache_size、shared_pool_size那么些参数,那么db_cache_size、shared_pool_size那一个参数值会作为最小值必要。官方关于Automatic
Shared Memory Management的介绍如下:

 

Automatic
Shared Memory Management

 

In
previous database releases, a database administrator (DBA) was required
to manually specify different SGA component sizes by setting a number of
initialization parameters, including the SHARED_POOL_SIZE,
DB_CACHE_SIZE, JAVA_POOL_SIZE, and LARGE_POOL_SIZE parameters.
Oracle Database 10g includes the Automatic Shared Memory Management
feature which simplifies the SGA memory management significantly. In
Oracle Database 10g, a DBA can simply specify the total amount of SGA
memory available to an instance using the SGA_TARGET initialization
parameter and the Oracle Database will automatically distribute this
memory among various subcomponents to ensure most effective memory
utilization.

 

When
automatic SGA memory management is enabled, the sizes of the different
SGA components are flexible and can adapt to the needs of a workload
without requiring any additional configuration. The database
automatically distributes the available memory among the various
components as required, allowing the system to maximize the use of all
available SGA memory.

 

ORACLE
10G本子伊始推出了ASMM,自动SGA管理,它的面世一定水平上支持DBA解决了管住SGA的题材,通过安装参数SGA_TARGET来控制ASMM,其中SGA_TARGET为零意味禁用ASMM,非零值表示启用ASMM。可是在10G
R1等中期版本,ASMM还不够成熟,而且存在比较多的BUG,导致了相比较多的难点。在ORACLE
10g R2后续版本中,ASMM才日渐完善并成熟。

 

到了11g过后,ORACLE又完毕了PGA和SGA的统一机动管理
,那一个称呼自动化内存管理(Automatic Memory
Management,AMM)。从那么些衍生和变化历程来看,ORACLE从最开头的手动配置种种零部件参数,渐渐逐步向智能化、傻瓜化、自动化的势头逐步前进。那个是一个一定的历史趋势。关于AMM的法定文档介绍如下:

 

About
Automatic Memory Management

 

The
simplest way to manage instance memory is to allow the Oracle Database
instance to automatically manage and tune it for you. To do so (on most
platforms), you set only a target memory size initialization parameter
(MEMORY_TARGET) and optionally a maximum memory size initialization
parameter (MEMORY_MAX_TARGET). The instance then tunes to the target
memory size, redistributing memory as needed between the system global
area (SGA) and the instance program global area (instance PGA). Because
the target memory initialization parameter is dynamic, you can change
the target memory size at any time without restarting the database. The
maximum memory size serves as an upper limit so that you cannot
accidentally set the target memory size too high, and so that enough
memory is set aside for the Oracle Database instance in case you do want
to increase total instance memory in the future. Because certain SGA
components either cannot easily shrink or must remain at a minimum size,
the instance also prevents you from setting the target memory size too
low.

 

If
you create your database with Database Configuration Assistant (DBCA)
and choose the basic installation option, automatic memory management is
enabled. If you choose advanced installation, Database Configuration
Assistant (DBCA) enables you to select automatic memory
management.

 

 

 

ORACLE
11g AMM 的引入, 组合出来有 5 种内存管理格局.

 

   
自动内存管理(AMM)   :
memory_target=非0,是电动内存管理,假诺开始化参数 LOCK_SGA=TRUE,则
AMM 是不可用的。

   
自动共享内存管理(ASMM): 在memory_target=0 and
sga_target为非0的情形下是机动内存管理

   
手工共享内存管理      : memory_target=0 and
sga_target=0 
指定
share_pool_size 、db_cache_size 等 sga 参数

    自动 PGA
管理         : memory_target=0 and
workarea_size_policy=auto 
and PGA_AGGREGATE_TARGET=值

    手动 PGA
管理         : memory_target=0 and
workarea_size_policy=manal 
然后指定 SORT_AREA_SIZE 等 PGA 参数,一般不采纳手动管理PGA。

 

 

Oracle
Database 11g

supports various memory management methods, which are chosen by
initialization parameter settings. Oracle recommends that you enable the
automatic memory management method.

 

 

  1. Automatic
    Memory Management – For Both the SGA and Instance PGA

  1. Automatic
    Shared Memory Management – For the SGA

  1. Manual
    Shared Memory Management – For the SGA

  1. Automatic
    PGA Memory Management –For the Instance PGA

  1. Manual
    PGA Memory Management – For the Instance PGA

 

 

 

 

 

ASMM切换到AMM

 

一般来说所示,当前实验环境下活动内存管理已被剥夺(memory_target=0)

 

SQL> select * from v$version;

 

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

PL/SQL Release 11.2.0.1.0 - Production

CORE    11.2.0.1.0      Production

TNS for Linux: Version 11.2.0.1.0 - Production

NLSRTL Version 11.2.0.1.0 - Production

 

SQL> show parameter memory_target ;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

memory_target                        big integer 0

SQL> show parameter memory_max_target;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

memory_max_target                    big integer 0

SQL> 

SQL> show parameter sga;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

lock_sga                             boolean     FALSE

pre_page_sga                         boolean     FALSE

sga_max_size                         big integer 1G

sga_target                           big integer 1G

 

 

在11g中,要是采用ASMM,对应的内存共享段是真心真意的共享段。

 

SQL> !

[oracle@DB-Server ~]$ ipcs -m

 

------ Shared Memory Segments --------

key        shmid      owner      perms      bytes      nattch     status      

0x00000000 4128770    root      644        80         2                       

0x00000000 4161540    root      644        16384      2                       

0x00000000 4194309    root      644        280        2                       

0xfc5d1940 7012369    oracle    660        1075838976 49     

 

 

正如所示,首先检查参数文件类型,然后修改参数sga_target、memory_max_target、memory_target。因为中间有些参数为静态参数,所以在修改参数后,需求重启数据库。

 

 

 

SQL> show parameter spfile;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

spfile                               string      /u01/app/oracle/product/11.1.0

                                                 /dbhome_1/dbs/spfilegsp.ora

SQL> alter system set sga_max_size=0 scope=spfile;

 

System altered.

 

SQL> alter system set sga_target=0 scope=spfile;

 

System altered.

 

SQL> alter system set pga_aggregate_target=0 scope=spfile;

 

 

SQL> alter system set memory_max_target=1G scope=spfile;

 

System altered.

 

SQL> alter system set memory_target=1G scope=spfile;

 

System altered.

 

SQL> 

 

重启数据库后,检核查应参数。

 

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

 

Total System Global Area  517816320 bytes

Fixed Size                  2214776 bytes

Variable Size             159384712 bytes

Database Buffers          348127232 bytes

Redo Buffers                8089600 bytes

Database mounted.

SQL> show parameter memory

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

hi_shared_memory_address             integer     0

memory_max_target                    big integer 1G

memory_target                        big integer 1G

shared_memory_address                integer     0

SQL> 

 

自行内存管理(AMM)启动将来,系统共享段变为“虚拟”共享段。

 

[oracle@DB-Server ~]$ ipcs -m

 

------ Shared Memory Segments --------

key        shmid      owner      perms      bytes      nattch     status      

0x00000000 4128770    root      644        80         2                       

0x00000000 4161540    root      644        16384      2                       

0x00000000 4194309    root      644        280        2                       

0xfc5d1940 7077905    oracle    660        4096       0            

 

 

 

 

 

11g
MEMORY_TARGET Parameter Dependency

 

这就是说有个疑问,自动内存管理(AMM)情势下边,sga_max_size、sga_target、memory_max_target、memory_target、pga_aggregate_target这多少个参数的关联是怎么的呢?其实官方文档已经有详实演说

 

If
MEMORY_TARGET is set to a non-zero value:

 

·        
If
SGA_TARGET and PGA_AGGREGATE_TARGET are set, they will be considered
the minimum values for the sizes of SGA and the PGA respectively.
MEMORY_TARGET values can range from SGA_TARGET +
PGA_AGGREGATE_TARGET to MEMORY_MAX_TARGET.

·        
If
SGA_TARGET is set and PGA_AGGREGATE_TARGET is not set, we will still
auto-tune both parameters. PGA_AGGREGATE_TARGET will be initialized to
a value of MEMORY_TARGET – SGA_TARGET.

·        
If
PGA_AGGREGATE_TARGET is set and SGA_TARGET is not set, we will still
auto-tune both parameters. SGA_TARGET will be initialized to the
minimum non-zero value of MEMORY_TARGET – PGA_AGGREGATE_TARGET and
SGA_MAX_SIZE and will auto tune its components.

·        
If
neither is set, they will be auto-tuned without any minimum or default
values. We will have a policy of distributing the total memory set by
MEMORY_TARGET parameter in a fixed ratio to the the SGA and PGA during
initialization. The policy is to give 60% to the SGA and 40% to the PGA
at startup.

 

If
MEMORY_MAX_TARGET has not been explicitly set, but MEMORY_TARGET has,
the instance automatically sets MEMORY_MAX_TARGET to the same value as
MEMORY_TARGET. If MEMORY_TARGET has not been explicitly set, but
MEMORY_MAX_TARGET has, then MEMORY_TARGET defaults to 0. After
instance startup, it then is possible to dynamically change
MEMORY_TARGET to a non-zero value, provided that it does not exceed the
value of MEMORY_MAX_TARGET.

 

If
MEMORY_TARGET is not set or set to set to 0 explicitly (default value
is 0 for 11g):

·        
If
SGA_TARGET is set we will only auto-tune the sizes of the components of
the SGA. PGA will be autotuned independent of whether it is explicitly
set or not. However, the combination of SGA and PGA will not be
auto-tuned, i.e. the SGA and PGA will not share memory and resize as
with the case of MEMORY_TARGET being set to a non-zero value.

·        
If
neither SGA_TARGET nor PGA_AGGREGATE_TARGET is set, we will follow
the same policy as we have today; PGA will be auto-tuned and the SGA
will not be auto-tuned and parameters for some of the SGA components
will have to be set explicitly (for SGA_TARGET).

·        
If
only MEMORY_MAX_TARGET is set, MEMORY_TARGET will default to 0 and we
will not auto tune the SGA and PGA. It will default to 10gR2
behavior.

·        
If
SGA_MAX_SIZE is not user set, it is internally set to
MEMORY_MAX_TARGET.

 

大家下边依旧通过试验一一验证一下:

 

1:当MEMORY_TARGET大于0的意况下,可以设置SGA_TARGET、PGA_AGGREGATE_TARGET的值为非0,对应的意思分别如下:

 

   
借使设置了SGA_TARGET和PGA_AGGREGATE_TARGET,它们各自表示SGA的的最小值和PGA的小小值。MEMORY_TARGET值的限量可以从SGA_TARGET

  • PGA_AGGREGATE_TARGET到MEMORY_MAX_TARGET。

    当然SGA_TARGET + PGA_AGGREGATE_TARGET的和必须低于等于memory_target,别的,如若同时安装了sga_target、pga_aggregate_target的值,memory_target的值必须高于等于sga_target与pga_aggregate_target之和。如下测试所示:

 

SQL> alter system set pga_aggregate_target=200m scope=both;

 

System altered.

 

SQL> show parameter pga_aggregate_target;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

pga_aggregate_target                 big integer 200M

SQL> 

 

 

SQL> show parameter sga;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

lock_sga                             boolean     FALSE

pre_page_sga                         boolean     FALSE

sga_max_size                         big integer 496M    #后面讲述为什么sga_max_size为什么没有被置为0

sga_target                           big integer 0

SQL> alter system set sga_target=400m scope=both;

 

System altered.

 

SQL> show parameter sga;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

lock_sga                             boolean     FALSE

pre_page_sga                         boolean     FALSE

sga_max_size                         big integer 496M

sga_target                           big integer 400M

SQL> 

图片 3

 

 

 

SQL> show parameter sga;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

lock_sga                             boolean     FALSE

pre_page_sga                         boolean     FALSE

sga_max_size                         big integer 496M

sga_target                           big integer 400M

SQL> show parameter pga_aggregate_target;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

pga_aggregate_target                 big integer 200M

SQL> alter system set memory_target=696m scope=both;

 

System altered.

 

SQL> alter system set memory_target=600m scope=both;

 

System altered.

 

SQL> alter system set memroy_target=500m scope=both;

alter system set memroy_target=500m scope=both

                 *

ERROR at line 1:

ORA-02065: illegal option for ALTER SYSTEM

 

 

SQL>  alter system set memory_target=500m scope=both;

 alter system set memory_target=500m scope=both

*

ERROR at line 1:

ORA-02097: parameter cannot be modified because specified value is invalid

ORA-00838: Specified value of MEMORY_TARGET is too small, needs to be at least 600M

 

图片 4

 

 

SQL> show parameter memory_target;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

memory_target                        big integer 600M

SQL> show parameter sga;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

lock_sga                             boolean     FALSE

pre_page_sga                         boolean     FALSE

sga_max_size                         big integer 496M

sga_target                           big integer 400M

SQL> show parameter pga

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

pga_aggregate_target                 big integer 200M

SQL> 

SQL> 

SQL> alter system set pga_aggregate_target=201m scope=both;

alter system set pga_aggregate_target=300m scope=both

*

ERROR at line 1:

ORA-02097: parameter cannot be modified because specified value is invalid

ORA-00840: PGA_AGGREGATE_TARGET cannot be modified to the specified value

 

如上测试所示,如若设置了pga_aggregate_target和sga_target,那么pga_aggregate_target

  • sga_target
    必须低于等于memory_target,另外,memory_target也不可能不大于等于(pga_aggregate_target
  • sga_target)

 

假设设置了SGA_TARGET并且PGA_AGGREGATE_TARGET没有安装,数据库如故会自动调整那多少个参数。
PGA_AGGREGATE_TARGET将被早先化为MEMORY_TARGET –
SGA_TARGET的值。

若果设置了PGA_AGGREGATE_TARGET并且没有安装SGA_TARGET,数据库依旧会活动调整那四个参数。
SGA_TARGET将被初步化为MEMORY_TARGET –
PGA_AGGREGATE_TARGET,并在这一个值和SGA_MAX_SIZE那些间隔范围内电动调整

如果SGA_TARGET和PGA_AGGREGATE_TARGET两者都并未设置的话,则它们将被自动调谐而没有其余最小值或默许值。 大家将有一个策略,在初叶化进程中,将由MEMORY_TARGET参数设置的总内存以固定的比例分配给SGA和PGA。 政策是在启动时给予SGA
60%和PGA 40%给PGA。

 

 

2:
没有安装SGA_MAX_SIZE,可是为何SGA_MAX_SIZE一向有值,即使将其安装为0或利用reset
alter system set sga_max_size=0 scope=spfile; SGA_MAX_SIZE向来有值。官方关于SGA_MAX_SIZE的介绍如下:

 

 

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

On
64-bit platforms and non-Windows 32-bit platforms, when either
MEMORY_TARGET or MEMORY_MAX_TARGET is specified, the default value of
SGA_MAX_SIZE is set to the larger of the two parameters. This causes
more address space to be reserved for expansion of the SGA.

On
Windows 32-bit platforms, the default value of SGA_MAX_SIZE is the
largest of the following values:

·        
 

·        
60%
of MEMORY_TARGET, if specified

·        
 

·        
60%
of MEMORY_MAX_TARGET, if specified

·        
 

·        
25%
of the total available virtual address space

 

也就是说在64位平台和非Windows 32位平台上,当指定MEMORY_TARGET或MEMORY_MAX_TARGET时,SGA_MAX_SIZE的默认值将设置为两个参数中较大的一个。 这导致更多的地址空间被保留用于SGA的扩展。

这也是之前一直让我迷惑的地方。另外,官方文档建议:当切换到AMM,即使用MEMORY_TARGET时,不应该设置参数SGA_MAX_SIZE(用于ASMM),因为这样做会修复SGA的大

小,因此与MEMORY_TARGET的预期用法相冲突。(原文:Check also for SGA_MAX_SIZE being set. When switching to AMM, i.e. using MEMORY_TARGET,

the parameter SGA_MAX_SIZE (used for ASMM) should not be set as doing so fixes the size of the SGA, and hence conflicts

with the intended use of MEMORY_TARGET.)

 

 

图片 5

 

   

SGA_MAX_SIZE的值最好不要去修改,即使其值超越MEMORY_MAX_TARGET的话,就报ORA-00844 & ORA-00851
错误。如下所示

 

SQL> alter system set sga_max_size=1025M scope=spfile;

 

System altered.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORA-00844: Parameter not taking MEMORY_TARGET into account

ORA-00851: SGA_MAX_SIZE 1090519040 cannot be set to more than MEMORY_TARGET 637534208.

SQL> 

 

 

此时内需转变对应spfile的pfile文件,然后找到*.sga_max_size那一个值,删除后重新生成对应的spfile,启动数据库实例即可,当然你也得以设置其值超出MEMORY_TARGET即可。

 

 

AMM切换到ASMM

 

SQL> show parameter target;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

archive_lag_target                   integer     0

db_flashback_retention_target        integer     1440

fast_start_io_target                 integer     0

fast_start_mttr_target               integer     0

memory_max_target                    big integer 1552M

memory_target                        big integer 1552M

parallel_servers_target              integer     16

pga_aggregate_target                 big integer 0

sga_target                           big integer 0

SQL> alter system set memory_max_target=0 scope=spfile;

 

System altered.

 

SQL> alter system set memory_target=0 scope=spfile;

 

System altered.

 

SQL> alter system set pga_aggregate_target=200m scope=spfile;

 

System altered.

 

SQL> alter system set sga_max_size=1g scope=spfile;

 

System altered.

 

SQL> alter system set sga_target=1g scope=spfile;

 

System altered.

 

SQL> 

 

 

SQL> startup

ORA-00843: Parameter not taking MEMORY_MAX_TARGET into account

ORA-00849: SGA_TARGET 1073741824 cannot be set to more than MEMORY_MAX_TARGET 0.

SQL> 

 

转移对应的spfile的pfile文件,然后删除memory_max_target和memory_target多少个参数后,然后生成对应的spfile,最后重启数据库实例即可。

 

SQL>
create pfile from spfile;

 

File
created.

 

 

*.memory_max_target=0

*.memory_target=0

 

SQL>
create spfile from pfile;

 

File
created.

 

SQL>

 

 

选择AMM还是HugePages

 

ORACLE
11g始发推出AMM,它是ORACLE在ASMM的基本功上的更加内存管理自动化的多变。ASMM是机动管理SGA,而AMM则是将SGA与PGA联合起来活动管理、调整。只须求设置memory_target一个参数就可以已毕总体数据库实例内存的配置。不过这几个功用没被大规模运用,因为AMM最大的标题在于无法选取正式大页。有时候为了利用规范大页功效,可能有点系统会禁用AMM.那么到底是用AMM依旧利用大页呢?很多个人(大师)倾向使用大页作用而非AMM,关于那几个可以参见下边博文

 

MEMORY_TARGET (SGA_TARGET) or HugePages – which to
choose?

AMM and Linux Huge
Pages

Oracle Memory Management and
HugePage

 

 

如何从AMM切换来HugePage,可以参照官方文档(ID
2128928.1)

 

How
To Convert A Database Using AMM (Automatic Memory Management) To A
Database That Has Been Configured With Hugepage

 

 

参考资料:

 

http://blog.ronnyegner-consulting.de/2010/03/31/memory_target-sga_target-or-hugepages-which-to-choose/

https://docs.oracle.com/cd/E18283_01/server.112/e17110/initparams230.htm

http://www.dba-oracle.com/t_amm_automatic_memory.htm

https://docs.oracle.com/cd/B28359\_01/server.111/b28310/memory003.htm\#ADMIN11011

https://www.jianshu.com/p/9715280a4ced

http://oracle-help.com/oracle-database/relationship-memory\_target-sga\_target-pga\_aggregate\_target/

https://support.oracle.com/epmos/faces/DocumentDisplay?\_afrLoop=275836827924018&id=443746.1&\_afrWindowMode=0&\_adf.ctrl-state=149nyur949\_198

Post Author: admin

发表评论

电子邮件地址不会被公开。 必填项已用*标注