当前位置: 首页 > 工具软件 > UnPlug > 使用案例 >

oracle 18c 18.3 学习之五 unplug drop plug pdb

阎啸
2023-12-01

os: centos 7.4
db: oracle 18c(18.3)

pdb 的优势之一就是 unplug、plug,本篇blog介绍下 pdb 的 unplug。

以 pdbdongg 为例,进行 unplug 操作。

unplug pdb

必须先 close,然后再 unplug。
需要再 cdb$root 下操作

$ sqlplus / as sysdba;

SQL> show con_name;

CON_NAME
------------------------------
CDB$ROOT

SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBPEIYB			  READ WRITE NO
	 4 PDBSHENZ			  READ WRITE NO
	 5 PDBGUANGZ			  READ WRITE NO
	 6 PDBDONGG			  READ WRITE NO

SQL> alter pluggable database PDBDONGG close immediate;

SQL> alter pluggable database PDBDONGG unplug into '/u01/app/oracle/unplug_pdb/PDBDONGG.xml';

SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBPEIYB			  READ WRITE NO
	 4 PDBSHENZ			  READ WRITE NO
	 5 PDBGUANGZ	      READ WRITE NO
	 6 PDBDONGG			  MOUNTED
	 

有兴趣,可以分析下 PDBDONGG.xml 文件,记录了很多重要的描述性信息。

drop pdb

close,unplug 之后就可以 drop了,感觉和U盘的使用规则一致,也符合人的认知思维。
drop 操作也可以同时删除数据文件,比较威猛,慎用。
需要再 cdb$root 下操作

SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBPEIYB			  READ WRITE NO
	 4 PDBSHENZ			  READ WRITE NO
	 5 PDBGUANGZ			  READ WRITE NO
	 6 PDBDONGG			  MOUNTED
SQL> 
SQL> drop pluggable database PDBDONGG keep datafiles;

SQL> 
SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBPEIYB			  READ WRITE NO
	 4 PDBSHENZ			  READ WRITE NO
	 5 PDBGUANGZ			  READ WRITE NO

下面命令为删除数据库及数据库文件

SQL> drop pluggable database PDBDONGG including datafiles;  

plug pdb

plug pdb 需要使用之前 unplug 导出的 xml文件。
需要再 cdb$root 下操作

SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBPEIYB			  READ WRITE NO
	 4 PDBSHENZ			  READ WRITE NO
	 5 PDBGUANGZ			  READ WRITE NO
SQL> create pluggable database PDBDONGG using '/u01/app/oracle/unplug_pdb/PDBDONGG.xml' nocopy tempfile reuse;

SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBPEIYB			  READ WRITE NO
	 4 PDBSHENZ			  READ WRITE NO
	 5 PDBGUANGZ			  READ WRITE NO
	 6 PDBDONGG			  MOUNTED
	 
SQL> alter pluggable database PDBDONGG open;

SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDBPEIYB			  READ WRITE NO
	 4 PDBSHENZ			  READ WRITE NO
	 5 PDBGUANGZ		  READ WRITE NO
	 6 PDBDONGG			  READ WRITE NO
	 

这里完全复用了之前的文件,也可以修改为新的数据库名和 新的目录。比如

SQL> CREATE PLUGGABLE DATABASE PDBDONGG_PLUG1
USING '/u01/app/oracle/unplug_pdb/PDBDONGG.xml' 
COPY
file_name_convert=('/u01/app/oracle/oradata/ORCL/pdbdongg/',
                   '/u01/app/oracle/oradata/ORCL/pdbdongg_plug1/')  
STORAGE ( MAXSIZE UNLIMITED 
          MAX_SHARED_TEMP_SIZE UNLIMITED
		 )
TEMPFILE REUSE		 
PATH_PREFIX = '/u01/app/oracle/oradata/ORCL/pdbdongg_plug1/';

参考:
https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/ALTER-PLUGGABLE-DATABASE.html#GUID-A29491AD-8F0F-4E52-9D94-57FC3FF8FBC7
https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/CREATE-PLUGGABLE-DATABASE.html#GUID-F2DBA8DD-EEA8-4BB7-A07F-78DC04DB1FFC
https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/DROP-PLUGGABLE-DATABASE.html#GUID-4A663783-E184-417A-8BE1-703E1CDBA30B

 类似资料: