本文共 5720 字,大约阅读时间需要 19 分钟。
容器数据库(CDB,multitenant container database)和可热插拔数据库(pluggable databases,PDB)。
官方文档:[oracle@oracle ~]$ dbca
选择高级模式选择使用的模板general purpose or transaction processing 事务处理custom database 自定义data warehouse 数据中心CDBEM设置数据库管理员密码设置监听(这里没设置,用netca设置的)netca
[oracle@oracle ~]$ ORACLE_SID=CDB
[oracle@oracle ~]$ sqlplus / as sysdba
SQL> show con_name
CDB$ROOT
SQL> show con_id1
SQL> conn sys/ycig1234@CDB as sysdba;
Connected.SQL> show con_nameCDB$ROOT
SQL> show con_id1
SQL> select name,con_id from v$active_services order by 1;
NAME CON_ID
CDB 1
CDBXDB 1SYS$BACKGROUND 1SYS$USERS 1SQL> conn / as sysdba
Connected.SQL> create pluggable database orcl admin user sde identified by sde roles=(DBA);create pluggable database orcl admin user sde identified by sde roles=(DBA)*ERROR at line 1:ORA-65016: FILE_NAME_CONVERT must be specified查看报错信息[oracle@oracle ~]$ oerr ora 65016处理方法一、指定file_name_convertSQL> create pluggable database orcl admin user sde identified by sde file_name_convert=('/data/oracle/app/oradata/CDB/pdbseed/','/data/oracle/app/oradata/CDB/orcl/');
/data/oracle/app/oradata/CDB/orcl/是PDB数据存放路径,需要手动创建
[oracle@oracle oradata]$ mkdir -pv /data/oracle/app/oradata/CDB/orcl/处理方法二、使用参数db_create_file_dest SQL> alter system set db_create_file_dest='/data/oracle/app/oradata/';System altered.
SQL> create pluggable database vms3devdb admin user c5web identified by c5web roles=(DBA);Pluggable database created.
SQL> select con_id,name,open_mode,restricted from v$pdbs order by 1;SQL> select name,con_id from v$active_services order by 1;查看监听状态
#启动单个PDB
SQL> alter pluggable database orcl open;Pluggable database altered.
#查看状态SQL> select name,open_mode from v$pdbs;NAME OPEN_MODE
PDB$SEED READ ONLY
ORCL READ WRITEVMS3DEVDB MOUNTED#启动所有PDBSQL> alter pluggable database all open;
Pluggable database altered.
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
PDB$SEED READ ONLY
ORCL READ WRITEVMS3DEVDB READ WRITE#关闭单个PDB
SQL> alter pluggable database orcl close immediate;Pluggable database altered.
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
PDB$SEED READ ONLY
ORCL MOUNTEDVMS3DEVDB READ WRITESQL> alter pluggable database all close immediate;
Pluggable database altered.
#关闭所有的PDBSQL> select name,open_mode from v$pdbs;NAME OPEN_MODE
PDB$SEED READ ONLY
ORCL MOUNTEDVMS3DEVDB MOUNTEDSQL> CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE BEGIN EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN'; END open_pdbs; /#查看所有PDB
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
2 PDB$SEED READ ONLY NO 3 ORCL READ WRITE NO 4 VMS3DEVDB READ WRITE NO #关闭orcl
SQL> alter pluggable database orcl close immediate;
Pluggable database altered.#查看所有PDB
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE ------------------------------ ---------- PDB$SEED READ ONLY ORCL MOUNTED VMS3DEVDB READ WRITE
#开启orcl的RES
SQL> alter pluggable database orcl open restricted;Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCL READ WRITE YES 4 VMS3DEVDB READ WRITE NO#使用orcl
SQL> alter session set container=orcl;
Session altered.# 修改orcl名称为orcl_test
SQL> alter pluggable database orcl rename global_name to orcl_test;
Pluggable database altered.#查看PDB
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
3 ORCL_TEST READ WRITE YES
SQL> conn / as sysdba
Connected.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
2 PDB$SEED READ ONLY NO 3 ORCL_TEST READ WRITE YES 4 VMS3DEVDB READ WRITE NO
SQL> conn sys/ycig1234@127.0.0.1:1521/orcl as sysdba
ERROR:ORA-12154: TNS:could not resolve the connect identifier specifiedWarning: You are no longer connected to ORACLE.
这是因为没有创建本地监听创建本地监听
[oracle@oracle ~]$ netca另外个也是这样创建[oracle@oracle ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Tue Jan 30 01:03:03 2018 Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to:Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
2 PDB$SEED READ ONLY NO 3 ORCL_TEST READ WRITE NO 4 VMS3DEVDB READ WRITE NO
SQL> conn sys/ycig1234@orcl_test as sysdba
Connected.
SQL> conn / as sysdba
Connected.
SQL> create tablespace CDBdata;
Tablespace created.
SQL> conn sys/ycig1234@orcl_test as sysdba
Connected.
SQL> create tablespace TEST datafile '/data/oracle/app/oradata/CDB/datafile/TEST1.dbf' size 1g autoextend on;
Tablespace created.
SQL> create user test identified by test default tablespace TEST;
User created.
管理方法和单实例一样
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
2 PDB$SEED READ ONLY NO 3 ORCL READ WRITE NO 4 VMS3DEVDB READ WRITE NO
SQL> alter pluggable database all close immediate;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
2 PDB$SEED READ ONLY NO 3 ORCL MOUNTED 4 VMS3DEVDB MOUNTED
SQL> drop pluggable database ORCL including datafiles;
Pluggable database dropped.
Oracle多租户特性的常用操作:
官方文档:转载于:https://blog.51cto.com/13323775/2066364