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
凯发app官方网站 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!
阅读(22049) | 评论(0) | 转发(1) |