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参数,查看官方文档说明:
- -home
- 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.
- 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.
简单的说,就是使用第一种方法,可以直接运行脚本:
- $ORACLE_HOME/deinstall/deinstall
使用第二种方法,必须带上-home参数:
- $ORACLE_HOME/deinstall/deinstall -home $ORACLE_HOME
这里我们将会使用第一种方法进行卸载数据库,当然,第二种方法也是类似,只不过需要单独下载工具。
1.2. 环境准备
查看服务器的环境变量
- [oracle@DB074 ~]$env | grep ORA
- ORACLE_SID=cams
- ORACLE_BASE=/u01/app/oracle
- ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
查看监听的状态,如监听启动,则关闭监听。
- [oracle@DB074 ~]$ lsnrctl status
- LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:16
- Copyright (c) 1991, 2013, Oracle. All rights reserved.
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
- STATUS of the LISTENER
- ------------------------
- Alias LISTENER
- Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
- Start Date 11-SEP-2017 14:44:32
- Uptime 0 days 0 hr. 0 min. 44 sec
- Trace Level off
- Security ON: Local OS Authentication
- SNMP OFF
- Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
- Listener Log File /u01/app/oracle/diag/tnslsnr/DB074/listener/alert/log.xml
- Listening Endpoints Summary...
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DB074.bj)(PORT=1521)))
- (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
- Services Summary...
- Service "cams" has 1 instance(s).
- Instance "cams", status READY, has 1 handler(s) for this service...
- Service "camsXDB" has 1 instance(s).
- Instance "cams", status READY, has 1 handler(s) for this service...
- The command completed successfully
- [oracle@DB074 ~]$ lsnrctl stop
- LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:29
- Copyright (c) 1991, 2013, Oracle. All rights reserved.
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
- The command completed successfully
- [oracle@DB074 ~]$ lsnrctl status
- LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:36
- Copyright (c) 1991, 2013, Oracle. All rights reserved.
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
- TNS-12541: TNS:no listener
- TNS-12560: TNS:protocol adapter error
- TNS-00511: No listener
- Linux Error: 111: Connection refused
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
- TNS-12541: TNS:no listener
- TNS-12560: TNS:protocol adapter error
- TNS-00511: No listener
- Linux Error: 2: No such file or directory
查看数据库实例的状态,如数据库实例启动,则关闭数据库实例。
- [oracle@DB074 ~]$ ps -ef | grep smon
- oracle 3559 1 0 14:44 ? 00:00:00 ora_smon_cams
- oracle 3662 31107 0 14:47 pts/1 00:00:00 grep smon
- [oracle@DB074 ~]$ sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.4.0 Production on Mon Sep 11 14:47:25 2017
- 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
- SYS@cams>shutdown immediate;
- Database closed.
- Database dismounted.
- ORACLE instance shut down.
- SYS@cams>exit
- Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- [oracle@DB074 ~]$ ps -ef | grep smon
- oracle 3675 31107 0 14:47 pts/1 00:00:00 grep smon
最后,确保没有oracle进程启动
- [oracle@DB074 ~]$ ps -ef | grep ora
- root 1987 1945 0 Sep09 ? 00:01:16 hald-addon-storage: polling /dev/sr0 (every 2 sec)
- oracle 3677 31107 0 14:48 pts/1 00:00:00 ps -ef
- oracle 3678 31107 0 14:48 pts/1 00:00:00 grep ora
- root 31106 30170 0 11:34 pts/1 00:00:00 su - oracle
- oracle 31107 31106 0 11:34 pts/1 00:00:00 –bash
1.3. 执行deinstall卸载脚本
在oracle用户下,执行deinstall脚本
- [oracle@DB074 ~]$ $ORACLE_HOME/deinstall/deinstall
整个交互过程如下:
- [oracle@DB074 ~]$ $ORACLE_HOME/deinstall/deinstall
- Checking for required files and bootstrapping ...
- Please wait ...
- Location of logs /tmp/deinstall2017-09-11_02-50-04PM/logs/
- ############ ORACLE DEINSTALL & DECONFIG TOOL START ############
- ######################### CHECK OPERATION START #########################
- ## [START] Install check configuration ##
- Checking for existence of the Oracle home location /u01/app/oracle/product/11.2.0/db_1
- Oracle Home type selected for deinstall is: Oracle Single Instance Database
- Oracle Base selected for deinstall is: /u01/app/oracle
- Checking for existence of central inventory location /u01/app/oraInventory
- Checking for sufficient temp space availability on node(s) : 'DB074'
- ## [END] Install check configuration ##
- Network Configuration check config START
- Network de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/netdc_check2017-09-11_02-50-10-PM.log
- Specify all Single Instance listeners that are to be de-configured [LISTENER]:(这里需要确认监听器名称,默认值没问题,直接回车)
- Network Configuration check config END
- Database Check Configuration START
- Database de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/databasedc_check2017-09-11_02-51-44-PM.log
- Use comma as separator when specifying list of values as input
- Specify the list of database names that are configured in this Oracle home [cams]:(这里需要确认数据库名称,默认值没问题,直接回车)
- ###### For Database 'cams' ######
- Single Instance Database
- The diagnostic destination location of the database: /u01/app/oracle/diag/rdbms/cams
- Storage type used by the Database: FS
- Database file location: /u01/app/oracle/oradata/cams,/u01/app/oracle/fast_recovery_area/cams,/home/oracle/cams/tablespace
- Fast recovery area location: /u01/app/oracle/fast_recovery_area/CAMS
- database spfile location: /u01/app/oracle/product/11.2.0/db_1/dbs/spfilecams.ora
- The details of database(s) cams have been discovered automatically. Do you still want to modify the details of cams database(s)? [n]:(这里需要确认数据库详细信息,默认值没问题,不需要修改,直接回车)
- Database Check Configuration END
- Enterprise Manager Configuration Assistant START
- EMCA de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/emcadc_check2017-09-11_02-52-24-PM.log
- Checking configuration for database cams
- Enterprise Manager Configuration Assistant END
- Oracle Configuration Manager check START
- OCM check log file location : /tmp/deinstall2017-09-11_02-50-04PM/logs//ocm_check4203.log
- Oracle Configuration Manager check END
- ######################### CHECK OPERATION END #########################
- ####################### CHECK OPERATION SUMMARY #######################
- Oracle Home selected for deinstall is: /u01/app/oracle/product/11.2.0/db_1
- Inventory Location where the Oracle home registered is: /u01/app/oraInventory
- Following Single Instance listener(s) will be de-configured: LISTENER
- The following databases were selected for de-configuration : cams
- Database unique name : cams
- Storage used : FS
- Will update the Enterprise Manager configuration for the following database(s): cams
- No Enterprise Manager ASM targets to update
- No Enterprise Manager listener targets to migrate
- Checking the config status for CCR
- Oracle Home exists with CCR directory, but CCR is not configured
- CCR check is finished
- Do you want to continue (y - yes, n - no)? [n]: y(输入y,然后回车)
- 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'
- 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'
- ######################## CLEAN OPERATION START ########################
- Enterprise Manager Configuration Assistant START
- EMCA de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/emcadc_clean2017-09-11_02-52-24-PM.log
- Updating Enterprise Manager Database Control configuration for database cams
- Updating Enterprise Manager ASM targets (if any)
- Updating Enterprise Manager listener targets (if any)
- Enterprise Manager Configuration Assistant END
- Database de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/databasedc_clean2017-09-11_02-53-16-PM.log
- Database Clean Configuration START cams
- This operation may take few minutes.
- Database Clean Configuration END cams
- Network Configuration clean config START
- Network de-configuration trace file location: /tmp/deinstall2017-09-11_02-50-04PM/logs/netdc_clean2017-09-11_02-54-11-PM.log
- De-configuring Single Instance listener(s): LISTENER
- De-configuring listener: LISTENER
- Stopping listener: LISTENER
- Warning: Failed to stop listener. Listener may not be running.
- Deleting listener: LISTENER
- Listener deleted successfully.
- Listener de-configured successfully.
- De-configuring backup files...
- Backup files de-configured successfully.
- The network configuration has been cleaned up successfully.
- Network Configuration clean config END
- Oracle Configuration Manager clean START
- OCM clean log file location : /tmp/deinstall2017-09-11_02-50-04PM/logs//ocm_clean4203.log
- Oracle Configuration Manager clean END
- Setting the force flag to false
- Setting the force flag to cleanup the Oracle Base
- Oracle Universal Installer clean START
- Detach Oracle home '/u01/app/oracle/product/11.2.0/db_1' from the central inventory on the local node : Done
- Delete directory '/u01/app/oracle/product/11.2.0/db_1' on the local node : Done
- Delete directory '/u01/app/oraInventory' on the local node : Done
- Delete directory '/u01/app/oracle' on the local node : Done
- Oracle Universal Installer cleanup was successful.
- Oracle Universal Installer clean END
- ## [START] Oracle install clean ##
- Clean install operation removing temporary directory '/tmp/deinstall2017-09-11_02-50-04PM' on node 'DB074'
- ## [END] Oracle install clean ##
- ######################### CLEAN OPERATION END #########################
- ####################### CLEAN OPERATION SUMMARY #######################
- Updated Enterprise Manager configuration for database cams
- Successfully de-configured the following database instances : cams
- Following Single Instance listener(s) were de-configured successfully: LISTENER
- Cleaning the config for CCR
- As CCR is not configured, so skipping the cleaning of CCR configuration
- CCR clean is finished
- Successfully detached Oracle home '/u01/app/oracle/product/11.2.0/db_1' from the central inventory on the local node.
- Successfully deleted directory '/u01/app/oracle/product/11.2.0/db_1' on the local node.
- Successfully deleted directory '/u01/app/oraInventory' on the local node.
- Successfully deleted directory '/u01/app/oracle' on the local node.
- Oracle Universal Installer cleanup was successful.
- (在deinstall工具执行完之后,需要用root完成删除的内容)
- Run 'rm -rf /etc/oraInst.loc' as root on node(s) 'DB074' at the end of the session.
- Run 'rm -rf /opt/ORCLfmap' as root on node(s) 'DB074' at the end of the session.
- Run 'rm -rf /etc/oratab' as root on node(s) 'DB074' at the end of the session.
- Oracle deinstall tool successfully cleaned up temporary directories.
- #######################################################################
- ############# ORACLE DEINSTALL & DECONFIG TOOL END #############
根据最后的提示信息,切换到root用户,删除相应的文件
- [oracle@DB074 ~]$ su - root
- Password:
- [root@DB074 ~]# rm -rf /etc/oraInst.loc
- [root@DB074 ~]# rm -rf /opt/ORCLfmap
- [root@DB074 ~]# rm -rf /etc/oratab
切换到oracle用户,检查$ORACLE_BASE路径下文件:
- [root@DB074 oracle]# su - oracle
- [oracle@DB074 ~]$ cd $ORACLE_BASE
- -bash: cd: /u01/app/oracle: No such file or directory
- [oracle@DB074 ~]$ cd /u01/app/
- [oracle@DB074 app]$ ll
- total 216
- drwxr-xr-x 7 oracle oinstall 4096 Aug 27 2013 database
- drwxr-xr-x 2 oracle oinstall 4096 May 9 13:31 dump
- -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)查看服务器的环境变量
- [oracle@DB074 ~]$ env | grep ORA
- ORACLE_SID=cams
- ORACLE_BASE=/u01/app/oracle
- ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
(3)查看监听的状态,如监听启动,则关闭监听。
- [oracle@DB074 ~]$ lsnrctl status
- LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:16
- Copyright (c) 1991, 2013, Oracle. All rights reserved.
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
- STATUS of the LISTENER
- ------------------------
- Alias LISTENER
- Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
- Start Date 11-SEP-2017 14:44:32
- Uptime 0 days 0 hr. 0 min. 44 sec
- Trace Level off
- Security ON: Local OS Authentication
- SNMP OFF
- Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
- Listener Log File /u01/app/oracle/diag/tnslsnr/DB074/listener/alert/log.xml
- Listening Endpoints Summary...
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DB074.bj)(PORT=1521)))
- (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
- Services Summary...
- Service "cams" has 1 instance(s).
- Instance "cams", status READY, has 1 handler(s) for this service...
- Service "camsXDB" has 1 instance(s).
- Instance "cams", status READY, has 1 handler(s) for this service...
- The command completed successfully
- [oracle@DB074 ~]$ lsnrctl stop
- LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:29
- Copyright (c) 1991, 2013, Oracle. All rights reserved.
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
- The command completed successfully
- [oracle@DB074 ~]$ lsnrctl status
- LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-SEP-2017 14:45:36
- Copyright (c) 1991, 2013, Oracle. All rights reserved.
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DB074.bj)(PORT=1521)))
- TNS-12541: TNS:no listener
- TNS-12560: TNS:protocol adapter error
- TNS-00511: No listener
- Linux Error: 111: Connection refused
- Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
- TNS-12541: TNS:no listener
- TNS-12560: TNS:protocol adapter error
- TNS-00511: No listener
- Linux Error: 2: No such file or directory
- (4)查看数据库实例的状态,如数据库实例启动,则关闭数据库实例。
-
- [oracle@DB074 ~]$ ps -ef | grep smon
- oracle 3559 1 0 14:44 ? 00:00:00 ora_smon_cams
- oracle 3662 31107 0 14:47 pts/1 00:00:00 grep smon
- [oracle@DB074 ~]$ sqlplus / as sysdba
- SQL*Plus: Release 11.2.0.4.0 Production on Mon Sep 11 14:47:25 2017
- 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
- SYS@cams>shutdown immediate;
- Database closed.
- Database dismounted.
- ORACLE instance shut down.
- SYS@cams>exit
- Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- [oracle@DB074 ~]$ ps -ef | grep smon
- oracle 3675 31107 0 14:47 pts/1 00:00:00 grep smon
- [oracle@DB074 ~]$ ps -ef | grep smon
(5)检查确保没有oracle进程启动
- [oracle@DB074 ~]$ ps -ef | grep ora
- root 1987 1945 0 Sep09 ? 00:01:16 hald-addon-storage: polling /dev/sr0 (every 2 sec)
- oracle 3677 31107 0 14:48 pts/1 00:00:00 ps -ef
- oracle 3678 31107 0 14:48 pts/1 00:00:00 grep ora
- root 31106 30170 0 11:34 pts/1 00:00:00 su - oracle
- oracle 31107 31106 0 11:34 pts/1 00:00:00 –bash
(6)切换到root用户,完整删除安装目录(如担心手滑,部分操作可以在oracle用户下完成)
- [root@DB074 oracle]# cd /
- [root@DB074 oracle]# rm -rf u01/
(7)将bin下面的文件删除,如果不知道具体在哪个bin路径下(有/usr/bin,/usr/local/bin等),可以先查找下系统路径
- [root@DB074 /]# find / -name oraenv
- /usr/local/bin/oraenv
- [root@DB074 /]# find / -name dbhome
- /usr/local/bin/dbhome
- [root@DB074 /]# find / -name coraenv
- /usr/local/bin/coraenv
- [root@DB074 /]# rm -rf /usr/local/bin/oraenv
- [root@DB074 /]# rm -rf /usr/local/bin/dbhome
- [root@DB074 /]# rm -rf /usr/local/bin/coraenv
(8)删除配置文件
- [root@DB074 ~]# rm -rf /etc/oraInst.loc
- [root@DB074 ~]# rm -rf /opt/ORCLfmap
- [root@DB074 ~]# rm -rf /etc/oratab
(9)删除home目录
- [root@DB074 ~]# rm -rf /home/oracle
(10)删除oracle用户和用户组
- [root@DB074 ~]# userdel -f oracle
- [root@DB074 ~]# groupdel -f oinstall
- [root@DB074 ~]# groupdel -f dba
(11)检查是否有自启动服务,进行删除
- [root@DB074 ~]#chkconfig –list
- [root@DB074 ~]#chkconfig --del XXX
3. 方法对比
(1)两种方法都能完成数据库软件的删除,使用deinstall工具的方法比较柔和,使用命令行删除的方法比较暴力。
(2)第一种方法删除后会有部分信息保留,如环境变量、安装软件、自定义目录等;第二种方法可以对数据库进行完整删除,也可以只删除部分内容。当然,两种方法没有好坏之分,可以视情况相结合使用。
(3)第二种方法操作过程中会多次在root用户下执行rm -rf命令,建议用户小心操作。
(4)文中没有尝试使用下载的deinstall工具进行卸载操作,读者可以在工作之余在测试环境中进行尝试。