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 參考文章

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/');
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章