千家信息网

Oracle 12c如何创建和删除PDB

发表于:2025-01-19 作者:千家信息网编辑
千家信息网最后更新 2025年01月19日,这篇文章主要为大家展示了"Oracle 12c如何创建和删除PDB",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Oracle 12c如何创建和删除PDB"
千家信息网最后更新 2025年01月19日Oracle 12c如何创建和删除PDB

这篇文章主要为大家展示了"Oracle 12c如何创建和删除PDB",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Oracle 12c如何创建和删除PDB"这篇文章吧。

1. 手工创建PDB

从SEED database 创建PDB的时候,可以指定文件存放的位置。 有两种方法可以指定文件的位置。

第一种是在CREATE PLUGGABLE DATABASE 语法中添加FILE_NAME_CONVERT选项。

http://www.cndba.cn/dave/article/221

http://www.cndba.cn/dave/article/221

SQL> set lin 120SQL> col name for a60SQL> select * from v$dbfile;    13 /u01/app/oracle/oradata/dave/pdb1/ado2.dbf                 3    14 /u01/app/oracle/oradata/dave/pdb1/cndba01.dbf             3    22 /u01/app/oracle/oradata/dave/cndba/system.dbf             4    23 /u01/app/oracle/oradata/dave/cndba/sysaux.dbf             4    24 /u01/app/oracle/oradata/dave/cndba/users.dbf              4    25 /u01/app/oracle/oradata/dave/cndba/ado1.dbf                 4    26 /u01/app/oracle/oradata/dave/cndba/ado2.dbf                 418 rows selected.



查看PDB的位置,创建新目录:

[oracle@Ora12c ~]$ mkdir /u01/app/oracle/oradata/dave/huainingSQL> create pluggable database huaining admin user cndba identified by cndbafile_name_convert=('/u01/app/oracle/oradata/dave/pdbseed/','/u01/app/oracle/oradata/dave/huaining/');Pluggable database created.


也可以简写:http://www.cndba.cn/dave/article/221

create pluggable database huaining admin user cndba identified by cndbafile_name_convert=('pdbseed','huaining');SQL> show pdbs    CON_ID CON_NAME              OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------     2 PDB$SEED              READ ONLY  NO     3 PDB1               READ WRITE NO     4 CNDBA              READ WRITE NO     5 HUAINING              MOUNTED



--查看PDB的状态:是NEW,测试是不可用的。

http://www.cndba.cn/dave/article/221

SQL> set lin 120SQL> col pdb_name for a15SQL>  select pdb_name,status from dba_pdbs;PDB_NAME    STATUS--------------- ---------PDB1        NORMALPDB$SEED    NORMALCNDBA        NORMALHUAINING    NEW


必须显示的打开数据库:http://www.cndba.cn/dave/article/221

SQL> alter pluggable database huaining open;Pluggable database altered.SQL> show pdbs    CON_ID CON_NAME              OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------     2 PDB$SEED              READ ONLY  NO     3 PDB1               READ WRITE NO     4 CNDBA              READ WRITE NO     5 HUAINING              READ WRITE NOSQL> select pdb_name,status from dba_pdbs;PDB_NAME    STATUS--------------- ---------PDB1        NORMALPDB$SEED    NORMALCNDBA        NORMALHUAINING    NORMAL



第二种方法,就是先指定PDB_FILE_NAME_CONVERT 参数的值,然后执行创建命令,此时就不需要指定FILE_NAME_CONVERT选项。

http://www.cndba.cn/dave/article/221

[oracle@Ora12c pdbseed]$ mkdir /u01/app/oracle/oradata/dave/ahdbaSQL> show parameter pdb_NAME                     TYPE     VALUE------------------------------------ ----------- ------------------------------pdb_file_name_convert             stringpdb_lockdown                 stringpdb_os_credential             stringSQL> alter session set pdb_file_name_convert='/u01/app/oracle/oradata/dave/pdbseed/','/u01/app/oracle/oradata/dave/ahdba/';     Session altered.SQL> show parameter pdb_NAME                     TYPE     VALUE------------------------------------ ----------- ------------------------------pdb_file_name_convert             string     /u01/app/oracle/oradata/dave/p                         dbseed/, /u01/app/oracle/orada                         ta/dave/ahdba/pdb_lockdown                 stringpdb_os_credential             stringSQL>SQL> create pluggable database ahdba admin user cndba identified by cndba;Pluggable database created.SQL> show pdbs    CON_ID CON_NAME              OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------     2 PDB$SEED              READ ONLY  NO     3 PDB1               READ WRITE NO     4 CNDBA              READ WRITE NO     5 HUAINING              READ WRITE NO     6 AHDBA              MOUNTEDSQL> alter pluggable database ahdba open;Pluggable database altered.SQL> show pdbs    CON_ID CON_NAME              OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------     2 PDB$SEED              READ ONLY  NO     3 PDB1               READ WRITE NO     4 CNDBA              READ WRITE NO     5 HUAINING              READ WRITE NO     6 AHDBA              READ WRITE NOSQL>





2. 手工删除PDB

在删除PDB的时候,有2个选项 KEEP DATAFILES 和 including DATAFILES,默认是KEEP.

SQL> show pdbs    CON_ID CON_NAME              OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------     2 PDB$SEED              READ ONLY  NO     3 PDB1               READ WRITE NO     4 CNDBA              READ WRITE NO     5 HUAINING              READ WRITE NO     6 AHDBA              READ WRITE NOSQL> drop pluggable database huaining;drop pluggable database huaining*ERROR at line 1:ORA-65179: cannot keep datafiles for a pluggable database that is not unpluggedSQL> !oerr ora 6517965179, 00000, "cannot keep datafiles for a pluggable database that is not unplugged"// *Cause:  An attempt was made to drop a pluggable database without//          specifying the INCLUDING DATAFILES clause, and the pluggable//          database has not been unplugged.// *Action: Unplug the pluggable database before dropping the pluggable//          database or use the INCLUDING DATAFILES clause in the//          DROP PLUGGABLE DATABASE statement.//SQL> drop pluggable database huaining including datafiles;Pluggable database dropped.SQL> show pdbs    CON_ID CON_NAME              OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------     2 PDB$SEED              READ ONLY  NO     3 PDB1               READ WRITE NO     4 CNDBA              READ WRITE NO     6 AHDBA              READ WRITE NOSQL>操作系统层面看,对应的文件,也一起删除了:[oracle@Ora12c huaining]$ pwd/u01/app/oracle/oradata/dave/huaining[oracle@Ora12c huaining]$ ls[oracle@Ora12c huaining]$




如果是使用KEEP datafiles,那么在执行drop 之前,必须先执行unplug的操作。

SQL> drop pluggable database ahdba keep datafiles;drop pluggable database ahdba keep datafiles*ERROR at line 1:ORA-65179: cannot keep datafiles for a pluggable database that is not unpluggedSQL> alter pluggable database ahdba unplug into '/tmp/ahdba.xml';Pluggable database altered.SQL> drop pluggable database ahdba keep datafiles;Pluggable database dropped.


删除成功。

以上是"Oracle 12c如何创建和删除PDB"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0