内存管理涉及到根据数据库变化的需要为Oracle实例内存结构保持最佳大小,Oracle数据库根据与内存相关的初始化参数的设置来管理内存。
内存管理有三种基本方式:
AMM (自动内存管理)
Automatic memory management:
ASMM (自动共享内存管理)
Automatic shared memory management:
Manual memory management(手动内存管理)
如果使用数据库配置助手(DBCA)创建数据库并选择基本安装选项,则默认为AMM(自动内存管理)
MEMORY_TARGET :
操作系统上 Oracle 所能使用的最大内存值(动态参数),是PAG 和SGA的总和。
1、AMM(自动内存管理)
memory_target=非0,如果初始化参数 LOCK_SGA = true ,则 AMM 是不可用的
2、ASMM (自动共享内存管理)
memory_target=0 and sga_target=非0
3、Manual memory management(手动内存管理)
memory_target=0 and sga_target=0,指定 share_pool_size 、db_cache_size 等 sga 参数
在设置memory_target与memory_max_target 需注意注意以下三点:
memory_target
而没有指定memory_max_target
重启后,memory_max_target
和memory_target
大小相等;memory_max_target
而没有指定memory_target
,重启后memory_target=0
;原理:登录数据库—>将memory_target与memory_max_target大小置为0—>修改sga、pga大小—>通过spfile指定路径创建一个pfile—>修改pfile中sga_target等参数—>使用pfile启动数据库—>通过该pfile创建spfile—>关闭数据库—>最后正常启动数据库即可
首先:创建spfile备份
SQL> create pfile='/u01/app/oracle/admin/orcl/pfile/pfile1.ora' from spfile;
File created.
SQL>
1、查看memory_target与memory_max_target大小:
SQL> show parameter memory
NAME TYPE VALUE
-------------------------------- ----------- ------------------------------
hi_shared_memory_address integer 0
memory_max_target big integer 0
memory_target big integer 0
shared_memory_address integer 0
SQL>
#根据输出的结果显示 memory_max_target=0 与 memory_target=0 说明目前已经是 ASMM 模式直接修改sga与pga大小即可
2、(如果值非零) 修改memory_target与memory_max_target大小:
#如果memory_max_target非0 与 memory_target非0,使用下面命令将值改为0
1、修改memory_max_target大小:
SQL> alter system set memory_max_target=0 scope=spfile;
System altered.
2、修改memory_target大小(memory_target<=memory_max_target):
SQL> alter system set memory_target=0 scope=spfile;
System altered.
3、修改sga与pga大小:
1、修改sga大小:
SQL> alter system set sga_max_size=2560M scope=spfile;
System altered.
SQL> alter system set sga_target=2560M scope=spfile;
System altered.
2、修改pga大小:
SQL> alter system set pga_aggregate_target=650M scope=spfile;
System altered.
4、通过spfile创建pfile并关闭数据库:
#创建路径为:/u01/app/oracle/admin/orcl/pfile/
#创建的pfile文件名为:pfile.ora
SQL> create pfile='/u01/app/oracle/admin/orcl/pfile/pfile.ora' from spfile;
File created.
SQL>
#关闭数据库:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
5、操作系统中编辑pfile文件:
#若在/u01/app/oracle/admin/orcl/pfile/pfile.ora文件中存在memory_max_target与memory_target参数,屏蔽或删除即可。
vi /u01/app/oracle/admin/orcl/pfile/pfile.ora
orcl.__db_cache_size=2046820352
orcl.__java_pool_size=16777216
orcl.__large_pool_size=33554432
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=654311424 #实例orcl 建议pga=(物理内存 x 80%) x 20%,由memory_target自动管理
orcl.__sga_target=2566914048 #实例orcl 建议sga=(物理内存 x 80%) x 80%,由memory_target自动管理
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=436207616
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
#*.memory_max_target=0 #将memory_max_target屏蔽或删除
#*.memory_target=0 #将memory_target屏蔽或删除
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.O7_DICTIONARY_ACCESSIBILITY=FALSE
*.open_cursors=300
*.pga_aggregate_target=681574400 #pga大小(alter system修改)
*.processes=1500
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=1655
*.sga_max_size=2684354560 #sga_max_size大小(alter system修改)
*.sga_target=2684354560 #sga_target大小(alter system修改)
*.undo_tablespace='UNDOTBS1'
6、通过pfile启动实例:
#通过pfile启动数据库实例:
SQL> startup pfile='/u01/app/oracle/admin/orcl/pfile/pfile.ora';
ORACLE instance started.
Total System Global Area 2672361472 bytes
Fixed Size 2256232 bytes
Variable Size 1073742488 bytes
Database Buffers 1577058304 bytes
Redo Buffers 19304448 bytes
Database mounted.
Database opened.
SQL>
7、查询sga、pga等验证:
#查看pga大小:
SQL> show parameter pga
NAME TYPE VALUE
------------------------------- ----------- ------------------------------
pga_aggregate_target big integer 650M #pga大小已经修改成功(原610M)
#查看sga大小:
SQL> show parameter sga
NAME TYPE VALUE
-------------------------------- ----------- -----------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 2560M #sga大小已经修改成功(原2450M)
sga_target big integer 2560M #sga大小已经修改成功(原2450M)
SQL> show parameter memory
NAME TYPE VALUE
------------------------------- ----------- ------------------------------
hi_shared_memory_address integer 0
memory_max_target big integer 0
memory_target big integer 0
shared_memory_address integer 0
SQL>
8、通过pfile创建spfile并关闭数据库:
SQL> create spfile from pfile='/u01/app/oracle/admin/orcl/pfile/pfile.ora';
File created.
SQL>
#关闭数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
9、使用startup启动数据库(默认使用spfile)
SQL> startup
ORACLE instance started.
Total System Global Area 2672361472 bytes
Fixed Size 2256232 bytes
Variable Size 1073742488 bytes
Database Buffers 1577058304 bytes
Redo Buffers 19304448 bytes
Database mounted.
Database opened.
#查看查询验证pga
SQL> show parameter pga
NAME TYPE VALUE
-------------------------------- ----------- ------------------------------
pga_aggregate_target big integer 650M #与修改结果一致
#查看查询验证sga
SQL> show parameter sga
NAME TYPE VALUE
-------------------------------- ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 2560M #与修改结果一致
sga_target big integer 2560M #与修改结果一致
SQL> show parameter memory
NAME TYPE VALUE
-------------------------------- ----------- ------------------------------
hi_shared_memory_address integer 0
memory_max_target big integer 0
memory_target big integer 0
shared_memory_address integer 0
SQL>
sga与pga修改成功!
至此结束,有什么问题欢迎留言,谢谢。