02 Secnarios 12c PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Oracle Database 12c - Scenarios

Scenario-1
Overview: In this scenario you change the password of a common user whereas one PDB is closed.
What happens when you open the PDB and need to connect under this user to the PDB ?
[oracle@12casm ~]$ . oraenv
ORACLE_SID = [cdb1] ? cdb1
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@12casm ~]$ sqlplus /nolog
SQL> connect sys/[email protected]:1521/cdb1 as sysdba
SQL> select name,open_mode from v$database;
SQL> select name,open_mode from v$pdbs;
NAME
-----------------------------PDB$SEED
PDB1
PDB2
PDB3

OPEN_MODE
---------READ ONLY
MOUNTED
MOUNTED
MOUNTED

SQL> alter pluggable database pdb1 open;


Pluggable database altered.
SQL> create user c##1 identified by oracle container=all;
User created.
SQL> grant create session to c##1 CONTAINER=ALL;
Grant succeeded.
SQL> select distinct username from cdb_users where username='C##1 ';
no rows selected
SQL> select username, common, con_id from cdb_users where username like 'C##%';
USERNAME
COM CON_ID
--- ---------------------------------------C##1
YES
1
C##1
YES
3
SQL> select name,con_id,open_mode from v$pdbs;

Oracle Database 12c - Scenarios

Page 1 of 10

NAME
CON_ID OPEN_MODE
------------------------------ ---------- ---------------------PDB$SEED
2
READ ONLY
PDB1
3
READ WRITE
PDB2
4
MOUNTED
PDB3
5
MOUNTED
SQL> grant create session to c##1 container=all;
Grant succeeded.
SQL> connect c##1/oracle@localhost:1521/pdb1;
Connected.
SQL> connect sys/[email protected]:1521/cdb1 as sysdba
Connected.
SQL> alter pluggable database pdb1 close;
Pluggable database altered.
SQL> alter user c##1 identified by oracle123;
User altered.
SQL> alter pluggable database pdb1 open;
Pluggable database altered.
SQL> connect c##1/oracle@localhost:1521/pdb1;
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL> connect c##1/oracle123@localhost:1521/pdb1;
Connected.
Result: The change to the common user waits for PDB4 to be opened and then is applied.

Oracle Database 12c - Scenarios

Page 2 of 10

Scenario-2
Overview: In this scenario you create a new PDB in a CDB where common users already exist.
Are the existing common users automatically created in the new PDB?
[oracle@localhost ~]$ . oraenv
ORACLE_SID = [oracle] ? cdb1
The Oracle base has been set to /u01/app/oracle
[oracle@localhost ~]$ sqlplus /nolog
SQL> connect sys/[email protected]:1521/cdb1 as sysdba
Connected.
SQL> ! df -h
Filesystem
/dev/sda2
tmpfs
/dev/sda1
/dev/sdb1
/dev/sdc1

Size Used Avail Use% Mounted on


12G 7.8G 3.2G 72% /
4.0G 416M 3.6G 11% /dev/shm
243M 73M 158M 32% /boot
9.9G 181M 9.2G 2% /opt
40G 32G 6.0G 85% /u01

SQL> !
[oracle@localhost ~]$ cd /u01/app/oracle/oradata/cdb1
[oracle@localhost cdb1]$ ls
backup_user_table cdbtemp01.dbf pdb1 pdb3 redo012.log redo022.log redo032.log redo04_2.log
sysaux01.dbf temp01.dbf users01.dbf
cdbdata01.dbf control01.ctl pdb2 pdbseed redo01.log redo02.log redo03.log redo04.log
system01.dbf undotbs01.dbf
[oracle@localhost cdb1]$ mkdir pdb5
[oracle@localhost cdb1]$ cd pdb5
[oracle@localhost pdb5]$ pwd
/u01/app/oracle/oradata/cdb1/pdb5
[oracle@localhost pdb5]$ exit
exit
SQL> col username format A25
SQL> select USERNAME, COMMON, CON_ID from cdb_users;
USERNAME
COM CON_ID
------------------------- --- ---------SYS
YES
1
SYSTEM
YES
1
----------------------------------------153 rows selected.
SQL> create user c##2 identified by oracle container=all;

Oracle Database 12c - Scenarios

Page 3 of 10

User created.
SQL> grant create session to c##2 CONTAINER=ALL;
Grant succeeded.
SQL> select username , con_id from cdb_users where username='c##2';
no rows selected
SQL> select username , con_id from cdb_users where username='C##2';
USERNAME
CON_ID
------------------------- ---------C##2
1
C##2
4
C##2
3
SQL> select name,open_mode,con_id from v$pdbs;
NAME
OPEN_MODE CON_ID
------------------------------ ---------- ------------------------PDB$SEED
READ ONLY
2
PDB2
READ WRITE
3
PDB1
READ WRITE
4
SQL> show con_id
CON_ID
-----------------------------1
SQL> show con_name
CON_NAME
-----------------------------CDB$ROOT
SQL> !
[oracle@localhost ~]$ vi /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora
[oracle@localhost ~]$ cat /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora
CDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cdb1)
)

Oracle Database 12c - Scenarios

Page 4 of 10

)
PDB5 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb5)
)
)
[oracle@localhost ~]$ cd /u01/app/oracle/oradata/cdb1
[oracle@localhost cdb1]$ l
bash: l: command not found
[oracle@localhost cdb1]$ ls
backup_user_table cdbtemp01.dbf pdb1 pdb3 pdbseed redo01.log redo02.log redo03.log
redo04.log system01.dbf undotbs01.dbf
cdbdata01.dbf control01.ctl pdb2 pdb5 redo012.log redo022.log redo032.log redo04_2.log
sysaux01.dbf temp01.dbf users01.dbf
[oracle@localhost cdb1]$ cd pdbseed/
[oracle@localhost pdbseed]$ ls -lrth
total 914M
-rw-r-----. 1 oracle oinstall 88M Jun 17 2013 pdbseed_temp01.dbf
-rw-r-----. 1 oracle oinstall 261M Nov 12 11:48 system01.dbf
-rw-r-----. 1 oracle oinstall 641M Nov 12 11:48 sysaux01.dbf
[oracle@localhost pdbseed]$ pwd
/u01/app/oracle/oradata/cdb1/pdbseed
[oracle@localhost pdbseed]$
[oracle@localhost pdbseed]$ exit
exit
SQL> CREATE PLUGGABLE DATABASE pdb5
ADMIN USER pdb5_admin
IDENTIFIED BY oracle ROLES=(CONNECT)
FILE_NAME_CONVERT=('/u01/app/oracle/oradata/cdb1/pdbseed','/u01/app/oracle/oradata/cdb1/pdb5
'); 2 3 4
Pluggable database created.
SQL> select name, con_id, open_mode from v$pdbs;
NAME
CON_ID OPEN_MODE
------------------------------ ---------- ---------PDB$SEED
2 READ ONLY
PDB2
3 READ WRITE
PDB1
4 READ WRITE

Oracle Database 12c - Scenarios

Page 5 of 10

PDB5

5 MOUNTED

SQL> alter pluggable database PDB5 open;


Pluggable database altered.
SQL> !
[oracle@localhost ~]$ cd /u01/app/oracle/oradata/cdb1/pdb5
[oracle@localhost pdb5]$ ls -lrth
total 901M
-rw-r-----. 1 oracle oinstall 21M Nov 13 17:12 pdbseed_temp01.dbf
-rw-r-----. 1 oracle oinstall 261M Nov 13 17:12 system01.dbf
-rw-r-----. 1 oracle oinstall 641M Nov 13 17:12 sysaux01.dbf
[oracle@localhost pdb5]$ exit
exit
SQL> connect pdb5_admin/oracle@pdb5
Connected.
SQL> show con_id
CON_ID
-----------------------------5
SQL> show con_name
CON_NAME
-----------------------------PDB5
SQL> connect sys/[email protected]:1521/cdb1 as sysdba
Connected.
SQL> select username , con_id from cdb_users where username='C##2';
USERNAME
CON_ID
------------------------- ---------C##2
1
C##2
5
C##2
3
C##2
4
SQL>

Oracle Database 12c - Scenarios

Page 6 of 10

Scenario-3
Overview: In this practice, you close PDBs. You create a new common user. Is the new common user
automatically created when PDBs are reopened ?
SQL> connect sys/[email protected]:1521/cdb1 as sysdba
Connected.
SQL> select name, open_mode from v$pdbs;
NAME
OPEN_MODE
------------------------------ ---------PDB$SEED
READ ONLY
PDB2
READ WRITE
PDB1
READ WRITE
PDB5
READ WRITE
SQL> alter pluggable database pdb5 close;
Pluggable database altered.
SQL> select name, open_mode from v$pdbs;
NAME
OPEN_MODE
------------------------------ ---------PDB$SEED
READ ONLY
PDB2
READ WRITE
PDB1
READ WRITE
PDB5
MOUNTED
SQL> create user c##3 identified by oracle container=all;
User created.
SQL> grant create session to c##3 CONTAINER=ALL;
Grant succeeded.
SQL> select username , con_id from cdb_users where username='C##3';
USERNAME
CON_ID
------------------------- ---------C##3
1
C##3
3
C##3
4
SQL> alter pluggable database pdb5 open;
Pluggable database altered.
SQL> select username , con_id from cdb_users where username='C##3';

Oracle Database 12c - Scenarios

Page 7 of 10

USERNAME
CON_ID
------------------------- ---------C##3
1
C##3
5
C##3
4
C##3
3
SQL> connect c##3/oracle@pdb1
Connected.
SQL> connect c##3/oracle@pdb2
Connected.
SQL> connect c##3/oracle@pdb5
Connected.
SQL> connect sys/[email protected]:1521/cdb1 as sysdba
Connected.
SQL> drop user c##3 cascade;
User dropped.

Oracle Database 12c - Scenarios

Page 8 of 10

Scenario-4
Overview: In this scenario you disabled a PDB from flashback. A common user is dropped. Can
you perform a flashback database?
[oracle@localhost ~]$ . oraenv
ORACLE_SID = [cdb3] ? cdb3
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@localhost ~]$ sqlplus /nolog
SQL> connect sys/oracle as sysdba
SQL> startup;
SQL> archive log list;
SQL> ALTER SYSTEM SET DB_FLASHBACK_RETENTION_TARGET=2880 SCOPE=BOTH;
System altered.
SQL> ALTER DATABASE FLASHBACK ON;
Database altered.
SQL> select con_id, name, open_mode from v$pdbs;
CON_ID NAME
OPEN_MODE
---------- ------------------------------ ---------2 PDB$SEED
READ ONLY
3 PDB1
MOUNTED
4 CDB3_PDB2
MOUNTED
5 PDB3
MOUNTED
6 PDB4
MOUNTED
SQL> alter pluggable database all open;
Warning: PDB altered with errors.
SQL> alter pluggable database cdb3_pdb2 close;
Pluggable database altered.
SQL> drop pluggable database CDB3_PDB2 including datafiles;
Pluggable database dropped.
SQL> select con_id, name, open_mode from v$pdbs;
CON_ID NAME
OPEN_MODE
---------- ------------------------------ -----------------------2 PDB$SEED
READ ONLY
3 PDB1
READ WRITE
5 PDB3
READ WRITE
6 PDB4
READ WRITE

Oracle Database 12c - Scenarios

Page 9 of 10

SQL> connect sys/[email protected]:1521/pdb4 as sysdba


Connected.
SQL> ALTER PLUGGABLE DATABASE pdb4 FLASHBACK OFF;
ALTER PLUGGABLE DATABASE pdb4 FLASHBACK OFF
*
ERROR at line 1:
ORA-03001: unimplemented feature
SQL> ALTER PLUGGABLE DATABASE pdb4 FLASHBACK ON;
ALTER PLUGGABLE DATABASE pdb4 FLASHBACK ON
*
ERROR at line 1:
ORA-03001: unimplemented feature
SQL>

Oracle Database 12c - Scenarios

Page 10 of 10

You might also like