ORacle12c创建PDB并设置开机自动启动

参考文章:
https://blog.csdn.net/dougfii/article/details/53897177
http://blog.itpub.net/29785807/viewspace-2137362/

1、创建默认表空间

1)用dba账户登陆
2)创建表空间,并修改用户默认表空间

-- 创建临时空间
create temporary tablespace pdbadmin_temp
tempfile '/home/oracle/app/oradata/orcl/pdborcl/pdbadmin_temp01.dbf'
size 32m
autoextend on
next 32m MAXSIZE unlimited  
extent management local;
-- 创建数据表空间
create tablespace pdbadmin_data
logging
datafile '/home/oracle/app/oradata/orcl/pdborcl/pdbadmin_data01.dbf'
size 10240m
autoextend on
next 100m MAXSIZE unlimited  
extent management local;
--Oracle创建用户权限
--创建用户  
create user pdbadmin identified by pdbadmin default tablespace pdbadmin_temp;  
-- 更改用户默认表空间
alter user pdbadmin default tablespace pdbadmin_data temporary tablespace pdbadmin_temp;

2、创建PDB

第一步:创建PDB实例

CREATE pluggable DATABASE pdborcl 
admin USER pdbadmin identified BY pdbadmin
roles=(resource)
file_name_convert= ('/home/oracle/app/oradata/orcl/pdbseed', '/home/oracle/app/oradata/orcl/pdborcl'); 

第二步:修改tnsnames.ora:

在"/home/oracle/app/oracle/product/12.2.0/dbhome_1/network/admin"目录下,用记事本打开tnsnames.ora,在最后添加

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

第三步:重启 reboot

3、启动PDB并设置开机启动

第一步:

SQL>show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL>select con_id, dbid, guid, name , open_mode from v$pdbs;

CON_ID DBID GUID NAME OPEN_MODE
---------- ------------------------------------------ ------------------------------ ----------
2 4088301206 F7C1E3C96BBF0585E0430A01A8C05459PDB$SEED READ ONLY
3 426143573 F7C209EB1DFC0854E0430A01A8C0B787 PDBORCL READ WRITE

第二步:

我们关闭CDB启动PDB:

SQL>shutdown immediate

SQL>startup

SQL>col name for a10;

SQL> select con_id, dbid, guid, name , open_modefrom v$pdbs;

CON_ID DBID GUID NAME OPEN_MODE
---------- ------------------------------------------ ------------------------------ ----------
2 4088301206F7C1E3C96BBF0585E0430A01A8C05459 PDB$SEED READ ONLY
3 426143573 F7C209EB1DFC0854E0430A01A8C0B787 PDBORCL MOUNTED

我们现在连接的是CDB,即root container。
注意这里的PDB,在CDB 启动之,PDB 是自动启动到mount状态,而不是OPEN。 所以我们还需要手工去open它,当然,也可以通过在CDB中配置触发器来自动open。

第三步:

注意这里是mount,表示PDB 是关闭的。

--打开PDB实例
SQL>ALTER PLUGGABLE DATABASE pdborcl OPEN;
或者
SQL>ALTER PLUGGABLE DATABASE ALL OPEN;

--指定PDB 数据库:
SQL>alter session set container=pdborcl;

Session altered.

SQL>startup

Pluggable Database opened.

SQL>select con_id, dbid, guid, name , open_mode from v$pdbs;

CON_ID DBID GUID NAME OPEN_MODE
-------------------- -------------------------------- --------------- ----------
3 426143573 F7C209EB1DFC0854E0430A01A8C0B787 PDBORCL READ WRITE

注意到PDBORCL READ WRITE说明已经启动成功

第四步:设置Pluggable Database (PDB) 的自动startup

SQL>show con_name

CON_NAME
------------------------------
PDBCNDBA

SQL>alter session set container=CDB$ROOT;

Session altered.

SQL>CREATE OR REPLACE TRIGGER open_pdbs
2 AFTER STARTUP ON DATABASE
3 BEGIN
4 EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
5 END open_pdbs;
6 /

Trigger created.

4、配置连接用户

查看用户名和用户状态
select username,account_status from dba_users order by username;

ALTER USER scott ACCOUNT UNLOCK IDENTIFIED BY tiger;

alter user hr account unlock;

alter user hr identified by hr;

grant connect, resource to scott;

你可能感兴趣的:(数据库)