Knight of the round table

          wansong

          ORACLE DBA

          *=========================================================================*/
          /*            顯示最近被改動的10個文件               */
          /*=========================================================================*/
          ls -alt|head
          /*=========================================================================*/
          /*            把Oracle的SGA釘在內存中               */
          /*=========================================================================*/
          HP-UX AND LINUX AS 3
          LOCK_SGA = TURE
          SUN Solaris
          USE_ISM=TRUE

          /*=========================================================================*/
          /*         匯出數據庫成文件                 */
          /*=========================================================================*/
          exp userid=arms/arms@arms owner=arms file=(arms_1123-1.dmp,arms_1123-2.dmp,
          arms_1123-3.dmp,arms_1123-4.dmp,arms_1123-5.dmp,arms_1123-6.dmp,arms_1123-7.dmp)
           filesize=2GB log=arms_1123.log

          imp armsetl/armsetl fromuser=armsetl touser=armsetl rows=y indexes=n
          commit=y buffer=65536 feedback=100000 ignore=n volsize=0
          file=exp_icd.dmp
          --oracle10g中匯入需要system用戶做匯入動作
          imp userid=sys/sys@ARMS fromuser=ARMS  touser=ARMSETL file=(arms_1123-1.dmp,arms_1123-2.dmp,
          arms_1123-3.dmp,arms_1123-4.dmp,arms_1123-5.dmp) filesize=2GB  COMMIT=Y log=ARMSETL.log

          E:\export>imp userid=system/arms@arms fromuser=arms touser=armsetl tables=VW_PAY
          MNTRESP indexes=n ignore=y file=VW_PAYMNTRESP.dmp filesize=2GB log=VW_PAYMNTRESP
          _imp.log

          D:\ARMS_EXP>exp userid=arms/arms@arms tables=VW_PAYMNTRESP direct=y file=VW_PAYM
          NTRESP.dmp filesize=2GB log=VW_PAYMNTRESP.log

          /*=========================================================================*/
          /*         查看消耗CPU的百分比                 */
          /*=========================================================================*/
          RHORA*ORA-/etc>ps auxgw|sort +2 |tail
          oracle   14482  0.0  3.9 303796 20068 ?      S    17:09   0:01 oracleORA (LOCAL=NO)
          oracle   14184  0.0  5.1 303132 26188 ?      S    11:58   0:01 ora_smon_ORA
          oracle   14305  0.0  5.9 303280 30208 ?      S    15:08   0:04 oracleORA (LOCAL=NO)
          oracle   14216  0.0  6.3 305588 32440 ?      S    12:04   0:10 oracleORA (LOCAL=NO)
          oracle   14180  0.1  0.8 308684 4248 ?       S    11:58   0:29 ora_lgwr_ORA
          oracle   14178  0.2  7.5 305536 38748 ?      S    11:58   0:50 ora_dbw0_ORA
          oracle   14512 14.1 11.2 309252 57364 ?      S    18:05   3:25 oracleORA (LOCAL=NO)
          oracle   14289  2.0 12.9 305088 65976 ?      S    13:51   5:44 oracleORA (LOCAL=NO)
          oracle   14226  2.3  3.1 305868 16116 ?      S    12:09   8:47 oracleORA (LOCAL=NO)
          USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND

          /*=========================================================================*/
          /*         查看消耗CPU最長時間的進程                 */
          /*=========================================================================*/
          RHORA*ORA-/etc>ps -ef |grep oracle|sort +6|tail
          sort 按第六排排序....
          tail顯示輸出后的多少行.默認為前10行
          /*=========================================================================*/
          /*          更改字符集問題解決詳細請見本人BLOG                    */
          /*=========================================================================*/
          select userenv('language') from dual;
          SIMPLIFIED CHINESE_CHINA.ZHT16BIG5
          SIMPLIFIED CHINESE_CHINA.WE8ISO8859P1
          SQL> ALTER DATABASE CHARACTER SET ZHT16BIG5;
          ALTER DATABASE CHARACTER SET ZHT16BIG5
          *
          ERROR at line 1:
          ORA-12712: new character set must be a superset of old character set
          使用平常的這種方式是不可以更改數據庫字符集的.
          改了字符集后
          SQL> conn / as sysdba;
          ERROR:
          ORA-12705: invalid or unknown NLS parameter value specified
          解決辦法:
          export NLS_LANG=CHINESE_CHINA.ZHT16BIG5
          當服務器客戶機無法登錄;
          /*=========================================================================*/
          /*          表空間文件丟失問題解決                    */
          /*=========================================================================*/
          SQL> startup
          ORACLE instance started.

          Total System Global Area  236000356 bytes
          Fixed Size                   451684 bytes
          Variable Size             201326592 bytes
          Database Buffers           33554432 bytes
          Redo Buffers                 667648 bytes
          Database mounted.
          ORA-01122: database file 18 failed verification check
          ORA-01110: data file 18: '/opt/oracle/product/9.2.0/dbs/LHB.DAT'
          ORA-01251: Unknown File Header Version read for file number 18
          問題如上所示:沒有辦法找到LHB.DAT
          1.SQL> startup mount
          ORACLE instance started.
          Total System Global Area  236000356 bytes
          Fixed Size                   451684 bytes
          Variable Size             201326592 bytes
          Database Buffers           33554432 bytes
          Redo Buffers                 667648 bytes
          Database mounted.
          SQL> alter database datafile '/opt/oracle/product/9.2.0/dbs/LHB.DAT' offline drop;
          Database altered.
          SQL> alter database open;
          Database altered.
          SQL>

          /*=========================================================================*/
          /*          修改global_name                     */
          /*=========================================================================*/
          conn / as sysdba
          update props$ set value$ = 'oradb' where name = 'GLOBAL_DB_NAME';
          commit;
          shutdown immediate
          startup
          之后再創建dblink即不帶域名。


          grant connect to arms
          /*=========================================================================*/
          /*          TO_DATE函數問題解決.                     */
          /*=========================================================================*/
          select OHDUEDATE,to_date(lhb.OHDUEDATE,'dd/mm/yy') from lhb --寫錯了這樣的一個格式,害得我花了半天的時間
          最終總結,要看清格式這點很重要:to_date/'dd/月/yy')...這種方式.'dd/mon/yy'這樣解決問題;

          /*=========================================================================*/
          /*              不斷顯示輸出新的行                       */
          /*=========================================================================*/
          tail -f logfile.log


          /*=========================================================================*/
          /*              設置ORACLE下的ksh命令提示符                       */
          /*=========================================================================*/
          export PS1="`hostname`*\${ORACLE_SID}-\${PWD}>"

          /*=========================================================================*/
          /*               強制在UNIX下關閉ORACLE進程                       */
          /*=========================================================================*/
           ps -ef |grep "ora_"|grep -v grep|awk '{print $2}' |xargs kill -9
           shutdown abort

          /*=========================================================================*/
          /*               db_block_size                       */
          /*=========================================================================*/
          show parameter db_block_size     (高速緩存區(Database Buffer Cache))
          每個表空間可以建立不同的DB_BLOCK_SIZE     說明:8k的高速緩存通過DB_8K_CACHE_SIZE
          參數來設定的.
          share pool 存儲數據字典高速緩存
          當share pool裝滿時,最近最少使用的執行路徑和分析樹將從庫高速緩存中刪除,以便為新的
          項騰出空間.

           

          /*=========================================================================*/
          /*                oracle 9.2.4+linux啟動與關閉相關                         */
          /*=========================================================================*/
          linux+oracle 9.2.4 的啟動方法與原來oracle 8.1.7的啟動方式有些不同
          方式為:
          [oracle@RHORA oracle]$ sqlplus /nolog
          SQL*Plus: Release 9.2.0.4.0 - Production on Wed Nov 8 17:24:47 2006
          Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
          SQL> conn / as sysdba
          Connected.
          SQL> startup
          關閉就改為shutdown immediate;

          LRM-00109: could not open parameter file '/opt/oracle/product/9.2.0/dbs/initORCL.ora'
          把initORA.ora拷貝過去就可以使用了.

          ORA-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'
          把密碼文件拷貝過去就可以啟動了.
          ORA-27037: unable to obtain file status
          Linux Error: 2: No such file or directory
          Additional information: 3

          /*=========================================================================*/
          /*                    utl_file的相關問題                        */
          /*=========================================================================*/
          查找導出路徑:show parameter utl_file_dir     -oracle 8i 可以直接更改初始參數文
          件而后重新啟動數據庫就可以保存;
          alter system set utl_file_dir='\home\oracle' scope=spfile;   更改9i的版本可以這樣更改
          注上面只能更改到spfile(也是所說的內存).要更改到pfile 請從pfile------spfile
          呵呵.

          startup mount;
          recover database until cancel;
          alter database open resetlogs;
          /*=========================================================================*/
          /*                     檢查剩余表空間                        */
          /*=========================================================================*/
          SELECT tablespace_name, sum ( blocks ) as free_blk , 
           
          trunc ( sum ( bytes ) /(1024*1024) ) as free_m, 
           
          max ( bytes ) / (1024) as big_chunk_k, count (*) as num_chunks 
           
          FROM dba_free_space GROUP BY tablespace_name;

          /*=========================================================================*/
          /*                      JOB按時間去執行存儲過程                            */
          /*=========================================================================*/
          DECLARE
            X NUMBER;
          BEGIN
            SYS.DBMS_JOB.SUBMIT
              ( job       => X
               ,what      => 'ARMS1.SP_OUTPUT_COL_CUST_PAY;'
               ,next_date => to_date('26-10-2006 20:09:06','dd/mm/yyyy hh24:mi:ss')
               ,interval  => 'TRUNC(LAST_DAY(SYSDATE)) + 1 + 1/24 + 30/1440'
               ,no_parse  => TRUE
              );
            SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
          END;
          /
          commit;
          午夜12點....TRUNC(SYSDATE+1)  
          第二天凌晨一點整 ...TRUNC(LAST_DAY(SYSDATE)) + 1 + 1/24
          如還要在后面加分鐘,可以繼續

          /*=========================================================================*/
          /*                      建立常用輸出包                                  */
          /*=========================================================================*/
          CREATE OR REPLACE Package PKG_APBT  As

              type Type_Ret_Curs is ref Cursor;

              msg_0 CONSTANT VARCHAR2(100) := '執行成功!';
              msg_1 CONSTANT VARCHAR2(100) := '執行失敗!';
              msg_2 CONSTANT VARCHAR2(100) := '沒有該紀錄!';
              msg_3 CONSTANT VARCHAR2(100) := '主鍵已經存在!';
              msg_4 CONSTANT VARCHAR2(100) := '長度太長!';
              msg_5 CONSTANT VARCHAR2(100) := '輸入參數不能為空!';
              msg_6 CONSTANT VARCHAR2(100) := '沒有數據!';
              msg_7 CONSTANT VARCHAR2(100) := '用戶不存在!';
              msg_9 CONSTANT VARCHAR2(100) := '輸入參數不正確!';
          End;
          /

          /*=========================================================================*/
          /*                      建日志表                                  */
          /*=========================================================================*/
          CREATE TABLE LOGDATA
          (
            LOG_DATE    VARCHAR2(20)     DEFAULT to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') NOT NULL,
            OPERATOR    VARCHAR2(50),
            LOG_TYPE    CHAR(1),
            USER_TABLE  VARCHAR2(50),
            INFO        VARCHAR2(4000),
            SYS_TYPE    NUMBER(1)   DEFAULT 0     NOT NULL
          )
          /*=========================================================================*/
          /*                      建立同義詞并使用                                   */
          /*=========================================================================*/
          我們先看如下的一系列執行:

          SQL> create or replace view v_bmw_pay_online_new as
            2  select *
            3  from taobao.bmw_pay_online_new@lnk_db215;
           
          SQL> create or replace procedure sp_v_test is
            2  v_id number;
            3  begin
            4     select id into v_id from v_bmw_pay_online_new where id=1;
            5  end;
            6  /

          Procedure created

          SQL> create or replace synonym s_bmw_pay_online_new
            2        for taobao.bmw_pay_online_new@lnk_db215;

          Synonym created

          SQL> create or replace procedure sp_s_test is
            2  v_id number;
            3  begin
            4     select id into v_id from s_bmw_pay_online_new where id=1;
            5  end;
            6  /

          Warning: Procedure created with compilation errors

          SQL> show error
          Errors for PROCEDURE TAOBAO.SP_S_TEST:

          LINE/COL ERROR
          -------- ------------------------------------------------------------------------------------
          4/29     PL/SQL: ORA-00600: 內部錯誤代碼,參數: [17069], [0x57E77854], [], [], [], [], [], []
          4/4      PL/SQL: SQL Statement ignored


          可以看到,在同樣一個遠程對象上面,我可以通過創建視圖,然后在該視圖上創建存儲過程,是沒有任何問題的,
          但是如果我對該遠程操作做一個同義詞,再在同義詞上創建存儲過程,則報出了Ora-00600。跟蹤也無果,
          看產生的日志文件也不能看出來什么,上metalink,搜索"ora-00600 17069",發現查出現的東西一大堆,
          大致是library cache錯誤,但是到底怎么會產生這個錯誤呢,online聯系上一個oracle在線技術支持,聊了一會兒,
          問題是解決了,但是他就是不承認是bug,呵呵。

          以下是聊天的總結:
          ORA-00600 [17069] reorted on compiling a procedure.

          Invalid lock in library cache.
          Unable to pin the object and hence the Error.

          <Note:39616.1> "Failed to pin a library cache object after 50 attempts"

          Clearing the shared memory will help to get rid of inconsistant information
          in memory which is causing the error.

          The inconsistency was suspected to be in the remote site. But flushing the
          shared pool in remote location didnt help.Tried recreation of the procedure
          after dropping and recreating the synonym in the local database. But the
          same failed.Flushed the shared pool in local database abd successfully
          created the procedure.

          alter system flush share_pool;

          /*=========================================================================*/
          /*                      建立同義詞并使用                                   */
          /*=========================================================================*/
          create synonym synonym_name for table_name@db_link;
          select * from table_name;

          /*=========================================================================*/
          /*                      建立DB-LINK連接并使用                              */
          /*=========================================================================*/
          設置之前請設置alter system set global_names = false
          create public database link db_link
          connect to user identified by pwd
          using 'connect string';
          select sysdate from dual@db_link;

          /*=========================================================================*/
          /*                               插入時間串                                */
          /*=========================================================================*/
          insert into test(IMPORT_DATE) values
          (to_date('2002-10-20 15:30:00','yyyy-mm-dd hh24:mi:ss'));
          insert into test(testtime) values(sysdate);
          取得時候可以to_char(sysdate,'yyyy-mm-dd   hh24:mi:ss')

          /*=========================================================================*/
          /*                      更改表時記錄其變化的TRIGGER                        */
          /*=========================================================================*/
          CREATE OR REPLACE TRIGGER T_APBT_CONTRACT_ALL_AIUDR
          after insert or update or delete on APBT_CONTRACT_ALL
          for each row   
          /*無論一條語句改變了多少條記錄,ORACLE對于每條記錄觸發一次觸發器*/
          /*before和after的區別:事件發生前還是事件發生后*/
          begin
              if inserting then
                  insert into A_APBT_CONTRACT_ALL(ID,CONTRACT_SERIAL_NUM,flag)
                  values (Seq_APBT_ARMS.NEXTVAL,:new.CONTRACT_SERIAL_NUM,1);/* :new*/
              elsif updating then
                  insert into A_APBT_CONTRACT_ALL(ID,CONTRACT_SERIAL_NUM,flag)
                  values (Seq_APBT_ARMS.NEXTVAL,:old.CONTRACT_SERIAL_NUM,2);
                  /*此句存在問題*/
              elsif deleting then
                  insert into A_APBT_CONTRACT_ALL(ID,CONTRACT_SERIAL_NUM,flag)
                  values (Seq_APBT_ARMS.NEXTVAL,:old.CONTRACT_SERIAL_NUM,3);
              end if;
          end;
          /

          /*=========================================================================*/
          /*                      你能夠創建被如下語句所觸發:                        */
          /*=========================================================================*/
          DML語句( DELETE,INSERT,UPDATE)
          DDL語句( CREATE,ALTER,DROP)
          數據庫操作( SERVERERROR, LOGON, LOGOFF, STARTUP, SHUTDOWN)

          /*=========================================================================*/
          /*                                  建立sequence序列:                        */
          /*=========================================================================*/
          DROP SEQUENCE ARMS.SEQ_APBT_ARMS;
          CREATE SEQUENCE ARMS.SEQ_APBT_ARMS
            START WITH 30
            MAXVALUE 999999999999999999999999999
            MINVALUE 1
            NOCYCLE
            CACHE 20
            NOORDER;

          posted on 2010-10-11 09:24 w@ns0ng 閱讀(316) 評論(0)  編輯  收藏 所屬分類: Database

          主站蜘蛛池模板: 广南县| 临猗县| 定兴县| 邓州市| 临泉县| 博湖县| 淄博市| 大兴区| 浮梁县| 长岛县| 澄迈县| 开阳县| 武定县| 仪陇县| 博白县| 衡阳市| 中牟县| 石狮市| 蒙城县| 景谷| 乌恰县| 武功县| 江北区| 正安县| 平湖市| 玉田县| 弥渡县| 繁昌县| 黎平县| 通化市| 昌宁县| 页游| 漯河市| 日喀则市| 南陵县| 泰和县| 高安市| 义马市| 宜城市| 虞城县| 兖州市|