番外:如何克隆可刷新的PDB(Refreshable PDB)

基於版本:19c (12.2.0.3) AskScutisql

建立方法:克隆建立c#

對應路徑:屬於克隆。PDB類型爲:Refreshable
session

相關係列請參考《Oracle建立PDB列表文章oracle

注意建立可刷新的PDB,源庫必須處於歸檔模式和本地UNDO模式app

 

內容總覽 ide

1. 環境概述測試

2. 檢查源庫環境spa

3. 源庫建立用戶並受權code

4. 目標庫編輯TNS對象

5. 目標庫建立DBLink

6. 目標庫建立可刷新PDB

7. 目標庫打開可刷新PDB

8. 可刷新PDB測試

 

1. 環境概述

爲了概念理解統一,提早約定下:

遠程CDB2中有個ERP1,咱們稱遠程CDB2爲「源CDB」,IP:192.168.1.14

本地CDB1中有個PDB1,咱們稱本地CDB1爲「目標CDB」,IP:192.168.1.12

注意:源CDB和目標CDB是相對而言。就是被克隆的對象叫「」,準備克隆出來的對象叫「目標」。所以,下面就是要經過源CDB2中的ERP1,遠程克隆出來一個可刷新的PDB,放在目標CDB1中,名稱爲PDB_REF。

 

2. 檢查源庫環境

檢查是否爲歸檔模式

[oracle@henry ~]$ rlwrap sqlplus / as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Sat Aug 31 07:27:48 2019 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle.  All rights reserved. Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------- ---------- ----------
     2 PDB$SEED      READ ONLY NO 3 ERP1 READ WRITE NO SQL> archive log list; Database log mode   Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/arch1 Oldest online log sequence     5
Next log sequence to archive   7
Current log sequence           7

 

檢查是否爲本地UNDO

SQL> select property_name,property_value from database_properties where property_name='LOCAL_UNDO_ENABLED'; PROPERTY_NAME PROPERTY_VALUE -------------------- --------------------
LOCAL_UNDO_ENABLED   TRUE

 

3. 源庫建立用戶並受權

SQL> create user c##u1 identified by oracle; User created. SQL> grant create session,create pluggable database,sysoper to c##u1 container=all; Grant succeeded.

 

4. 目標庫編輯TNS

CDB2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.14)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = CDB2) ) )

目標庫編輯tnsnames別名,指向源庫。

 

5. 目標庫建立DBLink

SQL> create database link cdb2_dblink connect to c##u1 identified by oracle using 'CDB2'; Database link created. #測試DBLINK SQL> select * from tab@cdb2_dblink; no rows selected

 

6. 目標庫建立可刷新PDB

注意:刷新模式子句只支持 CREATE PLUGGABLE DATABASE ... FROM 語句。

6.0 基於默認 REFRESH MODE NONE

默認缺省狀況下,建立普通PDB(非刷新PDB)

 

6.1 基於手工刷新 REFRESH MODE MANUAL

SQL> !mkdir /u01/app/oracle/oradata/CDB1/pdbref SQL> create pluggable database pdb_ref from erp1@cdb2_dblink create_file_dest='/u01/app/oracle/oradata/CDB1/pdbref' refresh mode manual;

 

6.2 基於自動刷新 REFRESH MODE EVERY number_of_minutes MINUTES

SQL> !mkdir /u01/app/oracle/oradata/CDB1/pdbrefauto SQL> create pluggable database pdb_refauto from erp1@cdb2_dblink create_file_dest='/u01/app/oracle/oradata/CDB1/pdbrefauto' refresh mode every 60 minutes;

 

查看

SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------- ---------- ----------
     2 PDB$SEED      READ ONLY NO 3 PDB1 MOUNTED 4 PDB_REF MOUNTED 5 PDB_REFAUTO MOUNTED

 

7. 目標庫打開可刷新PDB

可刷新PDB爲了保證和源庫一致,必須只能以 READ ONLY 只讀模式打開。

SQL> alter pluggable database pdb_ref open read only; Pluggable database altered. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------- ---------- ----------
     2 PDB$SEED      READ ONLY NO 3 PDB1 MOUNTED 4 PDB_REF       READ ONLY NO 5 PDB_REFAUTO   MOUNTED

沒法以讀寫模式打開

SQL> alter pluggable database pdb_ref open; alter pluggable database pdb_ref open
* ERROR at line 1: ORA-65341: cannot open pluggable database in read/write mode

 

8. 可刷新PDB測試

8.1 源庫建立測試數據

SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------- ---------- ----------
     2 PDB$SEED      READ ONLY NO 3 ERP1          READ WRITE NO SQL> alter session set container=erp1; Session altered. SQL> create table test_ref(id number); Table created. SQL> insert into test_ref select object_id from dba_objects where rownum<501; 500 rows created. SQL> commit; Commit complete. SQL> select count(*) from test_ref; COUNT(*) ----------
       500

 

8.2 目標庫刷新

刷新前查看

SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------- ---------- ----------
     2 PDB$SEED      READ ONLY NO 3 PDB1 MOUNTED 4 PDB_REF       READ ONLY NO 5 PDB_REFAUTO MOUNTED SQL> alter session set container=pdb_ref; Session altered. SQL> select count(*) from test_ref; select count(*) from test_ref * ERROR at line 1: ORA-00942: table or view does not exist

 

目標庫關閉PDB_REF進行手工刷新

注意:執行刷新時,必須關閉可刷新的PDB。若是嘗試自動刷新時未關閉可刷新的PDB,則將刷新延遲到下一次計劃。若是執行手動刷新時未關閉可刷新的PDB,則會報告錯誤。自動刷新模式的PDB也能夠執行手工刷新。

SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------- ---------- ----------
     4 PDB_REF       READ ONLY NO 
SQL
> alter pluggable database pdb_ref close immediate; Pluggable database altered. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------- ---------- ---------- 4 PDB_REF MOUNTED
SQL
> alter pluggable database pdb_ref refresh; Pluggable database altered.

 

8.3 目標庫刷新後查看

SQL> alter pluggable database pdb_ref open read only; Pluggable database altered. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------- ---------- ----------
     4 PDB_REF       READ ONLY NO SQL> select count(*) from test_ref; COUNT(*) ----------
       500
相關文章
相關標籤/搜索