col con_id format a10
col con_name format a20
select sys_context('userenv','con_id') as con_id,sys_context('userenv','con_name') as con_name from dual;
- [oracle@oracle-db-19c ~]$ sqlplus / as sysdba
-
- SQL*Plus: Release 19.0.0.0.0 - Production on Wed Nov 30 11:07:06 2022
- Version 19.3.0.0.0
-
- Copyright (c) 1982, 2019, Oracle. All rights reserved.
-
-
- Connected to:
- Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
- Version 19.3.0.0.0
-
- SQL> col con_id format a10
- SQL> col con_name format a20
- SQL> select sys_context('userenv','con_id') as con_id,sys_context('userenv','con_name') as con_name from dual;
-
- CON_ID CON_NAME
- ---------- --------------------
- 1 CDB$ROOT
-
- SQL>
- SQL> show con_name;
-
- CON_NAME
- ------------------------------
- CDB$ROOT
- SQL>
- SQL> show pdbs;
-
- CON_ID CON_NAME OPEN MODE RESTRICTED
- ---------- ------------------------------ ---------- ----------
- 2 PDB$SEED READ ONLY NO
- 3 PDB1 READ WRITE NO
- 4 PDB2 MOUNTED
- 5 CNDBAPDB MOUNTED
- 6 CNDBAPDB3 MOUNTED
- 7 CNDBAPDB2 MOUNTED
- 8 CNDBAPDB4_FRESH READ ONLY NO
- SQL> alter session set container=PDB1;
-
- Session altered.
-
- SQL> show user;
- USER is "SYS"
- SQL> show con_name;
-
- CON_NAME
- ------------------------------
- PDB1
- SQL>
- [oracle@oracle-db-19c ~]$
- [oracle@oracle-db-19c ~]$ sqlplus / as sysdba
-
- SQL*Plus: Release 19.0.0.0.0 - Production on Wed Nov 30 11:26:54 2022
- Version 19.3.0.0.0
-
- Copyright (c) 1982, 2019, Oracle. All rights reserved.
-
-
- Connected to:
- Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
- Version 19.3.0.0.0
-
- SQL> col name for a20
- SQL> select con_id,name,ispdb_modifiable from v$system_parameter where name='open_cursors';
-
- CON_ID NAME ISPDB
- ---------- -------------------- -----
- 0 open_cursors TRUE
-
- SQL> set linesize 200
- SQL> show parameter open_cursors;
-
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- open_cursors integer 300
- SQL> alter system set open_cursors = 301;
-
- System altered.
-
- SQL> show parameter open_cursors;
-
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- open_cursors integer 301
- SQL> alter session set container=PDB1;
-
- Session altered.
-
- SQL> show parameter open_cursors;
-
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- open_cursors integer 301
- SQL>
(1) 修改CDB。当公共用户连接的是CDB root时,通过ALTER DATABASE 命令执行如下语句会修改整个CDB.
startup/recovery/logfile/controlfile/standbydatabase/instance/security/RENAME/GLOBAL_NAME/ENABLE LOCK CHANGE TRACKING/DISABLE LOCK CHANGE TRACKING
(2) 只修改CDB root 。当公共用户连接的是CDB root时,通过ALTER DATABASE 命令执行如下语句只修改CDB root
datafile/DEFAULT EDITION/DEFAULT TABLESPACE/ DEFAULT TEMPORARY TABLESPACE
(3) 修改一个或多个PDB。公共用户连接到CDB root时,可以通过ALTER PLUGGABLE DATABASE 语句修改PDB的打开状态(MOUNT/READ ONLY/READ WRITE),以及保存/忽略PDB的打开状态。
2.使用ALTER DATABASE命令修改CDB的UNDO模式。
- [oracle@oracle-db-19c ~]$ sqlplus / as sysdba
-
- SQL*Plus: Release 19.0.0.0.0 - Production on Wed Nov 30 13:39:46 2022
- Version 19.3.0.0.0
-
- Copyright (c) 1982, 2019, Oracle. All rights reserved.
-
-
- Connected to:
- Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
- Version 19.3.0.0.0
-
- SQL> show user;
- USER is "SYS"
- SQL> show con_name;
-
- CON_NAME
- ------------------------------
- CDB$ROOT
- SQL> col property_name for a30;
- SQL> col property_value for a20;
- SQL> select property_name,property_value from database_properties where property_name='LOCAL_UNDO_ENABLED';
-
- PROPERTY_NAME PROPERTY_VALUE
- ------------------------------ --------------------
- LOCAL_UNDO_ENABLED TRUE
-
- SQL>
TRUE代表本地UNDO模式,FLASE代表共享UNDO模式。
(2)共享UNDO模式转换为本地UNDO模式的步骤如下:
关闭CDB,代码如下
shutdown immediate;
以UPGRADE方式启动CDB,代码如下:
STARTUP UPGRADE;
确认当前容器是CDB root,代码如下:
show con_name;
启动本地UNDO,代码
ALTER DATABASE LOCAL UNDO ON;
重启 CDB,正常打开,
- SHUTDOWN IMMEDIATE;
- STARTUP;
(3) 本地UNDO模式转换为共享UNDO模式的步骤如下:
关闭CDB
shutdown immediate
以UPGRADE方式启动CDB,
STARTUP UPGRADE;
确认当前容器是CDB root,
SHOW CON_NAME
禁用本地UNDO
ALTER DATABASE LOCAL UNDO OFF
重启CDB,正常打开,
- SHUTDOWN IMMEDIATE;
-
- STARTUP;
- # CDB
-
- SQL>
- SQL> show con_name;
-
- CON_NAME
- ------------------------------
- CDB$ROOT
- SQL> show parameter spfile;
-
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string /u01/app/oracle/product/19.3.0
- /dbhome_1/dbs/spfilecdb1.ora
- SQL>
-
-
- SQL> alter session set container=PDB1;
-
- Session altered.
-
- SQL> show parameter spfile;
-
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string /u01/app/oracle/product/19.3.0
- /dbhome_1/dbs/spfilecdb1.ora
- SQL> alter session set container=cdb$root;
-
- Session altered.
-
- SQL>
Fleet就是一个逻辑的CDB集合。其中,Lead CDB 是CDB Fleet中用于监控和管理其它CDB的。
在CDB Fleet中,可以通过以下方式来访问CDB和PDB中的数据:
1.设置Lead CDB ,通过以下命令启动该特性:
-
- # 启动 LEAD CDB
- SQL>
- SQL> alter database set lead_cdb = true;
-
- Database altered.
-
- SQL> select property_value from database_properties where property_name='LEAD_CDB';
-
- PROPERTY_VALUE
- --------------------
- TRUE
-
- SQL>
管理PDB和管理普通的Non-CDB一样,可以管理表空间、数据文件、临时文件和用户对象等。