Oracle体系结构及备份(五)sga
一 什么是SGA(参考 Oracle内存结构--SGA) SGA 是一组为系统分配的共享的内存结构,可以包含一个数据库实例的数据或控制信息。如果多个用户连接到同一个数据库实例,在实例的 SGA 中,数据可以被多个用户共享。当数据库实例启动时, SGA 的内存被自动分配;
一 什么是SGA(参考 Oracle内存结构--SGA)
SGA是一组为系统分配的共享的内存结构,可以包含一个数据库实例的数据或控制信息。如果多个用户连接到同一个数据库实例,在实例的SGA中,数据可以被多个用户共享。当数据库实例启动时,SGA的内存被自动分配;当数据库实例关闭时,SGA内存被回收。 SGA是占用内存最大的一个区域,同时也是影响数据库性能的重要因素。
SGA区是可读写的。所有登录到实例的用户都能读取SGA中的信息,而在oracle做执行操作时,服务进程会将修改的信息写入SGA区。
SGA主要包括了以下的数据结构:
数据缓冲(Buffer Cache)
重做日志缓冲(Redo Log Buffer)
共享池(Shared Pool)
Java池(Java Pool)
大池(Large Pool)
流池(Streams Pool --- 10g以后才有)
数据字典缓存(Data Dictionary Cache)
其他信息(如数据库和实例的状态信息)
The SGA is the Oracle structure that is located in shared memory. It contains static data structures, locks, and data buffers. Sufficient shared memory must be available to each Oracle process to address the entire SGA.
The maximum size of a single shared memory segment is specified by the shmmax kernel parameter.
The following table shows the recommended value for this parameter, depending on the platform:
If the size of the SGA exceeds the maximum size of a shared memory segment (shmmax or shm_max), then Oracle Database attempts to attach more contiguous segments to fulfill the requested SGA size. The shmseg kernel parameter specifies the maximum number of segments that can be attached by any process. Set the following initialization parameters to control the size of the SGA:
DB_CACHE_SIZE
DB_BLOCK_SIZE
JAVA_POOL_SIZE
LARGE_POOL_SIZE
LOG_BUFFERS
SHARED_POOL_SIZE
Alternatively, set the SGA_TARGET initialization parameter to enable automatic tuning of the SGA size.
Use caution when setting values for these parameters. When values are set too high, too much of the physical memory is devoted to shared memory. This results in poor performance.
An Oracle Database configured with Shared Server requires a higher setting for the SHARED_POOL_SIZE initialization parameter, or a custom configuration that uses the LARGE_POOL_SIZE initialization parameter. If you installed the database with Oracle Universal Installer, then the value of the SHARED_POOL_SIZE parameter is set automatically by Oracle Database Configuration Assistant. However, if you created a database manually, then increase the value of the SHARED_POOL_SIZE parameter in the parameter file by 1 KB for each concurrent user.
二 内存管理方式
Oracle 8i:手动 PGA管理
Oracle 9i:自动PGA内存管理、手工共享内存管理
Oracle 10g:自动共享内存管理
Oracle 11g:自动内存管理
三 SGA的分配
SGA的管理又三种方式
8i:SGA的总大小由所有内存组件大小之和决定,不能直接定义SGA大小。对内部组件大小的修改必须在数据库重启后才能生效,所以叫SGA的静态管理。
9i:SGA总大小由初始化参数SGA_MAX_SIZE确定,各个内存最贱大小之和不能超过这个参数,在这个大小之下,SGA各个内存组件可以在不重启数据库的情况下直接修改大小,所以叫做SGA的动态管理。
10g:SGA大小既可以像9i一样动态管理,也可以实施SGA的自动管理,只需要设置初始化参数SGA_TARGET,SGA各个内存组件就可以由数据库自动设置大小,设置的数据来源于系统自动收集的统计信息。在9i以后,SGA的内部组件大小可以动态调整,也可以由数据库自动管理,在设置内存大小的时候,分配的基本单位是粒度(granule).Granule是一段连续的虚拟内存,大小取决于SGA_MAX_SIZE的大小,如果SGA_MAX_SIZE小于128M,Granule为4M,否则Granule为16M。各个内存组件分配大小必须是Granule的整倍数。整个SGA最小不小于3个Granule大小。
9i中的规则如下
Linux/Unix
SGA
SGA > 128M granule 16M
Windows
SGA
SGA > 128M granule 8M
10G中的分配规则为
Linux/Unix/Windows
SGA 为4M,否则为16M
SGA的各个组件大小是可以动态调整的,总大小不超过参数SGA_MAX_SIZE或者SGA_TARGET的大小。
四 操作示例
SQL> SELECT name, bytes/1024/1024 MB, resizeable from v$sgainfo; NAME MB RES -------------------------------- ---------- --- Granule Size 4 No -------------------------------- ---------- --- SQL> show parameter sga_max_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ sga_max_size big integer 160M SQL> ALTER SYSTEM SET sga_max_size=1025m scope=spfile; System altered. SQL> startup force; ORACLE instance started. Total System Global Area 1090519040 bytes Fixed Size 1218944 bytes Variable Size 1056966272 bytes Database Buffers 16777216 bytes Redo Buffers 15556608 bytes Database mounted. Database opened. SQL> show parameter sga_max_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ sga_max_size big integer 1040M --因各个内存组件分配大小必须是Granule的整倍数,右1025隔1040最近,所以此处为1040M。 SQL> SELECT name, bytes/1024/1024 MB, resizeable from v$sgainfo; NAME MB RES -------------------------------- ---------- --- Granule Size 16 No -------------------------------- ---------- --- SQL> desc v$sgainfo; Name Null? Type ----------------------------------------- -------- ---------------------------- NAME VARCHAR2(32) BYTES NUMBER RESIZEABLE VARCHAR2(3) SQL> select * from v$sgainfo; NAME BYTES RES -------------------------------- ---------- --- Fixed SGA Size 1218316 No Redo Buffers 2973696 No Buffer Cache Size 92274688 Yes Shared Pool Size 62914560 Yes Large Pool Size 4194304 Yes Java Pool Size 4194304 Yes Streams Pool Size 0 Yes Granule Size 4194304 No Maximum SGA Size 167772160 No Startup overhead in Shared Pool 37748736 No Free SGA Memory Available 0 11 rows selected. SQL> SELECT name, bytes/1024/1024 MB, resizeable from v$sgainfo; NAME MB RES -------------------------------- ---------- --- Fixed SGA Size 1.16187668 No Redo Buffers 2.8359375 No Buffer Cache Size 88 Yes Shared Pool Size 60 Yes Large Pool Size 4 Yes Java Pool Size 4 Yes Streams Pool Size 0 Yes Granule Size 4 No Maximum SGA Size 160 No Startup overhead in Shared Pool 36 No Free SGA Memory Available 0 11 rows selected. SQL> show parameter sga_max_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ sga_max_size big integer 160M SQL> ALTER SYSTEM SET sga_max_size=1025m scope=spfile; System altered. SQL> startup force; ORACLE instance started. Total System Global Area 1090519040 bytes Fixed Size 1218944 bytes Variable Size 1056966272 bytes Database Buffers 16777216 bytes Redo Buffers 15556608 bytes Database mounted. Database opened. SQL> show parameter sga_max_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ sga_max_size big integer 1040M SQL> SELECT name, bytes/1024/1024 MB, resizeable from v$sgainfo; NAME MB RES -------------------------------- ---------- --- Fixed SGA Size 1.16247559 No Redo Buffers 14.8359375 No Buffer Cache Size 16 Yes Shared Pool Size 96 Yes Large Pool Size 16 Yes Java Pool Size 16 Yes Streams Pool Size 0 Yes Granule Size 16 No Maximum SGA Size 1040 No Startup overhead in Shared Pool 32 No Free SGA Memory Available 880 11 rows selected. SQL> show parameter shared_p; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ shared_pool_reserved_size big integer 4M shared_pool_size big integer 0 SQL> ALTER SYSTEM SET shared_pool_size=10m; System altered. SQL> ALTER SYSTEM SET sga_max_size=800m scope=spfile; System altered. SQL> startup force; ORACLE instance started. Total System Global Area 838860800 bytes Fixed Size 1222192 bytes Variable Size 734005712 bytes Database Buffers 100663296 bytes Redo Buffers 2969600 bytes Database mounted. Database opened. SQL> ALTER SYSTEM set shared_pool_size=10m; System altered. SQL> show parameter shared_p; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ shared_pool_reserved_size big integer 838860 shared_pool_size big integer 12M SQL> show parameter sga_max_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ sga_max_size big integer 800M SQL> show parameter sga_target; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ sga_target big integer 160M SQL> show parameter shared_pool_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ shared_pool_size big integer 12M SQL> show parameter large_pool_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ large_pool_size big integer 0 SQL> show parameter java_pool_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ java_pool_size big integer 0 SQL> show parameter streams_pool_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ streams_pool_size big integer 0 SQL> show parameter db_cache_size; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_cache_size big integer 0 SQL> show parameter sga_target; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ sga_target big integer 160M SQL>
五 总结
1. SGA是一组为系统分配的共享的内存结构,可以包含一个数据库实例的数据或控制信息。
2. SGA主要包括了以下的数据结构:数据缓冲(Buffer Cache)、重做日志缓冲(Redo Log Buffer)、共享池(Shared Pool)、Java池(Java Pool)、大池(Large Pool)、流池(Streams Pool --- 10g以后才有)、数据字典缓存(Data Dictionary Cache)、其他信息(如数据库和实例的状态信息);
3.可以通过v$sgainfo视图查看sga相关信息。
我的邮箱:wgbno27@163.com 新浪微博:@Wentasy27 微信公众平台:JustOracle(微信号:justoracle) IT交流群:336882565(加群时验证 From CSDN XXX) Oracle交流讨论组:https://groups.google.com/d/forum/justoracle By Larry Wen
@Wentasy |