CDB和PDB的创建、连接、启动和关闭方法
本篇内容主要讲解"CDB和PDB的创建、连接、启动和关闭方法",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"CDB和PDB的创建、连接、启动和关闭方法"吧!
一、CDB和PDB基本管理
基本概念:
Multitenant Environment:多租户环境
CDB(Container Database):数据库容器
PDB(Pluggable Database):可插拔数据库
二、创建
2.1创建CDB
PDB包含在CDB中,所以,要创建PDB,必须先创建CDB。一台机器上可以有多个CDB。Oracle软件安装完成后,就可以创建CDB
启动DBCA
C:\app\oracle\product\12.1.0\dbhome_1\BIN\dbca.bat)
2.2创建PDB
C:\app\oracle\product\12.1.0\dbhome_1\BIN\dbca.bat
三、连接
3.1连接CDB
Sqlplus默认连接CDB
sqlplus sys/oracle as sysdba
3.2连接PDB
pdb可以通过在CDB中alter session container
alter session set container=pdb1
也可以直接通过tns方式(如下)登录
sqlplus sys/oracle@pdb1 as sysdba
其中tnsnames.ora添加
PDB1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pdb1) ) )
四、启动与关闭
4.1启动关闭CDB
SQL> show con_nameCON_NAME------------------------------CDB$ROOTSQL> shutdown immediate数据库已经关闭。已经卸载数据库。ORACLE 例程已经关闭。SQL> startupORACLE 例程已经启动。Total System Global Area 5044088832 bytesFixed Size 2413072 bytesVariable Size 1040190960 bytesDatabase Buffers 3992977408 bytesRedo Buffers 8507392 bytes数据库装载完毕。数据库已经打开。SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------4122484437 PDB$SEED READ ONLY3387525155 PDB1 MOUNTED3946119498 PDB2 MOUNTEDSQL>
从上面的操作中可以看到数据库启动的时候所有的PDBs的状态为MOUNTED
4.2启动关闭PDB
pdb的管理可以在cdb中进行也可以在pdb中进行,如果是cdb中进行,需要PLUGGABLE关键字,如果是在pdb中直接和普通数据库一样
SQL> show con_nameCON_NAME------------------------------CDB$ROOTSQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------4122484437 PDB$SEED READ ONLY3387525155 PDB1 MOUNTED3946119498 PDB2 MOUNTEDSQL> alter pluggable database pdb1 open;插接式数据库已变更。SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------4122484437 PDB$SEED READ ONLY3387525155 PDB1 READ WRITE3946119498 PDB2 MOUNTEDSQL> alter pluggable database pdb2 open;插接式数据库已变更。SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------4122484437 PDB$SEED READ ONLY3387525155 PDB1 READ WRITE3946119498 PDB2 READ WRITESQL> alter pluggable database pdb1 close;插接式数据库已变更。SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------4122484437 PDB$SEED READ ONLY3387525155 PDB1 MOUNTED3946119498 PDB2 READ WRITESQL> alter pluggable database pdb2 close;插接式数据库已变更。SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------4122484437 PDB$SEED READ ONLY3387525155 PDB1 MOUNTED3946119498 PDB2 MOUNTEDSQL> alter pluggable database all open;插接式数据库已变更。SQL> alter pluggable database all close;插接式数据库已变更。SQL> alter session set container=pdb1 ;会话已更改。SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------3387525155 PDB1 MOUNTEDSQL> startup插接式数据库已打开。SQL> shutdown插接式数据库已关闭。SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------3387525155 PDB1 MOUNTEDSQL>
4.3自动启动所有PDB
从上面的操作中可以看到数据库启动的时候所有的PDBs的状态为MOUNTED,在实际应用可以考虑增加如下的触发器使所有的PDBs都处于打开状态。
create or replace trigger sys.after_startup after startup on databasebeginexecute immediate 'alter pluggable database all open ' ;end after_startup ;
验证过程
SQL> create or replace trigger sys.after_startup after startup on databasebeginexecute immediate 'alter pluggable database all open ' ;end after_startup ;/触发器已创建SQL> shutdown数据库已经关闭。已经卸载数据库。ORACLE 例程已经关闭。SQL> startupORACLE 例程已经启动。Total System Global Area 5044088832 bytesFixed Size 2413072 bytesVariable Size 1040190960 bytesDatabase Buffers 3992977408 bytesRedo Buffers 8507392 bytes数据库装载完毕。数据库已经打开。SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;CON_ID DBID NAME OPEN_MODE---------- ---------- ------------------------------ ----------4122484437 PDB$SEED READ ONLY3387525155 PDB1 READ WRITE3946119498 PDB2 READ WRITESQL>
五、常用SQL
--查看ORACLE 12C版本select * from v$version;--查看容器名称和IDshow con_name ;--查看状态select name ,open_mode from v$pdbs ;--切换containeralter session set container=pdb1
到此,相信大家对"CDB和PDB的创建、连接、启动和关闭方法"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!