由于Oracle 12c使用了CDB-PDB架构,类似于docker,在container-db内可以加载多个pluggable-db,因此安装后需要额外配置才能使用。
一、修改listener.ora , tnsnames.ora
###listener.ora###
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = orcl))
)
#sid list列举cdb和所有pdb的数据库名,所有sid与oracle环境变量保持一致#
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)
)
)
###listener.ora###
##tnsnames.ora###
#cdb
orcl =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) )
(CONNECT_DATA =
(SERVICE_NAME = orcl) #cdb的db_name
)
)
#pdb
pdborcl =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = pdborcl) #pdb的db_name
)
)
##tnsnames.ora###
在客户端连接时使用“service_name+domain_name”连接。如果出现ora-01017,很有可能是
二、创建pdb
cdb相当于操作系统,调用并管理各个pdb。pdb相当于真正提供业务需求的数据库实例。oracle 12c安装后只创建了cdb,需要自己生成相应的pdb。
1、创建pdb
在sqlplus下:
create pluggable database pdborcl
admin user pdbadmin identified by pdbadmin
role=(resource)
file_name_convert=( 'PDB$SEED's directory' , 'PDBOrcl's directory' );
2、同步文件
select pdb_name,status from cdb_pdbs
若pdb状态为need sync,则需要:
alter sesseion set container=pdborcl
shutdown immediate或者alter pluggable database pdborcl close immediate ;
alter pluggable database pdborcl open restricted ;
exec dbms_pdb.sync_pdb ; #调用dbms_pdb进行pdb
3、新增用户
create user scott account unlock identified by tiger ;
grant resource to scott ;
按照上述方法创建用户,如果出现ora-01017,很有可能是1、没有指定连接的service_name到具体pdb,或者oracle对密码大小写敏感。前者检查listener.ora中sid_list是否已经列出该pdb,并检查连接字符串是否在tnsnames.ora指定。后者如果无法修改前端程序,可以使用
alter system set SEC_CASE_SENSITIVE_LOGON = false ;
强制关闭oracle的大小写检查进行确认。
三、常用命令
show pdbs:查看当前数据库container中包含有多少个pdb。如果session在某个pdb中,可以查看当前的pdb。
alter session set container=PDBNAME
切换当前会话到某个pdb中。切换后才可使用当前pdb的私有用户进行操作
startup/shutdown immediate
关闭当前会话所在的cdb/pdb
alter pluggable database PDBNAME open ;
打开指定pdb
alter pluggable database PDBNAME close immediate ;
关闭指定pdb
: