2016年8月16日 星期二

[ORACLE] ORA-01114 IO error writing block to file

問題:
  前端執行會出現ORA-01114的錯誤訊息,資料庫的ALERT LOG也有出現以下錯誤
ORA-01114: IO error writing block to file (block # )
ORA-01114: IO error writing block to file 201  (block # 113440 )

原因:空間不足(包含TABLESPACE及實體空間)

處理程序:
1. 透過dba_extents查詢是哪個OWNER的TABLESPACE滿了
    SQL> select owner,tablespace_name,segment_type,segment_name from dba_extents where file_id = 201 and block_id = 113440;

     no rows selected

2. 步驟一查詢並沒有查到任何資料,進一步去dba_free_space及dba_data_file也都沒發現tablespace空間不足的訊息

3. 回到作業系統層檢查磁碟空間透過df指令去查發現根目錄使用率100%

4. 與前端確認後得知正在操作的TABLESPACE就是放在root下的datafile

解決方式:
方式一:Extend根目錄

方式二:將一些TABLESPACE offline後再把TABLESPACE下的datafile搬到有足夠空間的磁碟下後online

2016年8月15日 星期一

[ORACLE] ORACLE的RAC環境下的連接管理(此篇文章來自Oracle Technology Network)

筆記一篇:此篇只要是在說ORACLE的RAC環境CLIENT端的TNSNAME的設定方式

文章出處:http://www.oracle.com/technetwork/cn/articles/database-performance/oracle-rac-connection-mgmt-1650424-zhs.html

[ORACLE] 安裝設定GOLDENGATE從單機到RAC

環境:
RAC(以下稱TARGET端)環境下兩節點HOSTNAME,IP ADDRESS等相關設定如下
# Public
192.168.100.110 racnode01.dba.local racnode01
192.168.100.120 racnode02.dba.local racnode02
# Private
10.0.0.110 racnode01-priv.dba.local racnode01-priv
10.0.0.120 racnode02-priv.dba.local    racnode02-priv
# Virtual
192.168.100.111 racnode01-vip.dba.local racnode01-vip
192.168.100.121 racnode02-vip.dba.local racnode02-vip
# SCAN
192.168.100.101 racnode.dba.local racnode
192.168.100.102 racnode.dba.local racnode
192.168.100.103 racnode.dba.local racnode

單主機(以下稱SOURCE端)HOSTNAME,IP ADDRESS等相關設定如下
192.168.100.50 oggs.dba.local

STORAGE(DNS)主機相關設定
192.168.100.10 racstorage.dba.local

設定程序如下:
在SOURCE端
建立GOLDENGATE安裝目錄
      [oracle@oggs ~]$ mkdir /u01/app/goldengate
      [oracle@oggs ~]$ mkdir /u01/app/goldengate/ogg
將p17952585_1121017_Linux-x86-64.zip解壓縮到/u01/app/goldengate/ogg路徑下
      [oracle@oggs ~]$ unzip p17952585_1121017_Linux-x86-64.zip
      [oracle@oggs ~]$ tar –xvf fbo_ggs_Linux_x64_ora11g_64bit.tar

在TARGET端
建立GOLDENGATE安裝目錄(此路徑為ACFS,好處是當一個節點有問題時,另一個節點也可以使用,設定方式會有另一篇文章教學)
      [oracle@racnode01 ogg]$ mkdir /u01/app/goldengate
      [oracle@racnode01 ogg]$ mkdir /u01/app/goldengate/ogg

將p17952585_1121017_Linux-x86-64.zip解壓縮到/u01/app/goldengate/ogg路徑下
      [oracle@racnode01 ogg]$ unzip p17952585_1121017_Linux-x86-64.zip
      [oracle@racnode01 ogg]$ tar –xvf fbo_ggs_Linux_x64_ora11g_64bit.tar

在SOURCE端
建立goldengate工作目錄
       [oracle@oggs ogg]$ ./ggsci
       GGSCI (oggs.dba.local) 2> create subdirs

在TARGET端
建立goldengate工作目錄
        [oracle@racnode01 ogg]$ ./ggsci
        GGSCI (racnode01.dba.local) 1> create subdirs

在SOURCE端
建立GOLDENGATE的tablespace,user及權限
       [oracle@oggs ogg]$ sqlplus / as sysdba
       SQL> create tablespace ogg_data datafile '/oradata/ogg_data_01.dbf' size 2048M AUTOEXTEND ON;
      SQL> CREATE USER OGG
                 IDENTIFIED BY ogg
                 DEFAULT TABLESPACE ogg_data
                 TEMPORARY TABLESPACE TEMP
                 PROFILE DEFAULT
                 ACCOUNT UNLOCK;
      SQL> GRANT CONNECT TO OGG;
      SQL> GRANT RESOURCE TO OGG;
      SQL> GRANT DBA TO OGG;
      SQL> ALTER USER OGG DEFAULT ROLE ALL;
      SQL> GRANT CREATE ANY SYNONYM TO OGG;
      SQL> GRANT UNLIMITED TABLESPACE TO OGG;
      SQL> GRANT CREATE SYNONYM TO OGG WITH ADMIN OPTION;
      SQL> ALTER USER OGG QUOTA UNLIMITED ON ogg_data;
      SQL> grant create any table to ogg;
      SQL> grant create any view to ogg;
      SQL> grant create any procedure to ogg;
      SQL> grant create any sequence to ogg;
      SQL> grant create any index to ogg;
      SQL> grant create any trigger to ogg;

在SOURCE端
啟用supplemental log
        SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
        SQL> ALTER SYSTEM SWITCH LOGFILE;

在SOURCE端
在OGG的目錄下登入資料庫,設定並啟用DDL Replication
        [oracle@oggs ogg]$ sqlplus / as sysdba
        SQL> @marker_setup
               --在Enter Oracle GoldenGate schema name輸入[ogg]
        SQL> @ddl_setup
               --Enter Oracle GoldenGate schema name輸入[ogg]
        SQL> @role_setup
               --Enter GoldenGate schema name輸入[ogg]
        SQL> GRANT GGS_GGSUSER_ROLE TO ogg;
        SQL> @ddl_enable
        SQL> @ddl_pin ogg
        SQL> @SEQUENCE

在TARGET端
建立GOLDENGATE的tablespace,user及權限
        SQL> create tablespace ogg_data datafile '+DATA01' size 2048M AUTOEXTEND ON;
        SQL> CREATE USER OGG
                   IDENTIFIED BY ogg
                   DEFAULT TABLESPACE ogg_data
                   TEMPORARY TABLESPACE TEMP
                   PROFILE DEFAULT
                   ACCOUNT UNLOCK;
        SQL> GRANT CONNECT TO OGG;
        SQL> GRANT RESOURCE TO OGG;
        SQL> GRANT DBA TO OGG;
        SQL> ALTER USER OGG DEFAULT ROLE ALL;
        SQL> GRANT CREATE ANY SYNONYM TO OGG;
        SQL> GRANT UNLIMITED TABLESPACE TO OGG;
        SQL> GRANT CREATE SYNONYM TO OGG WITH ADMIN OPTION;
        SQL> ALTER USER OGG QUOTA UNLIMITED ON ogg_data;
        SQL> grant create any table to ogg;
        SQL> grant create any view to ogg;
        SQL> grant create any procedure to ogg;
        SQL> grant create any sequence to ogg;
        SQL> grant create any index to ogg;
        SQL> grant create any trigger to ogg;
        SQL> grant create any view to ogg;
       
在TARGET端
啟用supplemental log
        SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
        SQL> ALTER SYSTEM SWITCH LOGFILE;

在TARGET端
在OGG的目錄下登入資料庫,設定並啟用DDL Replication
       [oracle@racnode01 ogg]$ sqlplus / as sysdba
       SQL> @marker_setup
                 --在Enter Oracle GoldenGate schema name輸入[ogg]
       SQL> @ddl_setup
                --Enter Oracle GoldenGate schema name輸入[ogg]
       SQL> @role_setup
               --Enter GoldenGate schema name輸入[ogg]
       SQL> GRANT GGS_GGSUSER_ROLE TO ogg;
       SQL> @ddl_enable
       SQL> @ddl_pin ogg
       SQL> @SEQUENCE

在SOURCE端
啟用transaction data change capture
        [oracle@oggs ogg]$ ./ggsci
        GGSCI (oggs.dba.local) 1> dblogin userid ogg@orcl Password ogg
        GGSCI (oggs.dba.local) 2> add checkpointtable ogg.chktab
        GGSCI (oggs.dba.local) 3> add trandata OD_CAS.*   代表OD_CAS SCHEMA下都要同步
驗證補充日誌已經在那些TABLE打開
        GGSCI (oggs.dba.local) 4> info trandata OD_CAS.*
        SQL> select table_name from dba_tables where owner='OD_CAS' minus select table_name from dba_log_groups where owner='OD_CAS';

                   no rows selected

在TARGET端
啟用transaction data change capture
        [oracle@racnode01 ogg]$ ./ggsci
        GGSCI (racnode01.dba.local) 5> dblogin userid ogg@orcl Password ogg
        GGSCI (racnode01.dba.local) 6> add checkpointtable ogg.chktab

在SOURCE端
配置Goldengate Manager Process
        [oracle@oggs ogg]$ ./ggsci
        GGSCI (oggs.dba.local) 1> edit params mgr
             PORT 7809
             DYNAMICPORTLIST 7810-7820, 7830
             userid ogg@orcl password ogg
             --AUTOSTART ER *
             --AUTORESTART ER *, RETRIES 3, WAITMINUTES 5, RESETMINUTES 60
             STARTUPVALIDATIONDELAY 5
             PURGEOLDEXTRACTS /u01/app/goldengate/ogg/dirdat/*, USECHECKPOINTS, MINKEEPDAYS 3
             PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5    
             PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5  
啟動Manager
        GGSCI (oggs.dba.local) 2> start mgr

在TARGET端
配置Goldengate Manager Process
        [oracle@racnode01 ogg]$ ./ggsci
        GGSCI (racnode01.dba.local) 2> edit params mgr
             PORT 7809
             DYNAMICPORTLIST 7810-7820, 7830
             userid ogg@orcl password ogg
            --AUTOSTART ER *
            --AUTORESTART ER *, RETRIES 3, WAITMINUTES 5, RESETMINUTES 60
            STARTUPVALIDATIONDELAY 5
            PURGEOLDEXTRACTS /u01/app/goldengate/ogg/dirdat/*, USECHECKPOINTS, MINKEEPDAYS 3
            PURGEDDLHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5    
           PURGEMARKERHISTORY MINKEEPDAYS 3, MAXKEEPDAYS 5  
啟動Manager
       GGSCI (racnode01.dba.local) 3> start mgr

在SOURCE端
配置EXTRACT
        GGSCI (oggs.dba.local) 2> edit params e_odcas
              extract e_odcas
              setenv (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
              setenv (ORACLE_HOME="/u01/app/oracle/product/11.2.0.4/dbhome_1")
              --setenv (ORACLE_SID="orcl")
              userid ogg@orcl, password ogg
              --tranlogoptions dblogreader asmuser sys@sam2, asmpassword sss433
              --tranlogoptions altarchivelogdest threadid 1 F:\oracle\oradata\Archivelog,
              --altarchivelogdest threadid 2 F:\oracle\oradata\Archivelog
              exttrail /u01/app/goldengate/ogg/dirdat/E1
              ddl include mapped;
              ddloptions ADDTRANDATA, RETRYOP retrydelay 10 maxretries 10, getreplicates
              discardfile /u01/app/goldengate/ogg/dirrpt/e_odcas.dis, purge, megabytes 10
              dboptions ALLOWUNUSEDCOLUMN
              FETCHOPTIONS FETCHPKUPDATECOLS

              table od_cas.*;
              SEQUENCE od_cas.*

在SOURCE端
新增一個Extract group
       GGSCI (oggs.dba.local) 3> add extract e_odcas, tranlog, begin now
            --P.S.threads參數是指RAC節點數 add extract e_odcas, tranlog, threads 2, begin now

在SOURCE端
定義e_odcas trail file路徑
        GGSCI (oggs.dba.local) 4> add exttrail /u01/app/goldengate/ogg/dirdat/E1, extract e_odcas, megabytes 100

在SOURCE端
配置 pump process group
      GGSCI (oggs.dba.local) 5> edit params p_odcas
            extract p_odcas
            setenv (NLS_LANG="AMERICAN_AMERICA.AL32UTF8")
            setenv (ORACLE_HOME="/u01/app/oracle/product/11.2.0.4/dbhome_1")
            rmthost racnode.dba.local, mgrport 7809
            rmttrail /u01/app/goldengate/ogg/dirdat/R1
            passthru

           table od_cas.*;
           SEQUENCE od_cas.*

在SOURCE端
新增一組data pump名稱為p_odcas
       GGSCI (oggs.dba.local) 6> add extract p_odcas, exttrailsource /u01/app/goldengate/ogg/dirdat/E1, begin now

在SOURCE端
將p_odcas加入remote trail
       GGSCI (oggs.dba.local) 7> add rmttrail /u01/app/goldengate/ogg/dirdat/R1, extract p_odcas, megabytes 200

在SOURCE端
啟動extract及pump
        GGSCI (oggs.dba.local) 8> start extract e_odcas
        GGSCI (oggs.dba.local) 9> start extract p_odcas

在TARGET端配置replicat
        GGSCI (racnode01.dba.local) 5> edit params r_odcas
              replicat r_odcas
             setenv (ORACLE_HOME= "/u01/app/oracle/product/11.2.0.4/dbhome_1")
             setenv (ORACLE_SID=orcl)
             setenv (NLS_LANG="AMERICAN_TAIWAN.AL32UTF8")
             userid ogg@orcl, password ogg
             assumetargetdefs
             APPLYNOOPUPDATES
             BATCHSQL
             --reperror (default,discard)
             --reperror 1403, ignore
            discardfile /u01/app/goldengate/ogg/dirrpt/r_odcas.dsc,purge,megabytes 100 
           map od_cas.*, target od_cas.*;

在TARGET端
新增一個Replicat process
        GGSCI (racnode01.dba.local) 6> add replicat r_odcas, exttrail /u01/app/goldengate/ogg/dirdat/R1, checkpointtable ogg.chktab

在SOURCE端初始化資料(Initial Load)
取得SOURCE端資料庫SCN
        SQL> select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER from dual;
                  GET_SYSTEM_CHANGE_NUMBER
                  ------------------------
                        1016207

在SOURCE端匯出資料
         expdp system/Aa1234567@orcl directory=dumpfile dumpfile=exp_full.dmp logfile=exp_full.log schemas=od_cas FLASHBACK_SCN=1016207

在TARGET端匯入
         impdp system/Aa1234567@orcl1 directory=dumpfile dumpfile=exp_full.dmp logfile=imp_full.log

在TARGET端
啟動replicat processes
start replicat R_ODCAS, aftercsn 1016207

檢查GOLDENGATE是否正常
檢查重點
1. 所有服務的STATUS皆須為RUNNING
2.  Lag at Chkpt需小於10秒
3. Time Since Chkpt 需小於10秒
在SOURCE端
         GGSCI (oggs.dba.local) 6> info all
              Program           Status              Group            Lag at Chkpt    Time Since Chkpt
              MANAGER    RUNNING                                          
              EXTRACT      RUNNING     E_ODCAS     00:00:00           00:00:01  
              EXTRACT      RUNNING     P_ODCAS     00:00:00           00:00:03  

在TARGET端
         GGSCI (racnode01.dba.local) 5> info all
              Program           Status              Group             Lag at Chkpt    Time Since Chkpt
              MANAGER     RUNNING                                          
              REPLICAT      RUNNING     R_ODCAS     00:00:00           00:00:02  


2016年8月9日 星期二

[ORACLE] 在RAC環境下變更資料庫端的CHARACTER(字符集)

說明:
1. 從AL32UTF8轉換為ZHT16BIG5
2. NODE01的INSTANCE為orcl1(主要操作主機,重點在alter system set cluster_database=false scope=spfile sid='orcl1';)
3. NODE01的INSTANCE為orcl1
4. NODE02的INSTANCE為orcl2
5. 別用srvctl語法下上DB

在NODE01上
[oracle@racnode01 ~]$ sqlplus / as sysdba

SQL> select userenv('language') from dual;
          USERENV('LANGUAGE')
          ----------------------------------------------------
          AMERICAN_AMERICA.AL32UTF8

SQL> select instance_name from v$instance;
          INSTANCE_NAME
          ----------------
          orcl1

SQL> alter system set cluster_database=false scope=spfile sid='orcl1';

SQL> shutdown immediate;

在NODE02上
[oracle@racnode02 ~]$ sqlplus / as sysdba

SQL> select instance_name from v$instance;
          INSTANCE_NAME
          ----------------
          orcl2

SQL> shutdown immediate;

在NODE01上
SQL> startup nomount;

SQL> Alter database mount exclusive;

SQL> Alter system enable restricted session;

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;

SQL> Alter database open;

SQL> ALTER DATABASE CHARACTER SET INTERNAL_USE ZHT16BIG5;

SQL> alter system set cluster_database=true scope=spfile sid='orcl1';

SQL> shutdown immediate;

SQL> startup;

SQL> select userenv('language') from dual;
         USERENV('LANGUAGE')
         ----------------------------------------------------
         AMERICAN_AMERICA.ZHT16BIG5

在NODE02上
SQL> startup;

SQL> select userenv('language') from dual;
          USERENV('LANGUAGE')
          ----------------------------------------------------
         AMERICAN_AMERICA.ZHT16BIG5

2016年8月4日 星期四

[ORACLE] 建立sequence Part II

        最近在測試GOLDENGATE的時候需要測試sequence透過GOLDENGATE同步時的結果,之前有寫過透過TRIGGER方式來取號([ORACLE] 11g建立sequence),但是我個人是不太愛TRIGGER,因為剛開始使用TRIGGER時都會記得,但久了很多AP幾乎都忘記有這個東西,當有TRIGGER的TABLE資料有異常時,AP就會來問我為什麼資料會這樣,我只要問他是不是有TRIGGER,通常AP就會很快地記起有這件事情,這著實照成了一些困擾。

所以呢這次就改用另一個方式來做吧
01. 先建立一個測試TABLE EMP
       CREATE TABLE "OD_XYZ"."EMP"
            ( COLUMN1  NUMBER(*,0),
              COLUMN2  VARCHAR2(20 BYTE),
              COLUMN3  DATE
            ) TABLESPACE "OD_XYZ_DATA" ;

02. 建立一個名稱為emp_sequence的Sequence 
        CREATE SEQUENCE emp_sequence 
                  INCREMENT BY 1  -- 每次加幾個 
                  START WITH 1    -- 從1開始 
                  NOMAXVALUE      -- 在這邊先不設定最大值 
                  NOCYCLE         -- 採用累加方式不循環使用 
                  CACHE 10; 

03. 新增10000筆測試資料
begin
    for i in 1.. 100000
        loop
             insert into OD_XYZ.emp values (emp_sequence.nextval, 'LEWIS', SYSDATE);
        commit;
    end loop;
end;

04. 看結果
      select * from emp order by 1 desc;



2016年8月3日 星期三

[ORACLE] ORA-00600:內部錯誤代碼,參數:[qks3tAssert:1],[35072]

問題:
將DBMS_STATS.GATHER_TABLE_STATS包在PACKAGE中,在執行PACKAGE的時候會報ORA-00600錯誤(圖一),再去看一下對應的TRACE可以看到如圖二的錯誤訊息
圖一

圖二

描述:
        一般來說SQL執行速度慢,不外乎幾個處理方式,看執行計畫有沒有需要增加INDEX,需不需要rebuild index,更新一下統計資訊之類的,在此case增加一個DBMS_STATS.GATHER_TABLE_STATS其實也沒有錯,但是好巧不巧剛好踩到ORACLE 9.2.0.7之後的一個BUG,剛好出問題的是9.2.0.8,不過還好這個BUG有Patch(5089244)可以修正

資料來源:ORACLE SUPPORT
文件ID:418727.1

後記:
        其實這個CASE有個好玩的地方,在測試環境執行PACKAGE的時候是不會有ORA-00600的錯誤,但是上到正式環境就會出現ORA-00600,更好玩的是雖然出現ORA-00600的錯誤,但是實際去看該TABLE的Last Analyzed卻是有執行完成。

2016年8月1日 星期一

[ORACLE] 批次expdp卡住,在expdp log中出現ORA-31693,ORA-02354,ORA-01555的錯誤訊息

問題:批次expdp卡住,在expdp log會看到如下的錯誤訊息

ORA-31693: Table data object "$SCHEMA"."$TABLE_NAME" failed to load/unload and is being skipped due to error:
ORA-02354: error in exporting/importing data
ORA-01555: snapshot too old: rollback segment number 20 with name "_SYSSMU20_4037596720$" too small

解決方法:
1. 若有長時間DML語法,請不要在EXPDP時間發動
2. 增加undo_retention參數size
3. UNDO tablespace 空間必須足夠不然會出現ORA-01555錯誤
4. 在報錯的TABLE上若有欄位是LOB請參考http://www.dba-oracle.com/t_export_unload_blob_clob.htm
5. 增加rollback segment 大小


資料來源

2016年6月14日 星期二

[Oracle] 安裝Oracle RAC 11g R2 Cluster on RedHat Linux 6.5 (九) Enabled Archivelog (啟用歸檔模式)

在Oracle RAC 11g R2 Cluster啟用Archivelog(歸檔)有兩種方式,
一 不指定log_archive_dest_1,若不指定預設路徑會在FRA的路徑下
二 指定log_archive_dest_1(建議用這種)

方式一 不指定log_archive_dest_1
1. 在NODE01連線到資料庫
sqlplus / as sysdba
2. 查看是否啟用Archivelog
archive log list;
3. 回到作業系統,關閉資料庫
srvctl stop database -d orcl
4. 將資料庫啟動在mount
srvctl start database -d orcl -o mount
5. 連線到資料庫
sqlplus / as sysdba
6. 啟用Archivelog
ALTER DATABASE ARCHIVELOG;
7. 查看是否啟用Archivelog
archive log list;

完整執行程序如下
[oracle@racnode01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Jun 14 14:01:39 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> archive log list;
Database log mode        No Archive Mode
Automatic archival        Disabled
Archive destination        USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     11
Current log sequence        12
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
[oracle@racnode01 ~]$ srvctl stop database -d orcl
[oracle@racnode01 ~]$ srvctl start database -d orcl -o mount
[oracle@racnode01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Jun 14 14:03:42 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> ALTER DATABASE ARCHIVELOG;
Database altered.
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
[oracle@racnode01 ~]$ srvctl stop database -d orcl
[oracle@racnode01 ~]$ srvctl start database -d orcl
[oracle@racnode01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Jun 14 14:05:08 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> archive log list;
Database log mode        Archive Mode
Automatic archival        Enabled
Archive destination        USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     11
Next log sequence to archive   12
Current log sequence        12


方法二  指定log_archive_dest_1
1. 在NODE01連線到資料庫
sqlplus / as sysdba
2. 查看是否啟用Archivelog
archive log list;
3. 指定archivelog路徑,本範例為指定到ASM的DATA02
ALTER SYSTEM SET log_archive_dest_1='location=+DATA02' SCOPE=spfile;
4. 指定archivelog檔案格式
ALTER SYSTEM SET log_archive_format='arch_%t_%s_%r.arc' SCOPE=spfile;
5. 回到作業系統,關閉資料庫
srvctl stop database -d orcl
6. 將資料庫啟動在mount
srvctl start database -d orcl -o mount
7. 連線到資料庫
sqlplus / as sysdba
8. 啟用Archivelog
ALTER DATABASE ARCHIVELOG;
9. 查看是否啟用Archivelog
archive log list;

完整執行程序如下
[oracle@racnode01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jun 15 10:43:52 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> archive log list;
Database log mode        No Archive Mode
Automatic archival        Disabled
Archive destination        USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     11
Current log sequence        12
SQL> ALTER SYSTEM SET log_archive_dest_1='location=+DATA02' SCOPE=spfile;
System altered.
SQL> ALTER SYSTEM SET log_archive_format='arch_%t_%s_%r.arc' SCOPE=spfile;
System altered.
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
[oracle@racnode01 ~]$ srvctl stop database -d orcl
[oracle@racnode01 ~]$ srvctl start database -d orcl -o mount
[oracle@racnode01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jun 15 10:55:05 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> ALTER DATABASE ARCHIVELOG;
Database altered.
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
[oracle@racnode01 ~]$ srvctl stop database -d orcl
[oracle@racnode01 ~]$ srvctl start database -d orcl
[oracle@racnode01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jun 15 10:56:30 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> archive log list;
Database log mode        Archive Mode
Automatic archival        Enabled
Archive destination        +DATA02
Oldest online log sequence     11
Next log sequence to archive   12
Current log sequence        12






2016年5月22日 星期日

[ORACLE] ORA-00257 archiver error 解決方法

前言:
        這次出問題的資料庫為測試機,正常情況下是不會開啟archivelog及FRA(flash recovery area)。

問題:
        USER回報連不上資料庫,經過測試會出現ORA-00257的錯誤,發生原因就是archivelog爆了,但是去看實體空間其實還有很大,爆掉的其實是FRA,在預設的情形下若有開啟archivelog就會備份在此,可以透過v$flash_recovery_area_usage查看目前FRA空間使用情形。

解決方式:
1. 增加FRA空間,FAR最少就要跟資料庫一樣大(有錢的作法)
    alter system set DB_RECOVERY_FILE_DEST_SIZE=;

2. 清除FRA後關閉archivelog及FRA(這次處理方式),文章皆為轉錄
    2.1 清除flash recovery area
    2.2 關閉flash recovery area
    P.S. FLASHBACK DATABASE文章

以上文章出處為:樂沙彌的世界 MG05 學習筆記~

2016年5月2日 星期一

[ORACLE] 在Red Hat Enterprise 6.5安裝Oracle 11.2.0.4

安裝Red Hat Enterprise Linux 6.5及環境準備
01. 在[Welcome to Red Hat Enterprise Linux 6.5]視窗中游標選到[Install or upgrade an existing system]後按下[Enter]

02. 在[Disk Found]按下[Skip]

03 按下[Next]

04.  在[What language would you like to use during the installation process?]視窗按下[Next]

05. 在[Select the appropriate keyboard for the system.]視窗按下[Next]

06 在[What type of devices will your installation involve?]按下[Next]

07. 在[Storage Device Warning]視窗中按下[Yes, discard any data]

08. 在[Please name this computer. The hostname identifies the computer on a network.]視窗中的[Hostname]輸入[racnode01.dba.local],在按下下方的[Configure Network]

09. 在[Network Connections]視窗中點選[System eth0]後按下[Edit]

10. 在[Editing System eth0]視窗中勾選[Connect automatically],點選[IPv4 Settings]頁籤,將[Method]下拉選[Manual],再按下[Add]輸入如下資訊後按下[Apply]。每個環境不同在本例中相關資訊如下
Adderss:192.168.100.10
Netmask:24
Gateway:192.168.100.254
DNS server:192.168.100.100

11. 回到[Network Connections]視窗中按下[Close]

12. 回到[Please name this computer. The hostname identifies the computer on a network.]視窗按下[Next]

13. 在[Please select the nearest in your time zone]視窗中的[Select city]下拉選[Asia/Taipei]後按下[Next]

14. 在[The root account is used for administering the system. Enter a password for the root user]視窗中的[Root Password]及[Confirm]輸入兩次相同之密碼後按下[Next]

15. 在[Which type installation would you like?]視窗中點選[Use All Space],再將最下方的[Review and modify partitioning layout]勾選後按下[Next]

16. 點選[lv_root]後按下[Edit]

17. 在[Edit Logical Volume:lv_root]視窗中的[Size]輸入[32262]後按下[OK]
P.S.:縮小Root Mount Point主要是為了放大SWAP空間,因為在安裝Oracle時會檢查SWAP間是否有大於等於RAM,不然會不給安裝。

18. 點選[lv_swap]後按下[Edit]

19. 在[Edit Logical Volume:lv_swap]視窗中的[Size]輸入[8192]後按下[OK]

20. 回到[Please Select A Device]視窗按下[Next]

21. 在[Format Warnings]視窗中按下[Format]

22. 在[Writing storage configuration to disk]視窗中按下[Write change to disk]

23. 按下[Next]

24. 在[The default installition of Red Hat Enterprise Linux is a basic server install. You can optionally select a different set of software now.]視窗最下方點選[Customize now]後按下[Next]

25. 此步驟中的需安裝的Package詳閱文章最後的註一,選完後按下[Next]

26. 按下[Reboot]


27. 在[Welcome]視窗中按下[Rorward]


28. 在[License Information]視窗中按下[Next]


29. 在[Set Up Software Update]視窗中點選[No, I prefer to register at a later time]後按下[Forward]


30. 在[Are you Sure?]視窗中按下[register later]


31. 在[Finish Update Setup]視窗中按下[Forward]


32. 在[Create User]視窗中按下[Forward]


33. 按下[Yes]


34. 在[Date and Time]視窗中確認時間及日期是否正確後按下[Forward]


35. 在[Kdump]視窗中將[Enable kdump]取消勾選後按下[Finish]


36. 按下[Yes]


37. 按下[OK]

38. 安裝所需Package(安裝光碟片中有)。若在步驟25有安裝所需之PACKAGE的話,僅需再安裝以下兩隻,更完整的PACKAGE請詳閱註二
   1. ksh
   2. libaio-devel

39. 增加HOSTS資訊
vi /etc/hosts
192.168.100.10  racnode01.dba.local

40. 關閉SELinux
vi /etc/selinux/config
SELINUX=disabled

41. 關閉防火牆
/etc/rc.d/init.d/iptables stop
chkconfig iptables off

42. 建立相關帳號及群組
groupadd --gid 54321 oinstall
groupadd --gid 54322 dba
groupadd --gid 54323 asmdba
groupadd --gid 54324 asmoper
groupadd --gid 54325 asmadmin
groupadd --gid 54326 oper
useradd --uid 54321 --gid oinstall --groups dba,oper,asmdba,asmoper oracle
passwd oracle
useradd --uid 54322 --gid oinstall --groups dba,asmadmin,asmdba,asmoper grid
passwd grid

43. 建立軟體所需目錄
mkdir -p /u01/app/grid
mkdir -p /u01/app/11.2.4/grid
chown -R grid:oinstall /u01
mkdir -p /u01/app/oracle
chown oracle:oinstall /u01/app/oracle
chmod -R 775 /u01

44. 設定ORACLE帳號所需之環境變數
使用ORACLE帳號登入
vi /home/oracle/.bash_profile

if [ -f ~/.bashrc ]; then
      . ~/.bashrc
fi
alias ls="ls -FA"
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_UNQNAME=orcl; export ORACLE_UNQNAME
JAVA_HOME=/usr/local/java; export JAVA_HOME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/dbhome_1; export ORACLE_HOME
ORACLE_PATH=/u01/app/common/oracle/sql; export ORACLE_PATH
ORACLE_TERM=xterm; export ORACLE_TERM
NLS_DATE_FORMAT="DD-MON-YYYY HH24:MI:SS"; export NLS_DATE_FORMAT
TNS_ADMIN=$ORACLE_HOME/network/admin; export TNS_ADMIN
ORA_NLS11=$ORACLE_HOME/nls/data; export ORA_NLS11
PATH=.:${JAVA_HOME}/bin:${PATH}:$HOME/bin:$ORACLE_HOME/bin
PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
PATH=${PATH}:/u01/app/common/oracle/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export CLASSPATH
THREADS_FLAG=native; export THREADS_FLAG
export TEMP=/tmp
export TMPDIR=/tmp
umask 022

45. 設定GRID帳號所需之環境變數
使用GRID帳號登入
vi /home/grid/.bash_profile
if [ -f ~/.bashrc ]; then
      . ~/.bashrc
fi
alias ls="ls -FA"
JAVA_HOME=/usr/local/java; export JAVA_HOME
ORACLE_BASE=/u01/app/grid; export ORACLE_BASE
ORACLE_HOME=/u01/app/11.2.0.4/grid; export ORACLE_HOME
ORACLE_PATH=/u01/app/oracle/common/oracle/sql; export ORACLE_PATH
ORACLE_TERM=xterm; export ORACLE_TERM
NLS_DATE_FORMAT="DD-MON-YYYY HH24:MI:SS"; export NLS_DATE_FORMAT
TNS_ADMIN=$ORACLE_HOME/network/admin; export TNS_ADMIN
ORA_NLS11=$ORACLE_HOME/nls/data; export ORA_NLS11
PATH=.:${JAVA_HOME}/bin:${PATH}:$HOME/bin:$ORACLE_HOME/bin
PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
PATH=${PATH}:/u01/app/common/oracle/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export CLASSPATH
THREADS_FLAG=native; export THREADS_FLAG
export TEMP=/tmp
export TMPDIR=/tmp
umask 022

46. 設定shell權限
touch /etc/security/limits.d/99-grid-oracle-limits.conf
vi /etc/security/limits.d/99-grid-oracle-limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 10240
grid hard stack 32768

47. vi /etc/profile.d/oracle-grid.sh
#Setting the appropriate ulimits for oracle and grid user
if [ $USER = "oracle" ]; then
 if [ $SHELL = "/bin/ksh" ]; then
  ulimit -u 16384
  ulimit -n 65536
 else
  ulimit -u 16384 -n 65536
 fi
fi
if [ $USER = "grid" ]; then
 if [ $SHELL = "/bin/ksh" ]; then
  ulimit -u 16384
  ulimit -n 65536
 else
  ulimit -u 16384 -n 65536
 fi
fi

48. 設定Kernel Parameters,P.S.:在原本的設定中已經有kernel.shmmax及kernel.shmall請註記掉
vi /etc/sysctl.conf
vm.swappiness = 0
vm.dirty_background_ratio = 3
vm.dirty_ratio = 80
vm.dirty_expire_centisecs = 500
vm.dirty_writeback_centisecs = 100
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
# fs.file-max needs to be set to at least 6815744 for Oracle Installation.
fs.file-max = 6815744
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
# set to the appropriate private eth devices
net.ipv4.conf.em3.rp_filter = 2
net.ipv4.conf.em4.rp_filter = 2

49. 讓前述步驟修改的設定立即生效
sysctl -p

安裝ORACLE軟體
50. 用ORACLE帳號登入後安裝
[oracle@racnode01 database]$ ./runInstaller
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB.   Actual 21302 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 8191 MB    Passed
Checking monitor: must be configured to display at least 256 colors.    Actual 16777216    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2016-05-03_10-42-08AM. Please wait ...[oracle@racnode01 database]$

51. 在[Configure Security Updates]視窗中將[I wish to receive security updates via Oracle Support]取消勾選後按下[Next]

52. 在[My Oracle Support Username/Email Address Not Specified]視窗中按下[Yes]

53. 在[Download Software Updates]視窗中點選[Skip software updates]後按下[Next]

54. 在[Select Installation Option]視窗中點選[Install database software only]後按下[Next]

55. 在[Drid Installation Options]視窗中點選[Single instance database installation]後按下[Next]

56. 在[Slect Product Languages]視窗中按下[Next]

57. 在[Select Database Edition]視窗中按下[Next]


58. 在[Specify Insatllation Location]視窗中按下[Next]

59. 在[Create Inventory]視窗中按下[Next]

60. 在[Privileged Operating System Groups]視窗中按下[Next]

61. 在[Perform Prerequiste Checks]視窗中勾選[Ignore All]後按下[Next]。P.S.:因在步驟38中已安裝KSH故pdksh可不安裝。
62. 在[Oracle Database 11g Release 2 Installer]視窗中按下[Yes]

63. 在[Summary]視窗中按下[Install]

64. 在[Execture Configuration scripts]視窗中,透過root帳號依序執行[orainstRoot.sh]及[root.sh]後按下[OK]。詳細執行語法參閱註四。

65. 在[Finish]視窗中按下[Close]

設定Listener
66. 啟動NETCA
到/u01/app/oracle/product/11.2.0.4/dbhome_1/bin路徑下
./netca

67. 在[Oracle Net Configuration Assistant:Welcome]視窗中按下[Next]

68. 在[Oracle Net Configuration Assistant:Listener Configuration,Listener]視窗中按下[Next]

69. 在[Oracle Net Configuration Assistant:Listener Configuration,Listener Name..]視窗中按下[Next]

70. 在[Oracle Net Configuration Assistant:Listener Configuration,Select Proto...]視窗中按下[Next]

71. 在[Oracle Net Configuration Assistant:Listener Configuration,TCP/IP Proto..]視窗中按下[Next]

72. 在[Oracle Net Configuration Assistant:Listener Configuration,More Listen..]視窗中按下[Next]

73. 在[Oracle Net Configuration Assistant:Listener Configuration Done]視窗中按下[Next]

74. 在[Oracle Net Configuration Assistant:Welcome]視窗中按下[Finish]

安裝Oracle Database
75. 啟動DBCA
到/u01/app/oracle/product/11.2.0.4/dbhome_1/bin路徑下
./dbca

76. 在[Database Configuration Assistant:Welcome]視窗中按下[Next]


77. 在[Database Configuration Assistant, Step 1 of 12:Operations]視窗中按下[Next]

78. 在[Database Configuration Assistant, Step 2 of 12:Database Templates]視窗中按下[Next]


79. 在[Database Configuration Assistant, Step 3 of 12:Database Identificatiom]視窗中的[Global Database Name]輸入[orcl]後按下[Next]

80. 在[Database Configuration Assistant, Step 4 of 12:Management Options]視窗中按下[Next]

81. 在[Database Configuration Assistant, Step 5 of 12:Database Credentials]視窗中點選[Use the Same Administrative Paaword for all Accounts],輸入兩次密碼(此密碼不可含有特殊字元,不然安裝到約80%會報錯)後按下[Next]

82. 在[Database Configuration Assistant, Step 6 of 12:Database File Locations]視窗中按下[Next]

83. 在[Database Configuration Assistant, Step 7 of 12:Recovery Configuration]視窗中將[Specify Fast Recovery Area]取消勾選後按下[Next]。
P.S.:如果有足夠的磁碟空間建議開啟,且FRA空間大小需大於資料庫Size

84. 在[Database Configuration Assistant, Step 8 of 12:Database Content]視窗中按下[Next]

85. 在[Database Configuration Assistant, Step 9 of 12:Initialzation Parameters]視窗中的[memory]頁籤,將[Use Automatic Memory Management]勾選

86. 在[Database Configuration Assistant, Step 9 of 12:Initialzation Parameters]視窗中的[character Sets]頁籤,點選[Choose from the list of character Sets]勾選,在[Database character Sets]指定為[Al32UTF8......]後按下[Next]

87. 在[Database Configuration Assistant, Step 10 of 12:Database Storage]視窗中按下[Next]

88. 在[Database Configuration Assistant, Step 11 of 12:Creation Options]視窗中按下[Finish]

89. 在[Confirnation]視窗中按下[OK]

90. 在[Database Configuration Assistant]視窗中按下[Exit],完成安裝Database

91. 檢查Instance Status
[oracle@racnode01 ~]$ sqlplus / as sysdba@orcl
SQL*Plus: Release 11.2.0.4.0 Production on Tue May 3 13:39:53 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select instance_name,status from v$instance;
INSTANCE_NAME  STATUS
---------------- ------------
orcl   OPEN



註一:需安裝的Package如下
Base System > Base
Base System > Client management tools
Base System > Compatibility libraries
Base System > Hardware monitoring utilities
Base System > Large Systems Performance
Base System > Network file system client
Base System > Performance Tools
Base System > Perl Support
Servers > Server Platform
Servers > System administration tools
Desktops > Desktop
Desktops > Desktop Platform
Desktops > Fonts
Desktops > General Purpose Desktop
Desktops > Graphical Administration Tools
Desktops > Input Methods
Desktops > X Window System
Development > Additional Development
Development > Development Tools
Applications > Internet Browser

註二:安裝所需Package
cloog-ppl
compat-libcap1
compat-libstdc++-33
cpp
gcc
gcc-c++
glibc-devel
glibc-headers
kernel-headers
ksh
libXmu
libXt
libXv
libXxf86dga
libXxf86misc
libXxf86vm
libaio-devel
libdmx
libstdc++-devel
mpfr
make
ppl
xorg-x11-utils
xorg-x11-xaut

註三:Oracle建議的SWAP空間計算方式如下
Oracle建議您將交換空間的內存量的1.5倍與2 GB的RAM或更少的系統。對於具有2 GB的系統,
最小swap space=1.5GB
RAM<2GB-->swap space=RAM*1.5(或2)
RAM為2GB到16GB RAM-->swap space等於RAM。
RAM>16GB-->swap space=16GB
查看記憶體大小
cat /proc/meminfo | grep MemTotal
查看SWAP大小
cat /proc/meminfo | grep SwapTotal

註四:詳細執行語法
[root@racnode01 oraInventory]# ./orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.

[root@racnode01 dbhome_1]# ./root.sh
Performing root user operation for Oracle 11g
The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/11.2.0.4/dbhome_1
Enter the full pathname of the local bin directory: [/usr/local/bin]:
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...

Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Finished product-specific root actions.