2019-09-12 KK日记,oracle 19c 容器数据初体验

一、案例

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描述得这么好,那么到底怎么使用才能达到以上的目标呢?

三、理解和验证

3.1 初步理解

  • 节省成本,通过把多过部署在不同物理机上的db以pdb方式迁移到19c的容器数据库上,以减少物理机的使用数量;以及把多个系统的db以pdb保存在cdb上,通过cdb就能批量管理,减少dba的维护成本,提高运维效率。

前提:不同系统的对db资源使用不多。

关注1:多个pdb存在一起如何解决资源竞争问题呢?

关注2: 部署容器数据库对物理机的要求高吗?

3.2 测试验证

  1. 场景:从cdb seed 上创建pdb。
#脚本
使用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
  1. 到现在为止,已经成功建立好一个pdb,接着我们开始管理这个pdb
#切换到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;

  1. 控制pdb的资源使用量可以使用资源管理或pdb 初始化参数中与资源相关的参数。

如,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'

4 结论

  • 为了更好使用多租户特性,oracle配套了多种不同多资源控制方法,按方式不同可以分为资源管理器和系统参数控制,按作用域可以分为cdb 和 pdb。
  • 经过初步测试和资料查阅,oracle所提供的资源控制方法都是有效的。
  • 在资源有效控制和阻隔之下,我认为可以尝试使用多租户和资源控制技术搭建oracle私有云。我们可以在此把多个不同应用的系统以pdb方式迁入,然后根据历史性能数据评估得出每个系统对cpu、内存、io的使用情况,并作以控制。当遇到特殊情况(市场活动,业务增长),我们可以快速完成pdb的资源扩容(无需重启)。以达到资源共享使用,合理使用,使用最大化的目的。
  • 进一步构想,我们有一个oracle cdb,上面由多个x86服务器组成的集群,各个小系统的数据库以pdb方式部署在上面,当出现物理硬件不足时,我们是能够快速增加节点(节点配置可以存在差异)。当节点资源分配不均衡时,我们可以快速插拔数据库或通过服务重新分配资源的方式,均衡资源使用,保证系统稳定。

5 参考文章

  • 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.
  • 创建pdb 高级选项
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/');

你可能感兴趣的:(ORACLE,DBA)