Oracle数据库工程师手记:探究 Oracle PDB Application Container (二)

2022-08-19 21:08:23 浏览数 (1)

编者按:

本文作者系大连健哥, POSTGRESQL、ORACLE 数据库资深从业人员、IT 技术的深度爱好者。相信科学改变人类、技术创造未来。个人主页:https://www.cnblogs.com/gaojian/,经其本人授权发布。

【免责声明】本号文章仅代表个人观点,与任何公司无关。

Application Container 中 application 的升级:

需要执行:

代码语言:javascript复制
ALTER PLUGGABLE DATABASE APPLICATION ref_app BEGIN UPGRADE '1.0' TO '1.1';

对数据的增减、对结构的改动语句等

代码语言:javascript复制
ALTER PLUGGABLE DATABASE APPLICATION ref_app END UPGRADE;

验证过程:如同Oracle数据库工程师手记:探究 Oracle PDB Application Container (一)的那样,

先来做出 application container 和 application pdb ,以及 application:

代码语言:javascript复制
alter system set db_create_file_dest='/refresh/home/';
CREATE PLUGGABLE DATABASE appcon1 AS APPLICATION CONTAINER ADMIN USER app_admin IDENTIFIED BY Password1;
 
ALTER PLUGGABLE DATABASE appcon1 OPEN;
ALTER SESSION SET container = appcon1;
 
CREATE PLUGGABLE DATABASE apppdb1 ADMIN USER pdb_admin IDENTIFIED BY Password1;
ALTER PLUGGABLE DATABASE apppdb1 OPEN;
 
 
ALTER SESSION SET container = appcon1;
ALTER PLUGGABLE DATABASE APPLICATION ref_app BEGIN INSTALL '1.0';
 
 
CREATE TABLESPACE ref_app_ts DATAFILE SIZE 1M AUTOEXTEND ON NEXT 1M;
 
CREATE USER ref_app_user IDENTIFIED BY ref_app_user
  DEFAULT TABLESPACE ref_app_ts
  QUOTA UNLIMITED ON ref_app_ts
  CONTAINER=ALL;
 
GRANT CREATE SESSION, CREATE TABLE TO ref_app_user;
 
CREATE TABLE ref_app_user.reference_data SHARING=DATA (
  id          NUMBER,
  description VARCHAR2(50),
  CONSTRAINT t1_pk PRIMARY KEY (id)
);
 
INSERT INTO ref_app_user.reference_data
SELECT level,
       'Description of ' || level
FROM   dual
CONNECT by level <= 5;
COMMIT;
 
 
ALTER PLUGGABLE DATABASE APPLICATION ref_app END INSTALL;

然后执行 application 的升级:

代码语言:javascript复制
ALTER SESSION SET container = appcon1;
 
ALTER PLUGGABLE DATABASE APPLICATION ref_app BEGIN UPGRADE '1.0' TO '1.1';
 
alter table ref_app_user.reference_data drop column description;
 
ALTER PLUGGABLE DATABASE APPLICATION ref_app END UPGRADE;

回到 cdb$root;

可以发现: 除了这几个PDB 之外,还生成了一个特殊的 PDB:

代码语言:javascript复制
SQL> alter session set container=cdb$root;
 
Session altered.
 
SQL> show pdbs;
 
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED
         4 APPCON1                        READ WRITE NO
         5 APPPDB1                        READ WRITE NO
         6 F289887660_3_1                 READ ONLY  NO
SQL>

如果container 是 appcon1 ,则看不到这个 F289887660_3_1, 在 cdb$root 时,可以看到。

这个PDB 无法直接删除,可以这样删除:

先删除 APPPDB1, 再删除 APPCON1:

代码语言:javascript复制
alter pluggable database appcon1 close;
 
drop pluggable database apppdb1 including datafiles;
 
drop pluggable database appcon1 including datafiles;

这是,可以看到 F289887660_3_1 也随着 application container 一起消失了。

代码语言:javascript复制
SQL> show pdbs;
 
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED
SQL>

补充一点, 这个特殊的 PDB 是何时生成的呢?

代码语言:javascript复制
SQL> ALTER SESSION SET container = appcon1;
 
Session altered.
 
SQL> ALTER PLUGGABLE DATABASE APPLICATION ref_app BEGIN UPGRADE '1.0' TO '1.1';
 
Pluggable database altered.
 
SQL>

从另外的一个窗口,执行 show pdbs, 就已经可以发现有一个特殊的 PDB (F103021535_3_1)被生成。

在 19c 也是这样的。

代码语言:javascript复制
SQL> show pdbs;
 
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB193                         MOUNTED
         4 APPCON1                        READ WRITE NO
         5 APPPDB1                        READ WRITE NO
         7 F103021535_3_1                 READ WRITE NO
SQL>

也就是 BEGIN UPGRADE 语句,就有这个作用。

0 人点赞