查看pdb开启状态
select con_id, dbid, guid, name , open_mode from v$pdbs;
建立连接
进入cdb
sqlplus /nolog
conn sys/sys as dba
sqlplus sys/sys@localhost:1521/orcl as sysdba
进入pdb(pdb可以通过alter session container进入也可以直接通过tns方式(如下)登录)
sqlplus sys/sys@localhost:1521/pdborcl as sysdba
显示所有的plaggable db
show pdbs;
查看当前连接名称
show con_name;
新建pdb
CREATE PLUGGABLE DATABASE xff_db ADMIN USER xff IDENTIFIED BY xifenfei
STORAGE (MAXSIZE 2G MAX_SHARED_TEMP_SIZE 100M)
DEFAULT TABLESPACE xifenfei
DATAFILE '/u01/app/oracle/oradata/xifenfei/xff/xifenfei01.dbf' SIZE 25M AUTOEXTEND ON 5 PATH_PREFIX = '/u01/app/oracle/oradata/xifenfei/xff/'
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/xifenfei/pdbseed/',
'/u01/app/oracle/oradata/xifenfei/xff/');
#### 删除PDB
DROP PLUGGABLE DATABASE xff_db INCLUDING DATAFILES;
Unplugging PDB
alter pluggable database FF close immediate;
alter pluggable database ff UNPLUG into '/tmp/ff.xml';
Plug Unplugging PDB
create pluggable database ff using '/tmp/ff.xml' copy file_name_convert=('/u01/app/oracle/oradata/xifenfei/FF/','/u01/app/oracle/oradata/xff_l/xff');
exec DBMS_PDB.SYNC_PDB();
启动关闭PDB
- pdb的管理可以在cdb中进行也可以在pdb中进行,
- 如果是cdb中进行,需要PLUGGABLE关键字(如下alter),
- 如果是pdb中直接和普通数据库一样(startup/shutdown immediate)
打开单个pdb
lter pluggable database pdborcl open;
打开所有pdb
alter pluggable database all open;
关闭所有pdb
alter pluggable database all close immediate;
进入pdb
alter session set container=pdborcl;
--//
conn sys/sys@localhost:1521/pdborcl as sysdba;
进入cdb
alter session set container=cdb$root;
--//
conn / as sysdba;
创建用户
- 创建用户默认的是container=all,在cdb中只能创建全局用户(c##开头),
- 会在cdb和所有的pdb中创建该用户(但是pdb中的全局用户需要另外授权才能够在pdb中访问)。
- 在pdb中只能创建的用户为本地用户
创建全局用户
create user c##xff identified by xifenfei;
创建本地用户
alter session set container=pdborcl;
create user xxx identified by 123;
用户授权
- 用户授权默认情况下是只会给当前container,在cdb中也可以指定container=all,对所有open的pdb且存在该用户都进行授权
grant connect to c##xff;
grant resource to c##xff container=all
修改参数
- 在cdb中修改,pdb会继承进去;如果在pdb中修改会覆盖pdb从cdb中继承的参数含义
alter system set open_cursors=500 container=all;
show parameter open_cursors;
alter session set container=pdborcl;
show parameter open_cursors;
--//
alter system set open_cursors=100;
show parameter open_cursors;
conn / as sysdba
show parameter open_cursors;
使用触发器实现PDB自动启动
--先连接
conn / as sysdba
--创建触发器
CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;
\ --sqlplus中结束脚本编写