记录我的生活和学习历程
  • [Oracle] oracle删除归档日志

    2012-12-07

    某公司一工程师联系我,说应用系统报错,无法正常使用,报错信息:
    ORA-00257: archiver error. Connect internal only, until freed
    字面上看是归档日志的问题。
    首先看下归档日志使用情况:

    擦!归档日志马上100%了!不出问题才怪。接下来删除过期的归档日志文件,释放空间。操作方法:
    1:进入rman
    $rman target /
    2:手动删除归档日志。以下命令是删除7天前的归档日志,最后的时候会让你输入yes。
    RMAN>DELETE ARCHIVELOG ALL COMPLETED BEFORE ‘SYSDATE-7’;
    3:重新检查下
    RMAN>crosscheck archivelog all;
    4:完成

    参考:
    http://www.cnblogs.com/ungshow/archive/2009/04/03/1429218.html
    http://hi.baidu.com/asxsankohubgpxd/item/ef444e8a79f5b0874514cf69
    http://www.2cto.com/database/201203/124636.html

    作者:swappy | Categories:Oracle | Tags:
  • [Oracle] 不同字符集数据库之间的数据(汉字)传输

    2012-11-14

    前段时间用Oracle ODI同步2个数据库的数据,结果汉字字段全部是乱码,首先想到可能是数据库字符集不对。
    执行:
    select * from nls_database_parameters where parameter = ‘NLS_CHARACTERSET’;
    果然,源数据库是UTF8 ,目标数据库是GBK。
    于是开始从编码这块入手,经网上搜索,用oralce 自带的函数 utl_raw.cast_to_raw和utl_raw.cast_to_varchar2这两个函数可以解决。
    utl_raw.cast_to_raw是把字符串转成16进制数,utl_raw.cast_to_varchar2是把16进制数转成字符串。
    实现思路:
    环境:字符集为UTf-8/GBK的数据库A/B中有数据表t_table(id,xm),其中姓名为汉字。
    目的:把A库中的t_table 数据同步到B库中的t_table中
    1:在A中,创建视图v_table 用utl_raw.cast_to_raw()函数把xm字段转成16进制数
    create or replace view v_table as select id,utl_raw.cast_to_raw(xm) xm from t_table;
    2:把v_table 中的内容同步到B库中的T_table 中,可以用dblink,也可以用ODI,再次不过多描述。
    3:在B中,创建视图v_table 用utl_raw.cast_to_varchar2()函数 把16进制的xm字段转成字符串。
    create or replace view v_table as select id,utl_raw.cast_to_varchar2(xm) xm from t_table;
    网上看到,做到这一步,好多人都成功了。但是我同步过来的数据,依然是乱码!
    经过排查,发现2个问题。
    1:utl_raw.cast_to_raw这个函数在不同的字符集数据库环境下,转换同一个字符串结果是不一样的!比如:
    在UTF8下 select utl_raw.cast_to_raw(‘刘德华’) from dual;–结果是 E58898E5BEB7E58D8E
    在GBK下 select utl_raw.cast_to_raw(‘刘德华’) from dual;–结果是 C1F5B5C2BBAA
    2:不同字符集传输ABC字母的时候,也是乱码!
    解决思路:
    1:convert()用这个函数转换下编码,然后再进行16进制转换。
    2:把16进制数据转换成10进制数据然后跨库传输。
    操作步骤:
    1:在A/B数据库中添加自定义函数,功能:实现二进制、八进制、十进制、十六进制相互转换。内容见附录。
    2:更改A库中的视图,pkg_number_trans.f_hex_to_dec() 是自定义函数,把十六进制转成10进制:
    create or replace view v_table as
    select id,pkg_number_trans.f_hex_to_dec(utl_raw.cast_to_raw(convert(xm,’ZHS16GBK’,’AL32UTF8′))) xm from t_table;
    3:把v_table 中的内容同步到B库中的T_table 中。
    4:修改B库中的视图。
    create or replace view v_table as
    select id,utl_raw.cast_to_varchar2(pkg_number_trans.f_dec_to_hex(xm)) xm from t_table;
    5:成功!
    附录:

    CREATE OR REPLACE PACKAGE pkg_number_trans IS 
    
      FUNCTION f_bin_to_oct(p_str IN VARCHAR2) RETURN VARCHAR2; 
      
      FUNCTION f_bin_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2; 
      
      FUNCTION f_bin_to_hex(p_str IN VARCHAR2) RETURN VARCHAR2; 
    
      FUNCTION f_oct_to_bin(p_str IN VARCHAR2) RETURN VARCHAR2; 
      
      FUNCTION f_oct_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2; 
    
      FUNCTION f_oct_to_hex(p_str IN VARCHAR2) RETURN VARCHAR2; 
      
      FUNCTION f_hex_to_bin(p_str IN VARCHAR2) RETURN VARCHAR2; 
    
      FUNCTION f_hex_to_oct(p_str IN VARCHAR2) RETURN VARCHAR2; 
    
      FUNCTION f_hex_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2; 
      
      FUNCTION f_dec_to_bin(p_int IN VARCHAR2) RETURN VARCHAR2; 
    
      FUNCTION f_dec_to_oct(p_int IN VARCHAR2) RETURN VARCHAR2; 
    
      FUNCTION f_dec_to_hex(p_int IN VARCHAR2) RETURN VARCHAR2; 
      
    END pkg_number_trans; 
    / 
    CREATE OR REPLACE PACKAGE BODY pkg_number_trans IS 
      FUNCTION f_bin_to_oct(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        ----------------------------------------------------------------------------------------------
        -- 对象名称: f_bin_to_oct 
        -- 对象描述: 二进制转换八进制 
        -- 输入参数: p_str 二进制字符串 
        -- 返回结果: 八进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_bin_to_oct('11110001010') FROM dual; 
        -- 备    注: 需要定义f_stragg函数和type_str_agg类型 
        ------------------------------------------------------------------------------------------------
        v_return VARCHAR2(4000); 
        v_bin    VARCHAR2(4000); 
      BEGIN 
        v_bin := substr('00' || p_str, -3 * ceil(length(p_str) / 3)); 
        SELECT f_stragg(data1) INTO v_return 
          FROM (SELECT (CASE upper(substr(v_bin, (rownum - 1) * 3 + 1, 3)) 
                         WHEN '000' THEN '0' 
                         WHEN '001' THEN '1' 
                         WHEN '010' THEN '2' 
                         WHEN '011' THEN '3' 
                         WHEN '100' THEN '4' 
                         WHEN '101' THEN '5' 
                         WHEN '110' THEN '6' 
                         WHEN '111' THEN '7' 
                       END) data1 
                  FROM dual 
                CONNECT BY rownum <= length(v_bin) / 3); 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_bin_to_oct; 
    
      FUNCTION f_bin_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        ---------------------------------------------------------------------------------------- 
        -- 对象名称: f_bin_to_dec 
        -- 对象描述: 二进制转换十进制 
        -- 输入参数: p_str 二进制字符串 
        -- 返回结果: 十进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_bin_to_dec('11110001010') FROM dual; 
        ----------------------------------------------------------------------------------------- 
        v_return  VARCHAR2(4000); 
      BEGIN 
        SELECT SUM(data1) INTO v_return 
          FROM (SELECT substr(p_str, rownum, 1) * power(2, length(p_str) - rownum) data1 
                  FROM dual 
                CONNECT BY rownum <= length(p_str)); 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_bin_to_dec; 
    
      FUNCTION f_bin_to_hex(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        ----------------------------------------------------------------------------------- 
        -- 对象名称: f_bin_to_hex 
        -- 对象描述: 二进制转换十六进制 
        -- 输入参数: p_str 二进制字符串 
        -- 返回结果: 十六进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_bin_to_oct('11110001010') FROM dual; 
        -- 备    注: 需要定义f_stragg函数和type_str_agg类型 
        -------------------------------------------------------------------------------------- 
        v_return VARCHAR2(4000); 
        v_bin    VARCHAR2(4000); 
      BEGIN 
        v_bin := substr('000' || p_str, -4 * ceil(length(p_str) / 4)); 
        SELECT f_stragg(data1) INTO v_return 
          FROM (SELECT (CASE upper(substr(v_bin, (rownum - 1) * 4 + 1, 4)) 
                         WHEN '0000' THEN '0' 
                         WHEN '0001' THEN '1' 
                         WHEN '0010' THEN '2' 
                         WHEN '0011' THEN '3' 
                         WHEN '0100' THEN '4' 
                         WHEN '0101' THEN '5' 
                         WHEN '0110' THEN '6' 
                         WHEN '0111' THEN '7' 
                         WHEN '1000' THEN '8' 
                         WHEN '1001' THEN '9' 
                         WHEN '1010' THEN 'A' 
                         WHEN '1011' THEN 'B' 
                         WHEN '1100' THEN 'C' 
                         WHEN '1101' THEN 'D' 
                         WHEN '1110' THEN 'E' 
                         WHEN '1111' THEN 'F' 
                       END) data1 
                  FROM dual 
                CONNECT BY rownum <= length(v_bin) / 4); 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_bin_to_hex; 
    
      FUNCTION f_oct_to_bin(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        ------------------------------------------------------------------------------------------- 
        -- 对象名称: f_oct_to_bin 
        -- 对象描述: 八进制转换二进制 
        -- 输入参数: p_str 八进制字符串 
        -- 返回结果: 二进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_oct_to_bin('3612') FROM dual; 
        -- 备    注: 需要定义f_stragg函数和type_str_agg类型 
        -------------------------------------------------------------------------------------------- 
        v_return VARCHAR2(4000); 
      BEGIN 
        SELECT to_char(to_number(f_stragg(data1))) INTO v_return 
          FROM (SELECT (CASE upper(substr(p_str, rownum, 1)) 
                         WHEN '0' THEN '000' 
                         WHEN '1' THEN '001' 
                         WHEN '2' THEN '010' 
                         WHEN '3' THEN '011' 
                         WHEN '4' THEN '100' 
                         WHEN '5' THEN '101' 
                         WHEN '6' THEN '110' 
                         WHEN '7' THEN '111' 
                       END) data1 
                  FROM dual 
                CONNECT BY rownum <= length(p_str)); 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_oct_to_bin; 
    
      FUNCTION f_oct_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        ---------------------------------------------------------------------------------------------------------------------- 
        -- 对象名称: f_oct_to_dec 
        -- 对象描述: 八进制转换十进制 
        -- 输入参数: p_str 八进制字符串 
        -- 返回结果: 十进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_oct_to_dec('3612') FROM dual; 
        ---------------------------------------------------------------------------------------------------------------------- 
        v_return  VARCHAR2(4000); 
      BEGIN 
        SELECT SUM(data1) INTO v_return 
          FROM (SELECT substr(p_str, rownum, 1) * power(8, length(p_str) - rownum) data1 
                  FROM dual 
                CONNECT BY rownum <= length(p_str)); 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_oct_to_dec; 
      
      FUNCTION f_oct_to_hex(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        --------------------------------------------------------------------------------------------- 
        -- 对象名称: f_oct_to_bin 
        -- 对象描述: 八进制转换十六进制 
        -- 输入参数: p_str 八进制字符串 
        -- 返回结果: 十六进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_oct_to_hex('3612') FROM dual; 
        ---------------------------------------------------------------------------------------------- 
        v_return VARCHAR2(4000); 
        v_bin    VARCHAR2(4000); 
      BEGIN 
        SELECT pkg_number_trans.f_oct_to_bin(p_str) INTO v_bin FROM dual; 
        SELECT pkg_number_trans.f_bin_to_hex(v_bin) INTO v_return FROM dual; 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_oct_to_hex; 
    
      FUNCTION f_dec_to_bin(p_int IN VARCHAR2) RETURN VARCHAR2 IS 
        ---------------------------------------------------------------------------------------------------------------------- 
        -- 对象名称: f_dec_to_bin 
        -- 对象描述: 十进制转换二进制 
        -- 输入参数: p_str 十进制字符串 
        -- 返回结果: 二进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_dec_to_bin('1930') FROM dual; 
        ---------------------------------------------------------------------------------------------------------------------- 
        v_return VARCHAR2(4000); 
        v_hex    VARCHAR2(4000); 
      BEGIN 
        SELECT pkg_number_trans.f_dec_to_hex(p_int) INTO v_hex FROM dual; 
        SELECT pkg_number_trans.f_hex_to_bin(v_hex) INTO v_return FROM dual; 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_dec_to_bin; 
      
      FUNCTION f_dec_to_oct(p_int IN VARCHAR2) RETURN VARCHAR2 IS 
        ---------------------------------------------------------------------------------------------------------------------- 
        -- 对象名称: f_dec_to_oct 
        -- 对象描述: 十进制转换八进制 
        -- 输入参数: p_str 十进制字符串 
        -- 返回结果: 八进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_dec_to_oct('1930') FROM dual; 
        ---------------------------------------------------------------------------------------------------------------------- 
        v_return VARCHAR2(4000); 
        v_bin    VARCHAR2(4000); 
      BEGIN 
        SELECT pkg_number_trans.f_dec_to_bin(p_int) INTO v_bin FROM dual; 
        v_bin := substr('00' || v_bin, -3 * ceil(length(v_bin) / 3)); 
        SELECT f_stragg(data1) INTO v_return 
          FROM (SELECT (CASE upper(substr(v_bin, (rownum - 1) * 3 + 1, 3)) 
                         WHEN '000' THEN '0' 
                         WHEN '001' THEN '1' 
                         WHEN '010' THEN '2' 
                         WHEN '011' THEN '3' 
                         WHEN '100' THEN '4' 
                         WHEN '101' THEN '5' 
                         WHEN '110' THEN '6' 
                         WHEN '111' THEN '7' 
                       END) data1 
                  FROM dual 
                CONNECT BY rownum <= length(v_bin) / 3); 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_dec_to_oct; 
      
      FUNCTION f_dec_to_hex(p_int IN VARCHAR2) RETURN VARCHAR2 IS 
        ---------------------------------------------------------------------------------------------------------------------- 
        -- 对象名称: f_dec_to_oct 
        -- 对象描述: 十进制转换十六进制 
        -- 输入参数: p_str 十进制字符串 
        -- 返回结果: 十六进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_dec_to_hex('1930') FROM dual; 
        ---------------------------------------------------------------------------------------------------------------------- 
        v_return VARCHAR2(4000); 
      BEGIN 
        SELECT upper(TRIM(to_char(p_int, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'))) INTO v_return FROM dual; 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_dec_to_hex; 
      
      FUNCTION f_hex_to_bin(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        ---------------------------------------------------------------------------------------------------------------------- 
        -- 对象名称: f_dec_to_oct 
        -- 对象描述: 十六进制转换二进制 
        -- 输入参数: p_str 十六进制字符串 
        -- 返回结果: 二进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_hex_to_oct('78A') FROM dual; 
        ---------------------------------------------------------------------------------------------------------------------- 
        v_return VARCHAR2(4000); 
      BEGIN 
        SELECT to_char(to_number(f_stragg(data1))) INTO v_return 
          FROM (SELECT (CASE upper(substr(p_str, rownum, 1)) 
                         WHEN '0' THEN '0000' 
                         WHEN '1' THEN '0001' 
                         WHEN '2' THEN '0010' 
                         WHEN '3' THEN '0011' 
                         WHEN '4' THEN '0100' 
                         WHEN '5' THEN '0101' 
                         WHEN '6' THEN '0110' 
                         WHEN '7' THEN '0111' 
                         WHEN '8' THEN '1000' 
                         WHEN '9' THEN '1001' 
                         WHEN 'A' THEN '1010' 
                         WHEN 'B' THEN '1011' 
                         WHEN 'C' THEN '1100' 
                         WHEN 'D' THEN '1101' 
                         WHEN 'E' THEN '1110' 
                         WHEN 'F' THEN '1111' 
                       END) data1 
                  FROM dual 
                CONNECT BY rownum <= length(p_str)); 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_hex_to_bin; 
      
      FUNCTION f_hex_to_oct(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        ---------------------------------------------------------------------------------------------------------------------- 
        -- 对象名称: f_dec_to_oct 
        -- 对象描述: 十六进制转换八进制 
        -- 输入参数: p_str 十六进制字符串 
        -- 返回结果: 八进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_hex_to_oct('78A') FROM dual; 
        ---------------------------------------------------------------------------------------------------------------------- 
        v_return VARCHAR2(4000); 
        v_bin    VARCHAR2(4000); 
      BEGIN 
        SELECT pkg_number_trans.f_hex_to_bin(p_str) INTO v_bin FROM dual; 
        SELECT pkg_number_trans.f_bin_to_oct(v_bin) INTO v_return FROM dual; 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_hex_to_oct; 
      
      FUNCTION f_hex_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2 IS 
        ---------------------------------------------------------------------------------------------------------------------- 
        -- 对象名称: f_hex_to_dec 
        -- 对象描述: 十六进制转换十进制 
        -- 输入参数: p_str 十六进制字符串 
        -- 返回结果: 十进制字符串 
        -- 测试用例: SELECT pkg_number_trans.f_hex_to_dec('78A') FROM dual; 
        ---------------------------------------------------------------------------------------------------------------------- 
        v_return  VARCHAR2(4000); 
      BEGIN 
        SELECT SUM(data1) INTO v_return 
          FROM (SELECT (CASE upper(substr(p_str, rownum, 1)) 
                         WHEN 'A' THEN '10' 
                         WHEN 'B' THEN '11' 
                         WHEN 'C' THEN '12' 
                         WHEN 'D' THEN '13' 
                         WHEN 'E' THEN '14' 
                         WHEN 'F' THEN '15' 
                         ELSE substr(p_str, rownum, 1) 
                       END) * power(16, length(p_str) - rownum) data1 
                  FROM dual 
                CONNECT BY rownum <= length(p_str)); 
        RETURN v_return; 
      EXCEPTION 
        WHEN OTHERS THEN 
          RETURN NULL; 
      END f_hex_to_dec; 
      
    END pkg_number_trans; 
    / 
    
    CREATE OR REPLACE TYPE type_str_agg AS OBJECT 
    ( 
      total VARCHAR2(4000), 
    
      STATIC FUNCTION odciaggregateinitialize(sctx IN OUT type_str_agg) 
        RETURN NUMBER, 
    
      MEMBER FUNCTION odciaggregateiterate 
      ( 
        SELF  IN OUT type_str_agg, 
        VALUE IN VARCHAR2 
      ) RETURN NUMBER, 
    
      MEMBER FUNCTION odciaggregateterminate 
      ( 
        SELF        IN type_str_agg, 
        returnvalue OUT VARCHAR2, 
        flags       IN NUMBER 
      ) RETURN NUMBER, 
    
      MEMBER FUNCTION odciaggregatemerge 
      ( 
        SELF IN OUT type_str_agg, 
        ctx2 IN type_str_agg 
      ) RETURN NUMBER 
    ) 
    / 
    CREATE OR REPLACE TYPE BODY type_str_agg IS 
    
      STATIC FUNCTION odciaggregateinitialize(sctx IN OUT type_str_agg) 
        RETURN NUMBER IS 
      BEGIN 
        sctx := type_str_agg(NULL); 
        RETURN odciconst.success; 
      END; 
    
      MEMBER FUNCTION odciaggregateiterate 
      ( 
        SELF  IN OUT type_str_agg, 
        VALUE IN VARCHAR2 
      ) RETURN NUMBER IS 
      BEGIN 
        SELF.total := SELF.total || VALUE; 
        RETURN odciconst.success; 
      END; 
    
      MEMBER FUNCTION odciaggregateterminate 
      ( 
        SELF        IN type_str_agg, 
        returnvalue OUT VARCHAR2, 
        flags       IN NUMBER 
      ) RETURN NUMBER IS 
      BEGIN 
        returnvalue := SELF.total; 
        RETURN odciconst.success; 
      END; 
    
      MEMBER FUNCTION odciaggregatemerge 
      ( 
        SELF IN OUT type_str_agg, 
        ctx2 IN type_str_agg 
      ) RETURN NUMBER IS 
      BEGIN 
        SELF.total := SELF.total || ctx2.total; 
        RETURN odciconst.success; 
      END; 
    END; 
    / 
    
    CREATE OR REPLACE FUNCTION f_stragg(p_input VARCHAR2) RETURN VARCHAR2 
      PARALLEL_ENABLE 
      AGGREGATE USING type_str_agg; 
    / 
    
    作者:swappy | Categories:Oracle | Tags:
  • [Oracle]oracle 10G 定时Exp导出

    2012-06-05

    环境:
    操作系统:Redhat e5
    数据库:Oracle Cluster 10

    1:创建文件夹
    mkdir /backup/exp/expdata //exp导出数据文件目录
    mkdir /backup/exp/explog //日志目录
    mkdir /backup/exp/sh //脚本目录
    2:创建脚本 exp.sh 其中,环境变量部分可以参照本地数据库环境.bash_profile文件:
    ##########By swappy@20120215#########
    ORACLE_BASE=/u01/app/oracle
    ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db
    CRS_HOME=$ORACLE_BASE/product/10.2.0/crs
    ORACLE_SID=rac1
    ORACLE_TERM=xterm
    #NLS_LANG=”Simplified Chinese”_China.ZHS16CGB231280
    NLS_LANG=AMERICAN_AMERICA.AL32UTF8
    TMPDIR=/var/tmp
    umask 022
    NLS_DATE_FORMAT=”YYYY/MM/DD hh24:mi:ss”
    ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
    TNS_ADMIN=$ORACLE_HOME/network/admin
    export ORACLE_BASE ORACLE_HOME CRS_HOME ORACLE_SID
    export NLS_LANG
    export TMPDIR NLS_DATE_FORMAT ORA_NLS33 TNS_ADMIN DISPLAY
    LIBPATH=$ORACLE_HOME/lib
    export LIBPATH
    PATH=$PATH:$ORACLE_HOME/bin:$CRS_HOME/bin:/usr/sbin
    export PATH
    ############EXP#################
    D=$(date +%y-%m-%d);
    export D;
    $ORACLE_HOME/bin/exp system/passwd file=/backup/exp/expdata/data_${D}.dmp log=/backup/exp/explog/log_${D}.log owner=TRS,TRSPLUGINS
    3:创建后,chmod +x exp.sh 赋予可执行权限。然后./exp.sh 看看是执行成功。
    4:创建crontab计划
    crotab -e 编辑计划加入:
    * 12 * * * /backup/exp/sh/exp.sh
    保存后重启服务
    service crond restart

    作者:swappy | Categories:Oracle未分类 | Tags:
  • [Oracle]oracle安装琐碎命令

    2012-05-30

    我实在不想挨个敲了,记录在此,以后直接复制粘贴!

    /sbin/iscsiadm -m discovery -t sendtargets -p 192.168.0.2
    /sbin/iscsiadm -m node -T iqn.2007-09.jp.ne.peach.istgt:target0 -p 192.168.0.2 -l
    /sbin/iscsiadm -m node -T iqn.2007-09.jp.ne.peach.istgt:target1 -p 192.168.0.2 -l
    /sbin/iscsiadm -m node -T iqn.2007-09.jp.ne.peach.istgt:target2 -p 192.168.0.2 -l
    /sbin/iscsiadm -m node -T iqn.2007-09.jp.ne.peach.istgt:target3 -p 192.168.0.2 -l
    /sbin/iscsiadm -m node -T iqn.2007-09.jp.ne.peach.istgt:target4 -p 192.168.0.2 -l
    /sbin/iscsiadm -m node -T iqn.2007-09.jp.ne.peach.istgt:target5 -p 192.168.0.2 -l
    /sbin/iscsiadm -m node -T iqn.2007-09.jp.ne.peach.istgt:target6 -p 192.168.0.2 -l
    /sbin/iscsiadm -m node -T iqn.2007-09.jp.ne.peach.istgt:target7 -p 192.168.0.2 -l

    /bin/raw /dev/raw/raw1 /dev/sdb1
    /bin/raw /dev/raw/raw2 /dev/sdc1
    /bin/raw /dev/raw/raw3 /dev/sdd1
    /bin/raw /dev/raw/raw4 /dev/sde1
    /bin/raw /dev/raw/raw5 /dev/sdf1
    /bin/raw /dev/raw/raw6 /dev/sdg1
    /bin/raw /dev/raw/raw7 /dev/sdh1
    /bin/raw /dev/raw/raw8 /dev/sdi1

    ACTION==”add”, KERNEL==”sdb1″, RUN+=”/bin/raw /dev/raw/raw1 %N”
    ACTION==”add”, KERNEL==”sdc1″, RUN+=”/bin/raw /dev/raw/raw2 %N”
    ACTION==”add”, KERNEL==”sdd1″, RUN+=”/bin/raw /dev/raw/raw3 %N”
    ACTION==”add”, KERNEL==”sde1″, RUN+=”/bin/raw /dev/raw/raw4 %N”
    ACTION==”add”, KERNEL==”sdf1″, RUN+=”/bin/raw /dev/raw/raw5 %N”
    ACTION==”add”, KERNEL==”sdg1″, RUN+=”/bin/raw /dev/raw/raw6 %N”
    ACTION==”add”, KERNEL==”sdh1″, RUN+=”/bin/raw /dev/raw/raw7 %N”
    ACTION==”add”, ENV{MAJOR}==”8″, ENV{MINOR}==”17″, RUN+=”/bin/raw
    /dev/raw/raw1 %M %m”
    ACTION==”add”, ENV{MAJOR}==”8″, ENV{MINOR}==”33″, RUN+=”/bin/raw
    /dev/raw/raw2 %M %m”
    ACTION==”add”, ENV{MAJOR}==”8″, ENV{MINOR}==”49″, RUN+=”/bin/raw
    /dev/raw/raw3 %M %m”
    ACTION==”add”, ENV{MAJOR}==”8″, ENV{MINOR}==”65″, RUN+=”/bin/raw
    /dev/raw/raw4 %M %m”
    ACTION==”add”, ENV{MAJOR}==”8″, ENV{MINOR}==”65″, RUN+=”/bin/raw
    /dev/raw/raw5 %M %m”
    ACTION==”add”, ENV{MAJOR}==”8″, ENV{MINOR}==”81″, RUN+=”/bin/raw
    /dev/raw/raw6 %M %m”
    ACTION==”add”, ENV{MAJOR}==”8″, ENV{MINOR}==”113″, RUN+=”/bin/raw
    /dev/raw/raw7 %M %m”

    chown root:oinstall /dev/raw/raw1
    chown root:oinstall /dev/raw/raw2
    chown oracle:oinstall /dev/raw/raw3
    chown oracle:oinstall /dev/raw/raw4
    chown oracle:oinstall /dev/raw/raw5
    chown oracle:dba /dev/raw/raw6
    chown oracle:dba /dev/raw/raw7
    chmod 640 /dev/raw/raw1
    chmod 640 /dev/raw/raw2
    chmod 644 /dev/raw/raw3
    chmod 644 /dev/raw/raw4
    chmod 644 /dev/raw/raw5
    chmod 660 /dev/raw/raw6
    chmod 660 /dev/raw/raw7

    vi /etc/udev/rules.d/99-raw-perms.rules

    KERNEL==”raw1″, MODE=”0640″, GROUP=”oinstall”, OWNER=”root”
    KERNEL==”raw2″, MODE=”0640″, GROUP=”oinstall”, OWNER=”root”
    KERNEL==”raw3″, MODE=”0644″, GROUP=”oinstall”, OWNER=”oracle”
    KERNEL==”raw4″, MODE=”0644″, GROUP=”oinstall”, OWNER=”oracle”
    KERNEL==”raw5″, MODE=”0644″, GROUP=”oinstall”, OWNER=”oracle”
    KERNEL==”raw6″, MODE=”0660″, GROUP=”dba”, OWNER=”oracle”
    KERNEL==”raw7″, MODE=”0660″, GROUP=”dba”, OWNER=”oracle”

    /bin # ./oifcfg setif -global eth0/192.168.0.12:public
    /bin # ./oifcfg setif -global eth1/192.168.0.13:cluster_interconnect

    作者:swappy | Categories:Oracle | Tags:
  • [Oracle]Voing Disk的备份与恢复

    2012-03-14

    Voting Disk里面记录着节点成员信息,比如RAC数据库中有哪些节点成员,即节点增加或者删除时也会将信息记录进来。VotingDisk必须存放在共享存储上,通常来说存放在裸设备上,为保证安全,需要配置多个Voting Disk,oracle建议个数为奇数个,比如1、3、5个,每个VotingDisk的大小约为20M。
    Voing Disk的备份与恢复可以通过dd命令来操作。

    查看VotingDisk所在的位置

    [oracle@db1 ~]$ crsctl query css votedisk
     0.     0    /dev/raw/raw3
     1.     0    /dev/raw/raw4
     2.     0    /dev/raw/raw5

    备份操作:

    [oracle@db1 voting_disk]$ dd if=/dev/raw/raw3 of=/home/oracle/bak/voting_disk/vs_raw3_2012-03-14
    4191324+0 records in
    4191324+0 records out
    2145957888 bytes (2.1 GB) copied, 417.745 seconds, 5.1 MB/s

    恢复操作:

    [oracle@db1 voting_disk]$ dd if=/home/oracle/bak/voting_disk/vs_raw3_2012-03-14 of=/dev/raw/raw3
    4191324+0 records in
    4191324+0 records out
    2145957888 bytes (2.1 GB) copied, 417.745 seconds, 5.1 MB/s
    

    默认情况下Rac会在其中一个节点每4个小时自动进行一次OCR的备份,并且保留最近的3次备份,另外还保留最近2天以及最近两个周末的备份。
    通过ocrconfig-showbackup来查看

    [oracle@db1 ~]$ ocrconfig -showbackup
    db1     2012/03/14 19:33:58     /u01/app/oracle/product/10.2.0/crs/cdata/crs
    db1     2012/03/14 15:33:57     /u01/app/oracle/product/10.2.0/crs/cdata/crs
    db1     2012/03/14 11:33:57     /u01/app/oracle/product/10.2.0/crs/cdata/crs
    db1     2012/03/13 15:33:57     /u01/app/oracle/product/10.2.0/crs/cdata/crs
    db1     2012/03/05 03:03:01     /u01/app/oracle/product/10.2.0/crs/cdata/crs
    

    OCR默认的备份路径为$CRS_HOME/cdata/crs,可以通过ocrconfig -backuploc来更改ocr的备份路径。OCR备份时间间隔无法更改,但是可以通过ocrcofnig -export/-import来导出/导入OCR的内容。

    [oracle@db1 ~]$ ocrconfig -backuploc /home/oracle
    [oracle@db1 ~]$ ocrconfig -export /home/oracle/ocr.exp
    [oracle@db1 ~]$ ocrconfig -import /home/oracle/ocr.exp
    

    可以用ocrconfig -restore命令对OCR进行恢复:

    [oracle@db1 ~]$ ocrconfig -restore /u01/oracle/product/10.0.1/crs/cdata/crs/ backup00.ocr
    
    作者:swappy | Categories:Oracle | Tags: