Oracle 12c CDB PDB

2024-02-18 09:58
文章标签 oracle pdb 12c cdb

本文主要是介绍Oracle 12c CDB PDB,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Oracle 12c CDB & PDB

查看当前容器
SQL> show con_name;

CON_NAME
------------------------------
CDB$ROOT
SQL> select name,cdb,open_mode,con_id from v$database;

NAME      CDB OPEN_MODE                CON_ID
--------- --- -------------------- ----------
ORCL      YES READ WRITE                    0


查看当前容器下的pdb
SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDBORCL                        MOUNTED
SQL> 

查看数据文件存储路径
SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf

7 rows selected.

新建pdb库:
CREATE PLUGGABLE DATABASE pdb2 ADMIN USER pdb2 IDENTIFIED BY "1q2w3e"
STORAGE (MAXSIZE 10G)
DEFAULT TABLESPACE pdb
DATAFILE '/u01/app/oracle/oradata/orcl/pdb2/pdb01.dbf' SIZE 50M AUTOEXTEND ON
PATH_PREFIX = '/u01/app/oracle/oradata/orcl/pdb2/'
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl/pdbseed','/u01/app/oracle/oradata/orcl/pdb2');

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDBORCL                        MOUNTED
         4 PDB2                           MOUNTED
SQL> 


在创建完可插拔数据库后,新的PDB处于MOUNTED模式。在新PDB中创建一个新会话前,必须先打开它。因此,我们可以用下面的命令打开它:

alter pluggable database pdb2 open;

如果报错 Warning: PDB altered with errors. 执行:

select message,time from pdb_plug_in_violations;

Sync PDB failed with ORA-959 during 'create user c##dddba identified by * defaul
t tablespace users
 container = all'
20-NOV-20 11.54.03.627858 AM

报错因为之前在容器数据库中创建了一个公共用户C##dddba,现在还需要在所有可插入的数据库中创建该用户。这个用户是在数据库正常打开的情况下建立的,但是使用的是自定义表空间《IMPDATA》,当打开可插入数据库pdb2时将同步这个操作,也就是同步创建这个公共用户。但是 pdb2 这个可插入数据库中是没有 IMPDATA 表空间的,因此无法同步创建这个公共用户,最终可插入数据库 pdb2 仅以受限模式打开,状态显示如下(RESTRICTED):

SQL> 
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         4 PDB2                           READ WRITE YES
SQL> 


解决办法:
这时候去删除公共用户依然不行,因为同步动作已经在队列里面了。因此,唯一能做的就是在 pdb2 中创建该表空间,然后关闭数据库,再次进行同步即可。

create tablespace users datafile '/u01/app/oracle/oradata/orcl/pdb2/users01.dbf' size 10G;
alter pluggable database pdb2 close;
alter pluggable database pdb2 open;


检查容器数据库(CDB)和可插拔数据库(PDB)文件
alter session set container=pdb2;
select con_id, tablespace_name, file_name from cdb_data_files where file_name like '%orcl/pdbseed%' or file_name like '%orcl/pdb2%' order by 1,2;

SQL> alter session set container=pdb2;

Session altered.

SQL> select con_id, tablespace_name, file_name from cdb_data_files where file_name like '%orcl/pdbseed%' or file_name like '%orcl/pdb2%' order by 1,2;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
FILE_NAME
--------------------------------------------------------------------------------
         4 PDB
/u01/app/oracle/oradata/orcl/pdb2/pdb01.dbf

         4 SYSAUX
/u01/app/oracle/oradata/orcl/pdb2/sysaux01.dbf

         4 SYSTEM
/u01/app/oracle/oradata/orcl/pdb2/system01.dbf


SQL> 


如果要删除pdb数据库(先关闭、再删除)
alter pluggable database pdb2 close;
drop pluggable database pdb2 including datafiles;


切换pdb/cdb

alter session set container=pdb2;
show pdbs;

切换到pdb中创建本地用户
create user test identified by "1q2w3e";

alter session set container=CDB$ROOT;
show pdbs;


要连接pdb,还需要配置监听文件 tnsnames.ora & listener.ora

vim $ORACLE_HOME/network/admin/tnsnames.ora

[oracle@localhost orcl]$ cat $ORACLE_HOME/network/admin/tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.1.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl.localdomain)
    )
  )

PDBORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdborcl.localdomain)
    )
  )

PDB2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdb2.localdomain)
    )
  )

vim $ORACLE_HOME/network/admin/listener.ora 

[oracle@localhost admin]$ cat listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )


SID_LIST_LISTENER =
(SID_LIST =
 (SID_DESC =
 (GLOBAL_DBNAME = orcl) #cdb db_name
 (SID_NAME = orcl)
 )
 (SID_DESC =
 (GLOBAL_DBNAME = pdborcl) #pdb db_name
 (SID_NAME = orcl)
 )
 (SID_DESC =
 (GLOBAL_DBNAME = pdb2) #pdb db_name
 (SID_NAME = pdb2)
 )
)

lsnrctl stop

lsnrctl start

 
测试pdb

tnsping pdb2

[oracle@localhost orcl]$ lsnrctl start

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 20-NOV-2020 12:29:30

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/12.1.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.1.0.2.0 - Production
System parameter file is /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                20-NOV-2020 12:29:30
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Service "pdb2" has 1 instance(s).
  Instance "pdb2", status UNKNOWN, has 1 handler(s) for this service...
Service "pdborcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@localhost orcl]$ 
[oracle@localhost orcl]$ 
[oracle@localhost orcl]$ tnsping pdb2

TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 20-NOV-2020 12:29:39

Copyright (c) 1997, 2014, Oracle.  All rights reserved.

Used parameter files:
/u01/app/oracle/product/12.1.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pdb2.localdomain)))
OK (0 msec)
[oracle@localhost orcl]$

 

这篇关于Oracle 12c CDB PDB的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/720795

相关文章

Oracle type (自定义类型的使用)

oracle - type   type定义: oracle中自定义数据类型 oracle中有基本的数据类型,如number,varchar2,date,numeric,float....但有时候我们需要特殊的格式, 如将name定义为(firstname,lastname)的形式,我们想把这个作为一个表的一列看待,这时候就要我们自己定义一个数据类型 格式 :create or repla

ORACLE 11g 创建数据库时 Enterprise Manager配置失败的解决办法 无法打开OEM的解决办法

在win7 64位系统下安装oracle11g,在使用Database configuration Assistant创建数据库时,在创建到85%的时候报错,错误如下: 解决办法: 在listener.ora中增加对BlueAeri-PC或ip地址的侦听,具体步骤如下: 1.启动Net Manager,在“监听程序”--Listener下添加一个地址,主机名写计

Oracle Start With关键字

Oracle Start With关键字 前言 旨在记录一些Oracle使用中遇到的各种各样的问题. 同时希望能帮到和我遇到同样问题的人. Start With (树查询) 问题描述: 在数据库中, 有一种比较常见得 设计模式, 层级结构 设计模式, 具体到 Oracle table中, 字段特点如下: ID, DSC, PID; 三个字段, 分别表示 当前标识的 ID(主键), DSC 当

oracle分页和mysql分页

mysql 分页 --查前5 数据select * from table_name limit 0,5 select * from table_name limit 5 --limit关键字的用法:LIMIT [offset,] rows--offset指定要返回的第一行的偏移量,rows第二个指定返回行的最大数目。初始行的偏移量是0(不是1)。   oracle 分页 --查前1-9

ORACLE语法-包(package)、存储过程(procedure)、游标(cursor)以及java对Result结果集的处理

陈科肇 示例: 包规范 CREATE OR REPLACE PACKAGE PACK_WMS_YX IS-- Author : CKZ-- Created : 2015/8/28 9:52:29-- Purpose : 同步数据-- Public type declarations,游标 退休订单TYPE retCursor IS REF CURSOR;-- RETURN vi_co_co

Oracle主键和外键详解及实用技巧

在 Oracle 数据库中,主键(Primary Key)和外键(Foreign Key)用于维护数据库表之间的数据完整性。 1. 主键(Primary Key) 主键是一列或多列,能够唯一标识表中的每一行。表中只能有一个主键,并且主键列不能为空(即 NOT NULL)。 特性: 唯一性:主键中的每一个值都是唯一的,不能重复。非空性:主键列不能包含 NULL 值。索引:Oracle 自动为

12C 新特性,MOVE DATAFILE 在线移动 包括system, 附带改名 NID ,cdb_data_files视图坏了

ALTER DATABASE MOVE DATAFILE  可以改名 可以move file,全部一个命令。 resue 可以重用,keep好像不生效!!! system照移动不误-------- SQL> select file_name, status, online_status from dba_data_files where tablespace_name='SYSTEM'

分享MSSQL、MySql、Oracle的大数据批量导入方法及编程手法细节

1:MSSQL SQL语法篇: BULK INSERT      [ database_name . [ schema_name ] . | schema_name . ] [ table_name | view_name ]         FROM 'data_file'        [ WITH       (      [ [ , ] BATCHSIZE = batch_siz

Oracle start with connect BY 死循环

解决办法 检查start with前有没有where条件, 如果有的话,套一层select,再 Oracle start with connect BY

Java调用Oracle存储过程一

一、通过PL/SQL工具连接上Oracle数据库,创建表zx_test_procedure 二、创建存储过程 ①无返回值的存储过程 存储过程为: create or replace procedure testa (para1 in varchar2,para2 in varchar2) as begin insert into zx_test_procedure(i_id,i_n