Oracle 12c为PDB创建专用监听

在某些情况下,需要为一个或多个PDB使用特定的专用监听端口。这就需要创建新的监听,并确保PDB注册到它上面。
在下面的例子中,我们创建新的监听LISTENER_PDB,使用的端口为1522,修改listener.ora文件添加如下内容:
LISTENER_PDB =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.80.220)(PORT = 1522))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )
  
使用如下命令启动监听LISTENER_PDB:
$ lsnrctl start LISTENER_PDB

在tnsnames.ora中添加如下:
LISTENER_PDB =
  (ADDRESS = (PROTOCOL = TCP)(HOST = server)(PORT = 1522))

修改PDB的listener_networks参数:
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         4 ORCLPDB2                       READ WRITE NO
         
SQL> alter system set listener_networks='((NAME=PDB_NETWORK2)(LOCAL_LISTENER=LISTENER_PDB))' SCOPE=BOTH;
System altered.

注意:listener_address字符串是一个地址(或地址列表),用于解析指定的监听。可以使用别名,本例中就使用了别名,尽管这需要在tnsnames.ora文件中添加地址条目。

[oracle@server admin]$ lsnrctl status
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 18-APR-2019 17:53:04
Copyright (c) 1991, 2016, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.80.220)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                18-APR-2019 17:52:50
Uptime                    0 days 0 hr. 0 min. 14 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/db_home/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/server/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.80.220)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "8459af1e117074d1e053f950a8c04129" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "8459b38716af75ede053f950a8c0a006" has 2 instance(s).
  Instance "orcl", status READY, has 2 handler(s) for this service...
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclpdb1" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclpdb2" has 2 instance(s).
  Instance "orcl", status READY, has 2 handler(s) for this service...
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

[oracle@server admin]$ lsnrctl status listener_pdb
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 18-APR-2019 17:53:13
Copyright (c) 1991, 2016, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.80.220)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias                     listener_pdb
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                18-APR-2019 17:46:55
Uptime                    0 days 0 hr. 6 min. 18 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/db_home/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/server/listener_pdb/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.80.220)(PORT=1522)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1522)))
Services Summary...
Service "8459b38716af75ede053f950a8c0a006" has 1 instance(s).
  Instance "orcl", status READY, has 2 handler(s) for this service...
Service "orclpdb2" has 1 instance(s).
  Instance "orcl", status READY, has 2 handler(s) for this service...
The command completed successfully

[oracle@server admin]$ lsnrctl service listener_pdb
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 18-APR-2019 17:53:52
Copyright (c) 1991, 2016, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.80.220)(PORT=1522)))
Services Summary...
Service "8459b38716af75ede053f950a8c0a006" has 1 instance(s).
  Instance "orcl", status READY, has 2 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER
         (ADDRESS=(PROTOCOL=tcp)(HOST=server)(PORT=59880))
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "orclpdb2" has 1 instance(s).
  Instance "orcl", status READY, has 2 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER
         (ADDRESS=(PROTOCOL=tcp)(HOST=server)(PORT=59880))
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
The command completed successfully

现在PDB orclpdb2已经注册在新的监听上,就可以使用1522端口连接orclpdb2:
[oracle@server admin]$ sqlplus test/test@//server:1522/orclpdb2
SQL*Plus: Release 12.2.0.1.0 Production on Thu Apr 18 17:55:12 2019
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> show pdbs
SP2-0382: The SHOW PDBS command is not available
SQL> show con_id
CON_ID
------------------------------
4
SQL> show con_name
CON_NAME
------------------------------
ORCLPDB2

此时连接非指定的PDB将报错:
[oracle@server admin]$ sqlplus test/test@//server:1522/orclpdb1
SQL*Plus: Release 12.2.0.1.0 Production on Thu Apr 18 18:05:40 2019
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
Enter user-name: 

使用1521端口仍然可以连接:
[oracle@server admin]$ sqlplus test/test@//server:1521/orclpdb2
SQL*Plus: Release 12.2.0.1.0 Production on Thu Apr 18 18:00:10 2019
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Last Successful login time: Thu Apr 18 2019 17:59:12 +08:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> show con_name
CON_NAME
------------------------------
ORCLPDB2
SQL> 
为了不使用默认1521或公用端口连接,可将默认监听停止(lsnrctl stop listener)或者删除,为pdb指定专用监听。

Oracle 12c为PDB创建专用监听_第1张图片

 

你可能感兴趣的:(Oracle)