官术网_书友最值得收藏!

Effects of plugging/unplugging operations on users, roles, and privileges

The purpose of this recipe is to show what is going to happen to users, roles, and privileges when you unplug a pluggable database from one container database (cdb1) and plug it into some other container database (cdb2).

Getting ready

To complete this recipe, you will need the following:

  • Two container databases (cdb1 and cdb2)
  • One pluggable database (pdb1) in the container database cdb1
  • Local user mike in the pluggable database pdb1 with the local create session privilege
  • The common user c##john with the create session common privilege and create synonym local privilege on the pluggable database pdb1

How to do it...

  1. Connect to the root container of cdb1 as user sys:
    SQL> connect sys@cdb1 as sysdba
    
  2. Unplug pdb1 by creating an XML metadata file:
    SQL> alter pluggable database pdb1 unplug into '/u02/oradata/pdb1.xml';
    
  3. Drop pdb1 and keep the datafiles:
    SQL> drop pluggable database pdb1 keep datafiles;
    
  4. Connect to the root container of cdb2 as user sys:
    SQL> connect sys@cdb2 as sysdba
    
  5. Create (plug) pdb1 to cdb2 by using the previously created metadata file:
    SQL> create pluggable database pdb1 using '/u02/oradata/pdb1.xml' nocopy;
    

How it works...

By completing the previous steps, you unplugged pdb1 from cdb1 and plugged it into cdb2. After this operation, all local users and roles (in pdb1) are migrated with the pdb1 database.

The following is how you try to connect to pdb1 as a local user:

SQL> connect mike@pdb1

All local privileges are migrated even if they are granted to common users/roles. However, if you try to connect to pdb1 as a previously created common user, c##john, you'll get an error, as follows:

SQL> connect c##john@pdb1 
 ERROR:
ORA-28000: the account is locked
Warning: You are no longer connected to ORACLE.

This happened because, after migration, common users are migrated in a pluggable database as locked accounts. You can continue to use objects in these users' schemas, or you can create these users in a root container of a new CDB. To do this, we first need to close pdb1:

sys@CDB2> alter pluggable database pdb1 close;
Pluggable database altered. 
 sys@CDB2> create user c##john identified by oracle container=all;
User created. 
 sys@CDB2> alter pluggable database pdb1 open;
Pluggable database altered.

If we try to connect to pdb1 as the user c##john, we will get the following error:

SQL> conn c##john/oracle@pdb1
ERROR:
ORA-01045: user C##JOHN lacks CREATE SESSION privilege; logon denied
Warning: You are no longer connected to ORACLE.

Even though c##john had the create session common privilege in cdb1, he cannot connect to the migrated PDB. This is because common privileges are not migrated! So, we need to give the create session privilege (either common or local) to the user c##john, as follows:

sys@CDB2> grant create session to c##john container=all;
 Grant succeeded.

In the earlier recipe (Granting privileges and roles locally), we granted a create synonym local privilege to a user, c##john. Let's try this privilege on the migrated pdb2:

c##john@PDB1> create synonym emp for hr.employees;
Synonym created.

This proves that local privileges are always migrated.

主站蜘蛛池模板: 安康市| 朝阳区| 玛多县| 睢宁县| 涟水县| 福安市| 宜都市| 仙居县| 阜平县| 平乡县| 鄱阳县| 河间市| 广德县| 二连浩特市| 永和县| 自贡市| 襄城县| 定日县| 许昌市| 余庆县| 永宁县| 中牟县| 广河县| 兴隆县| 客服| 郸城县| 潮州市| 罗甸县| 靖远县| 塘沽区| 吉木萨尔县| 定兴县| 云霄县| 福州市| 太谷县| 汕尾市| 宝丰县| 阜新市| 攀枝花市| 玉溪市| 白山市|