oracle 12c 以上数据库的其中一个新特性是容器数据库,在oracle官方文档上描述使用该新特性可以带来多个好处,具体如下:
1. Cost reduction
By consolidating hardware and database infrastructure to a single set of background processes, and efficiently sharing computational and memory resources, you reduce costs for hardware and maintenance.
2. Easier and more rapid movement of data and code
By design, you can plug a PDB into a CDB, unplug the PDB from the CDB, and then plug this PDB into a different CDB. Therefore, you can easily move an application's database back end from one server to another.
3. Easier management and monitoring of the physical database
The CDB administrator can manage the environment as an aggregate by executing a single operation, such as patching or performing an RMAN backup, for all hosted tenants and the CDB root.
3. Separation of data and code
Although consolidated into a single physical CDB, PDBs mimic the behavior of traditional non-CDBs. For example, a PDB administrator can flush the shared pool or buffer cache in the context of a PDB without affecting other PDBs in the CDB.
4. Ease of performance tuning
It is easier to collect performance metrics for a CDB than for multiple non-CDBs. It is easier to size one SGA than several SGAs.
5. Support for Oracle Database Resource Manager
In any shared resource environment, administrators must manage system resources to provide a predictable environment for users and address unexpected or transient resource contention. To address these issues and to provide resource usage monitoring, you can use Oracle Database Resource Manager (see Using Oracle Resource Manager for PDBs with SQL*Plus).
6. Fewer patches and upgrades
It is easier to apply a patch to one CDB than to multiple non-CDBs and to upgrade one CDB than to upgrade several non-CDBs.
既然oracle描述得这么好,那么到底怎么使用才能达到以上的目标呢?
前提:不同系统的对db资源使用不多。
关注1:多个pdb存在一起如何解决资源竞争问题呢?
关注2: 部署容器数据库对物理机的要求高吗?
#脚本
使用oracle安装用户登陆本机
sqlplus / as sysdba # 登陆到cdb root
show con_name
CON_NAME
------------------------------
CDB$ROOT
#代表成功连接到root 上
#这时可以创建pdb了,最简单到创建方法
CREATE PLUGGABLE DATABASE qqtdb ADMIN USER qqadm IDENTIFIED BY "password";
# 查看是否成功创建pdb
select pdb_name from cdb_pdbs;
PDB_NAME
--------------------------------------------------------------------------------
PDB
PDB$SEED
PDB2
QQTDB
# 已经看到成功创建到PDB
# 切换到pdb管理模式
ALTER SESSION SET CONTAINER =qqtdb; #CDB$ROOT /PDB$SEED
show con_name
CON_NAME
------------------------------
QQTDB
#切换到pdb管理模式
# 启动pdb
startup
# 查看pdb的文件存放
select * from dba_data_files;
# 基本的使用应该与11g的使用一样了
# 发现pdb创建后直接继承了cdb 的sga设置
show parameter sga
# 是否可以修改pdb的sga?
alter system set sga_target=1024m scope=both; # 成功在pdb下直接执行
备注:You can modify an initialization parameter for a PDB when the ISPDB_MODIFIABLE column is TRUE for the parameter in the V$SYSTEM_PARAMETER view. The following query lists all of the initialization parameters that are modifiable for a PDB:
SELECT NAME FROM V$SYSTEM_PARAMETER WHERE ISPDB_MODIFIABLE='TRUE' ORDER BY NAME;
如,cpu_count; db_cache_size; sga_target; pga;max_iops max_mbps等。
# 测试使用非资源管理计划方式进行资源管理
# 修改sga_target
alter system set sga_target=1024m scope=both;
# 修改cpu_count
#alter system set sga_target=1 scope=both;
SQL> show parameter cpu_count
NAME TYPE VALUE
------------------------------------ -----------
cpu_count integer 80
SQL> alter system set cpu_count=2 scope=both;
System altered.
SQL> show parameter cpu_count
SQL> show parameter cpu_count
NAME TYPE VALUE
------------------------------------ -----------
cpu_count integer 2
# 测试cpu限制
# 生成数据
create table qq_object as
select * from dba_objects;
insert into qq_object
select * from qq_object;
select * from qq_object a;
select /*+ parallel(a 16) */ count(*) from qq_object a;
# cpu_count =2, cpu usage 3% ; cpu_count =16, cpu usage 13%
#由此说明是能够限制cpu的使用的。
# 测试iops限制,当设置为0时不限制。
alter system set max_iops=100 scope=both;
alter system set max_mbps=10 scope=both;
# 命令运行成功,但目前缺乏有效的用例验证。
# select event from v$session where status='ACTIVE' and sid=1821;
# 监控pdb io指标
set linesize 400
col PDB_NAME for a10
col BEGIN_TIME for a30
col END_TIME for a30
SELECTR.SNAP_ID,
R.CON_ID,
P.PDB_NAME,
TO_CHAR(R.BEGIN_TIME, 'YYYY-MM-DHH24:MI') AS BEGIN_TIME,
TO_CHAR(END_TIME, 'YYYY-MM-D HH24:MI')AS END_TIME,
R.IOPS,
R.IOMBPS,
R.IOPS_THROTTLE_EXEMPT,
R.IOMBPS_THROTTLE_EXEMPT,
R.AVG_IO_THROTTLE
FROM DBA_HIST_RSRC_PDB_METRIC R, CDB_PDBS P
WHERE R.CON_ID = P.CON_ID
ORDER BY R.BEGIN_TIME;
# 测试脚本
select segment_name,bytes/1024/1024 from dba_segments where segment_name='QQ_OBJECT'
https://docs.oracle.com/en/database/oracle/oracle-database/12.2/admin/creating-and-removing-pdbs-with-sql-plus.html#GUID-534B3B1D-0ED7-4828-9CA4-B1757398801F
37.4.1.1 About Enabling PDBs
To create a CDB, the CREATE DATABASE statement must include the ENABLE PLUGGABLE DATABASE clause. When this clause is included, the statement creates a CDB with the root and the CDB seed.
When the ENABLE PLUGGABLE DATABASE clause is not included in the CREATE DATABASE statement, the newly created database is a non-CDB. The statement does not create the root and the CDB seed, and the non-CDB can never contain PDBs.
CREATE PLUGGABLE DATABASE salespdb ADMIN USER salesadm IDENTIFIED BY password
STORAGE (MAXSIZE 2G)
DEFAULT TABLESPACE sales
DATAFILE '/disk1/oracle/dbs/salespdb/sales01.dbf' SIZE 250M AUTOEXTEND ON
PATH_PREFIX = '/disk1/oracle/dbs/salespdb/'
FILE_NAME_CONVERT = ('/disk1/oracle/dbs/pdbseed/', '/disk1/oracle/dbs/salespdb/');