Menu Close

从PDB$SEED创建可插拔数据库(PDB)

方法一:图形界面方式

在Oracle用户下运行dbca命令,调出数据库管理的图形界面:

  1. 选择 Manage Pluggable databases,点击“Next”:

  2. 选择 Create a Pluggable database,点击“Next”

  3. 选择需要添加pdb的容器数据库,并输入sys用户的密码,点击“Next”

  4. 选择种子PDB数据库(PDB$SEED),点击“Next”

  5. 填写新创建的PDB数据库名称以及管理员账户的用户名与密码,点击“Next”

  6. 选择新创建的PDB数据库文件存放位置,点击“Next”

  7. 显示新创建的PDB数据库的概要信息,点击“Finish”开始创建

  8. 新的PDB数据库创建过程中

  9. 新的PDB数据库创建成功

方法二、命令行方式

2.1. 针对普通文件系统的pdb$seed

SQL> CREATE PLUGGABLE DATABASE zytk
ADMIN USER pdbadmin IDENTIFIED BY zytkSystem ROLES=(dba)
FILE_NAME_CONVERT=('/u02/oradata/YKT/pdbseed','/u02/oradata/YKT/zytk');

SQL> alter pluggable database zytk open;

2.2. 针对ASM文件系统的pdb$seed

SQL> show pdbs;

SQL> alter session set container=pdb$seed;
Session altered.

SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/LCCDATA/64A52F53A7693286E053CDA9E80AED76/DATAFILE/system.271.1048642191
+DATA/LCCDATA/64A52F53A7693286E053CDA9E80AED76/DATAFILE/sysaux.270.1048642191
+DATA/LCCDATA/64A52F53A7693286E053CDA9E80AED76/DATAFILE/undotbs1.272.1048642191

SQL> select file_name from dba_temp_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/LCCDATA/AD0301590A3D70B5E053A0A3CE3AE926/TEMPFILE/temp.273.1048642209

SQL> alter session set container=cdb$root;

Session altered.

SQL> create pluggable database studypdb
     admin user study identified by "study"
     roles=(dba)
     file_name_convert=('+DATA/LCCDATA/64A52F53A7693286E053CDA9E80AED76','+DATA',
                        '+DATA/LCCDATA/AD0301590A3D70B5E053A0A3CE3AE926','+DATA');

Pluggable database created.

pdB数据库 studypdb 创建成功。

SQL> show pdbs;

SQL> alter pluggable database studypdb open;

Pluggable database altered.

SQL> alter pluggable database studypdb save state;

Pluggable database altered.

SQL> alter session set container=studypdb;

Session altered.

SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/LCCDATA/CBE9273758426DE6E053A0A3CE3A8D87/DATAFILE/system.299.1083220835
+DATA/LCCDATA/CBE9273758426DE6E053A0A3CE3A8D87/DATAFILE/sysaux.300.1083220835
+DATA/LCCDATA/CBE9273758426DE6E053A0A3CE3A8D87/DATAFILE/undotbs1.298.1083220835

SQL> select file_name from dba_temp_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/LCCDATA/CBE9273758426DE6E053A0A3CE3A8D87/TEMPFILE/temp.301.1083220855

由于创建的用户没有设置默认的表空间,所以强烈建议完成PDB的数据库创建后马上创建表空间,并将创建的用户设置默认表空间,防止数据写入system表空间。

SQL> show pdbs;

    CON_ID    CON_NAME         OPEN MODE    RESTRICTED
---------- ---------------    ----------   ----------
    6        STUDYPDB          READ WRITE     NO

SQL> create tablespace tbs_study datafile
    '+DATA' size 500m autoextend on next 200m maxsize 5g;

Tablespace created.

SQL> alter user study default tablespace tbs_study;

User altered.

SQL> alter user study quota unlimited on tbs_study;

User altered.

附录:删除PDB

SQL> alter session set container=cdb$root;
SQL> alter pluggable database zytk close;
SQL> drop pluggable database zytk including datafiles;