阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

192次阅读
没有评论

共计 15175 个字符,预计需要花费 38 分钟才能阅读完成。

1. deinstall工具

1.1. 工具 介绍

deinstall工具是 Oracle 提供的数据库软件卸载工具,使用方法可以参考官方文档路径:Installing and Upgrading→Database Installation Guide for Linux→ 7 Removing Oracle Database Software
具体路径为:http://docs.oracle.com/cd/E11882_01/install.112/e47689/remove_oracle_sw.htm#LADBI1336


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 11SEP2017 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. Alias LISTENER
  7. Version TNSLSNR for Linux: Version 11.2.0.4.0 Production
  8. Start Date 11SEP2017 14:44:32
  9. Uptime 0 days 0 hr. 0 min. 44 sec
  10. Trace Level off
  11. Security ON: Local OS Authentication
  12. SNMP OFF
  13. Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
  14. Listener Log File /u01/app/oracle/diag/tnslsnr/DB074/listener/alert/log.xml
  15. Listening Endpoints Summary...
  16.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DB074.bj)(PORT=1521)))
  17.   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  18. Services Summary...
  19. Service “cams” has 1 instance(s).
  20.   Instance “cams”, status READY, has 1 handler(s) for this service...
  21. Service “camsXDB” has 1 instance(s).
  22.   Instance “cams”, status READY, has 1 handler(s) for this service...
  23. The command completed successfully
  24.  
  25.  
  26. [oracle@DB074 ~]$ lsnrctl stop
  27. LSNRCTL for Linux: Version 11.2.0.4.0 Production on 11SEP2017 14:45:29
  28. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  29. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  30. The command completed successfully
  31.  
  32.  
  33. [oracle@DB074 ~]$ lsnrctl status
  34. LSNRCTL for Linux: Version 11.2.0.4.0 Production on 11SEP2017 14:45:36
  35. Copyright (c) 1991, 2013, Oracle. All rights reserved.
  36. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
  37. TNS12541: TNS:no listener
  38.  TNS12560: TNS:protocol adapter error
  39.   TNS00511: No listener
  40.    Linux Error: 111: Connection refused
  41. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
  42. TNS12541: TNS:no listener
  43.  TNS12560: TNS:protocol adapter error
  44.   TNS00511: No listener
  45.    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 haldaddonstorage: 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/deinstall20170911_025004PM/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 deconfiguration trace file location: /tmp/deinstall20170911_025004PM/logs/netdc_check20170911_025010PM.log
  16. Specify all Single Instance listeners that are to be deconfigured [LISTENER]:(这里需要确认监听器名称,默认值没问题,直接回车)
  17. Network Configuration check config END
  18. Database Check Configuration START
  19. Database deconfiguration trace file location: /tmp/deinstall20170911_025004PM/logs/databasedc_check20170911_025144PM.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 deconfiguration trace file location: /tmp/deinstall20170911_025004PM/logs/emcadc_check20170911_025224PM.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/deinstall20170911_025004PM/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 deconfigured: LISTENER
  43. The following databases were selected for deconfiguration : 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 deconfiguration trace file location: /tmp/deinstall20170911_025004PM/logs/emcadc_clean20170911_025224PM.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 deconfiguration trace file location: /tmp/deinstall20170911_025004PM/logs/databasedc_clean20170911_025316PM.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 deconfiguration trace file location: /tmp/deinstall20170911_025004PM/logs/netdc_clean20170911_025411PM.log
  68. Deconfiguring Single Instance listener(s): LISTENER
  69. Deconfiguring 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 deconfigured successfully.
  75. Deconfiguring backup files...
  76. Backup files deconfigured 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/deinstall20170911_025004PM/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 deconfigured the following database instances : cams
  98. Following Single Instance listener(s) were deconfigured 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. drwxrxrx 7 oracle oinstall 4096 Aug 27 2013 database
  8. drwxrxrx 2 oracle oinstall 4096 May 9 13:31 dump
  9. rwrr 1 root root 210877 Feb 6 2017 pdksh5.2.1437.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 11SEP2017 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. Alias LISTENER
  7. Version TNSLSNR for Linux: Version 11.2.0.4.0 Production
  8. Start Date 11SEP2017 14:44:32
  9. Uptime 0 days 0 hr. 0 min. 44 sec
  10. Trace Level off
  11. Security ON: Local OS Authentication
  12. SNMP OFF
  13. Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
  14. Listener Log File /u01/app/oracle/diag/tnslsnr/DB074/listener/alert/log.xml
  15. Listening Endpoints Summary...
  16.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DB074.bj)(PORT=1521)))
  17.   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  18. Services Summary...
  19. Service “cams” has 1 instance(s).
  20.   Instance “cams”, status READY, has 1 handler(s) for this service...
  21. Service “camsXDB” has 1 instance(s).
  22.   Instance “cams”, status READY, has 1 handler(s) for this service...
  23. The command completed successfully
 
  1. [oracle@DB074 ~]$ lsnrctl stop
  2. LSNRCTL for Linux: Version 11.2.0.4.0 Production on 11SEP2017 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 11SEP2017 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. TNS12541: TNS:no listener
  6.  TNS12560: TNS:protocol adapter error
  7.   TNS00511: No listener
  8.    Linux Error: 111: Connection refused
  9. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
  10. TNS12541: TNS:no listener
  11.  TNS12560: TNS:protocol adapter error
  12.   TNS00511: 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 haldaddonstorage: 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工具 进行 卸载操作,读者可以在工作之余在测试环境中进行尝试。

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-10/147441.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计15175字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中