3_Oracle_Admin_SPFILE
SPFILE储存在服务端,它不能自行修改(从而克服了PFILE的一些安全性隐患),如果使用文本编辑器查看SPFILE会发现这是个二进制文件,需要使用SQL命令,由Oracle Server进行管理,使用SQL命令修改的值会永久的保存起来。Oracle的备份恢复工具RMAN可以备份SPFILE。
[oracle@localhost ~]$ sqlplus/nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Aug 2710:40:15 2014 Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> create spfile frompfile;
File created.
[oracle@localhost dbs]$ ll
total 3-rw-r--r--. 1 oracle oinstall 2851 Aug 27 10:41 initorcl.oradrwxr-xr-x. 3 oracle oinstall 4096 Aug 27 10:20 old-rw-r-----. 1 oracle oinstall 1536 Aug 27 10:42spfileorcl.ora
SQL> startup
ORACLE instance started. Total System Global Area 422670336 bytesFixed Size 1336960 bytesVariable Size 318769536 bytesDatabase Buffers 96468992 bytesRedo Buffers 6094848 bytesDatabase mounted.Database opened.
=============查看SPFILE=============
由于SPFILE是个二进制文件,故不能使用文本编辑器查看,因此在Linux的命令行中使用strings命令来查看这个文件:
[oracle@localhost dbs]$strings spfileorcl.ora | more
orcl.__db_cache_size=96468992orcl.__java_pool_size=4194304orcl.__large_pool_size=4194304orcl.__oracle_base='/oracle'#ORACLE_BASE set fromenvironmentorcl.__pga_aggregate_target=146800640orcl.__sga_target=276824064orcl.__shared_io_pool_size=0orcl.__shared_pool_size=159383552orcl.__streams_pool_size=4194304*.audit_file_dest='/oracle/admin/orcl/adump'*.audit_trail='db'*.compatible='11.2.0.0.0'*.control_files='/oracle/oradata/orcl/control01.ctl','/oracle/flash_recovery_area/orcl/control02.ctl'*.db_block_size=8192*.db_domain=''*.db_name='orcl'*.db_recovery_file_dest='/oracle/flash_recovery_area'*.db_recovery_file_dest_size=4039114752*.diagnostic_dest='/oracle'*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'*.memory_target=421527552*.open_cursors=300*.processes=150*.remote_login_passwordfile='EXCLUSIVE'*.undo_tablespace='UNDOTBS1'
SPFILE不能使用文本编辑器手动修改,必须使用SQL命令来修改,其格式为:
ALTER system set parameter=value
手动修改了PFILE后,通常不能马上生效,必须等下次启动Instance才能生效;而SPFILE是Oracle内置的二进制文件,通过指定
通常情况下一个实例(Instance)对应一个数据库,但在RAC(大规模的集群数据库)环境中,通常是多个实例对应一个数据库,因此就需要指定
使用strings命令查看SPFILE,会发现很多文件前面都有一个*,它表示这个参数适用于所有的Instance;而没有带*号的,就需要指定SID,如orcl.__db_cache_size=96468992中,orcl就是SID。
/*==========修改SPFILE实例演示============*/
[oracle@localhost dbs]$strings spfileorcl.ora | less
orcl.__db_cache_size=96468992orcl.__java_pool_size=4194304…*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'*.memory_target=421527552
/*=== 现在来修改SPFILE的值 ===*/
SQL> show parameter fast_
NAME TYPE VALUE------------------------------------ -----------------------------------------fast_start_io_target integer 0fast_start_mttr_target integer 0fast_start_parallel_rollback string LOW
SQL> alter system setfast_start_mttr_target=250;
-- 没有加任何scope,则该值会保存到内存和磁盘文件上System altered.
SQL> show parameter fast_
NAME TYPE VALUE------------------------------------ -----------------------------------------fast_start_io_target integer 0fast_start_mttr_target integer 250fast_start_parallel_rollback string LOW
[oracle@localhost dbs]$strings spfileorcl.ora | more
orcl.__db_cache_size=96468992orcl.__java_pool_size=4194304…*.fast_start_mttr_target=250*.memory_target=421527552
/*===========再来看加了scope的情况=============*/
SQL> alter system setfast_start_mttr_target=260 scope=memory;
System altered.
SQL> show parameter fast_
NAME TYPE VALUE------------------------------------ ----------- ------------------------------fast_start_io_target integer 0fast_start_mttr_target integer 260-- 内存中已经修改为260了fast_start_parallel_rollback string LOW
[oracle@localhost dbs]$strings spfileorcl.ora | more
orcl.__db_cache_size=96468992orcl.__java_pool_size=4194304*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'*.fast_start_mttr_target=250# 磁盘上的值仍然是250*.memory_target=421527552
/*=================修改SPFILE时加注解==================*/
SQL> alter system set fast_start_mttr_target=260comment='hello Mickey!';
System altered.
SQL> desc v$parameter;
Name Null? Type ------------------------------------------------- ---------------------------- NUM NUMBER NAME VARCHAR2(80) TYPE NUMBER VALUE VARCHAR2(4000) DISPLAY_VALUE VARCHAR2(4000) ISDEFAULT VARCHAR2(9) ISSES_MODIFIABLE VARCHAR2(5) ISSYS_MODIFIABLE VARCHAR2(9) ISINSTANCE_MODIFIABLE VARCHAR2(5) ISMODIFIED VARCHAR2(10) ISADJUSTED VARCHAR2(5) ISDEPRECATED VARCHAR2(5) ISBASIC VARCHAR2(5) DESCRIPTION VARCHAR2(255) UPDATE_COMMENT VARCHAR2(255) HASH NUMBER
SQL> select name, value,update_comment
2 from v$parameter 3 where name = 'fast_start_mttr_target'; NAME VALUE UPDATE_COMMENT-------------------------------- --------------- ------------------------fast_start_mttr_target 260 hello Mickey!
[oracle@localhost dbs]$strings spfileorcl.ora | more
orcl.__db_cache_size=96468992orcl.__java_pool_size=4194304*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'*.fast_start_mttr_target=260#hello Mickey!# 已经加上注解了*.memory_target=421527552
有些参数必须延迟生效,这就需要在修改时加上deferred选项,在参数表v$parameter中ISINSTANCE_MODIFIABLE项中如果标注为deferred,就需要延迟生效
SQL> col name format a20
SQL> col issys_modifiableformat a20
SQL> select name,issys_modifiable
2 from v$parameter 3 where issys_modifiable = 'DEFERRED'; NAME ISSYS_MODIFIABLE------------------------------ --------------------backup_tape_io_slaves DEFERREDrecyclebin DEFERREDaudit_file_dest DEFERREDobject_cache_optimal_size DEFERREDobject_cache_max_size_percent DEFERREDsort_area_size DEFERREDsort_area_retained_size DEFERREDolap_page_pool_size DEFERRED 8 rows selected.
更多ALERT 的使用细节,可以查看联机文档reference中有关ALTER SYSTEM的相关章节。
如果不想要修改后的值,可以使用reset命令来恢复为缺省值
SQL> show parameter undo
NAME TYPE VALUE------------------------------------ -----------------------------------------undo_management string AUTOundo_retention integer 900undo_tablespace string UNDOTBS1
SQL> alter system setundo_retention=800;
System altered.
SQL> show parameter undo
NAME TYPE VALUE------------------------------------ -------------------------------------undo_management string AUTOundo_retention integer 800undo_tablespace string UNDOTBS1
SQL> alter system resetundo_retention sid='*';
System altered.
更多关于reset的细节,可以查询联机文档reference。
可以用spfile来创建pfile:
SQL> create pfile fromspfile;
File created.
[oracle@localhost dbs]$ ll
total 36-rw-r-----. 1 oracle oinstall 1544 Aug 27 10:47 hc_orcl.dat-rw-r--r--. 1 oracle oinstall 2851 Aug 27 13:36 init.ora-rw-r--r--. 1 oracle oinstall 904 Aug 27 13:34 initorcl.ora# 根据spfile创建出来的pfile文件-rw-r-----. 1 oracle oinstall 24 Aug 27 10:45 lkORCLdrwxr-xr-x. 3 oracle oinstall 4096 Aug 27 10:20 old-rw-r-----. 1 oracle oinstall 1536 Aug 27 10:45 orapworcldrwx------. 2 oracle oinstall 4096 Aug 27 10:47 peshm_orcl_0drwx------. 2 oracle oinstall 4096 Aug 27 09:31 peshm_ORCL_0-rw-r-----. 1 oracle oinstall 2560 Aug 27 13:27spfileorcl.ora