instance结构详解
1、
内存结构
主要包括sga(system
global area)和pga(program
global area)
Pga是当程序起来时,给server
process用(排序,数据挖掘等order by)
SGA(System Global Area)由一组内存结构组成,它是由所有用户进程共享的一块内存区域。启动例程时,Oracle自动分配SGA,关闭例程时,oracle自动释放SGA所占用的内存空间。
Sga包括,share
pool,db
buffer cache,redo
log buffer,large
pool,java
pool。
在9i
中我们都知道在管理Oracle中使用动态SGA时,Granule(是连续虚拟内存分配的单位)的大小是和SGA的大小有关系。
SGA 分配的最小单元为一个granule.Oracle SGA的大小总是granule的整数倍,即分配是以整数个granule来分配的。
9i 中的规则如下:
linux/unix
SGA <=128
M granule 4M
SGA
>128M granule 16M
Windows
SGA <=128 M
granule 4M
SGA
>128M granule 8M
10g 中的分配规则为
linux/unix
SGA <=1G granule 4M
SGA
>1G granule 16M
Windows
SGA <=1G granule 4M
SGA
>1G granule 8M
SQL> select component,
granule_size from v$sga_dynamic_components;
COMPONENT GRANULE_SIZE
----------------------------------------------------------------
------------
shared
pool 4194304
large
pool 4194304
java
pool 4194304
streams
pool 4194304
DEFAULT buffer
cache 4194304
KEEP buffer
cache 4194304
RECYCLE buffer
cache 4194304
DEFAULT 2K buffer
cache 4194304
DEFAULT 4K buffer
cache 4194304
DEFAULT 8K buffer
cache 4194304
DEFAULT 16K buffer
cache 4194304
DEFAULT 32K buffer
cache 4194304
ASM Buffer
Cache 4194304
13 rows selected.
Elapsed: 00:00:00.06
SQL>
SQL>desc
v$sga_dynamic_components;
Name Type
--------------------------------------------------------
COMPONENT VARCHAR2(64)
CURRENT_SIZE NUMBER
MIN_SIZE NUMBER
MAX_SIZE NUMBER
USER_SPECIFIED_SIZE NUMBER
OPER_COUNT NUMBER
LAST_OPER_TYPE VARCHAR2(13)
LAST_OPER_MODE VARCHAR2(9)
LAST_OPER_TIME DATE
GRANULE_SIZE NUMBER
SQL>
SQL> select *
from v$sga_dynamic_components;
COMPONENT CURRENT_SIZE MIN_SIZE MAX_SIZE
USER_SPECIFIED_SIZE OPER_COUNT LAST_OPER_TYP LAST_OPER LAST_OPER
GRANULE_SIZE
-------------------- ------------ ---------- ----------
------------------- ---------- ------------- --------- ---------
------------
shared
pool 92274688 92274688 0 0 0
STATIC 4194304
large pool 4194304 4194304 0 0 0
STATIC 4194304
java
pool 4194304 4194304 0 0 0
STATIC 4194304
streams
pool 0 0 0 0 0
STATIC 4194304
DEFAULT buffer
cache 62914560 62914560 0 0 0
INITIALIZING 4194304
KEEP buffer
cache 0 0 0 0 0
STATIC 4194304
RECYCLE buffer
cache 0 0 0 0 0
STATIC 4194304
DEFAULT 2K buffer
ca 0 0 0 0 0
STATIC 4194304
DEFAULT 4K buffer
ca 0 0 0 0 0
STATIC 4194304
DEFAULT 8K buffer
ca 0 0 0 0 0
STATIC 4194304
DEFAULT 16K buffer
c 0 0 0 0 0
STATIC 4194304
DEFAULT 32K buffer
c 0 0 0 0 0
STATIC 4194304
ASM Buffer
Cache 0 0 0 0 0
STATIC 4194304
13 rows selected.
Buffer Cache
Size
数据缓存,调高数据命中率可以提高性能。按数据块存放。
db_cache_size
db_keep_cache_size
db_recycle_cache_size
alter system set db_cache_size = xxx M
SQL> show parameter
advice
NAME_COL_PLUS_SHOW_PARAM TYPE VALUE_COL_PLUS_SHOW_PARAM
--------------------------------------------------------------------------------
db_cache_advice string ON
SQL>
SQL> select * from
v$db_cache_advice;
SQL>
Large Pool
Size rman和一些并行处理时候会用到。
Java Pool
Size java存储过程的支持
Streams Pool
Size
Oracle 10g 中sga_target自动调整只是针对这四项:data
buffer cache, large_pool, shared_pool, java_pool
1)
03:41:30 SQL>show
sga
2)
3)
Total System Global Area 285212672
bytes
4)
Fixed
Size 1218992 bytes
5)
Variable
Size 71304784 bytes
6)
Database
Buffers 209715200 bytes
7)
Redo
Buffers 2973696 bytes
8)
04:45:40 SQL>
9)
04:46:18 SQL>select
name,bytes/(1024*1024) ,resizeable from
v$sgainfo;
10)
11)
NAME BYTES/(1024*1024) RES
12)
-------------------------------- ----------------- ---
13)
Fixed SGA
Size 1.16252136 No
14)
Redo
Buffers 2.8359375 No
15)
Buffer Cache
Size 200 Yes
16)
Shared Pool
Size 60 Yes
17)
Large Pool
Size 4 Yes
18)
Java Pool
Size 4 Yes
19)
Streams Pool
Size 0
Yes
20)
Granule
Size 4
No
;区组大小为4M
21)
Maximum SGA
Size 272 No
22)
Startup overhead in Shared
Pool 36 No
23)
Free SGA Memory
Available 0
24)
04:49:34 SQL>select
sum(bytes)/(1024*1024) size_in_mb from
v$sgastat;
25)
26)
SIZE_IN_MB
27)
----------
28)
276.003071
29)
30)
04:48:19 SQL>select * from
v$sgastat;
31)
32)
POOL NAME BYTES
33)
------------ -------------------------- ----------
34)
shared pool KKJ WRK
LAT 300
35)
shared pool kfkhsh_kfdsg 2052
36)
shared pool event statistics
ptrarra 680
37)
shared pool KGKP
randnum 40000
38)
large pool PX msg
pool 206208
39)
large pool free
memory 3988096
40)
java pool free
memory 4194304
41)
42)
602 rows selected.
43)
04:50:37 SQL>show parameter
sga;
44)
45)
NAME TYPE VALUE
46)
------------------------------------ -----------
------------------------------
47)
lock_sga boolean FALSE
48)
pre_page_sga boolean FALSE
49)
sga_max_size big integer 272M
50)
sga_target big integer 272M
SGA动态尺寸总计不能超过初始化参数SGA_MAX_SIZE的值。
如果sga_target超过了sga_max_size的大小,在Instance重新启动后,sga_max_size会调整成和sga_target一样大小的值。
如果在初始化参数里这些内存池设置为非零,则系统启动后,这些值将作为该参数对应的最小值运行。如果那个值在系统运行时不够,则Oracle将自动为其添加容量,以帮助其优化操作,直到内存使用达到SGA_TARGET所表明的上限。
[oracle@oraserv ~]$
!sql
sqlplus '/as
sysdba';
SQL*Plus:
Release 10.2.0.1.0 - Production on Sat Mar 19 11:17:30
2011
Copyright (c)
1982, 2005, Oracle. All rights
reserved.
Connected to
an idle instance.
11:17:35
SQL> startup
ORACLE
instance started.
Total System
Global Area 419430400 bytes
Fixed
Size 1219784 bytes
Variable
Size 289407800 bytes
Database
Buffers 125829120 bytes
Redo
Buffers 2973696 bytes
Database
mounted.
Database
opened.
11:18:13
SQL> show parameter sga
NAME TYPE VALUE
------------------------------------
----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 400M
sga_target big integer 300M
11:18:23
SQL> alter system set sga_target=500m
;
alter
system set sga_target=500m
*
ERROR at
line 1:
ORA-02097:
parameter cannot be modified because specified value is
invalid
ORA-00823:
Specified value of sga_target greater than
sga_max_size
11:18:38
SQL> alter system set
sga_target=500m scope=spfile;
System
altered.
11:18:54
SQL> startup force;
ORACLE
instance started.
Total System
Global Area 524288000 bytes
Fixed
Size 1220360 bytes
Variable
Size 176161016 bytes
Database
Buffers 343932928 bytes
Redo
Buffers 2973696 bytes
Database
mounted.
Database
opened.
11:19:30
SQL> show parameter sga;
NAME TYPE VALUE
------------------------------------
----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size
big integer
500M
sga_target
big integer
500M
11:19:38
SQL>
利用后台进程MMAN进行SGA动态管理
[oracle@oracle ~]$ ps -ef
|grepora_|grepora_
oracle
8012 1 0 11:12
? 00:00:00 ora_mman_prod
share
pool:
共享池(Share
Pool)用于存放最近执行的SQL语句和数据字典信息。
共享池主要有库高速缓存(Library
Cache)和数据字典高速缓存(Dictionary
cache)两部分组成
1)库高速缓存(Library
Cache)
库高速缓存用于存放最近执行的sql语句信息,包括sql语句文本,解析代码值及执行计划。
假设执行一条sql语句
-select ename,job from emp where empno=7788;
如果最近(还没有被lru淘汰)执行过这条语句,他就会直接从cache里面读结果;如果没有执行过,就需要读数据文件,这个过程就比较复杂,效率差距很大。
这里还有两个概念:
物理i/o和逻辑i/o---------1:1000
物理i/o:从数据缓冲区找不到所需要的数据,就要从硬盘里面读取。
逻辑i/o:从数据缓冲区能找到所需要的数据,
理论上讲一个数据库性能是否良好,这个逻辑i/o应该占95%以上
2)、数据字典高速缓存区(Dictionary
cache)
用于存放数据字典的信息,包括表、列定义以及权限信息)
库高速缓存和数据字典高速缓存大小是动态变化的,不是固定的。
SQL> alter system set share_pool_size=60m;
DB buffer
数据高速缓存(Database Buffer cache)用于存放最近访问的数据块信息,它由许多小缓冲区(缓冲区大小=数据尺寸)组成
Db_cache_size 定义标准的高速缓存尺寸
Db_nk_cache_size 定义非标准的高速缓存尺寸
数据库高速缓存区:
Db_cache_size Default 默认池,所有段都被默认高速缓存到默认池。(采用LRU)
Db_keep_cache_size ,确保某些数据块始终被保留到内存中
Db_recycle_cache_size ,数据高速缓存区“回收池”
Redo log
buffer
重做日志缓存区(Redo
log buffer),用于记载实例的变化。执行DDL或DML语句时,服务器进程首先将事物的变化记载到重做日志缓存区,然后才会修改数据高速缓存。
重做日志缓存区由很多重做记录(Redo
record)组成,并且每条重做记录记载了被修改数据块的位置以及变换后的数据
Large
pool
PGA(Program Global
Area)
用于存放服务器进程的数据和控制信息,独立于SGA的一块内存区域。
当用户连接到Oracle
Server时,Oracle
server会为每个服务器进程分配相应的PGA.
SGA是所有服务器进程都可共享那个的一块内存区域,而每个服务器进程都具有私有的PGA内存空间。
客户端在通过sql语句连接database时,必须通过实例Instance来连接和管理数据库。
Connection:客户端进程和服务端进程建立通讯。
Session:当用户经过Oracle
server认证后开始建立会话,直到用户退出登录,会话结束