Showing posts with label Multitenant. Show all posts
Showing posts with label Multitenant. Show all posts

Sunday, March 27, 2022

Oracle Multitenant Cheat Sheet

 Oracle Multitenant Cheat Sheet 

Author - ADAM CUNNING 

Essential Termin­ology

Multit­enant
The Oracle Archit­ecture that consists of a CDB, and one or more PDBs
Container Database (CDB)
A tradit­ional database instance, but has the ability to support PDBs
Pluggable Database (PDB)
A collection of Tables­paces which supports it's own indepe­ndant Role and User security, and can be easily moved between CDBs
Root Database
The instance admini­str­ative layer that sets above PDBs. Users and Roles here must be preceded by c##
Seed Database
A PDB that remains offline to be used as a template for creating new blank PDBs

Daily Use Commands (from SQL command line)

Connect to Contaner or PDB
CONN <us­er>/<pw­d>@//<ho­st>:<li­stener port>/<se­rvi­ce> {as sysdba};
CONN <us­er>/<pw­d>@//<tn­s_e­ntr­y> {as sysdba};
Display Current Container or PDB
SHOW CON_NAME;
SELECT SYS_CO­NTE­XT(­'US­ERE­NV'­,'C­ON_­NAME')
SHOW CON_ID;
FROM DUAL;
List Containers and PDBs on Instance
SELECT PDB_NAME, Status
SELECT Name, Open_Mode
SELECT Name,PDB
FROM DBA_PDBS
FROM V$PDBS
FROM V$SERVICES
ORDER BY PDB_Name;
ORDER BY Name;
ORDER BY Name;
Change Container or PDB
ALTER SESSION SET container=<na­me>;
ALTER SESSION SET contai­ner­=cd­b$root;

Clonin­g/C­reating a PDB

First, set your source and target datafile paths...
ALTER SESSION SET PDB_FI­LE_­NAM­E_C­ONV­ERT='</seed path/>','</t­arget path/>';
Then run the create command from the target root contai­ner...
CREATE PLUGGABLE DATABASE <New PDB Name>
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ADMIN USER <Us­ern­ame>
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­IDE­NTIFIED BY <Pa­ssw­ord>
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ FROM <Source PDB[@d­bli­nk]>
Finally, Open the newly created databa­se...
ALTER PLUGGABLE DATABASE <target pdb> OPEN;
NOTE: Creating a PDB is just cloning from the seed db.
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ [@dblink] is optional and used when creating PDB from existing PDB on another instance.
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ If using dblink, the link user should be an admini­str­ative user on the source PDB

Managing a Multit­enant Database

Startup and Shutdown
Startup and Shutdown of a multit­enant database function the same as on a regular database,
 however, if connected to pluggable database, only the pluggable database shuts down. 
If connected to the root container database then the entire instance shuts down. 
Pluggable databases also have their own commands that can be run from the root container or
 other pluggable db.

ALTER PLUGGABLE DATABASE <na­me>OPEN READ WRITE{RESTR­ICT­ED}­{FORCE};
ALTER PLUGGABLE DATABASE <na­me> OPEN READ ONLY {RESTR­ICT­ED}­{FORCE};
ALTER PLUGGABLE DATABASE <na­me> OPEN UPGRADE {RESTR­ICTED};
ALTER PLUGGABLE DATABASE <na­me> CLOSE {IMMED­IATE};
To retain state as startup state of contai­ner...
ALTER PLUGGABLE DATABASE <na­me> SAVE STATE;

Roles and Users
Common Users and Roles must be created in the root container and prefixed by the characters c##
Local Users and Roles must be created in pdb

Granting Roles and Privileges
GRANT <pr­ive­leg­e/r­ole> TO <us­er> CONTAINER=<PDB name or ALL>;
If local only, grant from pdb and omit container argument.

Backup and Recovery

Backup
RMAN connection to root contai­ner...
Normal Backup will capture full instance
For just Root Container
BACKUP DATABASE ROOT
For Pluggable Databases
BACKUP PLUGGABLE DATABASE <pd­b1,­pdb­2,p­db3>

RMAN connection to pluggable database will only work on that pdb

Restore
Connect to root container. Normal restore is full instance. For pdb...
RUN {ALTER PLUGGABLE DATABASE <pd­b> CLOSE;
 ­ ­ ­ ­  SET UNTIL TIME "<ti­meset value>";
 ­ ­ ­ ­  RESTORE PLUGGABLE DATABASE <pd­b>;
 ­ ­ ­ ­  RECOVER PLUGGABLE DATABASE <pd­b>;
 ­ ­ ­ ­  ALTER PLUGGABLE DATABASE <pd­b>OPEN; }

Moving PDB's (Unplu­ggi­ng/­Plu­gging in PDB)

Export­ing­/Un­plu­gging An Existing PDB
To unplug a database, use the following commands. It is recomm­ended that the path used match 
the datafile storage location.
ALTER PLUGGABLE DATABASE <pd­b_n­ame> CLOSE;
ALTER PLUGGABLE DATABASE <pd­b_n­ame> UNPLUG INTO '</p­ath­/><­nam­e>.xml';
DROP PLUGGABLE DATABASE <pd­b_n­ame> KEEP DATAFILES;

Import­ing­/Pl­ugging in PDB into a CDB
Before import­ing­/pl­ugging in a PDB into a CDB a small procedure should be run to Validate the integrity
 and compat­ibility of the PDB.
SET SERVER­OUTPUT ON
DECLARE
 ­ ­ ­ ­ ­l_r­esult BOOLEAN;
BEGIN
 ­ ­ ­ ­ ­l_r­esult := DBMS_P­DB.C­HE­CK_­PLU­G_C­OMP­ATI­BILITY(
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­PDB­_DE­SCR­_FILE => '</p­ath­/><­nam­e>.xml',
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­PDB­_NA­ME       => '<na­me>');
 ­ ­ ­ ­ IF l_result THEN
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­DBM­S_O­UTP­UT.P­UT­_LI­NE(­'Co­mpa­tible, OK to Proceed');
 ­ ­ ­ ­ ELSE
 ­ ­ ­ ­ ­ ­ ­ ­ ­ ­DBM­S_O­UTP­UT.P­UT­_LI­NE(­'In­com­pat­ible, See PDB_PL­UG_­IN_­VIO­LATIONS for details');
 ­ ­ ­ ­ END IF;
END;

If the pdb is validated, then use the following commands to import­/plug it in. Reference the xml file path specified during export, and the datafile path...
CREATE PLUGGABLE DATABASE <ne­w_p­db_­nam­e> USING '</p­ath­/><­nam­e>.xml'
 ­ ­ ­ ­ ­ ­ ­FIL­E_N­AME­_CO­NVE­RT=('</s­ource path/>','</dest path/>');
ALTER PLUGGABLE DATABASE <ne­w_p­db_­nam­e> OPEN;

PROXY Database Functi­onality

A special type of PDB is a Proxy PDB. A Proxy PDB essent­ially is a PDB that is linked to another PDB
 so that if a PDB is being migrated to another enviro­nment and there is a desire to not modify all source
 code to new location references first, they can still use the old references on a Proxy and the actions 
will take place on the New DB.

To setup, first setup a dblink to the pluggable target
CREATE PLUGGABLE DATABASE <proxy pdb name> AS PROXY FROM <target pdb>@<db­lin­k>;
NOTE: dblink may be dropped after proxy db is created
In a proxy DB the alter Database and Alter Pluggable Database commands apply to the proxy db. All other DDL applies to the target db.

Misc Other Multit­enant Management Commands

Cloning from NonCDB to CDB
NonCDB must support multit­enant and use dblink on NONCDB to connect
DBLink user must have CREATE SESSION and CREATE PLUGGABLE DATABASE privileges
CREATE PLUGGABLE DATABASE <ne­w_p­db> FROM NON$CDB@<db­lin­k>
 ­ ­ ­ ­ ­ ­ ­FIL­E_N­AME­_CO­NVE­RT=('</s­ource datafile path/>,'</t­arget datafile path/>');
@ORACL­E_H­OME­/rd­bms­/ad­min­/no­ncd­b_t­o_p­db.sql
ALTER PLUGGABLE DATABASE <target pdb> OPEN;

Moving a PDB
CREATE PLUGGABLE DATABASE <new pdb> FROM <old pdb>@<db­lin­k> RELOCATE;
ALTER PLUGGABLE DATABASE <new pdb> OPEN;

Removing a PDB
ALTER PLUGGABLE DATABASE <na­me> CLOSE;
DROP PLUGGABLE DATABASE <na­me> INCLUDING DATAFILES;

Export­ing­/Un­plu­gging a pdb to a single compressed file
ALTER PLUGGABLE DATABASE <pd­b_n­ame> UNPLUG INTO '</p­ath­/><­fil­ena­me>.pdb';

Import­ing­/Pl­ugging in a pdb from a single compressed file
CREATE PLUGGABLE DATABASE <new pdb name> USING '</p­ath­/><­fil­ena­me>.pdb';
Note that compressed pdb files for export and import are suffixed by .pdb and are a zip fle format.

Saturday, March 19, 2022

Oracle Multitenant Migration

 Oracle Multitenant Migration

Multitenant Support 


What does this mean?

 1. Oracle Database 19c is the last release to support non-CDB architecture

2. Before upgrade to Oracle Database 21c or beyond, you must convert to the mulititenant architecture .




MUTLITENANT MIGRATION

CDB | Components 

CDB$ROOT must be a superset of all PDBs

Recommendation

 1. Install as many components as required 
2. But no more than that 

Number of components have big effect on upgrade duration Components (e.g., JAVAVM) may require patch regular activity

• Always use default of a given version
    • Example 19.0.0
    • Always use three digits only

• Should you change COMPATIBLE after applying a Release Update?
    • Example 19.10
    • Never


Plug In | Compatibility Check 

1. In source, generate manifest file

SQL> exec dbms_pdb.describe('/tmp/DB19.xml');


 2. In CDB, check compatibility

set serveroutput on
BEGIN
IF dbms_pdb.check_plug_compatibility('/tmp/DB19.xml') THEN
dbms_output.put_line('PDB compatible? ==> Yes');
ELSE
dbms_output.put_line('PDB compatible? ==> No');
END IF;
END;
/

3. Always check the details

SQL> select type, message
from PDB_PLUG_IN_VIOLATIONS
where name='DB19' and status<>'RESOLVED';

TYPE         MESSAGE
___________________________________________________________________________________
ERROR '19.9.0.0.0 Release_Update' is installed in the CDB but no release updates are installed in the PDB
ERROR DBRU bundle patch 201020: Not installed in the CDB but installed in the PDB
ERROR PDB's version does not match CDB's version: PDB's version 12.2.0.1.0. CDB's version 19.0.0.0.0.
WARNING CDB parameter compatible mismatch: Previous '12.2.0' Current '19.0.0'
WARNING PDB plugged in is a non-CDB, requires noncdb_to_pdb.sql be run. 


Plug In | Create PDB

1. Restart database in read-only mode

2. Generate manifest file and shut down

3. In CDB, create PDB from manifest file

SQL> shutdown immediate
SQL> startup mount
SQL> alter database open read only;
SQL> exec dbms_pdb.describe('/tmp/DB19.xml');
SQL> shutdown immediate;
SQL> create pluggable database DB19
using '/tmp/DB19.xml' nocopy tempfile reuse;










Convert | Create PDB


1. Open PDB
2. Convert and restart
3. Restart PDB
4. Check plug-in violations
5. Purge
6. Ensure PDB is open READ WRITE and unrestricted
7. Configure PDB to auto-start

SQL> alter pluggable database DB19 open;
SQL> alter session set container=DB19;
SQL> @?/rdbms/admin/noncdb_to_pdb.sql
SQL> alter pluggable database DB19 close;
SQL> alter pluggable database DB19 open;
SQL> select type, message from pdb_plug_in_violations
     where name='DB19' and status<>'RESOLVED';
SQL> select open_mode, restricted from v$pdbs;
SQL> alter pluggable database DB19 save state;

Convert | noncdb_to_pdb.sql

Requires downtime
• Runtime varies - typically 10-30 min
• Fix for Bug 25809128 is included since 19.9.0 and adds a significant improvement
• Runs only once in the life of a database
• Irreversible
• Re-runnable from 12.2


Fallback| PDB Downgrade 

Downgrade works for CDB/PDB entirely as well as for single/multiple PDBs
• Manual tasks
• catdwgrd.sql in current (after upgrade) environment
• catrelod.sql in previous (before upgrade) environment
• Don't change COMPATIBLE
• datapatch must roll back SPUs/PSUs/BPs manually

MOS Note: 2172185.1
How to Downgrade a Single Pluggable Oracle Database ( PDB ) to previous release


Migration | Last Words

Every migration 

• Is an architectural change 
• Requires downtime 
• Requires a fallback 
• Ends with a backup


How to migrate a non pluggable database that uses TDE to pluggable database ?
 (Doc ID 1678525.1)


Data Guard | Migration Options 

It is possible to preserve the standby database when you migrate from non-CDB to PDB

Special attention is needed 
You don't have to rebuild your standby database but you might find it is the easiest solution.



Follow Doc - Multitenant Migration

    
    

Tuesday, March 15, 2022

ORA-65149: PDB Name Conflicts With Existing Service Name

ORA-65149: PDB name conflicts with existing service name in the CDB or the PDB



Issue:

Facing below service conflict error while creating new PDB (Pluggable database)

Error:

ORA-65149: PDB name conflicts with existing service name in the CDB or the PDB

SQL> CREATE PLUGGABLE DATABASE ABC AS CLONE USING '/u01/app/oracle/ABC.xml';
CREATE PLUGGABLE DATABASE ABC AS CLONE USING '/u01/app/oracle/ABC.xml'
  *
ERROR at line 1:
ORA-65149: PDB name conflicts with existing service name in the CDB or the PDB

Verify existing services on CDB

set lines 300
set pages 200
col name for a30;
col PDB for a30;
select SERVICE_ID,NAME,PDB from cdb_SERVICES;


SERVICE_ID NAME                           PDB
---------- --------------------           ---------
         1 SYS$BACKGROUND                 CDB$ROOT
         2 SYS$USERS                      CDB$ROOT
         5 NEWCDBXDB                      CDB$ROOT
         6 NEWCDB                         CDB$ROOT
         3 ORADBXDB                       PDB1
         4 ORADB                          PDB1
         5 DB1DB1XDB                      PDB1
         6 DB1DB1                         PDB2
         7 DB1DMOXDB                      PDB3
    


As per above output ABC service already exists under PDB3 database.

To fix service conflict issue,Connect to PDB3 database and delete ABC service.

                   
SQL> alter session set container=PDB2;

Session altered.

SQL> exec dbms_service.delete_service('
DB1DMOXDB');

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

Now verify services and create PDB

SQL>set lines 300
set pages 200
col name for a30;
col PDB for a30;
select SERVICE_ID,NAME,PDB from cdb_SERVICES;

SERVICE_ID NAME                           PDB
---------- --------------------           ---------
         1 SYS$BACKGROUND                 CDB$ROOT
         2 SYS$USERS                      CDB$ROOT
         5 NEWCDBXDB                      CDB$ROOT
         6 NEWCDB                         CDB$ROOT
         3 ORADBXDB                       PDB1
         4 ORADB                          PDB1
         5 DB1DB1XDB                      PDB1
         6 DB1DB1                         PDB2
         7 DB1DMOXDB                      PDB3

SQL> CREATE PLUGGABLE DATABASE ABC AS CLONE USING '/u01/app/oracle/ABC.xml';


Pluggable database created.


Document Id - 
(Doc ID 2459056.1)

Sunday, October 17, 2021

Check temporary tablespace of CDB or PDB databases

 

Check temporary tablespace of CDB or PDB databases

CDB or PDB temporary tablespace files details:


col db_name for a10 col tablespace_name for a10 col file_name for a25 SELECT vc2.name "db_name",tf.file_name, tf.tablespace_name, autoextensible, maxbytes/1024/1024 "Max_MB", SUM(tf.bytes)/1024/1024 "MB_SIZE" FROM v$containers vc2, cdb_temp_files tf WHERE vc2.con_id = tf.con_id GROUP BY vc2.name,tf.file_name, tf.tablespace_name, autoextensible, maxbytes ORDER BY 1, 2;


Check the aggregated size of temporary tablespace for CDB or PDB databases

Col name for a10col tablespace_name for a15
SELECT  vc2.name, tf.tablespace_name, sum(decode(autoextensible,'NO',bytes,'YES',maxbytes))/1024/1024 "Max Bytes", SUM(tf.bytes)/1024/1024
FROM v$containers vc2, cdb_temp_files tf
WHERE vc2.con_id = tf.con_id
GROUP BY vc2.name, tf.tablespace_name
ORDER BY 1, 2;

Tuesday, August 17, 2021

Startup and Shutdown of a Container Database

 Startup and Shutdown of a Container Database



start and Shutdown Databases :-

SHUTDOWN CONTAINER DATABASES

Connect to CDB


$sqlplus / as sysdba

SQL>shutdown immediate


Start-up Container (CDB)



Connect to CDB

$sqlplus / as sysdba

SQL>startup


Check Pluggable Databases (PDB)


Connect to CDB

$sqlplus / as sysdba
SQL>set linesize 100
col open_time format a25
select con_id,name,open_mode,open_time,ceil(total_size)/1024/1024 total_size_in_mb from v$pdbs
order by con_id asc;


Note: After you restart the CDB your PDBs will be in a mounted state you need to open the PDBs.

CDB CONNECT




Open Pluggable Databases (PDB)


Connect to CDB

$sqlplus / as sysdba
SQL>alter pluggable database all open;


Note: If you just want to open one pluggable database you can use the following.

SQL>alter pluggable database <pdb_name> open;

Check Pluggable Databases (PDB)


Connect to CDB

$sqlplus / as sysdba
SQL>set linesize 100
col open_time format a25
select con_id,name,open_mode,open_time,ceil(total_size)/1024/1024 total_size_in_mb from v$pdbs
order by con_id asc;

We can see after issuing the open state on all pluggable databases the open mode changes to read write.

PDB CONNECT 




Check Services


$sqlplus / as sysdba
SQL>col name format a20
col network_name format a20
select con_id,con_name,name,network_name from v$active_services
order by con_id asc;


CON_ID CON_NAME             NAME                 NETWORK_NAME
---------- -------------------- -------------------- --------------------
         1 CDB$ROOT             SYS$USERS
         1 CDB$ROOT             FNSTCDBXDB            FNSTCDBXDB
         1 CDB$ROOT             FNSTCDB               FNSTCDB
         1 CDB$ROOT             SYS$BACKGROUND
         3 FNST20               FNST20_ebs_patch     FNST20_ebs_patch
         3 FNST20               fnst20               fnst20
         3 FNST20               ebs_FNST20           ebs_FNST20

7 rows selected.





Ref:- http://db12c.blogspot.com/



Saturday, August 7, 2021

Grant SYSDBA Fails With "ORA-01994: GRANT Failed: Password File Missing Or Disabled"

 Grant SYSDBA Fails With "ORA-01994: GRANT Failed: Password File Missing Or Disabled" 



You have set the database parameter REMOTE_LOGIN_PASSWORDFILE to EXCLUSIVE and you have created a password file using the "orapwd" utility
but when you execute the following statement it fails:


SQL> grant SYSDBA to SYS;
grant SYSDBA to SYS
*
ERROR at line 1:
ORA-01994: GRANT failed: password file missing or disabled


The password file was created using this command:


% orapwd file=$ORACLE_HOME/dbs/orapworcl password=<password> entries=10


but ORACLE_SID was set to ORCL.

The $ORACLE_SID part of the password file name is case sensitive.

SOLUTION 

Re-create the password file:

% orapwd file=$ORACLE_HOME/dbs/orapwORCL password=<password> entries=10

or

% orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=<password> entries=10


and then execute the grant again:

SQL> grant SYSDBA to SYS;


for Multitenant Archicture 


SQL> grant sysdba to c##RMANWYCDB container=all;


Grant succeeded.


Sunday, August 1, 2021

Oracle Multitenant -How to Create,Stop,Start,Delete,modify a Database Service Using DBMS_SERVICE in Oracle Database


Oracle Multitenant -

 How to Create,Stop,Start,Delete,modify a Database Service Using DBMS_SERVICE in Oracle Database


Oracle database has PL/SQL package called DBMS_SERVICE which is introduced in Oracle 10g, and has been extended with later releases.  DBMS_SERVICE is used to create,stop,start and define database services.


The dbms_service package has the following stored procedures.

  • create_service
  • start_service
  • stop_service
  • delete_service
  • disconnect_service
  • modify_service
  • activate_service

Set session to PDB

alter session set container=PDB ;


Check available Service

 Display informations about existing services using dba_services view as follows.

COLUMN name FORMAT A30
COLUMN network_name FORMAT A30

SELECT name,
       network_name
FROM   dba_services
ORDER BY 1;


Create a Service

We create a new service using the CREATE_SERVICE procedure. There are two overloads allowing you to amend a number of features of the service. 
One overload accepts an parameter array, while the other allows you to set some parameters directly. 
The only mandatory parameters are the the SERVICE_NAME and the NETWORK_NAME, which represent the internal name of the service in the data 
dictionary and the name of the service presented by the listener respectively.

BEGIN
  DBMS_SERVICE.create_service(
    service_name => 'my_new_service',
    network_name => 'my_new_service'
  );
END;
/

Modify a Service

The MODIFY_SERVICE procedure allows us to alter parameters of an existing service. Like the CREATE_SERVICE procedure, there are two overloads allowing you to amend a number of features of the service. One overload accepts an parameter array, while the other allows you to set some parameters directly.

BEGIN
  DBMS_SERVICE.modify_service(
    service_name => 'my_new_service',
    goal         => DBMS_SERVICE.goal_throughput
  );
END;
/


Stop a Service


The STOP_SERVICE procedure stops an existing service, so it is no longer available for connections via the listener.

BEGIN
  DBMS_SERVICE.stop_service(
    service_name => 'my_new_service'
  );
END;
/

Delete a Service


The DELETE_SERVICE procedure removes an existing service.

BEGIN
  DBMS_SERVICE.delete_service(
    service_name => 'my_new_service'
  );
END;
/

Disconnect a Service


The DISCONNECT_SERVICE procedure removes an existing service.

BEGIN
  DBMS_SERVICE.disconnect_service(
    service_name => 'my_new_service'
  );
END;
/


Save state the PDB. 

Save state the PDB. Other wise service needs to be manually started after PDB open each time.

 SQL> alter pluggable database save state;  
           Pluggable database altered.