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参数,查看官方文档说明:
-
-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
整个交互过程如下:
根据最后的提示信息,切换到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
(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工具进行卸载操作,读者可以在工作之余在测试环境中进行尝试。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31535639/viewspace-2154624/
,如需转载,请注明出处,否则将追究法律责任。