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.


2016年4月27日 星期三

[ORACLE][RMAN] 普通資料庫(非系統用的資料庫)災難復原

資料庫環境確認:
Instance啟動時:
1. 若一般資料庫datafile遺失,datafile headers毀損,startup只能啟動到mount

Instance執行中時:
1. 若一般資料庫datafile headers毀損時發生checkpoint,則該毀損的datafile會被標示為offline,但Instance不會有問題,而且重啟Instance時也不會有問題,但有問題的datafile依然是offline。
2. 若一般資料庫壞的不是datafile headers而是其他地方或是整個data毀損或被刪除,該datafile並不會被標示為offline,但重啟Instance時只能啟動到mount,不過還是可以透過alter database datafile <壞掉的檔案> offline;,再將Instance Open。

P.S.:此篇復原前提為參數檔(init),控制檔(controlfile),archivelog,redo log,關鍵資料庫(SYSTEM及UNDO)皆正常的情形下。

復原流程及完整指令:(以下範例為假設datafile 6毀損)
> 非datafile headers毀損,且資料庫為關閉的狀態
1. 將資料庫啟動到Mount
    startup mount;
2. 將有問題的datafile offline
    alter database datafile 6 offline;
3. 開啟資料庫
    alter database open;
4. 使用RMAN執行restore或是switch命令還原有問題的datafile
    restore datafile 6;
5. 使用RMAN執行recover,透過archivelog及redolog復原datafile
    recover datafile 6;
6. 將有問題的datafile online
    alter database datafile 6 online;

指令
1. 在RMAN
RUN{
startup mount;
sql 'alter database datafile 6 offline';
alter database open;
restore datafile 6;
recover datafile 6;
sql 'alter database datafile 6 online';
}

> 非datafile headers毀損,且資料庫為開啟的狀態
1. 將有問題的datafile offline
    alter database datafile 6 offline;
2. 使用RMAN執行restore或是switch命令還原有問題的datafile
    restore datafile 6;
3. 使用RMAN執行recover database,透過archivelog及redolog復原datafile
    recover datafile 6;
4. 將有問題的datafile online
    alter database datafile 6 online;


指令:
1. 在RMAN
RUN{
sql 'alter database datafile 6 offline';
restore datafile 6;
recover datafile 6;
sql 'alter database datafile 6 online';
}


>datafile headers毀損,且資料庫為開啟的狀態
1. 透過系統指令將毀損的datafile從作業系統刪除
    rm /oradata/test.dbf
2. 將有問題的datafile offline
    alter database datafile 6 offline;
3. 使用RMAN執行restore或是switch命令還原有問題的datafile
    restore datafile 6;
4. 使用RMAN執行recover database,透過archivelog及redolog復原datafile
    recover datafile 6;
5. 將有問題的datafile online
    alter database datafile 6 online;


指令:
1. 在作業系統
    rm /oradata/test.dbf
2. 在RMAN
RUN{
sql 'alter database datafile 6 offline';
restore datafile 6;
recover datafile 6;
sql 'alter database datafile 6 online';
}

>datafile headers毀損,且資料庫為關閉的狀態
1. 透過系統指令將毀損的datafile從作業系統刪除
    rm /oradata/test.dbf
2. 將資料庫啟動到Mount
    startup mount;
3. 將有問題的datafile offline
    alter database datafile 6 offline;
4. 開啟資料庫
    alter database open;
5. 使用RMAN執行restore或是switch命令還原有問題的datafile
    restore datafile 6;
6. 使用RMAN執行recover database,透過archivelog及redolog復原datafile
    recover datafile 6;
7. 將有問題的datafile online
    alter database datafile 6 online;

指令:
1. 在作業系統
    rm /oradata/test.dbf
2. 在RMAN
RUN{
startup mount;
sql 'alter database datafile 6 offline';
alter database open;
restore datafile 6;
recover datafile 6;
sql 'alter database datafile 6 online';
}

2016年4月25日 星期一

[ORACLE][RMAN]關鍵資料庫(SYSTEM及UNDO)災難復原

資料庫環境確認
1. Instance已經不正常結束
    sqlplus / as sysdba
    startup mount;

2. Instance尚在Open的狀況下
    2.1 還可以進入資料庫的情況下
          2.1.1 登入資料庫不會出現錯誤訊息
                   sqlplus / as sysdba
                   shutdown abort;
          2.1.2 登入資料庫但卻連到idle instance
                   直接KILL process,例如:kill SMON

3. 已無法進入資料庫
    直接KILL process,例如:kill SMON

P.S.:此篇復原前提為參數檔(init),控制檔(controlfile),archivelog,redo log皆正常的情形下。

復原流程:
1. 使用shutdown abort或是KILL process關閉資料庫
2. 執行startup mount;將資料庫啟動到Mount
3. 使用RMAN執行restore或是switch命令還原有問題的SYSTEM file或UNDO file
4. 使用RMAN執行recover database,透過archivelog及redolog復原資料庫
5. 執行alter database open開啟資料庫

復原詳細過程
1. 關閉資料庫
SQL> shutdown abort;
ORACLE instance shut down.

2. 啟動資料庫,發現有datafile毀損
SQL> startup;
ORACLE instance started.
Total System Global Area 3340451840 bytes
Fixed Size      2257840 bytes
Variable Size   1879051344 bytes
Database Buffers  1442840576 bytes
Redo Buffers     16302080 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/orclnofra/system01.dbf'

3. 檢查TRACE LOG
log路徑:/u01/app/oracle/diag/rdbms/orclnofra/orclnofra/trace/alert_orclnofra.log
log擷取部分錯誤如下

4. 透過restore database還原data file 1
RMAN> restore datafile 1;  
Starting restore at 25-APR-2016 17:28:00
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=129 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orclnofra/system01.dbf
channel ORA_DISK_1: reading from backup piece /backup/ORCLNOFR_20160425_6_1.bak
channel ORA_DISK_1: piece handle=/backup/ORCLNOFR_20160425_6_1.bak tag=TAG20160425T171813
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 25-APR-2016 17:28:15

5. 執行recover database
RMAN> recover database;
Starting recover at 25-APR-2016 17:28:55
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 25-APR-2016 17:28:56

6. 將資料庫OPEN
RMAN> alter database open;
database opened

7. 查看datafile是否OK
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orclnofra/system01.dbf
/u01/app/oracle/oradata/orclnofra/sysaux01.dbf
/u01/app/oracle/oradata/orclnofra/undotbs01.dbf
/u01/app/oracle/oradata/orclnofra/users01.dbf
/backup/test01.dbf
/backup/test02.dbf
6 rows selected.


2016年4月13日 星期三

[ORACLE][RMAN] ControlFile毀損情境三之利用沒問題Control file置換有問題的Control file

情境:
Control File至少還有一個是好的,其他都有問題

環境準備:
1. 確認Control file位置
SQL> select value from v$parameter where name like 'control_files%';

VALUE
--------------------------------------------------------------------------------
control_files
/u01/app/oracle/oradata/orclnofra/control01.ctl, /u01/app/oracle/oradata/orclnof
ra/control02.ctl

2. 刪除一個Control file
[oracle@nofra orclnofra]$ rm control01.ctl

完整執行過程:
1. 啟動資料庫
SQL> startup;
ORACLE instance started.

Total System Global Area 3340451840 bytes
Fixed Size      2257840 bytes
Variable Size   1879051344 bytes
Database Buffers  1442840576 bytes
Redo Buffers     16302080 bytes
ORA-00205: error in identifying control file, check alert log for more info

2. 查看ALERT LOG確認哪個Control File有問題
LOG路徑:/u01/app/oracle/diag/rdbms/orclnofra/orclnofra/trace
部分錯誤訊息如下
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL
=TCP))'...
starting up 1 shared server(s) ...
ORACLE_BASE from environment = /u01/app/oracle
Wed Apr 13 10:21:50 2016
ALTER DATABASE   MOUNT
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/orclnofra/control01.ctl'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
ORA-205 signalled during: ALTER DATABASE   MOUNT...

3. 把有問題的Control file用好的置換掉
[oracle@nofra orclnofra]$ cp control02.ctl control01.ctl

4. 將資料庫開在mount
SQL> alter database mount;

Database altered.

5.  將資料庫開在OPEN
SQL> alter database open;

Database altered.

2016年4月12日 星期二

[ORACLE][RMAN] ControlFile毀損情境二之還原方式(手動修復不一致)

情境:
1. 所有online Control file毀損
2. ControlFile Autobackup OFF
3. 備份完Control file後,DBA手動刪除了一個tablespace包含Data File,所以上次的Control file備份就沒有剛刪除的Data File

環境準備:
1. 新增一個Tablespace包含一個Datafile
SQL> create tablespace "myTest01" nologging
  2  datafile '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/myTest01_DT01.dbf'
  3  size 10m;
Tablespace created.

2. Switch LOG
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
System altered.

3. 手動備份controlfile
RMAN> backup current controlfile;
Starting backup at 12-APR-2016 14:18:03
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=197 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 12-APR-2016 14:18:05
channel ORA_DISK_1: finished piece 1 at 12-APR-2016 14:18:06
piece handle=/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/01r2rr8s_1_1 tag=TAG20160412T141803 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-APR-2016 14:18:06

4. 刪除剛剛建立的Tablespace
SQL> drop tablespace "myTest01" including contents and datafiles;
Tablespace dropped.

5. 手動刪除controlfile,模擬controlfile毀損
[oracle@nofra orclnofra]$ rm control01.ctl
[oracle@nofra orclnofra]$ rm control02.ctl


6. 重新啟動DB會出現如下錯誤
SQL> startup;
ORACLE instance started.
Total System Global Area 3340451840 bytes
Fixed Size      2257840 bytes
Variable Size   1879051344 bytes
Database Buffers  1442840576 bytes
Redo Buffers     16302080 bytes
ORA-00205: error in identifying control file, check alert log for more info

還原語法如下:
1. 在RMAN
restore controlfile from '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/01r2rr8s_1_1';
2. 在RMAN
mount database;

3. 復原資料庫,解法有兩種
解法一
3-1-1. 在SQLPLUS(在此範例中是編號5的datafile有問題)
alter database datafile 5 offline;
3-1-2. 在SQLPLUS
recover database using backup controlfile;
輸入:AUTO
3-1-2 在SQLPLUS
recover database using backup controlfile;
輸入redo log檔案路徑
3-1-3. 重複執行recover database using backup controlfile,並輸入redo log檔案路徑直到出現Media recovery complete

解法二
3-2-1 在RMAN
recover database skip tablespace "myTest01";

4. 在RMAN
alter database open resetlogs;


完整執行過程:
1. 還原Control File
RMAN> restore controlfile from '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/01r2rr8s_1_1';
Starting restore at 12-APR-2016 14:21:56
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=129 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orclnofra/control01.ctl
output file name=/u01/app/oracle/oradata/orclnofra/control02.ctl
Finished restore at 12-APR-2016 14:21:57

2. 將DB啟動在mount模式
RMAN> mount database;
database mounted
released channel: ORA_DISK_1

3. 恢復資料庫,會出現錯誤原因是在Control file中紀錄有剛剛建立的Tablespace但是實際上已經是不需要且被刪除了,但recover還是會一直要復原該檔案。
RMAN> recover database;
Starting recover at 12-APR-2016 14:22:48
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=129 device type=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/12/2016 14:22:48
RMAN-06094: datafile 5 must be restored

解法一
4-1-1. 將步驟三錯誤訊息中的datafile離線
SQL> alter database datafile 5 offline;
Database altered.

4-1-2. 透過using backup controlfile來復原資料庫,在出現[Specify log]提示時輸入[AUTO],在此例中又出現ORA-00308及ORA-27037的錯誤,但實際上並沒有損壞或是遭刪除,那就表示該資料尚未產生archive log,實際資料還在redo log中
SQL> recover database using backup controlfile;
ORA-00279: change 978477 generated at 04/12/2016 14:17:26 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_8_908881411.dbf
ORA-00280: change 978477 for thread 1 is in sequence #8

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00308: cannot open archived log
'/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_8_908881411.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log
'/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_8_908881411.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

4-1-3. 再次透過using backup controlfile來復原資料庫,在出現[Specify log]提示時輸入redo01.log的位置,結果發現並不存在於redo01.log
SQL> recover database using backup controlfile;
ORA-00279: change 978477 generated at 04/12/2016 14:17:26 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_8_908881411.dbf
ORA-00280: change 978477 for thread 1 is in sequence #8

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/orclnofra/redo01.log
ORA-00328: archived log ends at change 978453, need later change 978477
ORA-00334: archived log: '/u01/app/oracle/oradata/orclnofra/redo01.log'

4-1-4. 再次透過using backup controlfile來復原資料庫,在出現[Specify log]提示時輸入redo02.log的位置,若成功便會出現[Media recovery complete.]的訊息
SQL> recover database using backup controlfile;
ORA-00279: change 978477 generated at 04/12/2016 14:17:26 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch1_8_908881411.dbf
ORA-00280: change 978477 for thread 1 is in sequence #8

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/orclnofra/redo02.log
Log applied.
Media recovery complete.

解法二
4-2-1. 跳過有問題的Tablespace直接復原
RMAN> recover database skip tablespace "myTest01";
Starting recover at 11-APR-2016 16:45:10
using channel ORA_DISK_1
Executing: alter database datafile 6 offline
starting media recovery
archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oracle/oradata/orclnofra/redo01.log
archived log file name=/u01/app/oracle/oradata/orclnofra/redo01.log thread=1 sequence=1
media recovery complete, elapsed time: 00:00:00
Finished recover at 11-APR-2016 16:45:10

5. 將資料庫開啟
RMAN> alter database open resetlogs;
database opened

2016年4月11日 星期一

[ORACLE][RMAN] ControlFile毀損情境一之還原方式(自動修復不一致)

情境:
1. 所有online Control file毀損
2. ControlFile Autobackup OFF
3. 備份完Control file後,DBA手動加了一個tablespace包含Data File,所以上次的Control file備份就沒有剛新增的Data File

環境準備:
1. 手動備份controlfile
RMAN> backup current controlfile;
Starting backup at 11-APR-2016 14:15:54
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=9 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 11-APR-2016 14:15:56
channel ORA_DISK_1: finished piece 1 at 11-APR-2016 14:15:57
piece handle=/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/01r2p6or_1_1 tag=TAG20160411T141555 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-APR-2016 14:15:57

2. 新增一個tablespace包含一個Data File
SQL> create tablespace "myTest02" NOLOGGING
  2  datafile '/u01/app/oracle/oradata/orclnofra/myTest_Data02.dbf' SIZE 200M;
Tablespace created.

3. 手動刪除controlfile
[oracle@nofra orclnofra]$ rm control01.ctl
[oracle@nofra orclnofra]$ rm control02.ctl

4. 重新啟動DB會出現如下錯誤
RMAN> startup;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 04/11/2016 14:48:49
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/orclnofra/control01.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

還原語法如下:
1. 在RMAN
restore controlfile from '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/01r2p6or_1_1';
2. 在RMAN
recover database;
3. 在RMAN
alter database open resetlogs;

完整執行過程:
1.還原Control File
[oracle@nofra ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Apr 11 14:53:36 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database (not started)
RMAN> startup;
Oracle instance started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 04/11/2016 14:53:44
ORA-00205: error in identifying control file, check alert log for more info
RMAN> restore controlfile from '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/01r2p6or_1_1';
Starting restore at 11-APR-2016 14:55:12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=63 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orclnofra/control01.ctl
output file name=/u01/app/oracle/oradata/orclnofra/control02.ctl
Finished restore at 11-APR-2016 14:55:13

RMAN> recover database;
Starting recover at 11-APR-2016 14:57:46
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=129 device type=DISK
starting media recovery
archived log for thread 1 with sequence 6 is already on disk as file /u01/app/oracle/oradata/orclnofra/redo03.log
archived log file name=/u01/app/oracle/oradata/orclnofra/redo03.log thread=1 sequence=6
creating datafile file number=5 name=/u01/app/oracle/oradata/orclnofra/myTest_Data01.dbf
archived log file name=/u01/app/oracle/oradata/orclnofra/redo03.log thread=1 sequence=6
creating datafile file number=6 name=/u01/app/oracle/oradata/orclnofra/myTest_Data02.dbf
archived log file name=/u01/app/oracle/oradata/orclnofra/redo03.log thread=1 sequence=6
media recovery complete, elapsed time: 00:00:01
Finished recover at 11-APR-2016 14:57:50

RMAN> alter database open resetlogs;
database opened