0% found this document useful (0 votes)
14 views8 pages

Multitenant

The document describes how to create a container database (CDB) and pluggable databases (PDBs) in Oracle 19c. It provides SQL commands to create a CDB, add PDBs, open and close PDBs, view database objects belonging to different containers, and connect to a specific PDB.

Uploaded by

Srinivas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Multitenant

The document describes how to create a container database (CDB) and pluggable databases (PDBs) in Oracle 19c. It provides SQL commands to create a CDB, add PDBs, open and close PDBs, view database objects belonging to different containers, and connect to a specific PDB.

Uploaded by

Srinivas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Creating A Container Database (CDB) With A Subset Of Options (Doc ID 2001512.

1)

/u01/app/oracle/product/19c/db_1/dbs/inittestcdb.ora
startup nomount pfile='/u01/app/oracle/product/19c/db_1/dbs/inittestcdb.ora'

db_name=testcdb
CONTROL_FILES='+DATA1/testcdb/controlfile/control01.ctl','+DATA1/testcdb/
controlfile/control02.ctl'
ENABLE_PLUGGABLE_DATABASE=TRUE
DB_CREATE_FILE_DEST='+DATA1'
DB_CREATE_ONLINE_LOG_DEST_1='+DATA1'
DB_BLOCK_SIZE=8192
UNDO_MANAGEMENT=AUTO
UNDO_TABLESPACE=undotbs
USER_DUMP_DEST='/u01/app/oracle/admin/testcdb/udump/'
------------

SQL> startup nomount pfile='/u01/app/oracle/product/19c/db_1/dbs/inittestcdb.ora'


ORA-32006: USER_DUMP_DEST initialization parameter has been deprecated
ORACLE instance started.

Total System Global Area 352317720 bytes


Fixed Size 9134360 bytes
Variable Size 285212672 bytes
Database Buffers 50331648 bytes
Redo Buffers 7639040 bytes
SQL>

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

=====================================

create database testcdb


user sys identidifed by Oracle123
user system identified by Oracle123
maxlogfile 2
maxlogmembers 2
logfile group 1 size 20m, group 2 size 20m
undo tablespace undotbs datafile size 100m
enable pluggable database;

SQL> @/u01/app/oracle/product/19c/db_1/dbs/testcbd.sql

Database created.

SQL> select name,open_mode,CDB from v$database;

NAME OPEN_MODE CDB


--------- -------------------- ---
TESTCDB READ WRITE YES

SQL> select name,open_mode,CDB from v$database;

NAME OPEN_MODE CDB


--------- -------------------- ---
TESTCDB READ WRITE YES
Run catcdb.sql
and provide logfile location and log file name
and it may take around 30 minutes to complete

SQL> host perl -I &&rdbms_admin &&rdbms_admin_catcdb --logDirectory &&1 --


logFilename &&2
Enter value for 1: /u01/app/oracle/logfile
Enter value for 2: testcdb.log
Enter new password for SYS: Oakton123
Enter new password for SYSTEM: Oakton123
Enter temporary tablespace name: temp

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
SQL>

Now create a pluggable database

CREATE PLUGGABLE DATABASE testpdb1 ADMIN USER testpdb1_adm IDENTIFIED BY Oracle123;

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB1 MOUNTED

SQL> alter pluggable database TESTPDB1 open;

Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB1 READ WRITE NO

SQL> select TABLESPACE_NAME,CON_ID from cdb_tablespaces;

TABLESPACE_NAME CON_ID
------------------------------ ----------
SYSTEM 1
SYSAUX 1
UNDOTBS 1
SYSTEM 3
SYSAUX 3

SQL> show pdbs


CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB1 MOUNTED
SQL> alter pluggable database testpdb1 oepn;
alter pluggable database testpdb1 oepn
*
ERROR at line 1:
ORA-00922: missing or invalid option

SQL> alter pluggable database testpdb1 open;

Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB1 READ WRITE NO
SQL> select TABLESPACE_NAME,CON_ID from cdb_tablespaces;

TABLESPACE_NAME CON_ID
------------------------------ ----------
SYSTEM 1
SYSAUX 1
UNDOTBS 1
SYSTEM 3
SYSAUX 3

SQL> alter pluggable database testpdb1 save state;

Pluggable database altered.

SQL>

ALTER PLUGGABLE DATABASE pdb1 DISCARD STATE;

COLUMN con_name FORMAT A20


COLUMN instance_name FORMAT A20

SELECT con_name, instance_name, state FROM dba_pdb_saved_states;

Connecting to PDB:

alter session set container = testpdb1;

SELECT name || ' '|| pdb FROM v$services ORDER BY name;

lsnrctl services LISTENER

connect system/Oracle123@//test1:1521/testpdb1

testpdb1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = test1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testpdb1)
)
)

https://www.thegeekdiary.com/how-to-connect-to-an-oracle-pluggable-database-pdb/

How To Connect to PDB By OS Authentication In 19c Container Database Environment


(Doc ID 2729416.1)

=====================
select name,cdb,con_id from v$database;

For each container each service is created:

SQL> select name,con_id from v$services;

NAME CON_ID
---------------------------------------------------------------- ----------
testcdb 1
testpdb1 3
SYS$BACKGROUND 1
SYS$USERS 1

show con_name

select pdb_id, pdb_name, dbid, con_id from cdb_pdbs;

select con_id,name,open_mode from v$pdbs;

select group#,con_id, member from v$logfile;

select name,con_id from v$controlfile;

To view all datafiles including those of PDB and CDBs

SELECT FILE_NAME,TABLESPACE_NAME,CON_ID FROM CDB_DATA_FILES ORDER BY CON_ID;

only dba data files

SQL> select file_name, tablespace_name, file_id from dba_data_files;

select file_name, tablespace_name from cdb_temp_files;

select username,common,con_id from cdb_users where username ='SYSTEM';

select username, con_id from cdb_users where common='NO';

SQL> col role format a30


SQL> select role, common, con_id from cdb_roles order by 3;

the privielge when granted becomes a common or local privilege

CDB_SYS_PRIVS

SQL> COL GRANTEE FORMAT A15


SQL> COL GRANTED_ROLE FORMAT A30
SQL> L
1 select grantee, granted_role, common, con_id from cdb_role_privs
2* where grantee='SYSTEM'
SQL> /

GRANTEE GRANTED_ROLE COM CON_ID


--------------- ------------------------------ --- ----------
SYSTEM DBA

YES 1
SYSTEM AQ_ADMINISTRATOR_ROLE YES 1
SYSTEM DBA YES 3
SYSTEM AQ_ADMINISTRATOR_ROLE YES 3

select group#, con_id, member from v$logfile

SQL> col file_name format a50


SQL> set linesize 2000
SQL> select file_name, tablespace_name, con_id from cdb_data_files order by con_id;

FILE_NAME TABLESPACE_NAME
CON_ID
-------------------------------------------------- ------------------------------
----------
+DATA1/TESTCDB/DATAFILE/system.262.1137413199 SYSTEM
1
+DATA1/TESTCDB/DATAFILE/sysaux.264.1137413201 SYSAUX
1
+DATA1/TESTCDB/DATAFILE/undotbs.266.1137413201 UNDOTBS
1
+DATA1/TESTCDB/FC2D1298427027A3E0530118A8C02E63/DA SYSAUX
3
TAFILE/sysaux.267.1137419505

+DATA1/TESTCDB/FC2D1298427027A3E0530118A8C02E63/DA SYSTEM
3
TAFILE/system.268.1137419505

SQL> select username, common,con_id from cdb_users where username ='SYSTEM';

USERNAME
COM CON_ID
-----------------------------------------------------------------------------------
--------------------------------------------- --- ----------
SYSTEM
YES 1
SYSTEM
YES 3

SELECT USERNAME,CON_ID from cdb_users where common='NO';

SQL> col pdb_name format a10


SQL> select pdb_id, pdb_name, status from cdb_pdbs;

PDB_ID PDB_NAME STATUS


---------- ---------- ----------
3 SECONDPDB NORMAL
2 PDB$SEED NORMAL
4 TEST2PDB NEW

SQL> alter pluggable database test2pdb open;

Pluggable database altered.

SQL> select pdb_id, pdb_name, status from cdb_pdbs;

PDB_ID PDB_NAME STATUS


---------- ---------- ----------
3 SECONDPDB NORMAL
2 PDB$SEED NORMAL
4 TEST2PDB NORMAL

select con_id,name from v$datafile;

SQL> create pluggable database test2pdb


2 admin user pdb_admin identified by Oakton123
3 roles=(connect)
4 create_file_dest='+data1/';

SQL> select * from session_roles;

ROLE
--------------------------------------------------------------------------------
PDB_DBA
CONNECT

SQL> select username from dba_users where common='YES';


select username from dba_users where common='YES'
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> SELECT * FROM SESSION_PRIVS;

PRIVILEGE
----------------------------------------
SET CONTAINER
CREATE PLUGGABLE DATABASE
CREATE SESSION

SQL> SELECT * FROM USER_TAB_PRIVS;

no rows selected

SQL>

===============application pdbs======================

SQL> select name from v$database;

NAME
---------
ORCL
SQL> create pluggable database app_root
2 as application container
3 admin user app_admin identified by Oakton123
4 roles=(connect)
5 create_file_dest='+data1';

Pluggable database created.

SQL> select
name,con_id,application_root,application_seed,application_pdb,application_root_con_
id from v$containers;

create tablespace apps_root datafile 'appsroot.dbf' size 50m;

creae user app_user1 identified by Oakton123;

SQL> creae user app_user1 identified by Oakton123;


SP2-0734: unknown command beginning "creae user..." - rest of line ignored.
SQL> create user app_user1 identified by Oakton123;

User created.

SQL> grant dba to app_user1;

Grant succeeded.

SQL> create table firsttable (sno number(10), name varchar2(30));

Table created.

SQL> grant read,write on firsttable to app_user1;


grant read,write on firsttable to app_user1
*
ERROR at line 1:
ORA-02224: EXECUTE privilege not allowed for tables

SQL> grant read on firsttable to app_user1;

Grant succeeded.

SQL> grant write on firsttable to app_user1;


grant write on firsttable to app_user1
*
ERROR at line 1:
ORA-02224: EXECUTE privilege not allowed for tables

SQL> grant dba to appuser1;


grant dba to appuser1
*
ERROR at line 1:
ORA-01917: user or role 'APPUSER1' does not exist

SQL> grant dba to app_user1;


Grant succeeded.

SQL> alter pluggable database application app_root end install '1.0';

Pluggable database altered.

SQL>

SQL> select app_name, app_version, app_status from dba_applications where


app_name='APP_ROOT';

APP_NAME
--------------------------------------------------------------------------------
APP_VERSION APP_STATUS
------------------------------ ------------
APP_ROOT
1.0 NORMAL

SQL> create pluggable database as seed admin user app_admin identified by Oakton123
roles=(connect) create_file_dest='+data1';

Pluggable database created.

You might also like