共計 6755 個字符,預計需要花費 17 分鐘才能閱讀完成。
這篇文章給大家分享的是有關怎么配置 oracle 數據庫服務器的內存的內容。丸趣 TV 小編覺得挺實用的,因此分享給大家做個參考,一起跟隨丸趣 TV 小編過來看看吧。
SGA:是用于存儲數據庫信息的內存區,該信息為數據庫進程所共享。它包含 Oracle 服務器的數據和控制信息, 它是在 Oracle 服務器所駐留的計算機的實際內存中得以分配,如果實際內存不夠再往虛擬內存中寫。
PGA:是一塊包含一個服務進程的數據和控制信息的內存區域。它是 Oracle 在一個服務進程啟動時創建的,是非共享的。一個 Oracle 進程擁有一個 PGA 內存區。一個 PGA 也只能被擁有它的那個服務進程所訪問,只有這個進程中的 Oracle 代碼才能讀寫它。因此,PGA 中的結構是不需要 Latch 保護的。
我們重點就是設置 SGA,理論上 SGA 可占 OS 系統物理內存的 1 /2——1/3
ORACLE 給的建議是: OLTP 系統 PGA=(Total Memory)*80%*20%。DSS 系統 PGA=(Total Memory)*80%*50%。
ORACLE 建議一個數據庫服務器,分 80% 的內存給數據庫,20% 的內存給操作系統,那怎么給一個數據庫服務器配內存呢?
SQL select * from v$pgastat;
NAME VALUE UNIT
—————————————————————- ———- ————
aggregate PGA target parameter 104857600 bytes
—– 這個值等于參數 PGA_AGGREGATE_TARGET 的值,如果此值為 0,表示禁用了 PGA 自動管理。
aggregate PGA auto target 75220992 bytes
—– 表示 PGA 還能提供多少內存給自動運行模式,通常這個值接近 pga_aggregate_target-total pga inuse.
global memory bound 20971520 bytes
—– 工作區執行的最大值,如果這個值小于 1M,馬上增加 PGA 大小
total PGA inuse 30167040 bytes
—– 當前分配 PGA 的總大小,這個值有可能大于 PGA,如果 PGA 設置太小. 這個值接近 select sum(pga_used_mem) from v$process.
total PGA allocated 52124672 bytes
—– 工作區花費的總大小
maximum PGA allocated 67066880 bytes
total freeable PGA memory 0 bytes – 沒有了空閑的 PGA
process count 23 – 當前有 23 個 process
max processes count 25
PGA memory freed back to OS 0 bytes
total PGA used for auto workareas 8891392 bytes
maximum PGA used for auto workareas 22263808 bytes
total PGA used for manual workareas 0 bytes – 為 0 自動管理
maximum PGA used for manual workareas 0 bytes – 為 0 自動管理
over allocation count 0
如果 PGA 設置太小,導致 PGA 有時大于 PGA_AGGREGATE_TARGET 的值,此處為 0,說明 PGA 沒有擴展大于 TARGET 的值,如果此值出現過,那么增加 PGA 大小。
bytes processed 124434432 bytes
extra bytes read/written 0 bytes
cache hit percentage 100 percent — 命中率為 100%,如果太小增加 PGA
recompute count (total) 6651
19 rows selected
SQL select max(pga_used_mem)/1024/1024 M from v$process; —- 當前一個 process 消耗最大的內存
M
———-
9.12815189
SQL select min(pga_used_mem)/1024/1024 M from v$process where pga_used_mem —process 消耗最少內存
M
———-
0.19186878
SQL select max(pga_used_mem)/1024/1024 M from v$process ; —-process 曾經消耗的最大內存
M
———-
9.12815189
SQL select sum(pga_used_mem)/1024/1024 from v$process; —- 當前 process 一共消耗的 PGA
SUM(PGA_USED_MEM)/1024/1024
—————————
28.8192501068115
如何設置 PGA 呢?我們可以在壓力測試階段,模擬一下系統的運行,然后運行
select (select sum(pga_used_mem)/1024/1024 from v$process) /(select count(*) from v$process) from dual; 得到一個 process 大約占用了多少的內存,然后估算系統一共會有多少連接,比如一共有 500 個連接,
那么 Sessions=1.1*process +5=500,那么 processes=450, 再乘以一個 process 需要消耗的內存,就能大約估算出 PGA 需要設置多大。
最好將 PGA 設置的值比計算出的值大一點,PGA 值設定好后,就可以根據系統的性質, 如果系統為 OLTOP,那么總的內存可以設置為 PGA/0.16, 最后也能估算出 SGA 的大小,建議還是多配點內存,反正便宜。
下面摘抄 eygle 的關于一個 process 能夠分配的最大內存(串行操作) 的規則:
10gR1 之前,對于串行操作 (非并行) 一個 process 能夠分配的最大的內存為 min(5%pga_aggregate_target,100m)
10gR2 之后,對于串行操作 (非并行) 一個 process 能夠分配的最大內存有如下規則:
如果 pga_aggregate_target =500m, 那么最大的內存為 20%*pga_aggregate_target.
如果 500m
如果 1000m 如果 pga_aggregate_target 2.5G, 那么最大內存為 2.5G.
SQL SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
2 FROM SYS.x$ksppi x, SYS.x$ksppcv y
3 WHERE x.inst_id = USERENV (Instance)
4 AND y.inst_id = USERENV (Instance)
5 AND x.indx = y.indx
6 AND x.ksppinm LIKE % par%
7 /
NAME VALUE DESCRIB
——————————————————————————– ——————————————————————————– ——————————————————————————–
_smm_max_size 20480 maximum work area size in auto mode (serial)
SQL show parameter pga
NAME TYPE VALUE
———————————— ———– ——————————
pga_aggregate_target big integer 100M
此處我的一個 process 能夠分配的最大內存為 20M,因為我的 PGA=100M,符合上面的規則。
隱含參數_smm_max_size 表示一個 process 能夠分配最大的 memory.
買了 piner 的《oracle 高可用環境》一書,正好趁這段時間學習一下。
把看到的東西總結一下發表于此,今天先發第一章關于 SGA 與 PGA 的內容。
以后會陸續將總結在此發表,與大家共享。
SGA 與 PGA 的結構如下圖:
SGA:
查看 SGA:
Sqlp show sga
或 select * from v$sga;
Total System Global Area 289406976 bytes
Fixed Size 1248600 bytes
Variable Size 176161448 bytes
Database Buffers 109051904 bytes
Redo Buffers 2945024 bytes
Fixed Size:包括了數據庫與實例的控制信息、狀態信息、字典信息等,啟動時就被固定在 SGA 中,不會改變。
Variable Size:包括了 shard pool、large pool、java pool、stream pool、游標區和其他結構
Database Buffers:數據庫中數據塊緩沖的地方,是 SGA 中最大的地方,決定數據庫性能
Redo Buffers:提供 REDO 緩沖的地方,在 OLAP 中不需要太大
V$sgastat 記錄了 SGA 的一些統計信息
V$sga_dynamic_components 保存 SGA 中可以手動調整的區域的一些調整記錄
Shard pool:
Shard_pool_size 決定其大小,10g 以后自動管理
Shard_pool 中數據字典和控制區結構用戶無法直接控制,與用戶有關的只有 sql 緩沖區(library cache)。
將經常訪問的過程或包用 DBMS_SHARED_POOL.KEEP 存儲過程將該包 pin 在共享池中。
手工清除共享池的內容:alter system flush shard_pool;
共享池相關的幾個常用的視圖:
V$sqlarea 記錄了所有 sql 的統計信息,包括執行次數、物理讀、邏輯讀、耗費時間等
V$sqltext_with_newline 完全顯示 sql 語句,通過 hash_value 來標示語句,piece 排序
V$sql_plan 保存了 sql 的執行計劃,通過工具查看
V$shared_pool_advice 對共享池的預測,可以做調整 SGA 的參考
Data buffer:
在 OLTP 系統中要求 data buffer 的命中率在 95% 以上
select sum(pins) execution ,sum(pinhits) hits ,
((sum(pinhits)/sum(pins))*100) pinhitration ,
sum(reloads) misses ,((sum(pins)/(sum(pins)
+sum(reloads)))*100) relhitratio
from V$librarycache
PINS NUMBER Number of times a PIN was requested for objects of this namespace
PINHITS NUMBER Number of times all of the metadata pieces of the library object were found in memory
RELOADS NUMBER Any PIN of an object that is not the first PIN performed since the object handle was created, and which requires loading the object from disk
Oracle 把從 data buffer 中獲得的數據庫叫 cache hit,把從磁盤獲得的腳 cache miss
數據緩沖區中的數據塊通過臟列表(dirty list)和 LRU 列表(LRU list)來管理。
Data buffer 可細分為:default pool、keep pool、recycle pool 對應的參數為 db_cache_size、db_keep_cache_size、db_recycle_size 分別表示緩沖區大小
從 9i 開始 oracle 支持不同塊大小的表空間,相應的可以為不同塊大小的表空間指定不同塊大小的數據緩沖區,不同塊大小的數據緩沖區可以用相應的 db_nk_cache_size 來指定,其中 n 可以是 2、4、6、16 或 32
V$db_cache_advice 對數據緩沖區的預測,可以做調整 data buffer 的參考
V$bh、x$bh 記錄了數據塊在 data buffer 中緩沖的情況,通過這個視圖可以找系統中的熱點塊。通過下面語句找系統中 top 10 熱點快所在的熱點對象:
Select /*+ rule*/ owner,object_name from dba_objects
Where data_object_id in
(select obj from
(select obj from x$bh order by tch desc)
Where rownum
PGA:
用來保存于用戶進程相關的內存段。
從 9i 開始使用 PGA 自動管理,pga_aggregate_target 參數指定 session 一共使用的最大 PGA 內存的上限。Workarea_size_policy 參數用于開關 PGA 內存自動管理功能,auto/manual
在 OLTP 環境中,自動 PGA 管理只要設置到一定的值,如 2G 左右就能滿足系統的要求。
自動內存管理:
從 9i 開始,sga_max_size 參數設置 SGA 的內存大小,不能動態修改
從 10g 開始,指定了 sga_target 參數后,所有的 SGA 組件如:shared pool、data buffer、large pool 都不用手工指定了,Oracle 會自動管理。這一特性就是自動共享內存管理 ASMM。如果設置了 sga_target=0, 就自動關閉自動共享內存管理功能。Sga_target 大小不能超過 sga_max_size 的大小。
手動管理 SGA:
Alter system set sga_target=2000m;
Alter system set db_cache_size=1000m;
Alter system set shared_pool=200m;
Alter system set sga_target=0——— 關閉自動共享內存管理 ASMM
11G 以后 sga+pga 整個內存可以自動管理 AMM,相關參數 memory_max_target memory_target. 設置好這兩個參數后就不用關心 SGA 和 PGA 了
11g 手動內存管理:
Alter system set memory_target=3000m;
Alter system set sga_target=2000m;
Alter system set pga_aggregate_target=1000m;
Alter system set memory_target=0;——— 關閉自動內存管理 AMM
SGA+PGA 最好不要超過總內存的 70%
補充:總原則:OS 使用內存 +SGA+ 并發執行進程數 *(sort_area_size+hash_ara_size+2M) 0.7* 總內存
簡單說就是:SGA+PGA+OS 使用內存 總物理 RAM
關于 SGA、PGA 與系統內存三者間的關聯,目前有一個相對通用的計算規則可供參考:
對于 OLTP 數據庫,SGA= 系統內存 *70%*80%,PGA=SGA*(10%~20%)。SGA= 系統內存 *0.56 PGA= 系統內存 *(0.05~0.1)
對于 OLAP 數據庫,SGA= 系統內存 *80%*60%,PGA=SGA*(45%~65%)。SGA= 系統內存 *0.48 PGA= 系統內存 *(0.22~0.31)
(對于 32bit 平臺,默認情況下 SGA 最大可用內存有 1.7GB 的限制)
實例配置時需要考慮的因素
一:物理內存多大
二:操作系統估計需要使用多少內存
三:數據庫是使用文件系統還是裸設備
四:有多少并發連接
五:應用是 OLTP 類型還是 OLAP 類型
感謝各位的閱讀!關于“怎么配置 oracle 數據庫服務器的內存”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!