Sunday, March 17, 2019

Moving PDB in between CDB's


Step 1: Let's create PDB1 for demo
> create pluggable database pdb1
  admin user pdb1_admin identified by password
  role = (dba)
  default tablespace pdb1_ts datafile '/mnt/san_storage/oradata/orcl12c/pdb1/pdb1_ts_datafile1.dbf' size 50M autoextend on
  file_name_convert = ('/oradata/orcl12c/pdbseed','/oradata/orcl12c/pdb1');


Step 2: Open the PDB1
> alter pluggable database pdb1 open;


Step 3: For Moving PDB1, first close the PDB1
> alter pluggable database pdb1 close;


Step 4: Unplug the database
> alter pluggable database pdb1 unplug into 'mnt/san_storage/oradata/orcl12c/pdb1/pdb1.xml';


Step 5: Drop the database PDB1 keeping the datafiles;
> drop pluggable database pdb1 keep datafiles;


Step 6: Now plug PDB1 to the new CDB
> connect cdb$root of new CDB as sysdba
> create pluggable database pdb1_new using '/mnt/san_storage/oradata/orcl12c/pdb1/pdb1.xml' nocopy tempfile reuse;
Note : We can give new pdb name while using xml file or we can use the same name.


Step 7: Open newely plugged PDB1_NEW in the new CDB.
> alter pluggable database pdb1_new open;

Saturday, March 16, 2019

How to Create, Connect and Drop Pluggable database(PDB)


Some conceptual points for Create PLUGGABLE database -
  • Oracle 12c uses SEED$PDB as template to create new PDB's.
  • When you create a new PDB from SEED$PDB, you have to define admin user for that new PDB. This creates a local user inside the PDB.
  • Admin command also grants the PDB_DBA role to the ADMIN user that we created.
  • By default "CREATE PLUGGABLE DATABASE" command does not grant any privileges to the PDB_DBA role itself. So our admin user is powerless.
  • In order to let this user to control PDB, we have to explicitly grant dba role to PDB user.



Following is the command used to create new pluggable database in Oracle 12c.
> CREATE PLUGGABLE DATABASE my_new_pdb
   ADMIN USER my_pdb_admin IDENTIFIED BY password
   ROLES = (dba)
   DEFAULT TABLESPACE my_tbs 
   DATAFILE '/mnt/san_storage/oradata/orcl12c/my_new_pdb/mytbs01.dbf' SIZE 50M AUTOEXTEND ON
   FILE_NAME_CONVERT=('/oradata/orcl12c/pdbseed/','/oradata/orcl12c/my_new_pdb/');










To Check if this PDB is created run the following command
> select con_id, name from v$pdbs;









To connect the PDB, run following commands -
> alter pluggable database my_new_pdb open;
> exit;

sqlplus my_pdb_admin/password@localhost:1523/my_new_pdb
> show con_name;
> show con_id;
























Or, You can also use "alter session" command to directly connect to any container
> alter session set container = my_new_pdb;
> alter session set container = cbd$root;


To drop PDB use the following commands
> alter pluggable database my_new_pdb close;
> drop pluggable database my_new_pdb including datafiles;


















Thursday, March 14, 2019

How to check database size in Oracle


A DBA works on many aspects of database like cloning, backup, performance tuning etc. In every aspect of database administration, most of the times resolution depends upon the size of database. For example, DBA can implement DB FULL backup strategy on a very small database when compared to DB INCREMENTAL strategy on a very large database.

Use below script to check db size along with Used space and free space in database:

col "Database Size" format a20
col "Free space" format a20
col "Used space" format a20
select round(sum(used.bytes) / 1024 / 1024 / 1024 ) || ' GB' "Database Size" , round(sum(used.bytes) / 1024 / 1024 / 1024 ) - round(free.p / 1024 / 1024 / 1024) || ' GB' "Used space" , round(free.p / 1024 / 1024 / 1024) || ' GB' "Free space" from (select bytes from v$datafile union all select bytes from v$tempfile union all select bytes from v$log) used , (select sum(bytes) as p from dba_free_space) free group by free.p /


How to disable firewall in Linux 7


Firewall Status 
The below command will show you the current status “Active” in case firewall is running: 
# systemctl status firewalld

Firewall stop / start 
# service firewalld stop 
# service firewalld start 
You can start/stop Linux firewall with below commands:

Firewall Disable / Enable 
You can enable/disable firewall completely on Linux with below commands: 
# systemctl disable firewalld 
# systemctl enable firewalld

Oracle Database Administrator