分別用deinstall和命令列刪除Oracle資料庫軟體

neverinit發表於2017-09-11

1. deinstall工具

1.1. 工具介紹

deinstall工具是oracle提供的資料庫軟體解除安裝工具,使用方法可以參考官方文件路徑:Installing and Upgrading→Database Installation Guide for Linux→ 7 Removing Oracle Database Software
具體路徑為:


oracle
總共提供了2種使用deinstall方法

1如果Oracle安裝無誤,可以直接呼叫$ORACLE_HOME指令碼$ORACLE_HOME/deinstall/deinstall

2如果Oracle安裝有問題或者是其他情況,可以下載獨立的工具,然後使用工具進行解除安裝。

官方文件給出的下載路徑:

1.前往URL:


2.Oracle Database 11g Release 2下載區域找到對應的平臺版本,點選”See All”在新開啟的頁面底部可以下載到資料庫解除安裝工具。

另外,使用單獨的deinstall進行解除安裝的時候,必須指定-home引數,檢視官方文件說明

  1. -home
  2. Use this flag to indicate the home path of the Oracle home to check or deinstall. To deinstall Oracle software using the deinstall command in the Oracle home you plan to deinstall, provide a parameter file in another location, and do not use the -home flag.
  3. If you run deinstall from the $ORACLE_HOME/deinstall path, then the -home flag is not required because the tool knows from which home it is being run. If you use the standalone version of the tool, then -home is mandatory.

簡單的說,就是使用第一種方法,可以直接執行指令碼

  1. $ORACLE_HOME/deinstall/deinstall

使用第二種方法,必須帶上-home引數

  1. $ORACLE_HOME/deinstall/deinstall -home $ORACLE_HOME

這裡我們將會使用第一種方法進行解除安裝資料庫當然,第二種方法也是類似,只不過需要單獨下載工具。

1.2. 環境準備

檢視伺服器的環境變數

  1. [oracle@DB074 ~]$env | grep ORA
  2. ORACLE_SID=cams
  3. ORACLE_BASE=/u01/app/oracle
  4. ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

檢視監聽的狀態,如監聽啟動,則關閉監聽

  1. [oracle@DB074 ~]$ lsnrctl status
  2. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:16
  3. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  4. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  5. STATUS of the LISTENER
  6. ------------------------
  7. Alias LISTENER
  8. Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
  9. Start Date 11-SEP-2017 14:44:32
  10. Uptime 0 days 0 hr. 0 min. 44 sec
  11. Trace Level off
  12. Security ON: Local OS Authentication
  13. SNMP OFF
  14. Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
  15. Listener Log File /u01/app/oracle/diag/tnslsnr/DB074/listener/alert/log.xml
  16. Listening Endpoints Summary...
  17.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DB074.bj)(PORT=1521)))
  18.   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  19. Services Summary...
  20. Service "cams" has 1 instance(s).
  21.   Instance "cams", status READY, has 1 handler(s) for this service...
  22. Service "camsXDB" has 1 instance(s).
  23.   Instance "cams", status READY, has 1 handler(s) for this service...
  24. The command completed successfully


  25. [oracle@DB074 ~]$ lsnrctl stop
  26. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:29
  27. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  28. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  29. The command completed successfully


  30. [oracle@DB074 ~]$ lsnrctl status
  31. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:36
  32. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  33. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  34. TNS-12541: TNS:no listener
  35.  TNS-12560: TNS:protocol adapter error
  36.   TNS-00511: No listener
  37.    Linux Error: 111: Connection refused
  38. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
  39. TNS-12541: TNS:no listener
  40.  TNS-12560: TNS:protocol adapter error
  41.   TNS-00511: No listener
  42.    Linux Error: 2: No such file or directory

檢視資料庫例項的狀態,如資料庫例項啟動,則關閉資料庫例項


  1. [oracle@DB074 ~]$ ps -ef | grep smon
  2. oracle 3559 1 0 14:44 ? 00:00:00 ora_smon_cams
  3. oracle 3662 31107 0 14:47 pts/1 00:00:00 grep smon

  1. [oracle@DB074 ~]$ sqlplus / as sysdba
  2. SQL*Plus: Release 11.2.0.4.0 Production on Mon Sep 11 14:47:25 2017
  3. Copyright (c) 1982, 2013, Oracle. All rights reserved.
  4. Connected to:
  5. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  6. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  7. SYS@cams>shutdown immediate;
  8. Database closed.
  9. Database dismounted.
  10. ORACLE instance shut down.
  11. SYS@cams>exit
  12. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  13. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  14. [oracle@DB074 ~]$ ps -ef | grep smon
  15. oracle 3675 31107 0 14:47 pts/1 00:00:00 grep smon


最後確保沒有oracle程式啟動


  1. [oracle@DB074 ~]$ ps -ef | grep ora
  2. root 1987 1945 0 Sep09 ? 00:01:16 hald-addon-storage: polling /dev/sr0 (every 2 sec)
  3. oracle 3677 31107 0 14:48 pts/1 00:00:00 ps -ef
  4. oracle 3678 31107 0 14:48 pts/1 00:00:00 grep ora
  5. root 31106 30170 0 11:34 pts/1 00:00:00 su - oracle
  6. oracle 31107 31106 0 11:34 pts/1 00:00:00 –bash


1.3. 執行deinstall解除安裝指令碼

oracle使用者下,執行deinstall指令碼

  1. [oracle@DB074 ~]$ $ORACLE_HOME/deinstall/deinstall

整個互動過程如下:


  1. [oracle@DB074 ~]$ $ORACLE_HOME/deinstall/deinstall
  2. Checking for required files and bootstrapping ...
  3. Please wait ...
  4. Location of logs /tmp/deinstall2017-09-11_02-50-04PM/logs/
  5. ############ ORACLE DEINSTALL & DECONFIG TOOL START ############
  6. ######################### CHECK OPERATION START #########################
  7. ## [START] Install check configuration ##
  8. Checking for existence of the Oracle home location /u01/app/oracle/product/11.2.0/db_1
  9. Oracle Home type selected for deinstall is: Oracle Single Instance Database
  10. Oracle Base selected for deinstall is: /u01/app/oracle
  11. Checking for existence of central inventory location /u01/app/oraInventory
  12. Checking for sufficient temp space availability on node(s) : 'DB074'
  13. ## [END] Install check configuration ##
  14. Network Configuration check config START
  15. Network de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/netdc_check2017-09-11_02-50-10-PM.log
  16. Specify all Single Instance listeners that are to be de-configured [LISTENER]:(這裡需要確認監聽器名稱,預設值沒問題,直接回車)
  17. Network Configuration check config END
  18. Database Check Configuration START
  19. Database de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/databasedc_check2017-09-11_02-51-44-PM.log
  20. Use comma as separator when specifying list of values as input
  21. Specify the list of database names that are configured in this Oracle home [cams]:(這裡需要確認資料庫名稱,預設值沒問題,直接回車)
  22. ###### For Database 'cams' ######
  23. Single Instance Database
  24. The diagnostic destination location of the database: /u01/app/oracle/diag/rdbms/cams
  25. Storage type used by the Database: FS
  26. Database file location: /u01/app/oracle/oradata/cams,/u01/app/oracle/fast_recovery_area/cams,/home/oracle/cams/tablespace
  27. Fast recovery area location: /u01/app/oracle/fast_recovery_area/CAMS
  28. database spfile location: /u01/app/oracle/product/11.2.0/db_1/dbs/spfilecams.ora
  29. The details of database(s) cams have been discovered automatically. Do you still want to modify the details of cams database(s)? [n]:(這裡需要確認資料庫詳細資訊,預設值沒問題,不需要修改,直接回車)
  30. Database Check Configuration END
  31. Enterprise Manager Configuration Assistant START
  32. EMCA de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/emcadc_check2017-09-11_02-52-24-PM.log
  33. Checking configuration for database cams
  34. Enterprise Manager Configuration Assistant END
  35. Oracle Configuration Manager check START
  36. OCM check log file location : /tmp/deinstall2017-09-11_02-50-04PM/logs//ocm_check4203.log
  37. Oracle Configuration Manager check END
  38. ######################### CHECK OPERATION END #########################
  39. ####################### CHECK OPERATION SUMMARY #######################
  40. Oracle Home selected for deinstall is: /u01/app/oracle/product/11.2.0/db_1
  41. Inventory Location where the Oracle home registered is: /u01/app/oraInventory
  42. Following Single Instance listener(s) will be de-configured: LISTENER
  43. The following databases were selected for de-configuration : cams
  44. Database unique name : cams
  45. Storage used : FS
  46. Will update the Enterprise Manager configuration for the following database(s): cams
  47. No Enterprise Manager ASM targets to update
  48. No Enterprise Manager listener targets to migrate
  49. Checking the config status for CCR
  50. Oracle Home exists with CCR directory, but CCR is not configured
  51. CCR check is finished
  52. Do you want to continue (y - yes, n - no)? [n]: y(輸入y,然後回車)
  53. A log of this session will be written to: '/tmp/deinstall2017-09-11_02-50-04PM/logs/deinstall_deconfig2017-09-11_02-50-09-PM.out'
  54. Any error messages from this session will be written to: '/tmp/deinstall2017-09-11_02-50-04PM/logs/deinstall_deconfig2017-09-11_02-50-09-PM.err'
  55. ######################## CLEAN OPERATION START ########################
  56. Enterprise Manager Configuration Assistant START
  57. EMCA de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/emcadc_clean2017-09-11_02-52-24-PM.log
  58. Updating Enterprise Manager Database Control configuration for database cams
  59. Updating Enterprise Manager ASM targets (if any)
  60. Updating Enterprise Manager listener targets (if any)
  61. Enterprise Manager Configuration Assistant END
  62. Database de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/databasedc_clean2017-09-11_02-53-16-PM.log
  63. Database Clean Configuration START cams
  64. This operation may take few minutes.
  65. Database Clean Configuration END cams
  66. Network Configuration clean config START
  67. Network de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/netdc_clean2017-09-11_02-54-11-PM.log
  68. De-configuring Single Instance listener(s): LISTENER
  69. De-configuring listener: LISTENER
  70.     Stopping listener: LISTENER
  71.     Warning: Failed to stop listener. Listener may not be running.
  72.     Deleting listener: LISTENER
  73.     Listener deleted successfully.
  74. Listener de-configured successfully.
  75. De-configuring backup files...
  76. Backup files de-configured successfully.
  77. The network configuration has been cleaned up successfully.
  78. Network Configuration clean config END
  79. Oracle Configuration Manager clean START
  80. OCM clean log file location : /tmp/deinstall2017-09-11_02-50-04PM/logs//ocm_clean4203.log
  81. Oracle Configuration Manager clean END
  82. Setting the force flag to false
  83. Setting the force flag to cleanup the Oracle Base
  84. Oracle Universal Installer clean START
  85. Detach Oracle home '/u01/app/oracle/product/11.2.0/db_1' from the central inventory on the local node : Done
  86. Delete directory '/u01/app/oracle/product/11.2.0/db_1' on the local node : Done
  87. Delete directory '/u01/app/oraInventory' on the local node : Done
  88. Delete directory '/u01/app/oracle' on the local node : Done
  89. Oracle Universal Installer cleanup was successful.
  90. Oracle Universal Installer clean END
  91. ## [START] Oracle install clean ##
  92. Clean install operation removing temporary directory '/tmp/deinstall2017-09-11_02-50-04PM' on node 'DB074'
  93. ## [END] Oracle install clean ##
  94. ######################### CLEAN OPERATION END #########################
  95. ####################### CLEAN OPERATION SUMMARY #######################
  96. Updated Enterprise Manager configuration for database cams
  97. Successfully de-configured the following database instances : cams
  98. Following Single Instance listener(s) were de-configured successfully: LISTENER
  99. Cleaning the config for CCR
  100. As CCR is not configured, so skipping the cleaning of CCR configuration
  101. CCR clean is finished
  102. Successfully detached Oracle home '/u01/app/oracle/product/11.2.0/db_1' from the central inventory on the local node.
  103. Successfully deleted directory '/u01/app/oracle/product/11.2.0/db_1' on the local node.
  104. Successfully deleted directory '/u01/app/oraInventory' on the local node.
  105. Successfully deleted directory '/u01/app/oracle' on the local node.
  106. Oracle Universal Installer cleanup was successful.

  107. (在deinstall工具執行完之後,需要用root完成刪除的內容)
  108. Run 'rm -rf /etc/oraInst.loc' as root on node(s) 'DB074' at the end of the session.
  109. Run 'rm -rf /opt/ORCLfmap' as root on node(s) 'DB074' at the end of the session.
  110. Run 'rm -rf /etc/oratab' as root on node(s) 'DB074' at the end of the session.
  111. Oracle deinstall tool successfully cleaned up temporary directories.
  112. #######################################################################
  113. ############# ORACLE DEINSTALL & DECONFIG TOOL END #############


根據最後的提示資訊,切換到root使用者,刪除相應的檔案


  1. [oracle@DB074 ~]$ su - root
  2. Password:
  3. [root@DB074 ~]# rm -rf /etc/oraInst.loc
  4. [root@DB074 ~]# rm -rf /opt/ORCLfmap
  5. [root@DB074 ~]# rm -rf /etc/oratab


切換到oracle使用者,檢查$ORACLE_BASE路徑下檔案:


  1. [root@DB074 oracle]# su - oracle
  2. [oracle@DB074 ~]$ cd $ORACLE_BASE
  3. -bash: cd: /u01/app/oracle: No such file or directory
  4. [oracle@DB074 ~]$ cd /u01/app/
  5. [oracle@DB074 app]$ ll
  6. total 216
  7. drwxr-xr-x 7 oracle oinstall 4096 Aug 27 2013 database
  8. drwxr-xr-x 2 oracle oinstall 4096 May 9 13:31 dump
  9. -rw-r--r-- 1 root root 210877 Feb 6 2017 pdksh-5.2.14-37.el5_8.1.x86_64.rpm


顯然Oracle資料庫軟體已經刪除完畢。

2. 命令

假定伺服器原先是資料庫伺服器,現在要回收作為應用伺服器,需要將資料庫軟體等完全刪除。

1前期準備工作

將需要做保留的檔案進行備份,如資料庫資料,自定義資料庫指令碼等。

2)檢視伺服器的環境變數


  1. [oracle@DB074 ~]$ env | grep ORA
  2. ORACLE_SID=cams
  3. ORACLE_BASE=/u01/app/oracle
  4. ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1


3檢視監聽的狀態,如監聽啟動,則關閉監聽


  1. [oracle@DB074 ~]$ lsnrctl status
  2. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:16
  3. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  4. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  5. STATUS of the LISTENER
  6. ------------------------
  7. Alias LISTENER
  8. Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
  9. Start Date 11-SEP-2017 14:44:32
  10. Uptime 0 days 0 hr. 0 min. 44 sec
  11. Trace Level off
  12. Security ON: Local OS Authentication
  13. SNMP OFF
  14. Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
  15. Listener Log File /u01/app/oracle/diag/tnslsnr/DB074/listener/alert/log.xml
  16. Listening Endpoints Summary...
  17.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DB074.bj)(PORT=1521)))
  18.   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  19. Services Summary...
  20. Service "cams" has 1 instance(s).
  21.   Instance "cams", status READY, has 1 handler(s) for this service...
  22. Service "camsXDB" has 1 instance(s).
  23.   Instance "cams", status READY, has 1 handler(s) for this service...
  24. The command completed successfully

  1. [oracle@DB074 ~]$ lsnrctl stop
  2. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:29
  3. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  4. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  5. The command completed successfully

  1. [oracle@DB074 ~]$ lsnrctl status
  2. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:36
  3. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  4. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  5. TNS-12541: TNS:no listener
  6.  TNS-12560: TNS:protocol adapter error
  7.   TNS-00511: No listener
  8.    Linux Error: 111: Connection refused
  9. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
  10. TNS-12541: TNS:no listener
  11.  TNS-12560: TNS:protocol adapter error
  12.   TNS-00511: No listener
  13.    Linux Error: 2: No such file or directory

  1. (4)檢視資料庫例項的狀態,如資料庫例項啟動,則關閉資料庫例項。
    1. [oracle@DB074 ~]$ ps -ef | grep smon
    2. oracle 3559 1 0 14:44 ? 00:00:00 ora_smon_cams
    3. oracle 3662 31107 0 14:47 pts/1 00:00:00 grep smon
    4. [oracle@DB074 ~]$ sqlplus / as sysdba
    5. SQL*Plus: Release 11.2.0.4.0 Production on Mon Sep 11 14:47:25 2017
    6. Copyright (c) 1982, 2013, Oracle. All rights reserved.
    7. Connected to:
    8. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    9. With the Partitioning, OLAP, Data Mining and Real Application Testing options
    10. SYS@cams>shutdown immediate;
    11. Database closed.
    12. Database dismounted.
    13. ORACLE instance shut down.
    14. SYS@cams>exit
    15. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    16. With the Partitioning, OLAP, Data Mining and Real Application Testing options
    17. [oracle@DB074 ~]$ ps -ef | grep smon
    18. oracle 3675 31107 0 14:47 pts/1 00:00:00 grep smon


5檢查確保沒有oracle程式啟動


  1. [oracle@DB074 ~]$ ps -ef | grep ora
  2. root 1987 1945 0 Sep09 ? 00:01:16 hald-addon-storage: polling /dev/sr0 (every 2 sec)
  3. oracle 3677 31107 0 14:48 pts/1 00:00:00 ps -ef
  4. oracle 3678 31107 0 14:48 pts/1 00:00:00 grep ora
  5. root 31106 30170 0 11:34 pts/1 00:00:00 su - oracle
  6. oracle 31107 31106 0 11:34 pts/1 00:00:00 –bash


6切換到root使用者,完整刪除安裝目錄(擔心手滑,部分操作可以在oracle使用者下完成


  1. [root@DB074 oracle]# cd /
  2. [root@DB074 oracle]# rm -rf u01/


7bin下面的檔案刪除,如果不知道具體在哪個bin路徑下(有/usr/bin/usr/local/bin),可以先查詢下系統路徑

  1. [root@DB074 /]# find / -name oraenv
  2. /usr/local/bin/oraenv
  3. [root@DB074 /]# find / -name dbhome
  4. /usr/local/bin/dbhome
  5. [root@DB074 /]# find / -name coraenv
  6. /usr/local/bin/coraenv
  7. [root@DB074 /]# rm -rf /usr/local/bin/oraenv
  8. [root@DB074 /]# rm -rf /usr/local/bin/dbhome
  9. [root@DB074 /]# rm -rf /usr/local/bin/coraenv

8刪除配置檔案

  1. [root@DB074 ~]# rm -rf /etc/oraInst.loc
  2. [root@DB074 ~]# rm -rf /opt/ORCLfmap
  3. [root@DB074 ~]# rm -rf /etc/oratab

9刪除home目錄

  1. [root@DB074 ~]# rm -rf /home/oracle

10刪除oracle使用者使用者組

  1. [root@DB074 ~]# userdel -f oracle
  2. [root@DB074 ~]# groupdel -f oinstall
  3. [root@DB074 ~]# groupdel -f dba

11檢查是否有自啟動服務,進行刪除

  1. [root@DB074 ~]#chkconfig –list
  2. [root@DB074 ~]#chkconfig --del XXX

3. 方法對比

1兩種方法都能完成資料庫軟體的刪除,使用deinstall工具的方法比較柔和,使用命令列刪除的方法比較暴力。

2第一種方法刪除後會有部分資訊保留如環境變數、安裝軟體、自定義目錄等第二種方法可以對資料庫進行完整刪除,也可以只刪除部分內容。當然,兩種方法沒有好壞之分可以視情況結合使用。

3第二種方法操作過程中會多次在root使用者下執行rm -rf命令,建議使用者小心操作。

4文中沒有嘗試使用下載deinstall工具進行解除安裝操作,讀者可以在工作之餘在測試環境中進行嘗試。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31394774/viewspace-2144813/,如需轉載,請註明出處,否則將追究法律責任。

相關文章