Oracle Database 12C 学习之多租户(连载三)

简介:

我们先切换回根容器:


SYS@ora12c> alter session set container=CDB$ROOT;

Session altered.

接下来我们来创建用户及角色:

在12c中,如果我们还是按照11g以及以前版本中的命令来创建用户和角色,那是要报错的。因为12c中新引入了common_user_prefix参数,也就是说,你创建用户或者角色时,需要指定名称前缀,默认为c##。对于os认证的用户,也有相关的约束,参数为os_authent_prefix。

我们可以将该参数做一下处理。

SYS@ora12c> alter system set common_user_prefix='' scope=spfile;

System altered.

SYS@ora12c> startup force;

ORACLE instance started.

Total System Global Area 838860800 bytes

Fixed Size  2929936 bytes

Variable Size  687868656 bytes

Database Buffers  142606336 bytes

Redo Buffers  5455872 bytes

Database mounted.

Database opened.

SYS@ora12c> show parameter common_user_prefix;

NAME  TYPE  VALUE

------------------------------------ ----------- ------------------------------

common_user_prefix  string



SYS@ora12c> create user test_u1 identified by test container=current;

create user test_u1 identified by test container=current

*

ERROR at line 1:

ORA-65049: creation of local user or role is not allowed in CDB$ROOT

--在根容器中,不能创建本地用户。

SYS@ora12c> create user test_u1 identified by test container=all;

User created.

切换到种子容器试试:

SYS@ora12c> alter session set container=PDB$SEED;

Session altered.

SYS@ora12c> create user test_u3 identified by test container=current;

create user test_u3 identified by test container=current

*

ERROR at line 1:

ORA-00604: error occurred at recursive SQL level 1

ORA-16000: database or pluggable database open for read-only access

SYS@ora12c> alter session set container=ora12c_pdb1;

Session altered.

SYS@ora12c> create user test_u3 identified by test container=current;

create user test_u3 identified by test container=current

*

ERROR at line 1:

ORA-01109: database not open

SYS@ora12c> startup;

Pluggable Database opened.

SYS@ora12c> create user test_u3 identified by test container=current;

User created.

SYS@ora12c> create user test_u3 identified by test container=all;

create user test_u3 identified by test container=all

*

ERROR at line 1:

ORA-65050: Common DDLs only allowed in CDB$ROOT

也就是说,在根容器中创建用户,container默认为all;在某一可插拔数据库中创建用户,container默认为current;种子容器中不允许创建用户。

角色也是如此。

CDB的管理操作,我们不再多说,想了解更多细节的话,可以查阅官方文档管理员手册的第40、41两章。

接下来,我们来看看PDB的创建与管理。

oracle提供了多种创建或者克隆PDB的工具,比如说create pluggable database语句,比如说DBCA,再比如说EMCC(Enterprise Manager Cloud Control)。关于如何使用EMCC图形化的方式创建PDB,可以参考管理员手册的第39章。我们这里着重关注如何使用命令行来创建或者复制PDB。

通过create pluggable database语句,可以使用如下资源创建PDB:

1,种子容器;

2,已经存在的PDB(本地和远程的均可);

3,非CDB数据库;

4,被拔出的PDB。

如果使用DBCA,则可以使用如下资源创建PDB:

1,种子容器;

2,RMAN备份;

3,已被拔出的PDB。

先看如何使用create pluggable database语句来创建PDB:

使用克隆种子容器的方式:

SYS@ora12c> show pdbs;

CON_ID CON_NAME  OPEN MODE RESTRICTED

---------- ------------------------------ ---------- ----------

 3 ORA12C_PDB1  READ WRITE YES

SYS@ora12c> alter session set container=CDB$ROOT;

Session altered.

SYS@ora12c> show pdbs;

CON_ID CON_NAME  OPEN MODE RESTRICTED

---------- ------------------------------ ---------- ----------

 2 PDB$SEED  READ ONLY NO

 3 ORA12C_PDB1  READ WRITE YES

--注意,此时种子容器必须处于read only状态。

SYS@ora12c> create pluggable database oracdb_pdb2

admin user pdb2_admin identified by admin

file_name_convert = ('/u01/oracle/oradata/ora12c/pdbseed',

'/u01/oracle/oradata/ora12c/cdb/pdb2');

Pluggable database created.

--需要先确定种子容器的数据文件存放路径,

--以及创建新的可插拔数据库的数据文件存放目录。

--如果使用OMF,则不需要设置file_name_convert参数。

SYS@ora12c> show pdbs;

CON_ID CON_NAME  OPEN MODE RESTRICTED

---------- ------------------------------ ---------- ----------

 2 PDB$SEED  READ ONLY NO

 3 ORA12C_PDB1  READ WRITE YES

 4 ORACDB_PDB2  MOUNTED

SYS@ora12c> alter pluggable database ORACDB_PDB2 open;

Pluggable database altered.

SYS@ora12c> show pdbs;

CON_ID CON_NAME  OPEN MODE RESTRICTED

---------- ------------------------------ ---------- ----------

 2 PDB$SEED  READ ONLY NO

 3 ORA12C_PDB1  READ WRITE YES

 4 ORACDB_PDB2  READ WRITE NO

SYS@ora12c> conn pdb2_admin/admin@ORACDB_PDB2;

ERROR:

ORA-12154: TNS:could not resolve the connect identifier specified

Warning: You are no longer connected to ORACLE.

@>

此时需要配置下tns了。

vi $ORACLE_HOME/network/admin/tnsnames.ora

添加如下内容:

ORACDB_PDB2 =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = ora12)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = oracdb_pdb2)

)

)

再看一下监听的状态:

[oracle@ora12 admin]$ lsnrctl services;

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 17-DEC-2015 10:14:04

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ora12)(PORT=1521)))

Services Summary...

Service "ora12c" has 1 instance(s).

Instance "ora12c", status READY, has 1 handler(s) for this service...

Handler(s):

"DEDICATED" established:1 refused:0 state:ready

LOCAL SERVER

Service "ora12cXDB" has 1 instance(s).

Instance "ora12c", status READY, has 1 handler(s) for this service...

Handler(s):

"D000" established:0 refused:0 current:0 max:1022 state:ready

DISPATCHER <machine: ora12.oracle.com, pid: 4585>

(ADDRESS=(PROTOCOL=tcp)(HOST=ora12)(PORT=25789))

Service "ora12c_pdb1" has 1 instance(s).

Instance "ora12c", status READY, has 1 handler(s) for this service...

Handler(s):

"DEDICATED" established:1 refused:0 state:ready

LOCAL SERVER

Service "oracdb_pdb2" has 1 instance(s).

Instance "ora12c", status READY, has 1 handler(s) for this service...

Handler(s):

"DEDICATED" established:1 refused:0 state:ready

LOCAL SERVER

The command completed successfully

然后再测试一下:

SYS@ora12g> conn pdb2_admin/admin@ORACDB_PDB2;

Connected.

ok,好使了。

本文来自云栖社区合作伙伴“DBGEEK”

目录
相关文章
|
7天前
|
存储 NoSQL Oracle
Oracle 12c的内存列存储:数据的“闪电侠”
【4月更文挑战第19天】Oracle 12c的内存列存储以超高速度革新数据处理,结合列存储与内存技术,实现快速查询与压缩。它支持向量化查询和并行处理,提升效率,但需合理配置以平衡系统资源。作为数据管理员,应善用此功能,适应业务需求和技术发展。
|
7天前
|
存储 Oracle 关系型数据库
Oracle 12c的多重索引:数据的“多维导航仪”
【4月更文挑战第19天】Oracle 12c的多重索引提升数据查询效率,如同多维导航仪。在同一表上创建针对不同列的多个索引,加速检索过程。虽然过多索引会增加存储和维护成本,但合理选择和使用索引策略,结合位图、函数索引等高级特性,能优化查询,应对复杂场景。数据管理员应善用这些工具,根据需求进行索引管理,支持企业数据分析。
|
7天前
|
存储 Oracle 数据管理
Oracle 12c的自动数据优化(ADO)与热图:数据管理的“瘦身”与“透视”艺术
【4月更文挑战第19天】Oracle 12c的ADO和热图技术革新数据管理。ADO智能清理无用数据,优化存储,提升查询速度,实现数据&quot;瘦身&quot;;热图则以直观的视觉表示展示数据分布和状态,助力识别性能瓶颈,犹如数据的&quot;透视&quot;工具。这两项技术结合,强化数据管理,为企业业务发展保驾护航。
|
7天前
|
Oracle 安全 数据管理
Oracle 12c多租户架构:数据管理的“摩天大楼”
【4月更文挑战第19天】Oracle 12c的多租户架构允许多个独立数据库环境在同一实例中共享资源,提高效率,降低成本。该架构保证了数据隔离和安全性,同时提供灵活性和可扩展性,简化管理任务。通过理解其原理和管理方法,我们可以充分利用这一架构,为企业数据管理和业务发展提供强大支持。
|
4月前
|
SQL Oracle 关系型数据库
oracle学习
oracle学习
27 0
|
1月前
|
Oracle 关系型数据库 Linux
服务器Centos7 静默安装Oracle Database 12.2
服务器Centos7 静默安装Oracle Database 12.2
86 0
|
2月前
|
SQL 存储 关系型数据库
MySQL技能完整学习列表——1、数据库基础概念——1、关系型数据库(Relational Database)
MySQL技能完整学习列表——1、数据库基础概念——1、关系型数据库(Relational Database)
179 0
|
4月前
|
Oracle 关系型数据库 数据库
windows Oracle Database 19c 卸载教程
打开任务管理器 ctrl+Shift+Esc可以快速打开任务管理器,找到oracle所有服务然后停止。 停止数据库服务 在开始卸载之前,确保数据库服务已经停止。你可以使用以下命令停止数据库服务: net stop OracleServiceORCL Universal Installer 卸载Oracle数据库程序 一般情况运行Oracle自带的卸载程序,如使用Universal Installer 工具卸载。 点击开始菜单找到Oracle,然后点击Oracle安装产品,再点击Universal Installer。 点击之后稍等一会然后会进入进入下图界面,点击卸载产品。 选中要删除的Orac
118 1
|
3月前
|
Oracle 关系型数据库 数据库连接
【Oracle学习】—新建数据库连接,超详细
【Oracle学习】—新建数据库连接,超详细
|
3月前
|
Oracle 关系型数据库 数据库
【Oracle学习】—Oracle11g修改用户名与密码(一)
【Oracle学习】—Oracle11g修改用户名与密码(一)

推荐镜像

更多