1.查看当前容器
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
2.创建容器pdb数据库
(1)可能提示’FILE_NAME_CONVERT’错误,需要在sql语句后面添加相关种子数据库和新容器数据库路径。
(2)设置参数db_create_file_dest 也可处理’FILE_NAME_CONVERT’错误。
12cR2中源数据库不在要求是只读,只要开启归档和本地undo 就可以克隆
SQL> create PLUGGABLE DATABASE plug_test ADMIN user admin IDENTIFIED by "12345";
create PLUGGABLE DATABASE plug_test ADMIN user admin IDENTIFIED by "12345"
*
ERROR at line 1:
ORA-65016: FILE_NAME_CONVERT must be specified
create PLUGGABLE DATABASE plug_test ADMIN user admin IDENTIFIED by "12345";
FILE_NAME_CONVERT=('/opt/oracle/oradata/ORCLCDB/pdbseed',
'/opt/oracle/oradata/ORCLCDB/plug_test');
SQL> alter system set db_create_file_dest='/opt/oracle/oradata/ORCLCDB';
System altered.
克隆已有数据库pdb
alter pluggable database pdb1 close immediate;
alter pluggable database pdb1 open read only;
create pluggable database fxpdb3 from pdb1 storage unlimited file_name_convert=('/u01/app/oracle/oradata/orcl/pdb1','/u01/app/oracle/oradata/orcl/fxpdb3');
create pluggable database pdb2 from pdb1;
create pluggable database pdb1 from pdb2@pdb1_link;
3.查看pdb运行状态
select * from v$pdbs;
4.更改当前容器
SQL> alter session set container=plug_test;
Session altered.
5.打开所有容器数据库和特定容器数据库
1.前提条件必须是在cdb环境下
alter PLUGGABLE DATABASE database_name open;
alter PLUGGABLE DATABASE all open;
-----------------------------------------
打开所有数据库plug_test除外
alter PLUGGABLE DATABASE all except plug_test open;
6.关闭数据库
1.和普通shutdown命令一样,需要注意的是要先切换到相关容器数据库下
SQL> alter session set container=plug_test;
shutdown immediate;
-------------------------------------------------------------------
[oracle@instance-ej1hspdt ~]$ sqlplus c##guest/12345@172.16.0.4:1522/\plug_test
SQL> show con_name
CON_NAME
------------------------------
PLUG_TEST
SQL> shutdown
---------------------------------------------------------------------
alter pluggable database plug_test close;
7.在cdb重启时自动启动pdb容器数据库,取消相关状态
SQL> alter pluggable database plug_test/all/all except plug_test save state;
Pluggable database altered.
-------------------------------------------------------------
SQL> alter pluggable database plug_test/all/all except plug_test discard state;
Pluggable database altered.
8.插拔数据库
先关闭数据库
alter PLUGGABLE DATABASE plug_test1 CLOSE;
-------------------------------------------
SQL> alter PLUGGABLE DATABASE plug_test1 UNPLUG into '/opt/oracle/plug_test1.xml';
Pluggable database altered.
删除数据库并不清除数据文件的路径
drop PLUGGABLE DATABASE plug_test1;
删除数据库并且清理数据库中数据文件(注意操作系统当中文件并没有删除)
drop PLUGGABLE DATABASE plug_test2 INCLUDING DATAFILES;
添加数据库
create PLUGGABLE database plug_test2 USING '/opt/oracle/plug_test1.xml';
打开数据库
alter PLUGGABLE DATABASE plug_test2 open;
9.相关视图
select * from cdb_tablespaces;
select * from v$tablespace;
select * from v$containers;
select * from v$pdbs;
select * from cdb_pdbs;
10.备份恢复
备份
RMAN> backup pluggable database "CDB$ROOT";
RMAN> backup pluggable database pdb2,pdb3;
backup pluggable database fxpdb1,fxpdb2 plus archivelog;
恢复
restore pluggable database fxpdb1;
recover pluggable database fxpdb1;
alter pluggable database fxpdb1 open;
validate database;
validate database root;
validate pluggable database fxpdb1;
11.容器数据库创建用户
create user c##test identified by "password' container=all/containerName;
12.查看容器数据的信息
select * from v$containers;
13.pdb缺失表空间无法open
思路:先登录cdb切换session到pdb 离线缺失表空间再open;
之后在rman恢复缺失的文件
sqlplus / as sysdba
alter session datafile 12 offline;
alter pluggable database tplug open;
rman target robert/robert@10.1.1.1:1521/tplug
restore datafile 12;
recover datafile 12;
alter database datafile 12 online;
14.查询pdb对应的表空间文件
SELECT d.con_ID,p.PDB_NAME,d.FILE_ID,d.TABLESPACE_NAME,
d.FILE_NAME
FROM CDB_PDBS p, CDB_DATA_ FILES d where p.PDB_ID(+) = d.CON_ID
order by d.con_id;
15.查询用户对所有pdb 对应的表
SELECT p.PDB_ID,p.PDB_NAME,t.OWNER,t.TABLE_NAMEFROMCDB_PDBS p,CDB_TABLES t
where p.PDB_ID = t.CON_ID
AND T.OWNER='ORDDATA' ORDER BY t.TABLE_NAME;
16.检查PDB历史
(它是什么时候创建的)PDB是怎么来的(从哪里克隆而来)?是怎么被创建的?是什么时候创建的?这些重要信息都保存在CDB PDB_HISTORY 中,可以执行下面的查询:
SELECT DB_NAME,CON_ID,PDB_NAME,OPERATION,
OPTIMESTAMP,CLONED FROM PDB NAME
FROMCDB PDB_HISTORY
WHERE CON ID >2
ORDER BY CON_ID;
17.pdb 级别alter system 语句
ALTER SYSTEM FLUSH SHARED_POOL
ALTER SYSTEM FLUSH BUFFER_CACHE
ALTER SYSTEM SET USE_STORED_OUTLINES
ALTER SYSTEM CHECKPOINT
ALTER SYSTEM KILL SESSION
ALTER SYSTEM DISCONNECT SESSION
ALTER SYSTEM SET initialization_parameter
18.pdb 管理语句
ALTER PLUGGABLE DATABASE DATAFILE '/u03/oracle/pdb1_01.dbf' ONLINE/offline; 联机、离线数据文件
ALTER PLUGGABLE DATABASE DEFAULT TABLESPACE pdb1_tbss;设置pdb 级别默认表空间
ALTER PLUGGABLE DATABASE DEFAULT TEMPORARY TABLESPACE pdb1_temp;设置pdb级别临时表空间
ALTER PLUGGABLE DATABASE SET DEFAULT BIGFILE TABLESPACE;设置pdb 级别默认表空间类型
ALTER PLUGGABLE DATABASE STORAGE(MAXSIZE 2G); 设置pdb级别默认最大表空间大小
ALTER PLUGGABLE DATABASE STORAGE(MAXSIZE UNLIMITED);设置pdb级别默认表空间大小
ALTER PLUGGABLE DATABASE NOLOGGING; 设置pdb级别NOLOGGING 模式
ALTER PLUGGABLE DATABASE ENABLE FORCE LOGGING; 设置pdb级别强制NOLOGGING 模式
ALTER PLUGGABLE DATABASE DEFAULT EDITION = PDB1E3; 设置pdb级别 EDITION
ALTER PLUGGABLE DATABASE RENAME GLOBAL_NAME TO salespdb.example.com;修改pdb数据库名,此操作完成后需要重新打开pdb