温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Oracle 12c 日常维护

发布时间:2020-07-16 10:02:04 来源:网络 阅读:1465 作者:DoveLauren 栏目:关系型数据库

1.启动CDB和PDB数据库

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


    CON_ID DBID NAME     OPEN_MODE

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

2 1226396669 PDB$SEED     READ ONLY

3  411454583 DB12CCD     MOUNTED


SQL> alter pluggable database all open;


Pluggable database altered.


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


    CON_ID DBID NAME     OPEN_MODE

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

2 1226396669 PDB$SEED     READ ONLY

3  411454583 DB12CCD     READ WRITE


2.创建PDB数据库


SQL> select name,cdb from v$database;


NAME  CDB

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

DB12C  YES


SQL> select pdb_id,pdb_name,dbid,status,creation_scn from dba_pdbs;


    PDB_ID PDB_NAME      DBID STATUS    CREATION_SCN

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

3 DB12CCD 411454583 NORMAL  1744330

2 PDB$SEED 1226396669 NORMAL  1594399





SQL> create pluggable database test admin user test identified by test file_name_convert=('/u01/app/oracle/oradata/cdb/pdbseed/','/u01/app/oracle/oradata/cdb/test/');


Pluggable database created.


create pluggable database test1 admin user test1 identified by test1 file_name_convert=('/u01/app/oracle/oradata/cdb/test/','/u01/app/oracle/oradata/cdb/test1/'); 



3.建立连接  

--进入cdb  

sqlplus / as sysdba

sqlplus sys/sys@192.168.10.32:1521/cdb as sysdba



  

--进入pdb  

3.1)通过tns方式用创建的admin user登录



[oracle@ora12cA ~]$ sqlplus sys/oracle@192.168.10.32:1521/test as sysdba


SQL> show con_name


CON_NAME

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

TEST


--查看admin user拥有的权限 


SQL> select * from session_privs;


PRIVILEGE

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

SET CONTAINER

CREATE PLUGGABLE DATABASE

CREATE SESSION

  



3.2)通过set container来连接pdb

SQL> show pdbs


    CON_ID CON_NAME  OPEN MODE  RESTRICTED

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

2 PDB$SEED  READ ONLY  NO

3 PDB  MOUNTED

4 TEST  READ WRITE NO

SQL> alter session set container=test;


Session altered.


SQL> show con_name


CON_NAME

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

TEST



4.打开和关闭pdb 

 

SQL>alter pluggable database all close immediate;  

  

SQL> show pdbs


    CON_ID CON_NAME  OPEN MODE  RESTRICTED

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

2 PDB$SEED  READ ONLY  NO

3 PDB  MOUNTED

4 TEST  MOUNTED

--打开单个pdb  

SQL> alter pluggable database pdb open;


Pluggable database altered.


SQL> show pdbs


    CON_ID CON_NAME  OPEN MODE  RESTRICTED

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

2 PDB$SEED  READ ONLY  NO

3 PDB  READ WRITE NO

4 TEST  MOUNTED


--打开所有pdb  

SQL> alter pluggable database all open;


Pluggable database altered.


SQL> show pdbs


    CON_ID CON_NAME  OPEN MODE  RESTRICTED

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

2 PDB$SEED  READ ONLY  NO

3 PDB  READ WRITE NO

4 TEST  READ WRITE NO


--关闭所有pdb

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 PDB  MOUNTED

4 TEST  


5.创建用户。

   

1).概述

  在cdb默认是container=all,在cdb中只能创建全局用户;

  在pdb默认是container=current,在pdb只能创建本地用户。

  http://dovelauren.blog.51cto.com/9876026/1719310

  如果在cdb中创建用户会在cdb和所有的pdb中创建该用户,但是pdb中的全局用户需要另外授权才能够在pdb中访问)。  

  

2).创建全局用户  

SQL> show con_name


CON_NAME

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

CDB$ROOT

SQL> create user c##t identified by t;


User created.


SQL> show pdbs


    CON_ID CON_NAME  OPEN MODE  RESTRICTED

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

2 PDB$SEED  READ ONLY  NO

3 PDB  READ WRITE NO

4 PDB1  READ WRITE NO  

3).创建本地用户  

SQL> alter session set container=pdb1;


Session altered.


SQL> create user t identified by t;


User created.


SQL> show pdbs


    CON_ID CON_NAME  OPEN MODE  RESTRICTED

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

4 PDB1  READ WRITE NO

  

  

6.用户授权  

 用户授权默认情况下是只会给当前container,在cdb中也可以指定container=all,对所有open的pdb且存在该用户都进行授权  

Connected.

SQL> grant connect,resource to c##t;


Grant succeeded.


SQL> grant connect,resource to c##t container=all;


Grant succeeded.


7.修改参数  

 在cdb中修改,pdb会继承进去;如果在pdb中修改会覆盖pdb从cdb中继承的参数含义  

 SQL> show con_name


CON_NAME

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

CDB$ROOT

SQL> show parameter open_cursors


NAME     TYPE VALUE

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

open_cursors     integer 300

SQL> alter system set open_cursors=500;


System altered.


SQL> show pdbs


    CON_ID CON_NAME  OPEN MODE  RESTRICTED

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

2 PDB$SEED  READ ONLY  NO

3 PDB  READ WRITE NO

4 PDB1  READ WRITE NO

SQL> alter session set container=pdb1;


Session altered.


SQL> show parameter open_cursors


NAME     TYPE VALUE

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

open_cursors     integer 500

SQL> alter system set open_cursors=100;


System altered.


SQL> show parameter open_cursors


NAME     TYPE VALUE

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

open_cursors     integer 100

SQL> show con_name


CON_NAME

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

PDB1

SQL> alter session set container=CDB$ROOT;


Session altered.


SQL> show parameter open_cursors


NAME     TYPE VALUE

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

open_cursors     integer 500


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI