oracle多租用户实践
1、使用dbca创建CDB
2、创建前的准备工作
3、 创建PDB
创建PDB的方法
NO |
创建方法 |
描述 |
1 |
使用种子库创建 |
使用种子库模板创建 |
2 |
使用克隆方法创建 |
使用clone技术克隆非CDB或是一个PDB方式创建 |
3 |
从别的CDB迁移PDB |
将CDB1的PDB1迁移到CDB2 |
4 |
插入未装载的PDB |
使用XML方式配置数据库的当前插拔状态 |
5 |
创建一个代理PDB |
使用DBlink方式引用PDB创建一个代理PDB方式,被引用的PDB可以在当前CDB或者不同的CDB中。 |
6 |
使用非CDB创建PDB |
使用非CDB转换为PDB的方式创建 |
3.1 使用种子库创建PDB
3.1.1 不带条件的创建PDB
前提是PDB_FILE_NAME_CONVERT或CREATE_FILE_DEST已指定
SQL> select con_id,name,open_mode from v$containers;默认创建的CDB是存在一个种子库的,查看种子库相关信息
CON_ID NAME OPEN_MODE
---------- ------------------------------ ------------------------------
1 CDB$ROOT READ WRITE
2 PDB$SEED READ ONLY
SQL> alter session set container=pdb$seed;设置一下pdb_file_name_convert的值
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------
/u01/app/oracle/oradata/CDB/pdbseed/system01.dbf
/u01/app/oracle/oradata/CDB/pdbseed/sysaux01.dbf
SQL> alter session set container=cdb$root;启用pdb1,查看当前文件创建是否正确
会话已更改。
SQL> show parameter pdb_file_name_conver
NAME TYPEVALUE
------------------------------------ ---------- ------------------------------
pdb_file_name_convertstring/u01/app/oracle/oradata/CDB/pd
bseed/, /u01/app/oracle/oradata/CDB/pdb1/
SQL> create pluggable database pdb1 admin user adminpdb1 identified by oracle;
插接式数据库已创建。
SQL> select con_id,name,open_mode from v$containers;
CON_ID NAME OPEN_MODE
---------- ------------------------------ ------------------------------
1 CDB$ROOT READ WRITE
2 PDB$SEED READ ONLY
3 PDB1 MOUNTED
SQL> alter session set container=pdb1;
SQL> alter session set container=pdb1;会话已更改。SQL> startup插接式数据库已打开。SQL> select file_name from dba_data_files;FILE_NAME--------------------------------------------------/u01/app/oracle/oradata/CDB/pdb1/system01.dbf/u01/app/oracle/oradata/CDB/pdb1/sysaux01.dbf
3.1.2使用带条件的语句创建PDB
SQL>CREATE PLUGGABLE DATABASE pdb2 ADMIN USER pdbadmin2 IDENTIFIED BY oracle以上是带上了参数创建的pdb2的过程。
2 STORAGE (MAXSIZE 2G)
3 DEFAULT TABLESPACE sales
4 DATAFILE '/u01/app/oracle/oradata/CDB/pdb2/sales01.dbf' SIZE 250M AUTOEXTEND ON
5 PATH_PREFIX = '/u01/app/oracle/oradata/CDB/'
6* FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/CDB/pdbseed/', '/u01/app/oracle/oradata/CDB/pdb2/')
SQL> select con_id,name,open_mode from v$containers;
CON_ID NAME OPEN_MODE
---------- ------------------------------ ------------------------------
1 CDB$ROOT READ WRITE
2 PDB$SEED READ ONLY
3 PDB1 READ WRITE
4 PDB2 READ WRITE
3.2使用克隆方式创建PDB
3.2.1 不带参数条件克隆
SQL> alter session set pdb_file_name_convert ='/u01/app/oracle/oradata/CDB/pdb2','/u01/app/oracle/oradata/CDB/pdb3';--前提
会话已更改。
SQL> CREATE PLUGGABLE DATABASE pdb3 FROM pdb2;
插接式数据库已创建。
SQL> select con_id,name,open_mode from v$pdbs;
CON_ID NAME OPEN_MODE
---------- ------------------------------ ------------------------------
2 PDB$SEED READ ONLY
3 PDB1 MOUNTED
4 PDB2 READ WRITE
5 PDB3 MOUNTED
3.2.2 带参数的克隆
首先我们为pdb2创建一些service_name,在克隆的时候一并克隆并重命名。SQL> alter session set container=pdb2;为方便我们访问在tnsnames.ora文件中添加如下内容
SQL> exec dbms_service.create_service('pdb2_test1','pdb2_test1');
PL/SQL 过程已成功完成。
SQL> exec dbms_service.start_service('pdb2_test1');
PL/SQL 过程已成功完成。
SQL> exec dbms_service.stop_service('pdb2_test1');
PL/SQL 过程已成功完成。
SQL> exec dbms_service.create_service('pdb2_test2','pdb2_test2');
PL/SQL 过程已成功完成。
SQL> exec dbms_service.start_service('pdb2_test2');
PL/SQL 过程已成功完成。
pdb2_test1 =用pdb2 为模板复制pdb4并将pdb2 的service_name重命名
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 12c)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb2_test1)
)
pdb2_test2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 12c)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb2_test2)
)
)
SQL> alter session set container=cdb$root;启用pdb4 的service是否正常
会话已更改。
SQL> CREATE PLUGGABLE DATABASE pdb4 FROM pdb2
2 PATH_PREFIX = '/u01/app/oracle/oradata/CDB/pdb4/'
3 FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/CDB/pdb2/', '/u01/app/oracle/oradata/CDB/pdb4/')
4 SERVICE_NAME_CONVERT = ('pdb2_test1','pdb4_test1','pdb2_test2','pdb4_test2')
5 NOLOGGING;
插接式数据库已创建。
SQL> select con_id,name,open_mode from v$pdbs;
CON_ID NAME OPEN_MODE
---------- ------------------------------ ------------------------------
2 PDB$SEED READ ONLY
3 PDB1 MOUNTED
4 PDB2 READ WRITE
5 PDB3 MOUNTED
6 PDB4 MOUNTED
SQL> alter pluggable database pdb4 open; 插接式数据库已变更SQL> alter session set container=pdb4;会话已更改。SQL> exec dbms_service.start_service('pdb4_test1');PL/SQL 过程已成功完成。SQL> exec dbms_service.start_service('pdb4_test2');PL/SQL 过程已成功完成。测试是否正常登陆
[oracle@12c admin]$ sqlplus system/oracle@12c:1521/pdb4_test1查询当前service的状态
SQL*Plus: Release 12.1.0.2.0 Production on 星期五 5月 26 15:18:35 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
上次成功登录时间: 星期五 5月 26 2017 15:11:26 +08:00
连接到:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>
SQL> alter session set container=cdb$root;
SQL> select con_id,name,enabled,pdb from cdb_Services order by 1;
CON_ID NAME ENABLED PDB
---------- ------------------------------ --------- ----------
1 SYS$BACKGROUND NO CDB$ROOT
1 SYS$USERS NO CDB$ROOT
1 CDBXDB NO CDB$ROOT
1 CDB NO CDB$ROOT
4 pdb2 NO PDB2
4 pdb2_test1 NO PDB2
4 pdb2_test2 NO PDB2
6 pdb4_test1 NO PDB4
6 pdb4 NO PDB4
6 pdb4_test2 NO PDB4
已选择 10 行。