最近在连接database的时候发现一个问题,当我从本地连接的时候,它没有问题:
admin]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Aug 6 03:17:04 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> show conn sys/admin as sysdba
Connected.
可是当我通过网络连接的时候,它却总是连不上:
[oracle@test ~]$ sqlplus as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Aug 6 02:09:41 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
端口是开着的,可是如下红色提示部分所示,端口虽是开的,可是没有服务注册。
[oracle@test ~]$ lsnrctl status testdb
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 06-AUG-2009 02:47:38
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(SID_NAME=testdb)(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROCTEST)))
STATUS of the LISTENER
------------------------
Alias testdb
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 06-AUG-2009 01:27:44
Uptime 0 days 1 hr. 19 min. 53 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/oracle/product/10.2.0/db_3/network/admin/listener.ora
Listener Log File /u01/app/oracle/oracle/product/10.2.0/db_3/network/log/testdb.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROCTEST))(SID_NAME=testdb))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1666))(SID_NAME=testdb))
The listener supports no services
The command completed successfully
这个问题困扰我很久,始终找不到其解,后来在网上搜索,并在下文中找到了答案(感谢下文的3个作者):
原因是我用的端口不是默认端口,动态注册默认只注册到默认的监听器上(名称是LISTENER、端口是1521、协议是TCP),如果需要向非默认监听注册,则需要配置local_listener参数!
在未对local_listener配置之前,查看它的值,发现是空的:
[oracle@test admin]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Aug 6 03:17:04 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> show conn sys/admin as sysdba
Connected.
SQL> show parameter local_lis
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string
配置local_listener:
SQL> alter system set LOCAL_LISTENER='(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT=1666))';
System altered.
SQL> COMMIT;
Commit complete.
配置后再次查看loacal_listener:
SQL> show parameter local_lis
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string (ADDRESS = (PROTOCOL = TCP)(HO
ST = 127.0.0.1)(PORT=1666))
SQL> EXIT
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
配置了这个参数以后,再次查看listener status,发现testdb已经动态注册了:
[oracle@test admin]$ lsnrctl stuatus testdb
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 06-AUG-2009 03:25:00
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(SID_NAME=testdb)(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROCTEST)))
STATUS of the LISTENER
------------------------
Alias testdb
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 06-AUG-2009 01:27:44
Uptime 0 days 1 hr. 57 min. 15 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/oracle/product/10.2.0/db_3/network/admin/listener.ora
Listener Log File /u01/app/oracle/oracle/product/10.2.0/db_3/network/log/testdb.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROCTEST))(SID_NAME=testdb))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1666))(SID_NAME=testdb))
Services Summary...
Service "testdb" has 1 instance(s).
Instance "testdb", status READY, has 1 handler(s) for this service...
Service "testdbXDB" has 1 instance(s).
Instance "testdb", status READY, has 1 handler(s) for this service...
Service "testdb_XPT" has 1 instance(s).
Instance "testdb", status READY, has 1 handler(s) for this service...
The command completed successfully
配置完local_listener,再次尝试用网络连络db,结果终于通过了。
[oracle@test admin]$ sqlplus as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Aug 6 03:31:48 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
###################################################################################
另外一个问题:
oracle刚装好后,因为$ORACLE_HOME这个目录的所有者oracle 和它所属的组oinstall,所以非这个组的用户是无权访问的,所以其它非oinstall组的人也无法使用oracle客户端命令,也无法用sqlplus连接db.
[oracle@test admin]$ ls -ld $ORACLE_HOME
drwxr-xr-x 55 oracle oinstall 4096 May 22 05:11 /u01/app/oracle/oracle/product/10.2.0/db_3
如果我们用以其它用户来接连db,必须要做以下几步:
1)将其它用户加入到oinstall这个组来,如:
[root@test ~]# usermod -G oinstall root
[root@test ~]# id root
uid=0(root) gid=0(root) groups=0(root),501(oinstall)
[root@test ~]#
2)编辑/etc/profile and .bash_profile,加入以下几个环境变量:
ORACLE_HOME=/u01/app/oracle/oracle/product/10.2.0/db_3
ORACLE_BASE=/u01/app/oracle/oracle/product/10.2.0/db_3
ORACLE_SID=testdb
export ORACLE_HOME ORACLE_BASE ORACLE_SID
path=$PATH:$ORACLE_HOME/bin;export PATH
3)source /etc/profile and .bash_profile使第二步的配置立即生效或者退出当前的login window 然后重新登陆。
===============================================================================
[root@rachel ~]# sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Nov 5 18:01:22 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> connect / as sysdba
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
解决办法:
vi /etc/profile and add the following line:
ORACLE_SID=TEST
export ORACLE_SID
source /etc/profile
退出当前putty window and re login.