1. 程式人生 > >Oracle 參數文件

Oracle 參數文件

配置 aud war 一行 str stc 情況 描述 rdf

參數文件(10g中的參數文件)

主要用來記錄數據庫的配置文件,在數據庫啟動時,Oracle讀取參數文件,並根據參數文件中的參數設置來配置數據庫。

如內存池的分配,允許打開的進程數和會話數等。

兩類參數文件:

pfile:文本文件的參數文件,可以使用vi,vim等編輯器修改,文件名通常為init<sid>.ora

spfile:二進制的參數文件,不能直接修改,只能存放在Oracle服務器端,可以使用EM或指令來修改

(alter system|session set parameter_name = values <>),

文件名通常為spfile<sid>.ora,支持RMAN備份。

優先級別:

Oracle 啟動讀取參數文件的順序,如果個文件都不存在,則Oracle會報錯

spfile<sid>.ora --> spfile.ora -->init<sid>.ora

參數文件的路徑:*/

spfle:$ORACLE_HOME/dbs/spfile$ORACLE_SID.ora

pfile(9i):$ORALCE_HOME/dbs/init$ORALCE_SID.ora /*10g以後一般不用init<sid>.ora*/

pfile(10g):$ORALCE_BASE/admin/$ORACLE_SID/pfile /*僅當數據庫初始化時使用*/

pfile:$ORACLE_HOME/dbs/init.ora /*默認*/

/*

參數文件之間的轉化

spfile 轉化為pfile

pfile 轉換為spfile

從spfile來生成pfile

create pfile from spfile ,執行完畢後,pfile 將保存為$ORACLE_HOME/dbs/init$ORACLE_SID.ora

也可以指定pfile 的路徑:create pfile = ‘<dir>‘ from spfile;

由pfile 生成spfile

create spfile from pfile

create spfile from pfile = ‘<dir>‘

create spfile = ‘<dir>‘ from pfile

11g中的新指令,從memeory中生成

create spfile = ‘<dir>‘ from memeory */

/*

演示:*/

spfile --> pfile

SQL> create pfile from spfile;

File created.

SQL> ho ls -al /u01/app/oracle/10g/dbs/

total 56

drwxr-x--- 2 oracle oinstall 4096 Apr 8 13:49 .

drwxr-x--- 55 oracle oinstall 4096 Apr 7 09:48 ..

-rw-r----- 1 oracle oinstall 1544 Apr 6 12:06 hc_orcl.dat

-rw-r----- 1 oracle oinstall 8385 Sep 11 1998 init.ora

-rw-r----- 1 oracle oinstall 12920 May 3 2001 initdw.ora

-rw------- 1 oracle oinstall 1155 Apr 8 13:49 initorcl.ora

-rw-r----- 1 oracle oinstall 24 Apr 6 12:06 lkORCL

-rw-r----- 1 oracle oinstall 1536 Apr 7 15:50 orapworcl

-rw-r----- 1 oracle oinstall 3584 Apr 8 11:15 spfileorcl.ora

SQL> ho cat /u01/app/oracle/10g/dbs/initorcl.ora

orcl.__db_cache_size=251658240

orcl.__java_pool_size=4194304

orcl.__large_pool_size=4194304

orcl.__shared_pool_size=142606336

orcl.__streams_pool_size=0

*.audit_file_dest=‘/u01/app/oracle/admin/orcl/adump‘

*.background_dump_dest=‘/u01/app/oracle/admin/orcl/bdump‘

*.compatible=‘10.2.0.1.0‘

*.control_files=‘/u01/app/oracle/oradata/orcl/control01.ctl‘,‘/u01/app/oracle/oradata/orcl/control02.ctl‘, ‘/u01/app/oracle/oradata/orcl/control03.ctl‘

*.core_dump_dest=‘/u01/app/oracle/admin/orcl/cdump‘

*.db_block_size=8192

*.db_create_file_dest=‘/u01/app/oracle/oradata/orcl‘

*.db_create_online_log_dest_1=‘/u01/app/oracle/disk1‘

*.db_create_online_log_dest_2=‘/u01/app/oracle/disk2‘

*.db_domain=‘‘

*.db_file_multiblock_read_count=16

*.db_name=‘orcl‘

*.db_recovery_file_dest=‘/u01/app/oracle/flash_recovery_area‘

*.db_recovery_file_dest_size=2147483648

*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=orclXDB)‘

*.job_queue_processes=10

*.open_cursors=300

*.pga_aggregate_target=135266304

*.processes=150

*.remote_login_passwordfile=‘EXCLUSIVE‘

*.sga_target=406847488

*.undo_management=‘AUTO‘

*.undo_tablespace=‘UNDOTBS1‘

*.user_dump_dest=‘/u01/app/oracle/admin/orcl/udump‘

pfile --> spfile

SQL> create spfile from pfile; /*使用該命令的時候不能轉換,如下報錯,因為當前的spfile正在使用*/

create spfile from pfile

*

ERROR at line 1:

ORA-32002: cannot create SPFILE already being used by the instance

SQL> create spfile = ‘/u01/app/oracle/spfileorcl.ora‘ from pfile;

File created.

SQL> ho cat /u01/app/oracle/spfileorcl.ora;

a*orcl.__db_cache_size=251658240

orcl.__java_pool_size=4194304

orcl.__large_pool_size=4194304

orcl.__shared_pool_size=142606336

orcl.__streams_pool_size=0

*.audit_file_dest=‘/u01/app/oracle/admin/orcl/adump‘

*.background_dump_dest=‘/u01/app/oracle/admin/orcl/bdump‘

*.compatible=‘10.2.0.1.0‘

*.control_files=‘/u01/app/oracle/oradata/orcl/control01.ctl‘,‘/u01/app/oracle/oradata/orcl/control02.ctl‘,‘/u01/app/oracle/oradata/orcl/control03.ctl‘

*.core_dump_dest=‘/u01/app/oracle/admin/orcl/cdump‘

*.db_block_size=8192

*.db_create_file_dest=‘/u01/app/oracle/oradata/orcl‘

*.db_create_online_log_dest_1=‘/u01/app/oracle/disk1‘

*.db_create_online_log_dest_2=‘/u01/app/oracle/disk2‘

*.db_domain=‘‘

*.db_file_multiblock_read_count=16

*.db_name=‘orcl‘

*.db_recovery_file_dest=‘/u01/app/oracle/flash_recovery_area‘

*.db_recovery_file_dest_size=2147483648

*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=orclXDB)‘

*.job_queue_processes=10

*.open_cursors=300

*.pga_aggregate_target=135266304

*.processes=150

*.remote_login_passwordfile=‘EXCLUSIVE‘

*.sga_target=406847488

*.undo_management=‘AUTO‘

*.undo_tablespace=‘UNDOTBS1‘

*.user_dump_dest=‘/u01/app/oracle/admin/orcl/udump‘

/*

轉換後的使用:

假定修改了initorcl.ora中的參數,但Oracle啟動是先讀取spfile ,故可以在啟動的時候指定用initorcl.ora來

初始化參數,啟動完畢後,可以創建spfile,則下一次啟動就可以使用新的spfile.

假定我們對initorcl.ora作如下修改:*/

open_cursors=600

processes=250

/*

則關閉數據庫後指定以initorcl.ora參數來啟動數據庫*/

SQL> startup pfile = ‘/u01/app/oracle/10g/dbs/initorcl.ora‘;

ORACLE instance started.

Total System Global Area 406847488 bytes

Fixed Size 1219688 bytes

Variable Size 150995864 bytes

Database Buffers 251658240 bytes

Redo Buffers 2973696 bytes

Database mounted.

Database opened.

SQL> create spfile from pfile; /*修改的內容將會更新到spfile*/

File created.

--查看參數文件的名字

SQL> show parameter service_name

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

service_names string orcl

--查看當前使用的哪個參數文件啟動的

SQL> select distinct isspecified from v$spparameter;

ISSPEC

------

FALSE

/*

如果第一個值是FALSE還是TRUE,如果是FALSE,則是pfile,否則則是spfile.

也可以嘗試修改spfile ,如果報錯則可以判斷是從pfile啟動,當然所修改的參數必須是可以修改的*/

SQL> alter system set sga_target = 200m scope = spfile;

alter system set sga_target = 200m scope = spfile

*

ERROR at line 1:

ORA-32001: write to SPFILE requested but no SPFILE specified at startup

--強制啟動Oracle後再查看是使用的哪個參數啟動的。

SQL> startup force

ORACLE instance started.

Total System Global Area 406847488 bytes

Fixed Size 1219688 bytes

Variable Size 150995864 bytes

Database Buffers 251658240 bytes

Redo Buffers 2973696 bytes

Database mounted.

Database opened.

SQL> select distinct isspecified from v$spparameter;

ISSPEC

------

TRUE

FALSE

/*

第一行為TRUE可知,是從spfile啟動的,有兩行,其中第二行為FALSE,表示有兩個參數文件,一個是spfile,一個是pfile

再次嘗試看看能否修改spfile: */

SQL> alter system set sga_target = 380m scope = spfile; /*修改成功*/

System altered.

/*

參數文件的修改:

如果是pfile ,直接使用vi,vim來修改即可

如果是spfile ,則使用 */

alter system|session set parametername = values scope = memory | spfile |both sid = ‘sid‘ | ‘*’;

scope

memory : 只對當前實例有效,下次啟動則失效

spfile : 只對spfile 修改,必須經過下一次啟動才生效,當前的實例沒有修改

both :內存與參數文件都將修改,當不指定scope時,缺省為both.

system | session

system :

-- 查詢視圖:v$parameter

isses_modifiable 可以被alter session修改

isssy_modifiable 可以被alter system修改

-- sid:

sid :只對某一個實例

* :對所有的實例修改

SQL> show parameter sga_ /*查看與sga有關的參數*/

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

sga_max_size big integer 388M

sga_target big integer 388M

SQL> alter system set sga_max_size = 350m; /*特殊的參數不能被修改*/

alter system set sga_max_size = 350m

*

ERROR at line 1:

ORA-02095: specified initialization parameter cannot be modified

SQL> a scope = spfile

1* alter system set sga_max_size = 350m scope = spfile

SQL> /

System altered.

SQL> select instance_name from v$instance;

INSTANCE_NAME

----------------

orcl

SQL> alter system set sga_max_size = 350m scope = spfile sid = ‘orcl‘;

System altered.

--只改內存

SQL> show parameter pga

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

pga_aggregate_target big integer 129M

SQL> alter system set pga_aggregate_target = 130m scope = memory;

System altered.

-- 同時修改內存和參數文件,以下兩條語句等效

SQL> alter system set pga_aggregate_target = 130m scope = both;

System altered.

SQL> alter system set pga_aggregate_target = 130m ;

System altered.

--alter session

SQL> show parameter sql_

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

plsql_ccflags string

plsql_code_type string INTERPRETED

plsql_compiler_flags string INTERPRETED, NON_DEBUG

plsql_debug boolean FALSE

plsql_native_library_dir string

plsql_native_library_subdir_count integer 0

plsql_optimize_level integer 2

plsql_v2_compatibility boolean FALSE

plsql_warnings string DISABLE:ALL

sql92_security boolean FALSE

sql_trace boolean FALSE

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

sql_version string NATIVE

sqltune_category string DEFAULT

SQL> alter session set sql_trace = true;

Session altered.

-- 可以從v$parameter視圖中來得到哪些可以使用alter system修改,哪些可以使用alter session來修改。

SQL> col name for a40

SQL> select NAME,ISSES_MODIFIABLE,ISSYS_MODIFIABLE from v$parameter

2 where name like ‘sql%‘;

NAME ISSES ISSYS_MOD

---------------------------------------- ----- ---------

sql_trace TRUE IMMEDIATE

sql92_security FALSE FALSE

sql_version TRUE FALSE

sqltune_category TRUE IMMEDIATE

-- TURE:可以該類型修改,FLASE:不支持該類型修改,IMMEDIATE:也是支持該類型修改

SQL> alter system set sql_version = 8; /*不支持system類型修改*/

alter system set sql_version = 8

*

ERROR at line 1:

ORA-02096: specified initialization parameter is not modifiable with this option

SQL> alter session set sql_version = 8;

ERROR:

ORA-00096: invalid value 8 for parameter sql_version, must be from among MAX,

NATIVE, 8.1.6, 8.1.5

SQL> alter session set sql_version = ‘8.1.6‘; /*支持session類型修改*/

Session altered.

SQL> select distinct issys_modifiable from v$parameter;

ISSYS_MOD

---------

IMMEDIATE /*動態參數,直接修改到內存的參數alter system set <> = <>,後面不需要跟scope*/

FALSE /*靜態參數,不能直接修改到內存,alter system set <> = <> scope = spfile*/

DEFERRED /*會話級別參數,直接通過alter session set <> = <>*/

SQL> select distinct isses_modifiable from v$parameter;

ISSES

-----

TRUE

FALSE

--系統中的常用參數:

SQL> ho ls /u01/app/oracle/10g/dbs/

hc_orcl.dat initdw.ora lkORCL spfileorcl.ora

init.ora initorcl.ora orapworcl

SQL> ho cat /u01/app/oracle/10g/dbs/initorcl.ora

/*下面的參數描述了實例相關池的分配情況*/

orcl.__db_cache_size=251658240

orcl.__java_pool_size=4194304

orcl.__large_pool_size=4194304

orcl.__shared_pool_size=142606336

orcl.__streams_pool_size=0

*.audit_file_dest=‘/u01/app/oracle/admin/orcl/adump‘ /*警告日誌路徑*/

*.background_dump_dest=‘/u01/app/oracle/admin/orcl/bdump‘ /*後臺進程日誌路徑*/

*.compatible=‘10.2.0.1.0‘ /*版本兼容號*/

/*下面是控制文件的信息*/

*.control_files=‘/u01/app/oracle/oradata/orcl/control01.ctl‘,‘/u01/app/oracle/oradata/orcl/control02.ctl‘,‘/u01/app/oracle/oradata/orcl/control03.ctl‘

*.core_dump_dest=‘/u01/app/oracle/admin/orcl/cdump‘ /*服務器進程相關的日誌路徑*/

*.db_block_size=8192 /*內存塊的大小*/

*.db_create_file_dest=‘/u01/app/oracle/oradata/orcl‘ /*tablespace ,datafile路徑*/

*.db_create_online_log_dest_1=‘/u01/app/oracle/disk1‘ /*聯機日誌文件路徑*/

*.db_create_online_log_dest_2=‘/u01/app/oracle/disk2‘ /*聯機日誌文件路徑*/

*.db_domain=‘‘ /域名/

*.db_file_multiblock_read_count=16 /*一次可讀取塊的大小:*8k = 128kb*/

*.db_name=‘orcl‘ /數據庫標識符/

*.db_recovery_file_dest=‘/u01/app/oracle/flash_recovery_area‘ /*閃回路徑*/

*.db_recovery_file_dest_size=2147483648 /*閃回區可使用的大小GB*/

*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=orclXDB)‘ /*共享服務器的配置參數*/

*.job_queue_processes=10 /*當前作業進程數*/

*.open_cursors=600 /*可打開的遊標數*/

*.pga_aggregate_target=135266304 /*服務器進程大小*/

*.processes=250 /*描述當前可以運行的進程數*/

*.remote_login_passwordfile=‘EXCLUSIVE‘ /*遠程登陸是否要用密碼文件*/

*.sga_target=406847488 /*定義了sga的大小*/

*.undo_management=‘AUTO‘ /*Undo表空間的管理方式為自動管理*/

*.undo_tablespace=‘UNDOTBS1‘ /*指定使用哪一個undo表空間*/

*.user_dump_dest=‘/u01/app/oracle/admin/orcl/udump‘ /**/

--11g中的參數文件:

-- 隱藏參數:

SQL> desc x$ksppi /*Name列中為隱藏參數的名字*/

Name Null? Type

----------------------------------------- -------- ----------------------------

ADDR RAW(4)

INDX NUMBER

INST_ID NUMBER

KSPPINM VARCHAR2(80)

KSPPITY NUMBER

KSPPDESC VARCHAR2(255)

KSPPIFLG NUMBER

KSPPILRMFLG NUMBER

KSPPIHASH NUMBER

--下面視圖中為隱藏參數的值

SQL> desc x$ksppcv

Name Null? Type

----------------------------------------- -------- ----------------------------

ADDR RAW(4)

INDX NUMBER

INST_ID NUMBER

KSPPSTVL VARCHAR2(512)

KSPPSTDVL VARCHAR2(512)

KSPPSTDF VARCHAR2(9)

KSPPSTVF NUMBER

KSPPSTCMNT VARCHAR2(255)

--使用下面的命令來查看系統中的隱藏參數;

SQL> select ksppinm,ksppstvl from x$ksppi a,x$ksppcv b where a.indx = b.indx;

SQL> a and ksppinm like ‘%_allow%‘;

1* select ksppinm,ksppstvl from x$ksppi a,x$ksppcv b where a.indx = b.indx and ksppinm like‘%_allow%‘

SQL> /

KSPPINM KSPPSTVL

---------------------------------------- ----------

_allow_level_without_connect_by FALSE

_asm_allow_only_raw_disks TRUE

_asm_allow_resilver_corruption FALSE

/*

參數的刪除:

對於pfile直接編輯刪除即可

對於spfile 例如使用alter system set pga_aggregate_target reset將恢復到默認值 */

SQL> show parameter pga

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

pga_aggregate_target big integer 130M

SQL> alter system reset pga_aggregate_target scope = spfile sid = ‘*‘;

System altered.

-- 修改會默認值後重新啟動可以看到該參數的值由M變為M

SQL> show parameter pga;

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

pga_aggregate_target big integer 76M

Oracle 參數文件