presentation day4 oracle12c

34
ORACLE DATABASE 12C CREATION OF CDB AND PDB DATABASE (Reference – Oracle documentation) Check detailed contents on http://dbaboss.com/ 1

Upload: pradeep-srivastava

Post on 13-Jan-2017

451 views

Category:

Data & Analytics


0 download

TRANSCRIPT

Page 1: Presentation day4 oracle12c

1

ORACLE DATABASE 12C

CREATION OF CDB AND PDB DATABASE

(Reference – Oracle documentation)

Check detailed contents on http://dbaboss.com/

Page 3: Presentation day4 oracle12c

3

• Multitenant : Create and Configure a Container Database (CDB) in Oracle Database 12c Release 1 (12.1)

• The multitenant option introduced in Oracle Database 12c allows a single container database (CDB) to host multiple separate pluggable databases (PDB). This article covers the options available to create a new container database.

• There are articles specifically about installation of Oracle Database 12c here.• •Oracle Universal Installer (OUI)• •Database Configuration Assistant (DBCA)• •Manual Creation

• •Configure a Container Database (CDB)• • Oracle Universal Installer (OUI)

• The Oracle Universal Installer (OUI) allows you to create a container database (CDB) during the software installation. The "Typical Install Configuration" screen has a checkbox to indicate the database is a container database. You can optionally create a single pluggable database (PDB) in this screen also.

Check detailed contents on http://dbaboss.com/

Page 4: Presentation day4 oracle12c

Check detailed contents on http://dbaboss.com/

4

Page 5: Presentation day4 oracle12c

Check detailed contents on http://dbaboss.com/

5

Page 6: Presentation day4 oracle12c

6

• Database Configuration Assistant (DBCA)

• The Database Configuration Assistant (DBCA) gives similar options to the Oracle Universal Installer (OUI). The "Creation Mode" page allows you to enter the default installation configuration details directly

Check detailed contents on http://dbaboss.com/

Page 7: Presentation day4 oracle12c

7Check detailed contents on

http://dbaboss.com/

Page 8: Presentation day4 oracle12c

8Check detailed contents on

http://dbaboss.com/

Page 9: Presentation day4 oracle12c

9

Manual Creation• Creating Multitenant Container database

• Creating container database is similar to creating non-container database but with few changes. Following changes should be made if we want to create container database

• • 1) Define enable_pluggable_database parameter to true.• By default this parameter is false. Meaning that by default database will be created as non-multitenant

database. If you want to create multitenant database, you have to make this parameter true.• Failing to make this parameter true will give you following error if you try to create multitenant database• • ORA-65093: multitenant container database not set up properly• • 2) Change in “Create database” command• So if you are going to create multitenant database using “create database” command, you need to add

couple of clause to this command.• Following clause needs to be added• •ENABLE PLUGGABLE DATABASE• •SEED

Check detailed contents on http://dbaboss.com/

Page 10: Presentation day4 oracle12c

10

• Following steps can be used to create multitenant database• • Step 1) Create pfile and spfile• • You can use following parameters as generic to create test database. You can alter the memory parameters and

include/remove many parameters as required. But these are good enough to create test instance

Check detailed contents on http://dbaboss.com/

Page 11: Presentation day4 oracle12c

Check detailed contents on http://dbaboss.com/

11

• ORA-04031: unable to allocate 4096 bytes of shared memory (“java pool”,”/51835a0f_ReflectionFactoryGet”,”JOXLE^5cb1fb41″,”:SGAClass”)

• Step 2) Create database command•

Page 12: Presentation day4 oracle12c

12

• Step 3) run catcdb.sql• • DO NOT RUN catlog.sql and catproc.sql• If you are creating container database, you need to run only catcdb.sql.• This script takes care of running all other dependent scripts internally.• • If you run catlog.sql and catproc.sql, this script will fail later at many stages with following errors• catcon: ALL catcon-related output will be written to dbmsxdbt_catcon_2527.lst• catcon: See dbmsxdbt*.log files for output generated by scripts• catcon: See dbmsxdbt_*.lst files for spool files, if any• catconInit: database is not open on the default instance• Unexpected error encountered in catconInit; exiting • In case of normal database creation, we usually run catlog.sql and catproc.sql as mentioned in

http://docs.oracle.com/database/121/ADMIN/create.htm#ADMIN11082• But that’s for normal database creation and process is same in 12c. But for creating container database, we should be running

only catcdb.sql• • catcdb.sql will ask for 3 inputs – new sys password, new system password and temp tablespace• SQL> @?/rdbms/admin/catcdb.sql

• Session altered.

• Enter new password for SYS:• Enter new password for SYSTEM:• Enter temporary tablespace name: TEMP • Once you provide this, it will create root container database with whatever database name you give. Container name for root

container DB will be CDB$ROOT.• It will also create seed pluggable container database. Container name will be seed$pdb

Check detailed contents on http://dbaboss.com/

Page 13: Presentation day4 oracle12c

13

• SQL> @?/rdbms/admin/catcdb.sql

• Session altered.

• Enter new password for SYS:• Enter new password for SYSTEM:• Enter temporary tablespace name: TEMP • Once you provide this, it will create root container database with whatever

database name you give. Container name for root container DB will be CDB$ROOT.• It will also create seed pluggable container database. Container name will be

seed$pdb• • Step 4) Run utlrp.sql to compile invalid objects.• • There will be few invalid objects in database. You can run utlrp.sql to compile the

same

Check detailed contents on http://dbaboss.com/

Page 14: Presentation day4 oracle12c

14

• Validation• • You can run few commands to validate if you database is container databases and what all containers it has.• • We have a new column in v$database called CDB. If your database is container database it will show as YES• SYS.DEOCDB.PRIMARY>select name, cdb from v$database;

• NAME CDB• --------- ---• DEOCDB YES

• 1 row selected. • You can also check different containers in your database using following• SYS.DEOCDB.PRIMARY>select CON_ID, NAME, OPEN_MODE, TOTAL_SIZE from v$containers;

• CON_ID NAME OPEN_MODE TOTAL_SIZE• ---------- ------------------------------ ---------- ----------• 1 CDB$ROOT READ WRITE 0• 2 PDB$SEED READ ONLY 1599078400 • V$CONTAINER is the new view available in 12c. When this is run from root container, it shows all containers CDB as well as PDB. But if you

run same command from any PDB, it will show that container.• SYS.DEOCDB.PRIMARY>alter session set container=PDB$SEED;

• Session altered.

• SYS.DEOCDB.PRIMARY>select CON_ID, NAME, OPEN_MODE, TOTAL_SIZE from v$containers;

• CON_ID NAME OPEN_MODE TOTAL_SIZE• ---------- ------------------------------ ---------- ----------• 2 PDB$SEED READ ONLY 1599078400

Check detailed contents on http://dbaboss.com/

Page 15: Presentation day4 oracle12c

15

• Manual Creation through DBCA scripts

• Using the DBCA, either during or after the software installation, is the recommended approach to creating CDBs, but it is possible to create them manually.

• The simplest way to see how manual creation of a CDB is accomplished is to run the DBCA. Pick "Advanced Mode", select the "Custom Database" option (no template used) and at the end, uncheck the "Create Database" option and check the "Generate Database Creation Scripts" option. The resulting scripts will include one called "CreateDB.sql", with contents similar to this.

• SET VERIFY OFF• connect "SYS"/"&&sysPassword" as SYSDBA• set echo on• spool /u01/app/oracle/admin/cdb1/scripts/CreateDB.log append• startup nomount pfile="/u01/app/oracle/admin/cdb1/scripts/init.ora";• CREATE DATABASE "cdb1"• MAXINSTANCES 8• MAXLOGHISTORY 1• MAXLOGFILES 16• MAXLOGMEMBERS 3• MAXDATAFILES 1024• DATAFILE '/u01/app/oracle/oradata/cdb1/system01.dbf' SIZE 700M REUSE• AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED• EXTENT MANAGEMENT LOCAL• SYSAUX DATAFILE '/u01/app/oracle/oradata/cdb1/sysaux01.dbf' SIZE 550M REUSE• AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED• SMALLFILE DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/u01/app/oracle/oradata/cdb1/temp01.dbf' SIZE 20M REUSE• AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED

Check detailed contents on http://dbaboss.com/

Page 16: Presentation day4 oracle12c

16

• SMALLFILE UNDO TABLESPACE "UNDOTBS1" DATAFILE '/u01/app/oracle/oradata/cdb1/undotbs01.dbf' SIZE 200M REUSE• AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED• CHARACTER SET AL32UTF8• NATIONAL CHARACTER SET AL16UTF16• LOGFILE GROUP 1 ('/u01/app/oracle/oradata/cdb1/redo01.log') SIZE 50M,• GROUP 2 ('/u01/app/oracle/oradata/cdb1/redo02.log') SIZE 50M,• GROUP 3 ('/u01/app/oracle/oradata/cdb1/redo03.log') SIZE 50M• USER SYS IDENTIFIED BY "&&sysPassword" USER SYSTEM IDENTIFIED BY "&&systemPassword"• enable pluggable database• seed file_name_convert=('/u01/app/oracle/oradata/cdb1/system01.dbf','/u01/app/oracle/oradata/cdb1/pdbseed/

system01.dbf',• '/u01/app/oracle/oradata/cdb1/sysaux01.dbf','/u01/app/oracle/oradata/cdb1/pdbseed/sysaux01.dbf',• '/u01/app/oracle/oradata/cdb1/temp01.dbf','/u01/app/oracle/oradata/cdb1/pdbseed/temp01.dbf',• '/u01/app/oracle/oradata/cdb1/undotbs01.dbf','/u01/app/oracle/oradata/cdb1/pdbseed/undotbs01.dbf');• spool off• Most of the CREATE DATABASE statement should look familiar. Notice the ENABLE PLUGGABLE DATABASE and SEED

FILE_NAME_CONVERT options in bold.

• When the ENABLE PLUGGABLE DATABASE clause is present, the database is created as a CDB with both root and seed.

• The SEED FILE_NAME_CONVERT clause is used to determine the seed file names, based on the root file names. If you are using Oracle Managed Files (OMF), this clause is not necessary. If you prefer, you can specify the seed datafiles explicitly, rather than using the convert.

• SEED• SYSTEM DATAFILE '/u01/app/oracle/oradata/cdb1/pdbseed/system01.dbf' SIZE 700M REUSE• AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED• EXTENT MANAGEMENT LOCAL• SYSAUX DATAFILE '/u01/app/oracle/oradata/cdb1/pdbseed/sysaux01.dbf' SIZE 550M REUSE• AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED

Check detailed contents on http://dbaboss.com/

Page 17: Presentation day4 oracle12c

17

CREATION OF PDB DATABASES• There are articles specifically about installation of Oracle Database 12c here.• •Oracle Universal Installer (OUI)• •Database Configuration Assistant (DBCA)• ◦Create a Pluggable Database (PDB) using the DBCA• ◦Unplug a Pluggable Database (PDB) using the DBCA• ◦Plugin a Pluggable Database (PDB) using the DBCA• ◦Delete a Pluggable Database (PDB) using the DBCA• ◦Configure a Pluggable Database (PDB) using the DBCA• •SQL Developer• •Cloud Control GRID Infrastructure 12c• •Manual (SQL*Plus)• ◦Create a Pluggable Database (PDB) Manually• ◦Unplug a Pluggable Database (PDB) Manually• ◦Plugin a Pluggable Database (PDB) Manually• ◦Clone a Pluggable Database (PDB) Manually• ◦Clone a Pluggable Database (PDB) Manually (Metadata-Only : NO DATA)• ◦Delete a Pluggable Database (PDB) Manually

Check detailed contents on http://dbaboss.com/

Page 19: Presentation day4 oracle12c

19

• Oracle Universal Installer (OUI)

Check detailed contents on http://dbaboss.com/

Page 20: Presentation day4 oracle12c

20

• Database Configuration Assistant (DBCA)• The DBCA includes a new option on the opening "Database Operation" screen that allows you to manage

the pluggable databases of an existing container database. Select the "Manage Pluggable Databases" option and click the "Next" button.

Check detailed contents on http://dbaboss.com/

Page 21: Presentation day4 oracle12c

21Check detailed contents on

http://dbaboss.com/

Page 22: Presentation day4 oracle12c

22

• Create a Pluggable Database (PDB) using the DBCA• On the "Manage Pluggable Databases" screen shown previously, select the "Create a Pluggable Database"

option and click the "Next" button. On the resulting screen, select the container database to house the new pluggable database and click the "Next" button.

Check detailed contents on http://dbaboss.com/

Page 23: Presentation day4 oracle12c

23

• Select the "Create a new Pluggable Database" option and click the "Next" button. If you were plugging in a previously unplugged database, you would select the PDB Archive or PDB File Set options to match the format of the files containing the unplugged PDB.

Check detailed contents on http://dbaboss.com/

Page 24: Presentation day4 oracle12c

24

• Enter the pluggable database name, database location and admin credentials, then click the "Next" button

Check detailed contents on http://dbaboss.com/

Page 25: Presentation day4 oracle12c

25

• If you are happy with the summary information, click the "Finish" button

Check detailed contents on http://dbaboss.com/

Page 26: Presentation day4 oracle12c

26

• Wait while the pluggable database is created. Once complete, click the "OK" button on the message dialog and the "Close" button on the main screen. The new pluggable database has been created as a clone of the seed database.

Check detailed contents on http://dbaboss.com/

Page 27: Presentation day4 oracle12c

27

SQL Developer• The DBA section of SQL Developer includes tree node called "Container Database".

Check detailed contents on http://dbaboss.com/

Page 28: Presentation day4 oracle12c

28

• Right-clicking on the "Container Database" node produces a popup menu showing you what operations are available

Check detailed contents on http://dbaboss.com/

Page 29: Presentation day4 oracle12c

29

• Right-clicking on a specific PDB node produces a popup menu showing only those operations that are relevant to that PDB

Check detailed contents on http://dbaboss.com/

Page 30: Presentation day4 oracle12c

30

Cloud Control• Cloud Control 12cR3 onward supports pluggable database functionality. Once you click on the container

database, the "Oracle Database > Control > Open/Close Pluggable Database" menu option allows you to control the state of the PDBs owned by the CDB.

Check detailed contents on http://dbaboss.com/

Page 31: Presentation day4 oracle12c

31

• The "Oracle Database > Provision > Provision Pluggable Database" menu option allows you to perform other operations PDBs owned by the CDB, including cloning, unplugging amongst other things.

Check detailed contents on http://dbaboss.com/

Page 32: Presentation day4 oracle12c

32

Manual (SQL*Plus)• To create a new pluggable database from the seed database, all we have to do is tell Oracle where the file

should be placed. We can do this using one of two methods. The first method uses the FILE_NAME_CONVERT clause in the CREATE PLUGGABLE DATABASE statement.

• CONN / AS SYSDBA• CREATE PLUGGABLE DATABASE pdb2 ADMIN USER pdb_adm IDENTIFIED BY Password1• FILE_NAME_CONVERT=('/u01/app/oracle/oradata/cdb1/pdbseed/','/u01/app/oracle/oradata/cdb1/

pdb2/');• Alternatively, we can specify the PDB_FILE_NAME_CONVERT initialization parameter before calling the

command without using the FILE_NAME_CONVERT clause.• CONN / AS SYSDBA• ALTER SESSION SET PDB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/cdb1/pdbseed/','/u01/app/

oracle/oradata/cdb1/pdb3/';• CREATE PLUGGABLE DATABASE pdb3 ADMIN USER pdb_adm IDENTIFIED BY Password1;• Every time there is a need to convert file locations, either of these two methods will work. For the

remainder of the article I will stick to using the FILE_NAME_CONVERT method to cut down on the variations I have to display.

• We can see the PDBs are present by querying the DBA_PDBS and V$PDBS views.• COLUMN pdb_name FORMAT A20

Check detailed contents on http://dbaboss.com/

Page 33: Presentation day4 oracle12c

33

• SQL>SELECT pdb_name, status• FROM dba_pdbs• ORDER BY pdb_name;

• PDB_NAME STATUS• -------------------- -------------• PDB$SEED NORMAL• PDB1 NORMAL• PDB2 NEW• PDB3 NEW• SQL>

• SELECT name, open_mode• FROM v$pdbs• ORDER BY name;

• NAME OPEN_MODE• ------------------------------ ----------• PDB$SEED READ ONLY• PDB1 MOUNTED• PDB2 MOUNTED• PDB3 MOUNTED

• SQL>

Check detailed contents on http://dbaboss.com/

Page 34: Presentation day4 oracle12c

34

• The PDBs are created with the status of 'NEW'. They must be opened in READ WRITE mode at least once for the integration of the PDB into the CDB to be complete.

• ALTER PLUGGABLE DATABASE pdb2 OPEN READ WRITE;• ALTER PLUGGABLE DATABASE pdb3 OPEN READ WRITE;• SELECT pdb_name, status• FROM dba_pdbs• ORDER BY pdb_name;

• PDB_NAME STATUS• -------------------- -------------• PDB$SEED NORMAL• PDB1 NORMAL• PDB2 NORMAL• PDB3 NORMAL

• SQL>• SELECT name, open_mode• FROM v$pdbs• ORDER BY name;• NAME OPEN_MODE• ------------------------------ ----------• PDB$SEED READ ONLY• PDB1 MOUNTED• PDB2 READ WRITE• PDB3 READ WRITE

• SQL>

Check detailed contents on http://dbaboss.com/