19c 多租户下为了好区分登录位置,可以修改$ORACLE_HOME/sqlplus/admin/glogin.sql,加入:
set serveroutput on size 1000000
set trimspool on
set long 5000
set linesize 150
set pagesize 1000
col plan_plus_exp format a80
col global_name new_value gname
col member for a60
col file_name for a60
col table_name format a30
col index_name format a30
col owner format a20
set heading off
set termout off
define gname=idle
col global_name new_value gname
col global_name noprint
select lower(sys_context('userenv','current_user'))||'@'||sys_context('userenv','con_name')||':'||sys_context('userenv','db_name')||':'||userenv('sid') global_name from dual;
set sqlprompt '&gname> '
set heading on
set termout on
但遗憾的是还不能对alter session set container=PDB2后进行动态修改,解决方法是:
@sw pdb2
sw.sql 脚本内容:
alter session set container = &1;
@$ORACLE_HOME/sqlplus/admin/glogin.sql
效果如下:
[oracle@db1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Feb 9 00:16:13 2021
Version 19.9.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.9.0.0.0
sys@CDB$ROOT:orcl:226> sho pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
4 PDBNEW READ WRITE NO
5 PDBESB READ WRITE NO
7 PDB3 READ WRITE NO
sys@CDB$ROOT:orcl:226> show con_name
CON_NAME
------------------------------
CDB$ROOT
sys@CDB$ROOT:orcl:226> @sw pdb3
old 1: alter session set container = &1
new 1: alter session set container = pdb3
Session altered.
sys@PDB3:PDB3:226> show con_name
CON_NAME
------------------------------
PDB3
sys@PDB3:PDB3:226>
sys@PDB3:PDB3:226> @sw pdbnew
old 1: alter session set container = &1
new 1: alter session set container = pdbnew
Session altered.
sys@PDBNEW:PDBNEW:226> show con_name
CON_NAME
------------------------------
PDBNEW
sys@PDBNEW:PDBNEW:226> @sw pdbesb
old 1: alter session set container = &1
new 1: alter session set container = pdbesb
Session altered.
sys@PDBESB:PDBESB:226> sho pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
5 PDBESB READ WRITE NO
sys@PDBESB:PDBESB:226>
sys@PDBESB:PDBESB:226> @sw pdb1
old 1: alter session set container = &1
new 1: alter session set container = pdb1
Session altered.
sys@PDB1:PDB1:226> @sw pdb2
old 1: alter session set container = &1
new 1: alter session set container = pdb2
ERROR:
ORA-65011: Pluggable database PDB2 does not exist.
sys@PDB1:PDB1:226> sho con_name
CON_NAME
------------------------------
PDB1
sys@PDB1:PDB1:226>
因此,sw.sql适合以 sys 身份登录容器数据库,然后随便切换到各pdb,不适合pdb里用户登录后再切到其他pdb上,因为pdb1里的用户a可能在pdb3里不存在。
各 pdb 用户建议用以下方式
来登录。
SQL> conn 用户/密码@IP/PDB库名
sys@PDB3:PDB3:310> conn x/x@db1/pdb3
Good Luck!
阅读(5073) | 评论(0) | 转发(0) |