每次登录oracle时,都会收到错误消息:
ORA-12162 TNS:net service name is incorrectly specified
所以我被迫运行这个:
ORACLE_SID=mydb; export ORACLE_SID我想将mydb设置为默认的ORACLE_SID 。 我已经在寻找方法来做到这一点,但是我在linux上太生疏了,无法解决这个问题。 这是我到目前为止所尝试的内容:
[oracle]$ --> in .profile add export ORACLE_SID=mydb -bash: in: Permission denied [root]$ chsh -s /bin/bash oracle Changing shell for oracle. Shell changed.这是我的tnsnames.ora的样子:
MYDB= (DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=mydb, SID=mydb) ) )Every time I log in to oracle, I am given an error:
ORA-12162 TNS:net service name is incorrectly specified
So I am forced to run this:
ORACLE_SID=mydb; export ORACLE_SIDI'd like to set mydb to be the default ORACLE_SID. I have searched for ways to do this, but I'm too rusty on linux to pull this off. Here's what I've tried so far:
[oracle]$ --> in .profile add export ORACLE_SID=mydb -bash: in: Permission denied [root]$ chsh -s /bin/bash oracle Changing shell for oracle. Shell changed.Here's what my tnsnames.ora looks like:
MYDB= (DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=mydb, SID=mydb) ) )最满意答案
我必须定义ORACLE_SID并将其导出到oracle用户的.bash_profile 。 这意味着每次oracle用户登录时都会运行这两个步骤,因此它可能更像是一个hack,但它可以工作:
这是简短的版本。 如果您不确定自己在做什么,请转到详细部分,我会解释发生了什么。
$ sudo -i $ chsh /bin/bash oracle $ sudo su - oracle $ cd $ vi .bash_profile $ i ... # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH ###### ADD YOUR SID STUFF HERE ###### ORACLE_SID=mydb export ORACLE_SID ~ ~esc , :w! 保存, :q退出。
$ exit $ sudo su - oracle $ sqlplus / as sysdba而已。
细节
定义shell(可选)
如果你像我一样,并且系统管理员设置oracle帐户以在注销时自动禁用shell,则需要首先为oracle用户重新定义shell(以root身份):
$ sudo -i $ chsh /bin/bash oracle编辑配置文件然后您需要以oracle用户身份登录并编辑.bash_profile :
$ sudo su - oracle $ cd $ vi .bash_profile $ i您现在正在VI编辑器中编辑.bash_profile 。 它应该看起来像这样:
# .bash_profile ... # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH ~ ~你需要做的是在export PATH之后添加你的SID东西,所以它应该是这样的:
# User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH ###### ADD YOUR SID STUFF HERE ###### ORACLE_SID=mydb export ORACLE_SID ~ ~好的,现在你要保存文件,然后退出vi:
esc , :w! 保存, :q退出。
边栏疑难解答:如果由于oracle用户没有权限而导致保存文件时出现问题,那么您必须使用root用户执行此操作,这意味着您必须找到oracle的.bash_profile文件,这可能是在/home/oracle/ (请记住,它是一个隐藏文件,所以使用ls -a来查看它而不是ls )
好的,假设您仍然以oracle用户身份登录,则需要注销并重新登录。这将激活刚刚添加的代码,并定义ORACLE_SID。
$ exit $ sudo su - oracleI had to define the ORACLE_SID and export it in the oracle user's .bash_profile. This means these two steps are run each time the oracle user logs in, so it's possibly more of a hack, but it works:
Here's the short version. If you're not sure what you're doing, go to the detailed section where I explain what's going on.
$ sudo -i $ chsh /bin/bash oracle $ sudo su - oracle $ cd $ vi .bash_profile $ i ... # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH ###### ADD YOUR SID STUFF HERE ###### ORACLE_SID=mydb export ORACLE_SID ~ ~esc, :w! to save, :q to quit.
$ exit $ sudo su - oracle $ sqlplus / as sysdbaThat's it.
Details
Defining the shell (Optional)
If you're like me, and the sys admins set up the oracle account to automatically disable the shell on logout, you'll need to first redefine the shell for the oracle user (as root):
$ sudo -i $ chsh /bin/bash oracleEdit the profile Then you need to login as the oracle user and edit .bash_profile:
$ sudo su - oracle $ cd $ vi .bash_profile $ iYou're now editing the .bash_profile in the VI editor. It should look something like this:
# .bash_profile ... # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH ~ ~What you need to do is add your SID stuff after export PATH, so it should look like this:
# User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH ###### ADD YOUR SID STUFF HERE ###### ORACLE_SID=mydb export ORACLE_SID ~ ~OK, now you gotta save the file, and exit vi:
esc, :w! to save, :q to quit.
Troubleshooting Sidebar: If you have an issue saving the file because the oracle user doesn't have privileges, then you'll have to do it using the root user, which means you'll have to find oracle's .bash_profile file, which is probably in /home/oracle/ (Remember, it's a hidden file, so use ls -a to see it instead of ls)
OK, so assuming you're still logged in as the oracle user, you need to logout and log back in. That will activate the code you just added, and define the ORACLE_SID.
$ exit $ sudo su - oracle更多推荐
发布评论