分别用deinstall和命令行删除Oracle数据库软件

1. deinstall工具

1.1. 工具介绍


oracle
总共提供了2种使用deinstall方法

1如果Oracle安装无误,可以直接调用$ORACLE_HOME脚本$ORACLE_HOME/deinstall/deinstall

2如果Oracle安装有问题或者是其他情况,可以下载独立的工具,然后使用工具进行卸载。

官方文档给出的下载路径:

1.前往URL:

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

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.  
  26.  
  27. [oracle@DB074 ~]$ lsnrctl stop
  28. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:29
  29. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  30. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  31. The command completed successfully
  32.  
  33.  
  34. [oracle@DB074 ~]$ lsnrctl status
  35. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:36
  36. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  37. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  38. TNS-12541: TNS:no listener
  39.  TNS-12560: TNS:protocol adapter error
  40.   TNS-00511: No listener
  41.    Linux Error: 111: Connection refused
  42. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
  43. TNS-12541: TNS:no listener
  44.  TNS-12560: TNS:protocol adapter error
  45.   TNS-00511: No listener
  46.    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.  
  108. (在deinstall工具执行完之后,需要用root完成删除的内容)
  109. Run 'rm -rf /etc/oraInst.loc' as root on node(s) 'DB074' at the end of the session.
  110. Run 'rm -rf /opt/ORCLfmap' as root on node(s) 'DB074' at the end of the session.
  111. Run 'rm -rf /etc/oratab' as root on node(s) 'DB074' at the end of the session.
  112. Oracle deinstall tool successfully cleaned up temporary directories.
  113. #######################################################################
  114. ############# 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工具进行卸载操作,读者可以在工作之余在测试环境中进行尝试。

猜你喜欢

转载自www.linuxidc.com/Linux/2017-10/147441.htm
今日推荐