【翻译自mos文章】How to Set or Switch Oracle Homes on Windows (Doc ID 969581.1)

 

参考原文:
How to Set or Switch Oracle Homes on Windows (Doc ID 969581.1)

适用于:
Oracle Database - Enterprise Edition - Version 9.2.0.1 to 11.2.0.1.0 [Release 9.2 to 11.2]
Microsoft Windows (32-bit)
Microsoft Windows Itanium (64-bit)
Microsoft Windows x64 (64-bit)

解决方案:
在windows环境中,为什么 不能被设置'ORACLE_HOME' 环境变量。--->注意:注册表中的ORACLE_HOME 键 跟 "系统属性"-"高级"-"环境变量"中的ORACLE_HOME环境变量不是一回事。

本文强调的是:不能被设置'ORACLE_HOME' 环境变量,而不是把 注册表中的ORACLE_HOME 键 给搞掉。

设置ORACLE_HOME 环境变量会导致软件功能异常,当你在windows上调用oracle的可执行程序(sqlplus.exe,exp.exe,tnsping.exe等等)时,Oracle 软件会从环境变量(这里是指设置了ORACLE_HOME环境变量的情况)中得到ORACLE_HOME 的信息,该信息可能与从注册表中得到的信息不匹配。
--->注意:也就是说,正常情况下(也就是说windows 不要设置ORACLE_HOME环境变量的情况下)windows下的oracle 可执行程序,在运行时, 其实是从注册表中 ORACLE_HOME的键值获得的相关的变量信息(variable)

当你在windows上调用Oracle 可执行程序时,比如sqlplus.exe, 这些可执行程序用到的变量(variable)是由 PATH环境变量 和 这些可执行程序的所在位置(即:该程序所在Oracle Home)所决定的。

--->请额外注意:根据我在windows上使用oracle的经验,windows 在cmd 下敲一个命令 和在unix下敲一个命令,windows 和 unix操作系统对你敲的这个命令的查找方法是不同的:
windows下,你在当前目录(比如说c:\user\administrator这个目录)下敲一个sqlplus命令,windows会搜索当前的目录下有没有sqlplus.exe这个命令,没有的话,再去PATH环境变量中取查找有没有sqlplus命令
而unix下,你在shell提示符下敲一个sqlplus命令,unix只会从PATH里查找。


windows 上rac的一点注意:
11gR2上有2个home,分别是GI Home和 db Home。在windows 上设置ORACLE_HOME 环境变量会导致 所有的clusterware日志(还有其他潜在问题)被写入到Oracle Home中,这个会导致诊断clusterware问题的难度。

Oracle 确定 可执行程序所在位置(location)的方法。

第一、对在ORACLE_HOME\bin 目录下的可执行程序:
在环境变量中设置"ORACLE_HOME=某具体路径" 是不需要的。这是因为在运行的时候,Oracle 软件 会确定可执行文件的所在位置(比如说c:\...\oracle\bin ),然后会在该位置打开一个'pointer' file (指针文件),这个指针文件指定了在注册表中的哪个位置去搜索Oracle 变量。注册表中的ORACLE_HOME 键就是被Oracle软件使用的变量值。因此,没有必要为使用 ORACLE_HOME\bin 下的可执行文件的任何进程(process)设置ORACLE_HOME= 环境变量。

第二、对于那些不存在于ORACLE_HOME\bin 下,但又需要加载oracle software的可执行文件(比如说:一个web server process 或者 其他的第三方的software)
如果第三方软件需要特定的Oracle DLL(动态链接库),那么该第三方软件会查找PATH环境变量值,直到找到该DLL,然后该DLL会穿透(or 透过)进程(上面描述的进程)以找到 pointer file,进而会找到ORACLE_HOME value.

启动oracle 可执行程序的不同方法:

1.从cmd提示符下启动
当敲入可执行程序的名字并且不带全部路径时,此时会首先得到PATH环境变量和 Oracle Home的可执行程序。你可以使用set命令改变PATH环境变量, 或者 使用控制面板-系统,改变环境变量,点击应用,然后再打开一个新的cmd命令提示符。
--->额外注意:这个说法是不正确的,估计写这一条的oracle工程师不了解windows下的可执行程序的搜索顺序---windows下,你在当前目录(比如说c:\user\administrator这个目录)下敲一个sqlplus命令,windows会搜索当前的目录下有没有sqlplus.exe这个命令,没有的话,再去PATH环境变量中取查找有没有sqlplus命令

2.从开始菜单
会调用在快捷方式中指向的全部路径中的可执行程序

3.开始--运行中调用(不是在开始-运行中,敲入cmd,然后再敲可执行命令)
从PATH环境变量中读取可执行程序。

使用OUI来修改默认的Oracle Home 和 PATH环境变量
你可以使用OUI来指定一个Oracle Home为默认的Oracle Home,OUI会更新PATH环境变量信息以指向那个Oracle Home

从开始-程序-Oracle - OraDb10g_home1-Oracle Installation Products-Universal Installer调用出 OUI
再点击"已安装产品",然后再打开"环境"Tab页,就能看到Oracle Home的环境变量信息。

To set the `ORACLE_HOME` environment variable in Oracle database configuration, follow the appropriate steps based on your operating system: ### On Linux or UNIX: 1. Determine the Oracle home directory path, such as `/u01/app/oracle/product/12.1.0/db_1`. 2. Choose the shell you are using and add the environment variable accordingly: - **For Bash shell:** Add the following lines to the `.bashrc` or `.bash_profile` file in your home directory: ```bash export ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1 export PATH=$ORACLE_HOME/bin:$PATH ``` After saving the file, run `source ~/.bashrc` or `source ~/.bash_profile` to apply the changes. - **For Korn or Bourne shell:** Add the following lines to your `.profile` file: ```sh ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1 PATH=$ORACLE_HOME/bin:$PATH export ORACLE_HOME PATH ``` Run `source ~/.profile` to apply the changes. - **For C shell (csh or tcsh):** Add the following lines to your `.cshrc` or `.tcshrc` file: ```csh setenv ORACLE_HOME /u01/app/oracle/product/12.1.0/db_1 set path=($ORACLE_HOME/bin $path) ``` ### On Windows: 1. Right-click on **This PC** or **Computer** on the desktop or in File Explorer and select **Properties**. 2. Click on **Advanced system settings** and then click on the **Environment Variables** button. 3. Under **System variables**, click **New** to create the `ORACLE_HOME` variable and set its value to the Oracle home directory path, such as `C:\app\oracle\product\12.1.0\db_1`. 4. Locate the existing `Path` system variable and edit it to include `%ORACLE_HOME%\bin` in the path. 5. Click **OK** to save the changes. Ensure that the `ORACLE_HOME` environment variable points to the correct Oracle installation directory to avoid configuration issues during database startup or operations[^2]. ### Verification To verify the setting of `ORACLE_HOME`, run the following commands in the terminal (Linux/UNIX) or Command Prompt (Windows): - On Linux/UNIX: ```sh echo $ORACLE_HOME ``` - On Windows: ```cmd echo %ORACLE_HOME% ``` These commands should display the Oracle home directory path you configured. ### Additional Considerations - If multiple Oracle homes exist on the system, ensure that the correct `ORACLE_HOME` is set to avoid conflicts or incorrect execution of Oracle tools. - When performing operations such as detaching or attaching an Oracle home using Oracle Universal Installer (OUI), explicitly specify the `ORACLE_HOME` parameter in the command line to ensure the correct home directory is used[^2].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值