配置静态监听解决ORA-12514错误的案例

今天做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測试网络server名是否正常
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,乍一看好像非常正常,可是解析确实出现了问题,那么怎么办呢?

之前只不过给server配置了一个动态监听,内容例如以下:

--主库监听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进程再去启动。这样速度更快。不用再等待若干秒,我们的client就能够通过静态监听马上脸上数据库server了。也就是说,能够不依赖server进程,完毕监听的工作。









posted @ 2017-04-25 10:04  yfceshi  阅读(1289)  评论(0编辑  收藏  举报