今天做Linux下DG配置的时候,遇到一个现象,tnsname.ora文件配置都正常,tnsping也正常,监听也正常,但是仍然报ORA-12514错误:
 
SQL> set lin 130 pages 130 
SQL> select dest_id,error from v$archive_dest;
 
   DEST_ID ERROR
---------- -----------------------------------------------------------------
         1
         2 ORA-12514: TNS:listener does not currently know of service
           requested in connect descriptor
 
         3
         4
         5
         6
         7
         8
         9
        10
 
--查看主库监听
SQL> !lsnrctl status
 
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:31:46
 
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=prd)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date                08-OCT-2014 10:34:51
Uptime                    0 days 1 hr. 56 min. 54 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=prd)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "prd" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
Service "prdXDB" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
Service "prd_XPT" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
The command completed successfully
 
--tnsnames.ora文件内容
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
 
EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )
 
PRD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = prd)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = prd)
    )
  )
 
STD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = prd)
    )
  )
 
--主库tnsping测试网络服务名是否正常
SQL> !tnsping prd
 
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:32:35
 
Copyright (c) 1997,  2010, Oracle.  All rights reserved.
 
Used parameter files:
 
 
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = prd)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prd)))
OK (10 msec)
 
SQL> !tnsping std
 
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:32:43
 
Copyright (c) 1997,  2010, Oracle.  All rights reserved.
 
Used parameter files:
 
 
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prd)))
OK (20 msec)
 
--查看备库监听
[oracle@std ~]$ lsnrctl status
 
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:29:52
 
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=std)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date                08-OCT-2014 09:41:41
Uptime                    0 days 2 hr. 48 min. 11 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=std)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "std" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
Service "std_XPT" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
The command completed successfully
 
--查看备库远程归档路径
SQL> set lin 130 pages 130 
SQL> col error for a20
SQL> select dest_id,error,status from v$archive_dest;
 
   DEST_ID ERROR                STATUS
---------- -------------------- ---------
         1                      VALID
         2                      VALID
         3                      INACTIVE
         4                      INACTIVE
         5                      INACTIVE
         6                      INACTIVE
         7                      INACTIVE
         8                      INACTIVE
         9                      INACTIVE
        10                      INACTIVE
        11                      VALID
 
--备库tnsping测试网络服务器名是否正常
SQL> !tnsping prd
 
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:39:40
 
Copyright (c) 1997,  2010, Oracle.  All rights reserved.
 
Used parameter files:
 
 
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = prd)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prd)))
OK (20 msec)
 
SQL> !tnsping std
 
TNS Ping Utility for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:39:44
 
Copyright (c) 1997,  2010, Oracle.  All rights reserved.
 
Used parameter files:
 
 
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prd)))
OK (10 msec)
 
tnsping测试下来也都是通的,这就比较奇怪了,但是ORA-12514错误很明显是指监听方面的问题,导致服务名无法解析,由于主备库采用的是同一个实例名,因此两边的instance_name用的都是prd,乍一看好像很正常,但是解析确实出现了问题,那么怎么办呢?
 
之前仅仅只是给服务器配置了一个动态监听,内容如下:
 
--主库监听listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
  )
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = prd)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )
 
--主库监听listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
  )
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )
 
可以看到,区别仅仅是主机名不同而已,一个是prd,另一个是std,静态监听并未配置,即SID_LIST_LISTENER这一项里面的栏目,那么现在为主备库都配置一个监听。静态监听可以用netmgr配置,这里为了方便,不再进入图形界面执行该命令,而是直接通过修改listener.ora文件来达到目的,其效果是一样的,在原来的listener.ora文件中的SID_LIST_LISTENER中添加如下内容(红色部分):
 
SID_LIST_LISTENER =
  (SID_LIST =
   (SID_DESC =
      (GLOBAL_DBNAME = prd)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = prd)
    )
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
  )
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )
 
注意,加上的内容中,SID_NAME,即instance_name,而GLOBAL_DBNAME,即tnsnames.ora中的SERVICE_NAME,由于tnsnames.ora中的SERVICE_NAME都是prd,因此这里的两个名字是一样的,不会有什么影响,把修改好的文件替换掉原文件,再重新加载监听文件
 
SQL> !
[oracle@prd ~]$ lsnrctl reload
 
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:55:17
 
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=prd)(PORT=1521)))
The command completed successfully
[oracle@prd ~]$ lsnrctl status
 
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:55:24
 
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=prd)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date                08-OCT-2014 10:34:51
Uptime                    0 days 2 hr. 20 min. 33 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=prd)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "prd" has 2 instance(s).
  Instance "prd", status UNKNOWN, has 1 handler(s) for this service...
  Instance "prd", status READY, has 1 handler(s) for this service...
Service "prdXDB" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
Service "prd_XPT" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@prd ~]$ 
 
注意,这个UNKNOW的prd实例对应的服务名prd就是刚才我们通过静态监听发现的服务名,同那样地,备库也重新加载监听:
 
[oracle@std ~]$ lsnrctl reload
 
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:57:15
 
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=std)(PORT=1521)))
The command completed successfully
[oracle@std ~]$ lsnrctl status
 
LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 08-OCT-2014 12:57:25
 
Copyright (c) 1991, 2010, Oracle.  All rights reserved.
 
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=std)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.5.0 - Production
Start Date                08-OCT-2014 09:41:41
Uptime                    0 days 3 hr. 15 min. 44 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=std)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "prd" has 1 instance(s).
  Instance "prd", status UNKNOWN, has 1 handler(s) for this service...
Service "std" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
Service "std_XPT" has 1 instance(s).
  Instance "prd", status READY, has 1 handler(s) for this service...
The command completed successfully
 
可以看到,此时备库也多了一个UNKNOWN的,和实例名prd对应的服务prd
 
--再次查看主库远程归档路径状态
SQL> select dest_id,status,error from v$archive_dest_status;
 
   DEST_ID STATUS    ERROR
---------- --------- --------------------
         1 VALID
         2 VALID
         3 INACTIVE
         4 INACTIVE
         5 INACTIVE
         6 INACTIVE
         7 INACTIVE
         8 INACTIVE
         9 INACTIVE
        10 INACTIVE
 
原来dest_id=2的那个远程归档路径的ORA-12514的问题解决了,此时归档日志就可以通过网路远程传输到备库相应的归档路径中了,再执行redo apply也不会有任何问题了。
 
总结:
 
这个案例是由于主备库都采用了同一个实例名产生的问题,当我们只配置一个默认的动态监听,会发现主库无法监听到远程备库的相应服务,通过静态监听手动添加上与实例名对应的服务,才能解决这个问题。使用静态监听的另一个好处是,当Oracle数据库实例还没有启动的时候,就会先把对应的服务和实例名,通过静态配置的监听文件给启动起来,而不是等启动实例后由pmon进程再去启动,这样速度更快。不用再等待若干秒,我们的客户端就可以通过静态监听立即脸上数据库服务器了,也就是说,可以不依赖服务器进程,完成监听的工作。
http://m.blog.csdn.net/blog/aaron8219/39892437
 
 
04-28 09:07