Oracle19C PDB中普通用户可以通过sqlplus scott/tiger连接吗

发布时间 2023-06-21 16:57:49作者: PiscesCanon

 

Oracle19C PDB中普通用户可以通过sqlplus scott/tiger连接吗

 

先说结论,目前我还没找到方式。

研究了挺久,通过百度,通过mos上搜索,也想通过触发器来实现,发现都不行。

 

先说sys用户,是可以的。

通过设置ORACLE_PDB_SID这个环境变量,可以实现sys直接登录后连接到指定的PDB上。

[oracle@oem13c ~]$ unset ORACLE_PDB_SID
[oracle@oem13c ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jun 21 16:45:20 2023
Version 19.19.0.0.0

Copyright (c) 1982, 2022, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.19.0.0.0

16:45:20 SYS@oemdb(25)> show con_name

CON_NAME
------------------------------
CDB$ROOT
16:45:23 SYS@oemdb(25)> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
[oracle@oem13c ~]$ export ORACLE_PDB_SID=empdbrepos
[oracle@oem13c ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jun 21 16:45:45 2023
Version 19.19.0.0.0

Copyright (c) 1982, 2022, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.19.0.0.0

16:45:45 SYS@oemdb(25)> show con_name

CON_NAME
------------------------------
EMPDBREPOS

 

 

普通用户则不行会直接报错"ORA-01017: invalid username/password; logon denied"防偷防爬

[oracle@oem13c ~]$ export ORACLE_PDB_SID=empdbrepos
[oracle@oem13c ~]$ sqlplus scott/tiger

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jun 21 16:46:57 2023
Version 19.19.0.0.0

Copyright (c) 1982, 2022, Oracle.  All rights reserved.

ERROR:
ORA-01017: invalid username/password; logon denied


Enter user-name: 

 

 

 

MOS文档How to Connect to a Pluggable Database (PDB)? (文档 ID 2783729.1)明确提到了,当连接可插入数据库时,无论是本地或者远程,必须始终提供指向到PDB的services有效的连接字符串。

原话如下:

When connecting to a pluggable database, a valid service connection string that points to its service (previously configured and started) MUST always be provided, whether the connection is attempted locally or remotely

[oracle@oem13c ~]$ sqlplus scott/tiger@oem13c/empdbrepos

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jun 21 16:48:04 2023
Version 19.19.0.0.0

Copyright (c) 1982, 2022, Oracle. All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.19.0.0.0

16:48:04 SCOTT@oem13c/empdbrepos(240)>

 

 

不知道有没有其他方式可以不通过@connect_str来连接。