1. 程式人生 > >【跟我學oracle18c】第十五天:Multitenant Architecture多租戶框架:1.3 Path to Database Consolidation

【跟我學oracle18c】第十五天:Multitenant Architecture多租戶框架:1.3 Path to Database Consolidation

在其存在期間, a database is either a CDB or a non-CDB.

您必須在建立時將資料庫定義為CDB,然後在這個CDB中建立PDBs和應用程式容器。. You cannot later transform a non-CDB into a CDB, or a CDB into a non-CDB.

This section contains the following topics:

  • Creation of a CDB
    The CREATE DATABASE ... ENABLE PLUGGABLE DATABASE SQL statement creates a new CDB.
  • Creation of a PDB
    The CREATE PLUGGABLE DATABASE SQL statement creates a PDB.

1.3.1 Creation of a CDB

The CREATE DATABASE ... ENABLE PLUGGABLE DATABASE SQL statement creates a new CDB.

如果您沒有指定ENABLE PLUGGABLE DATABASE子句,那麼新建立的資料庫是非cdb資料庫。. In this case, the non-CDB can never contain PDBs.

當您建立一個CDB時,Oracle資料庫會自動建立一個根容器(CDB$ root)和一個種子PDB (PDB$ seed). The following graphic shows a newly created CDB:

Figure 1-6 CDB with Seed PDB

Description of Figure 1-6 follows
Description of "Figure 1-6 CDB with Seed PDB"

Example 1-3 怎樣查詢一個數據庫是否為CDB

The following simple query determines whether the database to which an administrative user is currently connected is a non-CDB, or a container in a CDB:

SQL> SELECT NAME, CDB, CON_ID FROM V$DATABASE;
 
NAME      CDB     CON_ID
--------- --- ----------
CDB1      YES          0

See Also:

Parent topic: Path to Database Consolidation

1.3.2 Creation of a PDB

The CREATE PLUGGABLE DATABASE SQL statement creates a PDB.

建立的PDB自動包含一個完整的資料字典,包括元資料和到CDB根中系統提供的物件的內部連結. You must define every PDB from a single root: either the CDB root or an application root.

每個PDB都有一個全域性唯一識別符號(GUID)。PDB GUID主要用於為儲存PDB檔案的目錄生成名稱,包括Oracle託管檔案目錄和非Oracle託管檔案目錄.

This section contains the following topics:

See Also:

"Creating and Removing PDBs and Application Containers"

Parent topic: Path to Database Consolidation

注意提前設定一下

alter system set db_create_file_dest='F:\ORACLE\PRODUCT\18C\ORADATA\';

不然報錯缺少ORA-65016: 必須指定 FILE_NAME_CONVERT

(個人認為其實最好指定FILE_NAME_CONVERT引數,不然oracle自己生成的目錄名直接一堆字母如下圖的語句和截圖,不如自己寫的清楚)

SQL> CREATE PLUGGABLE DATABASE hrpdb ADMIN USER hr IDENTIFIED BY hr;
SQL> CREATE PLUGGABLE DATABASE hrpdb1 from ORCLPDB;

 

1.3.2.1 Creation of a PDB by Cloning

One technique for creating a PDB is called cloning.

You can clone a PDB from PDB$SEED, an application seed, a remote or local PDB, or a non-CDB. This section contains the following topics:

Parent topic: Creation of a PDB

1.3.2.1.1 Creation of a PDB from a Seed

You can use the CREATE PLUGGABLE DATABASE statement to create a PDB from a seed.

A seed is a PDB that serves as a template for creation of another PDB. Creating a PDB from a seed copies some or all of the contents of a PDB, and then assigns a new unique identifier.

A seed PDB is either of the following:

  • The PDB seed (PDB$SEED), which is a system-supplied template for creating PDBs

    Every CDB has exactly one PDB$SEED, which cannot be modified or dropped.

  • An application seed, which is a user-created PDB for a specified application root

    Within an application container, you can create an application seed using the CREATE PLUGGABLE DATABASE AS SEED statement, which you can then use to accelerate creation of new application PDBs.

Figure 1-7 Creation from PDB$SEED

Description of Figure 1-7 follows
Description of "Figure 1-7 Creation from PDB$SEED"

Example 1-4 Creation of a PDB from PDB$SEED

The following SQL statement creates a PDB named hrpdb from PDB$SEED using Oracle Managed Files:

CREATE PLUGGABLE DATABASE hrpdb
 ADMIN USER dba1 IDENTIFIED BY password;

See Also:

"Creating a PDB from Scratch"

Parent topic: Creation of a PDB by Cloning

1.3.2.1.2 Creation of a PDB by Cloning a PDB or a Non-CDB

To clone a PDB or non-CDB, use the CREATE PLUGGABLE DATABASE statement with the FROMclause.

In this technique,

the source is either a non-CDB, or a PDB in a local or remote CDB.

The target is the PDB copied from the source.

克隆操作將與源關聯的檔案複製到新的位置,然後分配一個新的GUID來建立PDB.

這種技術對於快速建立用於測試和開發的PDBs非常有用。例如,在將應用程式部署到生產PDB之前,可以在克隆的PDB上測試新的或修改過的應用程式。如果PDB處於本地撤消模式,那麼在操作期間,源PDB可以以讀/寫模式開啟,這稱為熱克隆.

Note:

If you clone a PDB from a remote CDB, then you must use a database link.

If you run CREATE PLUGGABLE DATABASE statement in an application root, then the cloned PDB is created in the application container.

在這種情況下,源PDB的應用程式名稱和版本必須與應用程式容器的應用程式名稱和版本相容.

The following graphic illustrates cloning a PDB when both source and target are in the same CDB.

Figure 1-8 Cloning a PDB

Description of Figure 1-8 follows
Description of "Figure 1-8 Cloning a PDB"

Example 1-5 Cloning a PDB

The following SQL statement clones a PDB named salespdb from the plugged-in PDB named hrpdb:

CREATE PLUGGABLE DATABASE salespdb FROM hrpdb;

This section contains the following topics:

  • Snapshot Copy PDBs
    If the underlying file system supports storage snapshots, then you can use them by specifying the SNAPSHOT COPY clause. Snapshot copies make cloning almost instantaneous.
  • Refreshable Clone PDBs
    refreshable clone PDB is a read-only clone that can periodically synchronize with its source PDB.

See Also:

Parent topic: Creation of a PDB by Cloning

1.3.2.1.2.1 Snapshot Copy PDBs

如果底層檔案系統支援儲存快照,那麼可以通過指定快照複製子句來使用它們。快照複製使得克隆幾乎是瞬間完成的.

在建立快照複製PDB時,Oracle資料庫不生成源資料檔案的完整副本。相反,Oracle資料庫建立底層檔案系統的儲存級快照,然後使用快照建立PDB克隆。與標準的克隆PDB不同,快照複製PDB不能從CDB根或應用程式根拔起.

Note:

"About Cloning a PDB" to learn how to clone a PDB using the SNAPSHOT COPY clause

Parent topic: Creation of a PDB by Cloning a PDB or a Non-CDB

1.3.2.1.2.2 Refreshable Clone PDBs

refreshable clone PDB is a read-only clone that can periodically synchronize with its source PDB.

根據重新整理模式子句中指定的值,同步將自動或手動進行。例如,如果hrpdb_re_clone是hrpdb的克隆,那麼每個月您都可以手動重新整理hrpdb_re_clone來修改hrpdb。或者,您可以配置hrpdb,以便每24小時自動將更改傳播到hrpdb_re_clone.

您可以切換源PDB及其可重新整理克隆的角色。這種切換對於CDBs之間的負載平衡以及源PDB出現故障時非常有用。

Note:

"About Cloning a PDB" to learn how to clone a PDB using the REFRESH MODE clause

Parent topic: Creation of a PDB by Cloning a PDB or a Non-CDB

1.3.2.2 Creation of a PDB by Plugging In

You can create a PDB by plugging in an unplugged PDB, or plugging in a non-CDB as a PDB.

This section contains the following topics:

Parent topic: Creation of a PDB

1.3.2.2.1 Creation of a PDB by Plugging In an Unplugged PDB

An unplugged PDB is a self-contained set of data files, and an XML metadata file that specifies the locations of the PDB files. To plug in an unplugged PDB, use the CREATE PLUGGABLE DATABASEstatement with the USING clause.

When plugging in an unplugged PDB, you have the following options:

  • Specify the XML metadata file that describes the PDB and the files associated with the PDB.

  • Specify a PDB archive file, which is a compressed file that contains both the XML file and PDB data files. You can create a PDB by specifying the archive file, and thereby avoid copying the XML file and the data files separately.

The following graphic illustrates plugging in an unplugged PDB using the XML file.

Figure 1-9 Plugging In an Unplugged PDB

Description of Figure 1-9 follows
Description of "Figure 1-9 Plugging In an Unplugged PDB"

Example 1-6 Plugging In a PDB

The following SQL statement plugs in a PDB named salespdb based on the metadata stored in the named XML file, and specifies NOCOPY because the files of the unplugged PDB do not need to be moved to a new location:

CREATE PLUGGABLE DATABASE salespdb USING '/disk1/usr/salespdb.xml' NOCOPY;

See Also:

"Plugging In an Unplugged PDB"

Parent topic: Creation of a PDB by Plugging In

1.3.2.2.2 Creation of a PDB from a Non-CDB

You can move a non-CDB into a PDB.

You can accomplish this task in the following ways:

  • Executing DBMS_PDB.DESCRIBE on a non-CDB in Oracle Database 12c

    將非cdb置於事務一致的狀態,然後執行DBMS_PDB。描述用於生成關於此資料庫的XML元資料的函式。當連線到CDB中的根目錄時,執行CREATE PLUGGABLE DATABASEstatement從現有的非CDB建立PDB。最後,要將PDB資料字典中的定義轉換為對CDB$ROOT中的物件的引用,請登入到PDB並執行noncdb_to_pdb.sql指令碼.

  • Using Oracle Data Pump with or without transportable tablespaces

    您可以使用Oracle資料泵在非cdb上定義資料集。這個非cdb可以在當前或以前的Oracle資料庫版本中,例如Oracle資料庫10g。在現有的CDB中建立一個空的PDB,然後使用Oracle資料泵將資料集匯入PDB.

    完整的可傳輸匯出使用Oracle資料泵匯出建立資料庫完整副本所需的所有物件和資料。Oracle資料泵使用直接路徑解除安裝和外部表匯出物件,然後使用直接路徑插入和外部表匯入物件。完整的可傳輸轉儲檔案包含資料庫中的所有物件,而不僅僅是與表相關的物件。可以從Oracle資料庫11g版本2(11.2.0.3)中開始完整的可傳輸匯出,以便匯入Oracle資料庫12c或更高版本.

  • Using Oracle GoldenGate replication

    將資料從非cdb複製到PDB。當PDB與非cdb合流時,您將切換到PDB.

The following figure illustrates running the DBMS_PDB.DESCRIBE function on a non-CDB, and then creating a PDB using the non-CDB files.

Figure 1-10 Creating a PDB from a Non-CDB

Description of Figure 1-10 follows
Description of "Figure 1-10 Creating a PDB from a Non-CDB"

See Also:

Parent topic: Creation of a PDB by Plugging In

1.3.2.3 Creation of a PDB by Relocating

To relocate a PDB from one CDB to another, use the CREATE PLUGGABLE DATABASE statement with the FROM clause and RELOCATE keyword.

This technique has the following advantages:

  • 遷移發生在停機時間最少的情況下.

  • 該技術使重新定位的PDB在重新定位期間以讀/寫模式開啟,然後在新的位置將PDB聯機。

     

您必須在目標CDB上建立一個數據庫連結,這個CDB將包含重新定位的PDB。此外,源PDB必須使用本地撤消資料.

The following graphic depicts a PDB relocation.

Figure 1-11 Relocating a PDB

Description of Figure 1-11 follows
Description of "Figure 1-11 Relocating a PDB"

Example 1-7 PDB Relocation

The following statement, which is issued at a target CDB, relocates hrpdb from the source CDB to the target CDB:

CREATE PLUGGABLE DATABASE hrpdb FROM [email protected]_to_source RELOCATE;

See Also:

Parent topic: Creation of a PDB

1.3.2.4 Creation of a PDB as a Proxy PDB

A proxy PDB provides access to different PDB, called the referenced PDB, in a remote CDB.

代理PDBs使您能夠聚合來自多個數據源的資料。提交到代理PDB中執行的SQL語句在引用的PDB中執行.

典型的用例是引用應用程式根副本的代理PDB。如果多個CDBs具有相同的應用程式定義(例如,相同的表和PL/SQL包),那麼您可以在主應用程式根的應用程式容器中建立代理PDB。代理PDB的引用PDB是另一個CDB中的應用程式根。通過在主根中執行安裝指令碼,其他CDBs中的應用程式根成為主應用程式根的副本.

要建立代理PDB,請使用create PLUGGABLE資料庫語句和FROM子句,該子句必須指定到遠端CDB中引用的PDB的資料庫連結,以及AS proxy子句.

Note:

如果您將代理PDB直接插入到CDB$ROOT中,那麼您必須在CDB$ROOT中建立代理。應用程式PDB的代理必須都插入到應用程式根目錄中。

The following graphic shows the creation of a proxy PDB that references a PDB in a remote CDB.

Figure 1-12 Creating a Proxy PDB

Description of Figure 1-12 follows
Description of "Figure 1-12 Creating a Proxy PDB"

Example 1-8 Creation of a Proxy PDB

This example creates a proxy PDB named pdb1. The referenced PDB is specified using a database link.

CREATE PLUGGABLE DATABASE pdb1 AS PROXY FROM [email protected]_link;

Note:

"Creating a PDB as a Proxy PDB"