Oracle 修改数据库基本参数
Oracle 通過ALTER SYSTEM語句修改數據庫參數,其語法:
ALTER?SYSTEM?SET?<parameter_name>=<value>?scope=[?memory?|?spfile?|?both?]?[sid=<sid_name>]SCOPE表示應用的范圍,分成三種
memeory:只在當前實例中修改生效,重啟后失效(內存中)
spfile:只在服務參數文件中修改,不重啟不生效(物理文件中)
both:在內存和物理文件中同時修改,立即生效且永久保存修改之。
?
在RAC環境中需要指定SID來指明需要修改的實例名稱。
?
修改某個系統參數并查看該語句實際的執行效果
范例:
SQL>?alter?system?set?sql_trace=true; System?altered. SQL>?alter?database?open; Database?altered. SQL>?alter?system?set?db_cache_advice=off?scope=memory; System?altered. SQL>?show?parameter?db_cache_advice NAME?????????????????????????????????TYPE??????????????????????????????VALUE ------------------------------------?---------------------------------?------------------------------ db_cache_advice??????????????????????string????????????????????????????OFFWarning: Switching off db_cache_advice with sga_target on is not recommended
ALTER SYSTEM SET db_cache_advice='OFF' SCOPE=MEMORY;
重啟數據庫后觀察該參數被自動還原
SQL>?show?parameter?db_cache_advice NAME?????????????????????????????????TYPE??????????????????????????????VALUE ------------------------------------?---------------------------------?------------------------------ db_cache_advice??????????????????????string????????????????????????????ON繼續修改該參數,并且應用范圍修改為spfile,觀察發現當前實例下并未生效。
SQL>?alter?system?set?db_cache_advice=off?scope=spfile; System?altered. SQL>?show?parameter?db_cache_advice NAME?????????????????????????????????TYPE??????????????????????????????VALUE ------------------------------------?---------------------------------?------------------------------ db_cache_advice??????????????????????string????????????????????????????ON SQL>?startup?force ORA-32004:?obsolete?or?deprecated?parameter(s)?specified?for?RDBMS?instance ORACLE?instance?started. Total?System?Global?Area?6680915968?bytes Fixed?Size??????????????????2213936?bytes Variable?Size????????????3758098384?bytes Database?Buffers?????????2885681152?bytes Redo?Buffers???????????????34922496?bytes Database?mounted. Database?opened. SQL>?show?parameter?db_cache_advice NAME?????????????????????????????????TYPE??????????????????????????????VALUE ------------------------------------?---------------------------------?------------------------------ db_cache_advice??????????????????????string????????????????????????????OFF?可以看到該參數值重啟后發生改變,另上面出現一個ORA報錯,說死過期和被棄用的參數,日志提示
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
視乎不是這個參數導致的,查看網上說是log_archive_start參數,在10G以后數據庫通過alter database archivelog自動開啟歸檔進程,而棄用該參數。
SQL>?col?name?for?a30 SQL>?col?value?for?a30 SQL>?select?name,value,isdeprecated?from?v$parameter?where?name?like?'%log_archive_start'; NAME???????????????????????????VALUE??????????????????????????ISDEPRECATED ------------------------------?------------------------------?--------------- log_archive_start??????????????FALSE??????????????????????????TRUE SQL>?startup?force ORA-32004:?obsolete?or?deprecated?parameter(s)?specified?for?RDBMS?instance SQL>?alter?system?reset?log_archive_start?scope=spfile; System?altered. SQL>?startup?force ORACLE?instance?started.SQL>?alter?database?archivelog;修改后發現不對,思考了下該錯誤是我在開始SQL_TRACE后發生的。那么我們先看看當前有哪些參數是被棄用的
SQL>?select?name,?value?from?v$parameter?where?isdeprecated='TRUE'; NAME????????????????????????????????VALUE -----------------------------------?--------------- ...... commit_write sql_trace???????????????????????????TRUE SQL>?alter?system?set?sql_trace=false?scope=both; System?altered. SQL>?startup?force SQL>?alter?system?reset?sql_trace?scope=spfile; SQL>?shutdown?immediate SQL>?startup?好了報錯問題解決了。同時實驗結束。
?
另外如果錯誤的修改了spfile,可以在關閉服務的情況下,可以修改pfile中的參數,在通過pfile生成spfile文件:
SQL>?startup?nomount?pfile='/DBBK/oracle/product/11.2.0.1.0/dbs/initorcl.ora' ORACLE?instance?started. Total?System?Global?Area?6680915968?bytes Fixed?Size??????????????????2213936?bytes Variable?Size????????????3758098384?bytes Database?Buffers?????????2885681152?bytes Redo?Buffers???????????????34922496?bytes SQL>?show?parameter?pfile NAME????????????????????????????TYPE???????????????????????????????VALUE -------------------------------?--------------------------------?------------------------------ spfile???????????????????????????????string SQL>?create?spfile?from?pfile; File?created. SQL>?create?pfile?from?spfile; File?created.spfile之前的博客中也提到過時一個二進制文件,因此盡量不要用工具直接編輯該文件,以免照成破壞導致無法啟用數據庫的狀況。
?
上面范例中我還提到一個重置系統參數值得命令:
alter?system?reset?<parameter>?scope=[?memory?|?spfile?|?both?]?sid=<?sid_name?|?*?> 該命令通常用于修改RAC環境中,也可以在單實例中使用,其目的是從spfile中去除某個參數值SQL>?startup?mount?pfile='/DBBK/oracle/product/11.2.0.1.0/dbs/initorcl.ora' ORACLE?instance?started. Total?System?Global?Area?6680915968?bytes Fixed?Size??????????????????2213936?bytes Variable?Size????????????3758098384?bytes Database?Buffers?????????2885681152?bytes Redo?Buffers???????????????34922496?bytes Database?mounted.啟動后有兩種方式確認是否讀取的pfile文件參數,查詢v$spparameter視圖確認服務參數值,或者用show parameter命令。實際上show parameter命令也是在查該視圖。之前的博客已展示過show parameter 實際調用的語句
SQL>?select?count(*)?from?v$spparameter?where?value?is?not?null;COUNT(*) ----------0 SQL>?show?parameter?spfile NAME?????????????????????????????????TYPE??????????????????????????????VALUE ------------------------------------?---------------------------------?------------------------------ spfile???????????????????????????????string 其他方法,通過ISSPECIFIED(表示是否被SPFILE引用的參數)字段判斷 SQL>?select?decode(count(*),1,'spfile','pfile')?USE?from?v$spparameter?where?isspecified='TRUE'; --下面的語句,如果查詢TRUE為空也表明使用的是pfile文件 select?isspecified,count(*)?from?v$spparameter?group?by?isspecified;如果使用的是默認spfile啟動的結果
SQL>?select?count(*)?from?v$spparameter?where?value?is?not?null;COUNT(*) ----------27 SQL>?show?parameter?spfile; NAME?????????????????????????????????TYPE????????VALUE ------------------------------------?-----------?------------------------------ spfile???????????????????????????????string??????/u01/oracle/product/11.2.0.3.0/dbs/spfilesss.ora?
轉載于:https://blog.51cto.com/onlinekof2001/1608268
總結
以上是生活随笔為你收集整理的Oracle 修改数据库基本参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: log4j和logback的冲突导致日志
- 下一篇: 源码安装 vim