2013年(13)
分类: Oracle
2013-08-07 22:24:58
登录一个PDB。登录哪个PDB,就是要对哪个PDB进行管理。
[oracle@rac1 db_home]$ sqlplus /nolog
SQL*Plus: Release 12.1.0.1.0 Production on Sun Aug 4 12:42:34 2013
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> connect sys@pdb1 as sysdba
Enter password:
Connected.
SQL>
关闭PDB,实际上是切换到mounted状态(并不是关闭CDB实例)
SQL> SHUTDOWN IMMEDIATE;
Pluggable Database closed.
SQL>
启动PDB
SQL> STARTUP OPEN;
Pluggable Database opened.
把PDB切换到mounted状态。
mounted状态下,PDB相关的信息已经被从内存中删除,这时候的PDB的状态和普通数据库的状态类似,允许进行数据库维护。
SQL> ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;
Pluggable database altered.
切换PDB到只读
SQL> ALTER PLUGGABLE DATABASE OPEN READ ONLY;
Pluggable database altered.
SQL>
切换PDB到读写状态
SQL> ALTER PLUGGABLE DATABASE OPEN FORCE;
Pluggable database altered.
在PDB中创建表空间
create tablespace tbs_pdb1
datafile '/taryartar/12c/db_base/oradata/TCDB/pdb1_datafile.ora' size 5m,'/taryartar/12c/db_base/oradata/TCDB/pdb2_datafile.ora' size 5m;
改变PDB的默认表空间
SQL> ALTER PLUGGABLE DATABASE DEFAULT TABLESPACE tbs_pdb1;
Pluggable database altered.
创建表
SQL> create table tb_tar2(a varchar(20),b varchar(20));
Table created.
SQL>
创建临时表空间
create temporary tablespace temp_pdb1
TEMPFILE '/taryartar/12c/db_base/oradata/TCDB/pdb1_temp1.ora' size 50m,'/taryartar/12c/db_base/oradata/TCDB/pdb1_temp2.ora' size 50m;
改变PDB的默认临时表空间
ALTER PLUGGABLE DATABASE DEFAULT TEMPORARY TABLESPACE temp_pdb1;
改变PDB1的所有表空间的空间限制
ALTER PLUGGABLE DATABASE STORAGE(MAXSIZE 4G);
列出可以被PDB改变的参数
SELECT NAME FROM V$SYSTEM_PARAMETER WHERE ISPDB_MODIFIABLE='TRUE' ORDER BY NAME;
前面已经有文章介绍,如果通过DBCA创建PDB,接下来,我们将介绍通过脚本创建PDB。有很多种方法创建PDB。方法图解如下:
创建新的PDB的方法有好多种,我们这里只列举出其中的两种方法:
n 根据种子(seed)创建PDB。
SQL> CREATE PLUGGABLE DATABASE pdb66 ADMIN USER adm IDENTIFIED BY Xzzp2008 ROLES=(DBA);
Pluggable database created.
SQL> SELECT NAME, CON_ID, DBID, CON_UID, GUID FROM V$CONTAINERS ORDER BY CON_ID;
NAME CON_ID DBID CON_UID GUID
-------- ---------- ---------- ---------- --------------------------------
CDB$ROOT 1 2019279893 1 DD7C48AA5A4504A2E04325AAE80A403C
PDB$SEED 2 4065152146 4065152146 E3248235F4082FA2E0433300A8C0A61B
PDB3 3 3938652388 3938652388 E324F5B46388341EE0433300A8C09AC8
PDB4 4 3833224900 3833224900 E32580EB506A38C6E0433300A8C02AC2
PDB66 5 3270209553 3270209553 E357324FEC4921FDE0433300A8C0B6DD
adm是PDB管理员
Xzzp2008是管理员的密码
PDB66处于MOUNTED状态
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
-------- ----------
PDB$SEED READ ONLY
PDB3 MOUNTED
PDB4 MOUNTED
PDB66 MOUNTED
打开PDB66
SQL> alter pluggable database PDB66 open;
n 根据现有PDB创建新的PDB。
关闭源PDB
SQL> alter pluggable database PDB3 close immediate;
Pluggable database altered.
把源PDB切换到只读模式
SQL> ALTER PLUGGABLE DATABASE PDB3 OPEN READ ONLY;
Pluggable database altered.
根据源PDB3克隆出新的PDB(PDB33)
SQL> CREATE PLUGGABLE DATABASE PDB33 FROM PDB3;
Pluggable database created.
新的PDB处于MOUNTED状态
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
-------- ----------
PDB$SEED READ ONLY
PDB3 READ ONLY
PDB4 READ WRITE
PDB66 READ WRITE
PDB33 MOUNTED
SQL>
打开PDB
SQL> alter pluggable database PDB33 open;
Pluggable database altered.
SQL>
用sysdba进行登录
[oracle@rac1 db_home]$ export ORACLE_SID=tcdb2
[oracle@rac1 db_home]$ sqlplus
SQL*Plus: Release 12.1.0.1.0 Production on Tue Aug 6 20:59:41 2013
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter user-name: sys as sysdba
Enter password:
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
查看各种ID
SQL> COLUMN NAME FORMAT A8
SQL> SELECT NAME, CON_ID, DBID, CON_UID, GUID FROM V$CONTAINERS ORDER BY CON_ID;
NAME CON_ID DBID CON_UID GUID
-------- ---------- ---------- ---------- --------------------------------
CDB$ROOT 1 883454903 1 DD7C48AA5A4504A2E04325AAE80A403C
PDB$SEED 2 4065159988 4065159988 E31EE23FE4340E49E0433300A8C01AD7
PDB1 3 3330272355 3330272355 E31F5B4DC25B11FEE0433300A8C07605
PDB2_V2 4 3888812375 3888812375 E31F8C34A7E31371E0433300A8C000F9
查看PDB的状态
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 READ WRITE
PDB2_V2 READ WRITE
关闭PDB2_V2
SQL> alter pluggable database PDB2_V2 close immediate;
Pluggable database altered.
查看PDB2_V2的状态,MOUNTED说明PDB已经关闭
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDB1 READ WRITE
PDB2_V2 MOUNTED
拔出PDB2_V2
SQL> alter pluggable database PDB2_V2 unplug into '/test_data/PDB2_V2.xml';
Pluggable database altered.
SQL>
从CDB中拔出PDB,只是断开了他们之间的联系,并没有删除数据库。被拔出的数据库将不能被访问。
删除PDB2_V2,连数据文件也一起删除
SQL> drop pluggable database PDB2_V2 INCLUDING DATAFILES;