RAC 環境下引數檔案(spfile)管理
阿新 • • 發佈:2019-02-20
RAC環境下,初始化引數檔案與但例項下引數檔案有些異同,主要表現在初始化引數可以為多個例項公用,也可以單獨設定各個例項的初始化引數。對於那些非共用的初始化引數則必須要單獨設定,而共用的則可以單獨設定,但一般不建議這麼用。本文描述RAC 環境下引數檔案(spfile)的相關管理工作。
有關RAC環境下的重要引數描述,請參考:RAC 環境下重要引數
1、引數檔案的位置 SQL> show parameter instance_name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ instance_name string ora10g1 SQL> show parameter spfile; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string +DG1/ora10g/spfileora10g.ora SQL> show parameter instance_name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ instance_name string ora10g2 SQL> show parameter spfile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string +DG1/ora10g/spfileora10g.ora SQL> show parameter cluster NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ cluster_database boolean TRUE cluster_database_instances integer 2 oracle@bo2dbp:~> cd /u01/oracle/admin/ora10g oracle@bo2dbp:/u01/oracle/admin/ora10g> ls adump bdump cdump dpdump hdump pfile udump oracle@bo2dbp:/u01/oracle/admin/ora10g> cd pfile oracle@bo2dbp:/u01/oracle/admin/ora10g/pfile> ls -hltr total 4.0K -rw-r----- 1 oracle oinstall 2.7K 2012-09-27 12:12 init.ora.8272012121245 oracle@bo2dbp:/u01/oracle/admin/ora10g/pfile> cd $ORACLE_HOME/dbs oracle@bo2dbp:/u01/oracle/db/dbs> ls *.ora init+ASM1.ora initdw.ora initGOBO1A_tmp.ora initGOBO4A.ora init.ora initora10g1.ora oracle@bo2dbp:/u01/oracle/db/dbs> more initora10g1.ora SPFILE='+DG1/ora10g/spfileora10g.ora' oracle@bo2dbs:/u01/oracle/db/dbs> more initora10g2.ora SPFILE='+DG1/ora10g/spfileora10g.ora' #由上面的查詢可知RAC環境下的引數檔案通常都存放在RAW或者ASM中,預設路徑為$ORACLE_HOME/dbs/init{ORACLE_SID}.ora #各個例項只是存放pfile檔案,pfile檔案的內容是指向spfile檔案的位置,即告訴,兄弟,你去xx去找那個spfile吧,哈哈,,, #注,Oracle資料庫啟動時會先找spfile${ORACLE_SID.ora},如果對應的spfile不存在則找spfile.ora #如果spfile.ora找不到,則找相應的pfile(init{ORACLE_SID}.ora) #那,要是都找不到呢,那就是用預設的init.ora嘗試啟動例項 2、引數檔案的備份 引數檔案備份的方式有很多種,一般情況下當啟用了RMAN自動備份控制檔案時,會自動備份引數檔案。 其次是手工備份引數檔案,這種方式通常是將spfile內容轉換為pfile,說簡單點,轉為文字檔案儲存,檔名任意。 建議在修改引數檔案之前先手工備份引數檔案,使用命令: create pfile=['<dir>'] from spfile; 注,單例項情形下,如果使用spfile檔案啟動例項,可以通過上面的方式直接備份,RAC環境下這麼幹,那就把pfile檔案給覆蓋了 因此,RAC環境下建議為pfile檔案指定不同的檔名。如當前為initora10g1.ora,則可以指定為initora10g1.ora.bak SQL> create pfile='/u01/oracle/db/dbs/initora10g1.ora.bak' from spfile; File created. SQL> ho ls /u01/oracle/db/dbs/*ora10g* /u01/oracle/db/dbs/hc_ora10g1.dat /u01/oracle/db/dbs/initora10g1.ora.bak /u01/oracle/db/dbs/initora10g1.ora /u01/oracle/db/dbs/orapwora10g1 SQL> ho more /u01/oracle/db/dbs/initora10g1.ora.bak ora10g2.__db_cache_size=142606336 ora10g1.__db_cache_size=163577856 ora10g1.__java_pool_size=4194304 ora10g2.__java_pool_size=4194304 ora10g1.__large_pool_size=4194304 ora10g2.__large_pool_size=4194304 ora10g2.__shared_pool_size=180355072 ora10g1.__shared_pool_size=159383552 ora10g1.__streams_pool_size=0 ora10g2.__streams_pool_size=0 *.audit_file_dest='/u01/oracle/admin/ora10g/adump' *.background_dump_dest='/u01/oracle/admin/ora10g/bdump' *.cluster_database_instances=2 *.cluster_database=true *.compatible='10.2.0.3.0' *.control_files='+DG2/ora10g/controlfile/current.286.795096347', '+REV/ora10g/controlfile/current.295.795096347' *.core_dump_dest='/u01/oracle/admin/ora10g/cdump' *.db_block_size=8192 *.db_create_file_dest='+DG2' *.db_domain='' *.db_file_multiblock_read_count=16 *.db_name='ora10g' *.db_recovery_file_dest='+REV' *.db_recovery_file_dest_size=2147483648 *.dispatchers='(PROTOCOL=TCP) (SERVICE=ora10gXDB)' ora10g2.instance_number=2 ora10g1.instance_number=1 *.job_queue_processes=10 ora10g1.local_listener='local_lsnr_ora10g1' ora10g2.local_listener='local_lsnr_ora10g2' *.open_cursors=300 *.pga_aggregate_target=112197632 *.processes=150 *.remote_listener='REMOTE_LSNR_ORA10G' *.remote_login_passwordfile='exclusive' *.sga_target=337641472 ora10g2.thread=2 ora10g1.thread=1 *.undo_management='AUTO' ora10g2.undo_tablespace='UNDOTBS2' ora10g1.undo_tablespace='UNDOTBS1' *.user_dump_dest='/u01/oracle/admin/ora10g/udump' 對於上面的引數檔案裡列出的資訊,如果引數前面帶有星號,則表明當前的引數為共用引數,前面有例項名的則為例項引數 3、引數檔案的修改 引數檔案中引數修改方式如下: alter system|session set parametername = values scope = memory | spfile |both sid = 'sid' | ‘*’; scope memory : 只對當前有效,下次啟動則失效 spfile : 只對spfile 修改,必須經過下一次啟動才生效,當前的例項沒有修改 both :記憶體與引數檔案都將修改,當不指定scope時,預設為both. system | session system : system級別有效,影響整個系統及所有使用者 session : 僅當前session有效,一旦退出之後將實效 'sid' | ‘*’ 這個在RAC環境下使用的較為頻繁,指定sid_name則當前指定的例項生效,如果指定 '*',則所有例項生效 注,預設情況下為sid='*',因此修改是不要忘了,如果沒有指定sid,則RAC上的所有例項都會被修改 下面是修改示例 SQL> show parameter instance_name NAME TYPE VALUE ------------------------------------ ----------- ------------------- instance_name string ora10g1 SQL> show parameter pga NAME TYPE VALUE ------------------------------------ ----------- ------------------- pga_aggregate_target big integer 107M SQL> alter system set pga_aggregate_target=100m scope=both sid='ora10g1'; -->將ora10g1的pga改為100m System altered. SQL> alter system set pga_aggregate_target=90m sid='ora10g2'; -->將ora10g2的pga改為90m System altered. SQL> show parameter pga -->當前的pga已經被改為100m NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ pga_aggregate_target big integer 100M SQL> conn system/oracle@ora10g2 -->連線到例項 ora10g2 Connected. SQL> show parameter instance_name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ instance_name string ora10g2 SQL> show parameter pga -->此時pga的值顯示為90m NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ pga_aggregate_target big integer 90M SQL> create pfile='/u01/oracle/db/dbs/initora10g1.ora.emp' from spfile; create pfile='/u01/oracle/db/dbs/initora10g1.ora.emp' from spfile * ERROR at line 1: ORA-01031: insufficient privileges -->缺乏許可權,因為當前連線的是instance ora10g2 SQL> conn system/oracle@ora10g1 Connected. SQL> create pfile='/u01/oracle/db/dbs/initora10g1.ora.tmp' from spfile; File created. SQL> ho cat /u01/oracle/db/dbs/initora10g1.ora.tmp |grep pga *.pga_aggregate_target=112197632 #新的pfile檔案中同時存在pga的值 ora10g1.pga_aggregate_target=104857600 #有兩個指定了例項名,此時誰生效呢?我們前面已經查詢出了結果 ora10g2.pga_aggregate_target=94371840 #同一引數,有例項名的值將優先有帶*的引數值 SQL> alter system reset pga_aggregate_target sid='ora10g1';-->使用reset方式重置pga,或恢復預設值 -->如果需要保留兩個新改的引數,建議reset之前的共用引數以避免混淆 System altered. -->在reset原來的引數時,不指定sid或sid='*' SQL> show parameter pga NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ pga_aggregate_target big integer 100M SQL> conn system/oracle@ora10g2 Connected. SQL> alter system reset pga_aggregate_target sid='ora10g2'; System altered. #Author : Robinson #Blog : http://blog.csdn.net/robinson_0612 SQL> show parameter pga NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ pga_aggregate_target big integer 90M oracle@bo2dbp:~> srvctl stop instance -d ora10g -i ora10g1 oracle@bo2dbp:~> srvctl start instance -d ora10g -i ora10g1 SQL> show parameter instance_name NAME TYPE VALUE ------------------------------------ ----------- ------------------- instance_name string ora10g1 SQL> show parameter pga NAME TYPE VALUE ------------------------------------ ----------- ------------------- pga_aggregate_target big integer 107M 4、spfile檔案位置的修改 SQL> show parameter spfile; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string +DG1/ora10g/spfileora10g.ora SQL> create spfile='+REV/ORA10G/spfileora10g.ora' 2 from pfile='/u01/oracle/db/dbs/initora10g1.ora.bak'; File created. SQL> ho echo "spfile='+REV/ORA10G/spfileora10g.ora'" >/u01/oracle/db/dbs/initora10g1.ora SQL> ho more /u01/oracle/db/dbs/initora10g1.ora spfile='+REV/ORA10G/spfileora10g.ora' SQL> startup force; SQL> show parameter spfile; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string +REV/ora10g/spfileora10g.ora SQL> shutdown immediate; SQL> exit oracle@bo2dbp:~> ssh bo2dbs Last login: Fri Sep 28 15:42:59 2012 from 192.168.1.108 oracle@bo2dbs:~> echo "spfile='+REV/ORA10G/spfileora10g.ora'" >/u01/oracle/db/dbs/initora10g2.ora oracle@bo2dbs:~> srvctl stop database -d ora10g oracle@bo2dbs:~> srvctl start database -d ora10g oracle@bo2dbs:~> export ORACLE_SID=ora10g2 oracle@bo2dbs:~> sqlplus / as sysdba SQL> show parameter pfile; -->檢視時還是使用之前的spfile檔案 NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string +DG1/ora10g/spfileora10g.ora oracle@bo2dbs:~> srvctl config database -d ora10g -a bo2dbp ora10g1 /u01/oracle/db bo2dbs ora10g2 /u01/oracle/db DB_NAME: ora10g ORACLE_HOME: /u01/oracle/db SPFILE: +DG1/ora10g/spfileora10g.ora DOMAIN: null DB_ROLE: null START_OPTIONS: null POLICY: AUTOMATIC ENABLE FLAG: DB ENABLED #下面將引數檔案路徑更新到ocr,此時資料庫並未shutdown,生產環境建議先停止資料庫然後再修改 oracle@bo2dbs:~> srvctl modify database -d ora10g -p '+REV/ORA10G/spfileora10g.ora' oracle@bo2dbs:~> srvctl stop database -d ora10g oracle@bo2dbs:~> srvctl config database -d ora10g -a bo2dbp ora10g1 /u01/oracle/db bo2dbs ora10g2 /u01/oracle/db DB_NAME: ora10g ORACLE_HOME: /u01/oracle/db SPFILE: +REV/ORA10G/spfileora10g.ora DOMAIN: null DB_ROLE: null START_OPTIONS: null POLICY: AUTOMATIC ENABLE FLAG: DB ENABLED oracle@bo2dbs:~> srvctl start database -d ora10g oracle@bo2dbs:~> sqlplus / as sysdba SQL> show parameter spfile; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string +REV/ora10g/spfileora10g.ora #使用srvctl start啟動時,不會依賴類似於單例項環境或rac環境下的sqlplus啟動資料庫時按順序尋找spfile檔案, #而是直接根據ocr中spfile檔案位置啟動資料庫。
更多參考