create pluggable database notedpdb admin user pdbadmin identified by "Password123"; alter pluggable database notedpdb open instances=all; alter pluggable database notedpdb save state instances=all;
define _editor=vi set serveroutput on size 1000000 set trimspool on set long 5000 set pagesize 5000 set linesize 256 column plan_plus_exp format a80 column global_name new_value gname alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; set termout off define gname=idle column global_name new_value gname select lower(user)||'@'||'('||(select distinct sid from v$mystat ) ||'_'||(select sys_context('USERENV','CON_NAME') from dual)||')' global_name from v$instance; set sqlprompt '&gname> ' set termout on
PDB 的创建
1、 使用seed创建新的pdb
最简单的创建pdb 语句
1
SQL>create pluggable database pdborcl admin user pdbadmin identified by pdbadmin ;
[TOC00000] Jump to table of contents Dump continued from file: /u01/app/oracle/diag/rdbms/tdecdb/tdecdb/trace/tdecdb_ora_6143.trc [TOC00001] ORA-07445: exception encountered: core dump [prsetsesc()+59] [SIGSEGV] [ADDR:0x40] [PC:0x80C08EB] [Address not mapped to object] []
[TOC00001-END] [TOC00002] ========= Dump for incident 30873 (ORA 7445 [prsetsesc]) ======== [TOC00003] ----- Beginning of Customized Incident Dump(s) ----- Dumping swap information Memory (Avail / Total) = 98.76M / 3788.92M Swap (Avail / Total) = 2799.84M / 4096.00M Exception [type: SIGSEGV, Address not mapped to object] [ADDR:0x40] [PC:0x80C08EB, prsetsesc()+59] [flags: 0x0, count: 1] Registers: %rax: 0x000000000000044b %rbx: 0x00007f793d560ac0 %rcx: 0x00007f7938b6e19f %rdx: 0x00007f793d3e4af8 %rdi: 0x00007f793d548ca0 %rsi: 0x00007f793d560ac0 %rsp: 0x00007ffffbfa3ff0 %rbp: 0x00007ffffbfa4030 %r8: 0x0000000000000048 %r9: 0x0000000005a95350 %r10: 0x0000000000000000 %r11: 0x000000000ef64fc8 "/u01/app/oracle/diag/rdbms/tdecdb/tdecdb/incident/incdir_30873/tdecdb_ora_6143_i30873.trc" 62161L, 3160770C 1,1 Top Dump file /u01/app/oracle/diag/rdbms/tdecdb/tdecdb/incident/incdir_30873/tdecdb_ora_6143_i30873.trc Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options ORACLE_HOME = /u01/app/oracle/product/12.1.0.2/dbhome_1 System name: Linux
1 2 3 4 5
CREATE PLUGGABLE DATABASE pathprepdb ADMIN USER pdbadm IDENTIFIED BY pdbadm roles=(DBA) STORAGE (MAXSIZE 2G MAX_SHARED_TEMP_SIZE 10M) DEFAULT TABLESPACE sales DATAFILE '/oradata/tdecdb/pathprepdb/sales01.dbf' SIZE 20M AUTOEXTEND ON FILE_NAME_CONVERT = ('/oradata/tdecdb/sys/pdbseed/', '/oradata/tdecdb/pathprepdb/');
sys@tdecdb(603)> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY Password23 with backup;
keystore altered.
sys@tdecdb(603)>select*from V$ENCRYPTION_WALLET;
WRL_TYPE WRL_PARAMETER STATUS WALLET_TYPE WALLET_OR FULLY_BAC CON_ID -------------------- ---------------------------------------- ------------------------------ -------------------- --------- --------- ---------- FILE /etc/ORACLE/WALLETS/tdecdb/OPEN PASSWORD SINGLE NO0
就可以进行正常的pdb操作了。
使用seed创建新的 tde 加密pdb 完成。
删除 pdb
1 2
alter Pluggable database PDBORCL close; drop pluggable database PDBORCL including datafiles;
2、 从本地 PDB 进行克隆
1 2 3 4 5 6 7 8 9 10
SQL>CREATE PLUGGABLE DATABASE hrpdb FROM salespdb no data STORAGE unlimited; Pluggable database created. SYS@ora12c> col name for a15 SYS@ora12c>select con_id, name,open_mode from v$containers; CON_ID NAME OPEN_MODE ---------- --------------- -------------------- 1 CDB$ROOT READ WRITE 2 PDB$SEED READ ONLY 3 SALESPDB READ ONLY 4 HRPDB MOUNTED
1 2 3 4 5 6 7 8 9 10
show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 TDEPDB READ WRITE NO 4 TDEPDB2 READ WRITE NO 6 SALESPDB READ WRITE NO
CREATE PLUGGABLE DATABASE hrpdb_tde FROM TDEPDB STORAGE unlimited;
2.1.源 pdb 未启用 tde 加密进行克隆
1 2 3 4 5 6 7
SQL>CREATE PLUGGABLE DATABASE hrpdb FROM salespdb no data STORAGE unlimited; Pluggable database created. 2 PDB$SEED READ ONLYNO 3 TDEPDB READ WRITE NO 4 TDEPDB2 READ WRITE NO 5 HRPDB MOUNTED 6 SALESPDB READ WRITE NO
库能够正常打开。
2.2.源库启用 tde 加密进行克隆
分两种情况进行测试
2.2.1 钱包打开,克隆数据和不克隆数据进行测试
克隆数据库不包含数据
1 2 3 4 5 6
CREATE PLUGGABLE DATABASE hrpdbtdenodata FROM TDEPDB no data STORAGE unlimited; Pluggable database created. sys@tdecdb(26)>alter Pluggable database hrpdbtdenodata open;
Warning: PDB altered with errors. 6 HRPDBTDENODATA READ WRITE YES
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 9 HRPDB_TDECLOSE READ WRITE YES sys@tdecdb(23)> exit Disconnected from Oracle Database 12c Enterprise Edition Release12.1.0.2.0-64bit Production With the Partitioning, OLAP, Advanced Analytics andReal Application Testing options [oracle@tcloud_for_12c_tdecdb:/home/oracle]$ sqlplus hr/Password123@localhost:1521/HRPDB_TDECLOSE
SQL*Plus: Release12.1.0.2.0 Production on Mon Mar 1407:34:552022
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Last Successful login time: Mon Mar 14202207:24:13+08:00
Connected to: Oracle Database 12c Enterprise Edition Release12.1.0.2.0-64bit Production With the Partitioning, OLAP, Advanced Analytics andReal Application Testing options
*************************************************************** WARNING: Pluggable Database HRPDB_CLOSE with pdb id - 8 is altered with errors or warnings. Please look into PDB_PLUG_IN_VIOLATIONS view for more details. ***************************************************************
查看视图信息
1 2 3 4 5 6 7
select*from PDB_PLUG_IN_VIOLATIONS; TIME NAME CAUSE TYPE ERROR_NUMBER LINE MESSAGE STATUS ACTION ------------------------------ --------------- -------------------- --------- ------------ ---------- -------------------------------------------------- --------- -------------------------------------------------- 14-MAR-2207.27.02.585205 AM HRPDB_TDE Wallet Key Needed ERROR 01 PDB needs to import keys from source. PENDING Import keys from source. 14-MAR-2207.34.35.744234 AM HRPDB_TDECLOSE Wallet Key Needed ERROR 01 PDB needs to import keys from source. PENDING Import keys from source. 14-MAR-2207.37.33.449191 AM HRPDB_CLOSE Wallet Key Needed ERROR 01 PDB needs to import keys from source. PENDING Import keys from source.
提示: PDB needs to import keys from source
查看钱包状态
1 2 3 4 5
sys@tdecdb(219)> select * from v$encryption_wallet;
administer key management import encryption keys with secret "password" from'/etc/ORACLE/WALLETS/tdecdb/ewallet.p12' force keystore identified by delphixclone with backup;
1
select*from v$encryption_wallet;
首先从源库导出密钥
源库导出密钥
1
ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET "mySecret" TO'/tmp/export.p12' IDENTIFIED BY Password23;
目标库导入
导入之前需要保证 钱包是 open 状态,否则
1 2
ERROR at line 1: ORA-46658: keystore not open in the container
1 2 3
sys@tdecdb(26)> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23;
keystore altered.
然后导入密钥
1 2 3
sys@tdecdb(26)> administer key management import encryption keys with secret "mySecret" from'/tmp/export.p12' identified by Password23 with backup;
keystore altered.
查看状态
1 2 3 4 5 6 7
select*from V$ENCRYPTION_WALLET; WRL_TYPE WRL_PARAMETER STATUS WALLET_TYPE WALLET_OR FULLY_BAC CON_ID
TIME NAME CAUSE TYPE ERROR_NUMBER LINE MESSAGE STATUS ACTION ------------------------------ ------------------------- -------------------- --------- ------------ ---------- -------------------------------------------------- --------- ----------------------------------- 14-MAR-2207.34.35.744234 AM HRPDB_TDECLOSE Wallet Key Needed ERROR 01 PDB needs to import keys from source. PENDING Import keys from source. 14-MAR-2208.38.58.435334 AM HRPDB_CLOSE Wallet Key Needed ERROR 01 PDB needs to import keys from source. PENDING Import keys from source. 14-MAR-2208.56.37.229458 AM HRPDB_TDE Wallet Key Needed ERROR 01 PDB needs to import keys from source. RESOLVED Import keys from source. 15-MAR-2210.58.46.331944 AM HRPDBTDENODATA Wallet Key Needed ERROR 01 PDB needs to import keys from source. PENDING Import keys from source.
CREATE PLUGGABLE DATABASE hrpdb FROM salespdb no data STORAGE unlimited; CREATE PLUGGABLE DATABASE ORA12CPDB2 FROM PDBTEST@dlink NO DATA STORAGE unlimited;
3.1、创建 dblink
1
CREATE DATABASE LINK dl4tdepdb CONNECT TO system IDENTIFIED BY Password123 USING 'TDEPDB';
3.2、确认dblink
1 2 3 4
sys@(11_CDB$ROOT)> select NAME,OPEN_MODE,RESTRICTED from v$pdbs@dl4tdepdb; NAME OPEN_MODE RESTRICTED ------------------------------ ---------- -------------------- TDEPDB READ WRITE NO
3.3、克隆远程 PDB
1
CREATE PLUGGABLE DATABASE remtdepdb FROM TDEPDB@dl4tdepdb NO DATA STORAGE unlimited;
需要注意的是源 PDB 需要在open状态,否则会报
1 2 3
ERROR at line 1: ORA-17627: ORA-01033: ORACLE initialization or shutdown in progress ORA-17629: Cannot connect to the remote database server
1 2 3 4 5 6 7 8 9 10 11
sys@(11_CDB$ROOT)> CREATE PLUGGABLE DATABASE remtdepdb FROM TDEPDB@dl4tdepdb NO DATA STORAGE unlimited;
Pluggable database created.
sys@(11_CDB$ROOT)> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 TDEPDB READ WRITE NO 12 REMTDEPDB MOUNTED
可以看到 REMTDEPDB 已经克隆完成,启动数据库
3.4、启动数据库
1 2
alter pluggable database REMTDEPDB open instances=all; alter pluggable database REMTDEPDB save state instances=all;
ADMINISTER KEY MANAGEMENT EXPORT ENCRYPTION KEYS WITH SECRET "mySecret" TO'/tmp/export.p12' IDENTIFIED BY Password23;
目标库导入
导入之前需要保证 钱包是 open 状态,否则
1 2
ERROR at line 1: ORA-46658: keystore not open in the container
3.5.2 目标 PDB 打开 钱包
1 2 3
sys@(404_REMTDEPDB)> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23;
keystore altered.
3.5.3 目标 PDB 导入密钥
1 2 3
sys@(404_REMTDEPDB)> administer key management import encryption keys with secret "mySecret" from'/tmp/export.p12' identified by Password23 with backup;
keystore altered.
3.5.4目标 PDB 查看状态
1 2 3 4 5 6 7 8 9 10
sys@(404_REMTDEPDB)>set lines 200 sys@(404_REMTDEPDB)> col WRL_PARAMETER for a50 sys@(404_REMTDEPDB)>select*from V$ENCRYPTION_WALLET;
WRL_TYPE WRL_PARAMETER STATUS WALLET_TYPE WALLET_OR FULLY_BAC CON_ID -------------------- -------------------------------------------------- ------------------------------ -------------------- --------- --------- ---------- FILE /etc/ORACLE/WALLETS/tdecdb/OPEN PASSWORD SINGLE NO0
sys@(25_CDB$ROOT)>select PDB_ID,PDB_NAME,STATUS from dba_pdbs; PDB_ID PDB_NAME STATUS ---------- -------------------- --------- 3 TDEPDB UNPLUGGED 2 PDB$SEED NORMAL 可以看到 TDEPDB 的状态为 UNPLUGGED
将 pdb 拔下之后,是无法再打开次数据pdb,只能进行drop操作了。
1 2 3 4
sys@(214_CDB$ROOT)> alter session set container=TDEPDB; Session altered. sys@(214_CDB$ROOT)> startup ORA-65086: cannot open/close the pluggable database
sys@(591_CDB$ROOT)> create pluggable database cbtdepdb using '/tmp/tdepdb.xml' nocopy tempfile reuse; create pluggable database cbtdepdb using '/tmp/tdepdb.xml' nocopy tempfile reuse * ERROR at line 1: ORA-65122: Pluggable database GUID conflicts with the GUID of an existing container.
删除源 PDB保留数据文件
1 2 3
sys@(11_CDB$ROOT)> drop pluggable database TDEPDB keep datafiles;
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLYNO 3 CBTDEPDB MOUNTED SQL>alter session set container=CBTDEPDB; Session altered. SQL>select name from v$datafile; NAME ---------------------------------------------------------------------------------------------------- /oradata/tdecdb/undo/undotbs01.dbf /oradata/tdecdb/data/TDECDB/D87EC3294E251264E0530418000A849E/datafile/o1_mf_system_k15x87v3_.dbf /oradata/tdecdb/data/TDECDB/D87EC3294E251264E0530418000A849E/datafile/o1_mf_sysaux_k15x87vb_.dbf /oradata/tdecdb/data/TDECDB/D87EC3294E251264E0530418000A849E/datafile/o1_mf_test_tde_k18b3y43_.dbf
检查插入的PDB
打开目标数据库
1 2
sys@(11_CDB$ROOT)> alter pluggable database CBTDEPDB open; Warning: PDB altered with errors.
同样显示有告警
1 2 3 4 5 6 7 8 9 10 11 12 13 14
sys@(11_CDB$ROOT)> set linesize 1000; column MESSAGE format a50; column name format a16; column ACTION format a64; column type format a16; column cause format a24;
sys@(11_CDB$ROOT)> select name,cause,type,status,message,action from pdb_plug_in_violations where name ='CBTDEPDB';
NAME CAUSE TYPE STATUS MESSAGE ACTION ---------------- ------------------------ ---------------- --------- -------------------------------------------------- ---------------------------------------------------------------- CBTDEPDB Wallet Key Needed ERROR PENDING PDB needs to import keys from source. Import keys from source.
导入密钥key
1
目标库导入密钥
导入之前需要保证 钱包是 open 状态,否则
1 2
ERROR at line 1: ORA-46658: keystore not open in the container
1 2 3 4 5 6 7 8 9 10 11
sys@(11_CDB$ROOT)> conn sys/Password123@127.0.0.1/cbtdepdb as sysdba Connected. sys@(11_CBTDEPDB)>show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 3 CBTDEPDB READ WRITE YES sys@(11_CBTDEPDB)> sys@tdecdb(26)> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23;
keystore altered.
然后导入密钥
1 2 3
sys@tdecdb(26)> administer key management import encryption keys with secret "mySecret" from'/tmp/export.p12' identified by Password23 with backup;
keystore altered.
查看状态
1 2 3 4 5 6 7
select*from V$ENCRYPTION_WALLET; WRL_TYPE WRL_PARAMETER STATUS WALLET_TYPE WALLET_OR FULLY_BAC CON_ID