CDB和PDB基本管理
这篇文章主要介绍CDB和PDB的基本管理,资料来源oracle官方。
基本概念:
Multitenant Environment:多租户环境
CDB(Container Database):数据库容器
PD(Pluggable Database):可插拔数据库
CDB与PDB关系图
环境信息如下:
DB version:12.0.1
ORACLE_HOME: /u01/app/oracle/product/12.1.0
TNS Listener port: 1521
Container databases:
SID: cdbtest
1、查看数据库是否为CDB
SYS@cdbtest> select name, decode(cdb, ‘YES‘, ‘Multitenant Option enabled‘, ‘Regular 12c Database: ‘) "Multitenant Option" , open_mode, con_id from v$database;
NAME Multitenant Option OPEN_MODE CON_ID
--------- -------------------------- -------------------- ----------
CDBTEST Multitenant Option enabled READ WRITE 0
2、连接到CDB
2.1、简易方式连接
首先查看服务状态:
$lsnrctl service
LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 14-APR-2014 20:54:47
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
Services Summary...
Service "cdbtest.oracle.com" has 1 instance(s).
Instance "cdbtest", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:2 refused:0 state:ready
LOCAL SERVER
Service "cdbtestXDB.oracle.com" has 1 instance(s).
Instance "cdbtest", status READY, has 1 handler(s) for this service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: localhost.localdomain, pid: 2681>
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=60617))
Service "pdb1.oracle.com" has 1 instance(s).
Instance "cdbtest", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:2 refused:0 state:ready
LOCAL SERVER
Service "pdb3_his.oracle.com" has 1 instance(s).
Instance "cdbtest", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:2 refused:0 state:ready
LOCAL SERVER
The command completed successfully
可以看到上面有cdbtest.oracle.com ,pdb1.oracle.com,pdb3_his.oracle.com 这3个服务,下面使用cdbtest.oracle.com来连接
$sqlplus sys/password@localhost:1521/cdbtest.oracle.com as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Mon Apr 14 20:53:22 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SYS@localhost:1521/cdbtest.oracle.com>
2.2、使用net service方式连接
需要在$ORACLE_HOME/network/admin/tnsnames.ora中进行配置,本例配置如下:
oracle*cdbtest*/u01/app/oracle/product/12.1.0/db_1/network/admin>$more tnsnames.ora
cdbtest=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=
(SID=cdbtest)
(SERVICE_NAME=cdbtest.oracle.com)
(INSTANCE_NAME=cdbtest)))
使用cdbtest来连接:
$sqlplus sys/password@cdbtest as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Mon Apr 14 20:57:30 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SYS@cdbtest>
2.3、使用os认证的方式连接
oracle*cdbtest*/home/oracle>$sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Mon Apr 14 20:59:13 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SYS@cdbtest>
2.4、查看容器名称和ID
SYS@cdbtest> show con_name ;
CON_NAME
------------------------------
CDB$ROOT
SYS@cdbtest> show con_id ;
CON_ID
------------------------------
1
3、查看root和PDBS的服务信息
SYS@cdbtest> select name ,con_id from v$active_services order by 1 ;
NAME CON_ID
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
SYS$USERS 1
cdbtest.oracle.com 1
cdbtestXDB 1
pdb1.oracle.com 3
pdb3_his.oracle.com 4
6 rows selected.
4、连接到PDBs
使用简单连接方式
连接到pdb1.oracle.com:
$sqlplus sys/password@localhost:1521/pdb1.oracle.com as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Mon Apr 14 21:04:22 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SYS@localhost:1521/pdb1.oracle.com>
连接到pdb3_his.oracle.com:
$sqlplus sys/password@localhost:1521/pdb3_his.oracle.com as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Mon Apr 14 21:04:42 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SYS@localhost:1521/pdb3_his.oracle.com>
5、创建一个新的PDB
从seed PDB创建一个PDB(每个CDB有一个PDB template,名为PDB$Seed)
准备工作:
创建一个操作系统的目录用来存放新创建的PDB数据库的数据文件和临时文件:
mkdir -p /u01/app/oracle/oradata/cdbtest/pdb4
5.1、创建PDB
$sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Mon Apr 14 21:12:11 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SYS@cdbtest> create pluggable database pdb4
2 admin user odb4_admin identified by password
3 roles=(dba)
4 file_name_convert=(‘/u01/app/oracle/oradata/cdbtest/pdbseed‘,‘/u01/app/oracle/oradata/cdbtest/pdb4‘) ;
Pluggable database created.
5.2、验证
SYS@cdbtest> select pdb_name,status from cdb_pdbs ;
PDB_NAME STATUS
------------------------------ -------------
PDB1 NORMAL
PDB$SEED NORMAL
PDB3_HIS NORMAL
PDB4 NEW
如果status状态为NEED SYNC,要运行DBMS_PDB.SYNC_PDB将状态改变
SYS@cdbtest> select name,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 READ WRITE
PDB3_HIS READ WRITE
PDB4 MOUNTED
SYS@cdbtest> select name ,con_id from v$active_services order by 1 ;
NAME CON_ID
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
SYS$USERS 1
cdbtest.oracle.com 1
cdbtestXDB 1
pdb1.oracle.com 3
pdb3_his.oracle.com 4
pdb4.oracle.com 5
5.3、列出数据文件
SYS@cdbtest> select name from v$datafile where con_id=5 ;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/cdbtest/pdb4/system01.dbf
/u01/app/oracle/oradata/cdbtest/pdb4/sysaux01.dbf
6、打开和关闭PDBs
关闭
SYS@cdbtest> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
打开
SYS@cdbtest> startup
ORACLE instance started.
Total System Global Area 584568832 bytes
Fixed Size 2290992 bytes
Variable Size 461376208 bytes
Database Buffers 117440512 bytes
Redo Buffers 3461120 bytes
Database mounted.
Database opened.
查看状态
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB3_HIS MOUNTED
PDB4 MOUNTED
启动PDB4
SYS@cdbtest> alter pluggable database pdb4 open ;
Pluggable database altered.
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB3_HIS MOUNTED
PDB4 READ WRITE
启动所有的PDBs
SYS@cdbtest> alter pluggable database all open ;
Pluggable database altered.
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 READ WRITE
PDB3_HIS READ WRITE
PDB4 READ WRITE
关闭PDB1
SYS@cdbtest> alter pluggable database pdb1 close immediate ;
Pluggable database altered.
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB3_HIS READ WRITE
PDB4 READ WRITE
关闭所有的PDBs
SYS@cdbtest> alter pluggable database all close immediate ;
Pluggable database altered.
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB3_HIS MOUNTED
PDB4 MOUNTED
从上面的操作中可以看到数据库启动的时候所有的PDBs的状态为MOUNTED,在实际应用可以考虑增加如下的触发器使所有的PDBs都处于打开状态。以下为验证过程:
SYS@cdbtest> create or replace trigger sys.after_startup after startup on database
2 begin
3 execute immediate ‘alter pluggable database all open ‘ ;
4 end after_startup ;
5 /
Trigger created.
SYS@cdbtest> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@cdbtest> startup
ORACLE instance started.
Total System Global Area 584568832 bytes
Fixed Size 2290992 bytes
Variable Size 461376208 bytes
Database Buffers 117440512 bytes
Redo Buffers 3461120 bytes
Database mounted.
Database opened.
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 READ WRITE
PDB3_HIS READ WRITE
PDB4 READ WRITE
5.4、rename PDB
rename pdb时pdb需要处于open restricted状态。
SYS@cdbtest> alter pluggable database pdb4 close immediate ;
Pluggable database altered.
SYS@cdbtest> alter pluggable database pdb4 open restricted ;
Pluggable database altered.
SYS@cdbtest> select name ,restricted from v$pdbs ;
NAME RES
------------------------------ ---
PDB$SEED NO
PDB1 NO
PDB3_HIS NO
PDB4 YES
SYS@cdbtest> conn sys/password@localhost:1521/pdb4.oracle.com
ERROR:
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
Warning: You are no longer connected to ORACLE.
连接到PDB4
SYS@cdbtest> conn sys/password@localhost:1521/pdb4.oracle.com as sysdba
Connected.
SYS@localhost:1521/pdb4.oracle.com> alter pluggable database pdb4 rename global_name to pdb4_his ;
Pluggable database altered.
SYS@localhost:1521/pdb4.oracle.com> alter pluggable database close immediate ;
Pluggable database altered.
SYS@localhost:1521/pdb4.oracle.com> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB4_HIS MOUNTED
SYS@localhost:1521/pdb4.oracle.com> conn / as sysdba
Connected.
SYS@cdbtest> alter pluggable database close immediate ;
alter pluggable database close immediate
*
ERROR at line 1:
ORA-65000: missing or invalid pluggable database name
SYS@cdbtest> alter pluggable database all close immediate ;
Pluggable database altered.
SYS@cdbtest> alter pluggable database all open ;
Pluggable database altered.
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 READ WRITE
PDB3_HIS READ WRITE
PDB4_HIS READ WRITE
6、存储管理
查看数据文件信息
SYS@cdbtest> conn / as sysdba
Connected.
SYS@cdbtest> select tablespace_name,con_id from cdb_tablespaces where con_id =1 ;
TABLESPACE_NAME CON_ID
------------------------------ ----------
SYSTEM 1
SYSAUX 1
UNDOTBS1 1
TEMP 1
USERS 1
CDATA 1
6 rows selected.
SYS@cdbtest> col file_name for a50
SYS@cdbtest> select file_name,con_id from cdb_data_files where con_id =1 ;
FILE_NAME CON_ID
-------------------------------------------------- ----------
/u01/app/oracle/oradata/cdbtest/system01.dbf 1
/u01/app/oracle/oradata/cdbtest/sysaux01.dbf 1
/u01/app/oracle/oradata/cdbtest/undotbs01.dbf 1
/u01/app/oracle/oradata/cdbtest/users01.dbf 1
/u01/app/oracle/oradata/cdbtest/cdata01.dbf 1
在root中创建持久表空间
SYS@cdbtest> create tablespace cdata01 datafile ‘/u01/app/oracle/oradata/cdbtest/cdata0101.dbf‘ size 10m;
Tablespace created.
SYS@cdbtest> select tablespace_name ,con_id from cdb_tablespaces order by con_id ;
TABLESPACE_NAME CON_ID
------------------------------ ----------
SYSTEM 1
CDATA01 1
CDATA 1
SYSAUX 1
TEMP 1
UNDOTBS1 1
USERS 1
SYSTEM 2
SYSAUX 2
TEMP 2
SYSTEM 3
TABLESPACE_NAME CON_ID
------------------------------ ----------
EXAMPLE 3
SYSAUX 3
TEMP 3
USERS 3
SYSTEM 4
TEMP_PDB3 4
SYSAUX 4
TEMP 4
LDATA 4
SYSTEM 5
TEMP 5
TABLESPACE_NAME CON_ID
------------------------------ ----------
SYSAUX 5
23 rows selected.
SYS@cdbtest> select file_name,con_id from cdb_data_files order by con_id ;
FILE_NAME CON_ID
-------------------------------------------------- ----------
/u01/app/oracle/oradata/cdbtest/system01.dbf 1
/u01/app/oracle/oradata/cdbtest/cdata0101.dbf 1
/u01/app/oracle/oradata/cdbtest/sysaux01.dbf 1
/u01/app/oracle/oradata/cdbtest/users01.dbf 1
/u01/app/oracle/oradata/cdbtest/undotbs01.dbf 1
/u01/app/oracle/oradata/cdbtest/cdata01.dbf 1
/u01/app/oracle/oradata/cdbtest/pdbseed/sysaux01.dbf 2
/u01/app/oracle/oradata/cdbtest/pdbseed/system01.dbf 2
FILE_NAME CON_ID
-------------------------------------------------- ----------
/u01/app/oracle/oradata/cdbtest/pdb1/system01.dbf 3
/u01/app/oracle/oradata/cdbtest/pdb1/sysaux01.dbf 3
/u01/app/oracle/oradata/cdbtest/pdb1/SAMPLE_SCHEMA 3
_users01.dbf
/u01/app/oracle/oradata/cdbtest/pdb1/example01.dbf 3
/u01/app/oracle/oradata/cdbtest/pdb3/system01.dbf 4
/u01/app/oracle/oradata/cdbtest/pdb3/sysaux01.dbf 4
/u01/app/oracle/oradata/cdbtest/pdb3/ldata01.dbf 4
/u01/app/oracle/oradata/cdbtest/pdb4/sysaux01.dbf 5
FILE_NAME CON_ID
-------------------------------------------------- ----------
/u01/app/oracle/oradata/cdbtest/pdb4/system01.dbf 5
17 rows selected.
在root中创建临时表空间
SYS@cdbtest> create temporary tablespace temp_root_01 tempfile ‘/u01/app/oracle/oradata/cdbtest/temproot0101.dbf‘ size 10m ;
Tablespace created.
SYS@cdbtest> select tablespace_name ,con_id from cdb_tablespaces where contents=‘TEMPORARY‘ and con_id=1 ;
TABLESPACE_NAME CON_ID
------------------------------ ----------
TEMP 1
TEMP_ROOT_01 1
SYS@cdbtest> select file_name ,con_id from cdb_temp_files where con_id =1 ;
FILE_NAME CON_ID
-------------------------------------------------- ----------
/u01/app/oracle/oradata/cdbtest/temp01.dbf 1
/u01/app/oracle/oradata/cdbtest/temproot0101.dbf 1
SYS@cdbtest>
SYS@cdbtest> conn system/password@localhost:1521/pdb4_his.oracle.com
Connected.
在pdb4_his中创建持久表空间
SYSTEM@localhost:1521/pdb4_his.oracle.com> create tablespace ldata datafile ‘/u01/app/oracle/oradata/cdbtest/pdb4/ldata01.dbf‘ size 10m ;
Tablespace created.
SYSTEM@localhost:1521/pdb4_his.oracle.com> select tablespace_name,con_id from cdb_tablespaces order by con_id ;
TABLESPACE_NAME CON_ID
------------------------------ ----------
SYSTEM 5
SYSAUX 5
TEMP 5
LDATA 5
SYSTEM@localhost:1521/pdb4_his.oracle.com> select file_name from dba_data_files ;
FILE_NAME
--------------------------------------------------
/u01/app/oracle/oradata/cdbtest/pdb4/system01.dbf
/u01/app/oracle/oradata/cdbtest/pdb4/sysaux01.dbf
/u01/app/oracle/oradata/cdbtest/pdb4/ldata01.dbf
在pdb4_his中创建临时表空间
SYSTEM@localhost:1521/pdb4_his.oracle.com> create temporary tablespace temp_pdb4 tempfile ‘/u01/app/oracle/oradata/cdbtest/pdb4/temppdb401.dbf‘ size 10m ;
Tablespace created.
SYSTEM@localhost:1521/pdb4_his.oracle.com> select tablespace_name,con_id from cdb_tablespaces where contents=‘TEMPORYARY‘;
no rows selected
SYSTEM@localhost:1521/pdb4_his.oracle.com> select tablespace_name,con_id from cdb_tablespaces where contents=‘TEMPORARY‘;
TABLESPACE_NAME CON_ID
------------------------------ ----------
TEMP 5
TEMP_PDB4 5
SYSTEM@localhost:1521/pdb4_his.oracle.com> select file_name from dba_temp_files
2 ;
FILE_NAME
--------------------------------------------------
/u01/app/oracle/oradata/cdbtest/pdb4/pdbseed_temp01.dbf
/u01/app/oracle/oradata/cdbtest/pdb4/temppdb401.dbf
7、安全管理
7.1、用户管理
SYSTEM@localhost:1521/pdb4_his.oracle.com> conn / as sysdba
Connected.
在root中创建用户c##1,用户名需要以c##开头,在root中创建的用户会复制到所有的pdbs中,除了seed pdb。
SYS@cdbtest> create user c##2 identified by password container=all ;
User created.
SYS@cdbtest> select username,common,con_id from cdb_users where username like ‘C##%‘ ;
USERNAME COM CON_ID
------------------------------ --- ----------
C##1 YES 4
C##2 YES 4
C##1 YES 3
C##2 YES 3
C##1 YES 1
C##2 YES 1
C##1 YES 5
C##2 YES 5
从上面的输出中可以看到在每个PDB中都有用户C##1,除了pdb seed。
尝试登录
SYS@cdbtest> conn c##2/password@localhost:1521/pdb4_his.oracle.com
ERROR:
ORA-01045: user C##2 lacks CREATE SESSION privilege; logon denied
Warning: You are no longer connected to ORACLE.
在pdb中创建用户
SYS@cdbtest> conn system/password@localhost:1521/pdb4_his.oracle.com
Connected.
SYSTEM@localhost:1521/pdb4_his.oracle.com> create user hr identified by password ;
User created.
SYSTEM@localhost:1521/pdb4_his.oracle.com> select username,common,con_id from cdb_users where username like ‘HR‘;
USERNAME COM CON_ID
------------------------------ --- ----------
HR NO 5
尝试登录
SYSTEM@localhost:1521/pdb4_his.oracle.com> conn hr/password@localhost:1521/pdb4_his.oracle.com
ERROR:
ORA-01045: user HR lacks CREATE SESSION privilege; logon denied
Warning: You are no longer connected to ORACLE.
SYSTEM@localhost:1521/pdb4_his.oracle.com> conn system/password@localhost:1521/pdb4_his.oracle.com
Connected.
单独在pdb中赋予create session权限
SYSTEM@localhost:1521/pdb4_his.oracle.com> grant create session to c##2 ;
Grant succeeded.
再次登录pdb4
SYSTEM@localhost:1521/pdb4_his.oracle.com> conn c##2/password@localhost:1521/pdb4_his.oracle.com
Connected.
测试登录pdb3
C##2@localhost:1521/pdb4_his.oracle.com> conn c##2/password@localhost:1521/pdb3_his.oracle.com
ERROR:
ORA-01045: user C##2 lacks CREATE SESSION privilege; logon denied
Warning: You are no longer connected to ORACLE.
C##2@localhost:1521/pdb4_his.oracle.com> grant create session to hr ;
SP2-0640: Not connected
C##2@localhost:1521/pdb4_his.oracle.com> conn system/password@localhost:1521/pdb4_his.oracle.com
Connected.
SYSTEM@localhost:1521/pdb4_his.oracle.com> grant create session to hr ;
Grant succeeded.
SYSTEM@localhost:1521/pdb4_his.oracle.com> conn hr/password@localhost:1521/pdb4_his.oracle.com
Connected.
在所有的pdbs给用户c##2赋予create session权限
HR@localhost:1521/pdb4_his.oracle.com> conn / as sysdba
Connected.
SYS@cdbtest> grant create session to c##2 container=all ;
Grant succeeded.
SYS@cdbtest> conn c##2/password@localhost:1521/pdb1.oracle.com
Connected.
7.2、角色管理
C##2@localhost:1521/pdb1.oracle.com> conn / as sysdba
Connected.
SYS@cdbtest> create role c##r2 container=all ;
Role created.
SYS@cdbtest> select role,common,con_id from cdb_roles where role=‘C##R2‘ ;
ROLE COM CON_ID
---------- --- ----------
C##R2 YES 5
C##R2 YES 4
C##R2 YES 3
C##R2 YES 1
从上面的输出可以看到每个pdb(除了seed)都有role C##R2
SYS@cdbtest> conn system/password@localhost:1521/pdb4_his.oracle.com
Connected.
单独在pdb中创建role
SYSTEM@localhost:1521/pdb4_his.oracle.com> create role hr_manager ;
Role created.
SYSTEM@localhost:1521/pdb4_his.oracle.com> select role,common,con_id from cdb_roles where role=‘HR_MANAGER‘;
ROLE COM CON_ID
---------- --- ----------
HR_MANAGER NO 5
SYSTEM@localhost:1521/pdb4_his.oracle.com> create role c##r2 container=all ;
create role c##r2 container=all
*
ERROR at line 1:
ORA-65050: Common DDLs only allowed in CDB$ROOT
在root中给角色授予权限
SYSTEM@localhost:1521/pdb4_his.oracle.com> conn / as sysdba
Connected.
SYS@cdbtest> grant create session to c##2 container=all ;
Grant succeeded.
SYS@cdbtest> select grantee,privilege,common,con_id from cdb_sys_privs
2 where privilege=‘CREATE SESSION‘ and grantee=‘C##2‘;
GRANTEE PRIVILEGE COM CON_ID
------------------------------ ---------------------------------------- --- ----------
C##2 CREATE SESSION NO 5
C##2 CREATE SESSION YES 5
C##2 CREATE SESSION YES 4
C##2 CREATE SESSION YES 3
C##2 CREATE SESSION YES 1
SYS@cdbtest> conn c##2/password@localhost:1521/pdb4_his.oracle.com
Connected.
C##2@localhost:1521/pdb4_his.oracle.com> select * from session_privs ;
PRIVILEGE
----------------------------------------
CREATE SESSION
C##2@localhost:1521/pdb4_his.oracle.com> conn c##2/password@localhost:121/pdb4_his.oracle.com
ERROR:
ORA-12541: TNS:no listener
Warning: You are no longer connected to ORACLE.
C##2@localhost:1521/pdb4_his.oracle.com> conn c##2/password@localhost:1521/pdb4_his.oracle.com
Connected.
C##2@localhost:1521/pdb4_his.oracle.com> select * from session_privs ;
PRIVILEGE
----------------------------------------
CREATE SESSION
C##2@localhost:1521/pdb4_his.oracle.com> connect system/password@localhost:1521/pdb4_his.oracle.com
Connected.
SYSTEM@localhost:1521/pdb4_his.oracle.com> grant create session to hr container=all ;
grant create session to hr container=all
*
ERROR at line 1:
ORA-65030: one may not grant a Common Privilege to a Local User or Role
SYSTEM@localhost:1521/pdb4_his.oracle.com> grant create session to hr ;
Grant succeeded.
SYSTEM@localhost:1521/pdb4_his.oracle.com> select grantee,privilege,common,con_id from cdb_sys_privs
2 where privilege=‘CREATE SESSION‘ and grantee=‘HR‘ ;
GRANTEE PRIVILEGE COM CON_ID
------------------------------ ---------------------------------------- --- ----------
HR CREATE SESSION NO 5
8、PDBs删除
SYSTEM@localhost:1521/pdb4_his.oracle.com> conn / as sysdba
Connected.
SYS@cdbtest>
SYS@cdbtest> alter pluggable database all close immediate ;
Pluggable database altered.
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB3_HIS MOUNTED
PDB4_HIS MOUNTED
SYS@cdbtest> drop pluggable database pdb4_his including datafile ;
drop pluggable database pdb4_his including datafile
*
ERROR at line 1:
ORA-02000: missing DATAFILES keyword
SYS@cdbtest> drop pluggable database pdb4_his including datafiles ;
Pluggable database dropped.
SYS@cdbtest> select name ,open_mode from v$pdbs ;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB3_HIS MOUNTED
SYS@cdbtest>
SYS@cdbtest> drop user c##1;
User dropped.
SYS@cdbtest> drop user c##2;
User dropped.
SYS@cdbtest> drop role c##r1 ;
Role dropped.
SYS@cdbtest> drop role c##r2 ;
Role dropped.
SYS@cdbtest> drop tablespace cdata01 including contents ;
Tablespace dropped.
SYS@cdbtest> drop tablespace cdata including contents ;
Tablespace dropped.
SYS@cdbtest> drop tablespace temp_root_01 including contents ;
Tablespace dropped.