Wednesday, July 10, 2013

Pluggable Database : An Introduction


What is PDB:


Pluggable database , also referred to as Multitenancy, is the new option of Oracle Database 12c that enables dense database consolidation, rapid provisioning and rapid cloning as well as rapid patching and upgrades. It enables the administrators to manage many databases as one and allows resource management between databases.

In 12c, you can create two types of database: container database and non container database. Container database, referred to as CDB, is the database that can contain several PDBs. Non-container database, referred to as non-CDB, is the regular database that existed prior to 12c.

Multitenacy is  just a deployment choice. When you create a database, you choose whether you want to create a CDB or a non-CDB. Once you make that choice and create the  database, nothing else changes. The way you connect to database and the way you interact with database remains the same for both CDB and non-CDB.


Business challenges that PDB address:


Prior to 12c , database consolidation would happen through one of the following two ways:

1) Server or OS consolidation: You would start several database instances on a single server. Each instance would be on a server virtualized environment like  LDOMs or on an OS virtualized environment such as Solaris Containers.The advantages of this approach is that it provides complete isloation and maximum security. No two distinct database users can ever meddle with each other..as there are usually that many instances as the number of databases. This form of database consolidation cannot provide very dense consolidation as it is not sharing any of the database resources: there are as many copies of Oracle background process and SGA as there are databases so the system very soon exhaust its CPU and memory.

2) Consolidation in the database : You would enable schema based consolidation where each database is represented as a schema in a single monolithic database instance.In this approach, you can consolidate lot of database (schema) into one database instance thereby attaining dense database consolidation. However, the disadvantages are its weak or no name space isolation and very weak security model. A database user can view/change data of another database schema.

Pluggable database provides database consolidation within the database. In a way, it is  a supported version of schema based consolidation with all disadvantages of schema based consolidation removed. Additionally,  it also provides additional features like pluggability and rapid cloining.

 Introduction to Multitenancy architecture:

 

At a higher level, an Oracle Database consist of Oracle Database Instance and Oracle Database. The instance consist of group of Oracle background process and a shared memory. The database consist of group of data files; some of which contain the user data and some contain Oracle system data. When you start an Oracle database, you essentially have a bunch of Oracle background processes, a bunch of shared memory and data files for storing the data. And this gets replicated for each database that is created. So, each database needs additional shared memory and series of Oracle database process....which quickly consumes the available server resources.

With multitenant architecture you can create an empty container database and then plug in the databases as PDBs. Now you are using just one SGA and one set of Oracle database processing thereby saving the system resources to enable dense database consolidation

By consolidating existing databases as PDBs, administrators can manage many databases as one. For example, tasks such as backup and disaster recovery are performed at the level of the CDB. The multitenant architecture also provides the flexibility to take backups and perform point-in-time recovery at the PDB level, if required. 

At a physical level Oracle database consist of a bunch of files: data files as well as bootstrap files like control files, spfile and so on. The physical data files implements the logical entity tablespace which in turn implements tables. Tables hold only three kinds of data

1) metadata that describes the oracle System
2) Metadata that describes the user schema
3) Actual user data .

Prior to 12c, the metadata that describes Oracle system and the metadata that describes user schema were stored collectively in a set of tables that are referred to as data dictionary. This data dictionary tables were stored in dedicated tablespace namely System and Sysaux.


Initially when you create the database, the data dictionary tables only have Oracle system related metadata. Later on when user creates its own data, the data dictionary tables contain user and system metadata. And the user tablespace contains only user data.

Now, if you want to transport a user tablespace from one database to another, you can simply copy the data files containing the tablespace from database location to another . However, you will have to go through the data dictionary view to find out user metadata information and then transport it. If the user metadata information was stored seperately from the Oracle sytem metadata,  than you could simply copy user's tablespace metadata  from one location to another to transport a tablespace.

Hence , in 12c the data dictionary tables got horizontally partitioned;  one partition containing Oracle System metadata is stored in CDB$root container  and another  partition container user data related metadata is stored in the PDB. Now, transporting a tablespace from one database to another means copy the data files as well as files containing the metadata information of user schema. The user related metadata is stored in SYSTEM and SYSAUX tablespaces of PDB and the Oracle metadata is stored in SYSTEM and SYSAUX tablespaces of CDB$root

In other words, each data dictionary table now occurs twice, once for Oracle System and once for the user schema. Every query against a data dictionary table is now a union between the two occurrences of that table.

The primary physical difference between CDB’s and non-CDB is the system data files. A non-CDB has only one set of system data files. In contrast the root and each PDB in a CDB has its own SYSTEM and SYSAUX tablespaces which has its own complete set of dictionary tables describing the objects in itself.

There are two ways for provisioning new PDBs in multitenant architecture.  One is by cloining and another is plug in an previously unplugged PDB.   You clone the PDB when you want an extra copy of that PDB and you plug in a PDB when you want to move the PDB from one CDB to another. When you create a new PDB with out explicitly stating the source PDB from which you want to clone, than Oracle creates the new PDB by cloning that PDB from pdb$seed container. In other words, creation of a PDB is internally a clone operation.


  These operations are done using SQL commands. which  can be executed from any client machine and, hence, access privileges to the server machine are not needed. In addition, the SQL commands can be run in parallel thereby reducing execution times. They can also be programmed in PL/SQL to automate the process of provisioning and cloning.


Thursday, January 17, 2013

Steps to create container for Oracle DB installation

  • Create a vnic named public1

dladm create-vnic public1 -l net0
  • Create a zone.template file as under:
create -b
set zonepath=/oraclePool/zones/test
set limitpriv=default,proc_priocntl
set max-shm-memory=50G
add net
 set physical=public1
end
  • Generate sysconfig.xml file for initial zone configuration
There are two ways to generate the sysconfig.xml file
  • Generate it from scratch by issuing the following command
sysconfig create-profile -o sysconfig.xml
  • Update the hostname by searching system/identity and ip address by searching network/install on an existing sysconfig.xml file
A typical sysconfig.xml file is as under:
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type="profile" name="sysconfig">
  <service version="1" type="service" name="system/config-user">
    <instance enabled="true" name="default">
      <property_group type="application" name="root_account">
        <propval type="astring" name="login" value="root"/>
        <propval type="astring" name="password" value="$5$Px97tHB0$X3mcS7MybV7fk
YTB7Z4NEDDwDJDBPEvIA41w.UmbRm."/>
        <propval type="astring" name="type" value="normal"/>
      </property_group>
    </instance>
  </service>
  <service version="1" type="service" name="system/timezone">
    <instance enabled="true" name="default">
      <property_group type="application" name="timezone">
        <propval type="astring" name="localtime" value="US/Eastern"/>
      </property_group>
    </instance>
  </service>
  <service version="1" type="service" name="system/environment">
    <instance enabled="true" name="init">
      <property_group type="application" name="environment">
        <propval type="astring" name="LANG" value="en_US.UTF-8"/>
      </property_group>
    </instance>
  </service>
  <service version="1" type="service" name="system/identity">
    <instance enabled="true" name="node">
      <property_group type="application" name="config">
        <propval type="astring" name="nodename" value="dat-zone1"/>
      </property_group>
    </instance>
  </service>
  <service version="1" type="service" name="system/keymap">
    <instance enabled="true" name="default">
      <property_group type="system" name="keymap">
        <propval type="astring" name="layout" value="US-English"/>
      </property_group>
    </instance>
  </service>
  <service version="1" type="service" name="system/console-login">
  <instance enabled="true" name="default">
      <property_group type="application" name="ttymon">
        <propval type="astring" name="terminal_type" value="vt100"/>
      </property_group>
    </instance>
  </service>
  <service version="1" type="service" name="network/physical">
    <instance enabled="true" name="default">
      <property_group type="application" name="netcfg">
        <propval type="astring" name="active_ncp" value="DefaultFixed"/>
      </property_group>
    </instance>
  </service>
  <service version="1" type="service" name="network/install">
    <instance enabled="true" name="default">
      <property_group type="application" name="install_ipv4_interface">
        <propval type="astring" name="address_type" value="static"/>
        <propval type="net_address_v4" name="static_address" value="10.129.195.211/24"/>
        <propval type="astring" name="name" value="public1/v4"/>
        <propval type="net_address_v4" name="default_route" value="10.129.195.1"/>
      </property_group>
      <property_group type="application" name="install_ipv6_interface">
        <propval type="astring" name="stateful" value="yes"/>
        <propval type="astring" name="stateless" value="yes"/>
        <propval type="astring" name="address_type" value="addrconf"/>
        <propval type="astring" name="name" value="public1/v6"/>
      </property_group>
    </instance>
  </service>
  <service version="1" type="service" name="system/name-service/switch">
    <property_group type="application" name="config">
      <propval type="astring" name="default" value="files"/>
      <propval type="astring" name="host" value="files dns"/>
      <propval type="astring" name="printer" value="user files"/>
    </property_group>
    <instance enabled="true" name="default"/>
  </service>
 <service version="1" type="service" name="system/name-service/cache">
    <instance enabled="true" name="default"/>
  </service>
  <service version="1" type="service" name="network/dns/client">
    <property_group type="application" name="config">
      <property type="net_address" name="nameserver">
        <net_address_list>
          <value_node value="130.35.249.41"/>
          <value_node value="130.35.249.52"/>
          <value_node value="144.20.190.70"/>
        </net_address_list>
      </property>
      <property type="astring" name="search">
        <astring_list>
          <value_node value="us.oracle.com oraclecorp.com oracle.com"/>
        </astring_list>
      </property>
    </property_group>
    <instance enabled="true" name="default"/>
  </service>
</service_bundle>
  • Execute the following script to configure, install and boot the zone
zoneName=test
zoneTemplate=zone.template
VNIC=public1
echo "zone template : ${zoneTemplate}

echo "Configuring the zone :${zoneName}
zonecfg -z ${zoneName} -f ${zoneTemplate}
echo "Verify that zone ${zoneName} has been configured"
zoneadm list -icv | grep ${zoneName}


echo " Install the zone : ${zoneName}"
zoneadm -z ${zoneName} install -c /tmp/sysconfig.xml
echo "Verify that zone ${zoneName} has been installed"
zoneadm list -icv | grep ${zoneName}


echo "Wait for a minute before booting the zone"
sleep 60
echo "Boot the zone : ${zoneName} "
zoneadm -z ${zoneName} boot
echo "Verify that zone ${zoneName} is running"
zoneadm list -icv | grep ${zoneName}

  • Verify if the smf services are up and running on the zone:
Issue : zlogin  test  ; svcs
If the smf services are not up, login to console for a couple of minutes and check again
zlogin -C test
  • Verify that zone is up and running

ping <zone-hostname> from global zone
ping <global-hostname> from local zone
Verify network is configured correctly in the local zone
zlogin  test
root@dat-zone1:~# dladm show-physroot@dat-zone1:~# dladm show-vnic
LINK                OVER         SPEED  MACADDRESS        MACADDRTYPE       VID
public1             ?            1000   2:8:20:af:91:c8   random            0
root@dat-zone1:~# ipadm show-addr
ADDROBJ           TYPE     STATE        ADDR
lo0/v4            static   ok           127.0.0.1/8
public1/v4        static   ok           10.129.195.211/24
lo0/v6            static   ok           ::1/128
public1/v6        addrconf ok           fe80::8:20ff:feaf:91c8/10
root@dat-zone1:~#


Add asm disk and the directory where the Oracle bits are available to zone and reboot the zone. 
Create a file named addtoZone.template

add device
        set match=/dev/rdsk/c2t8d3s2
        set allow-partition=true
        set allow-raw-io=true
end
add fs
   set dir=/installer
set special=/installer
set type=lofs
end
   

Reconfigure and reboot the zone


zonecfg -z test -f addtoZone.template
zonecfg -z test reboot
Prepare for Oracle installation. Install Oracle and asm

Log on to test container and execute the following script:
asmDisk=/dev/rdsk/c2t8d3s2
groupadd -g 201 dba
groupadd -g 200 oinstall
useradd -g oinstall -G dba -u 200 oracle
mkdir /export/home/oracle
chown -R oracle:oinstall /export/home/oracle
mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01
chmod -R 775 /u01
echo "Enter password for Oracle"
passwd oracle
pkg install   SUNWarc SUNWbtool SUNWhea SUNWlibm SUNWlibms SUNWpool SUNWsprot SUNWtoo SUNWuiu8 SUNWfont-xorg-core SUNWfont-xorg-iso8859-1 SUNWmfrun SUNWxorg-client-programs SUNWxorg-clientlibs SUNWxwfsw  pkg://solaris/SUNWxwplt
chown oracle:oinstall ${asmDisk}
chmod 660 ${asmDisk}
Invoke grid installer and db installer to install ASM and Oracle DB.

V2V across servers : From non-global zone on one server to non-global zone on another server

I have a non-global zone, namely db1Zone, on server dat01. The following post explains the steps to migrate this zone to a non-global zone in another server dat02.

  • Create a archive of db1Zone that needs to be migrated:
zoneadm -z db1Zone shutdown
zoneadm -z db1Zone detach
zonecfg -z db1Zone export > db1Zone.cfg
zfs list -H -o name /zonespool/zones/db1Zone ; zoneroot can  be obtained from db1Zone.cfg
zfs snapshot -r zonespool/zones/db1Zone@migr
zfs send -rc zonespool/zones/db1Zone@migr > db1Zone.zfs

Detaching a zone is the first step in moving a zone from one step to anoter. Once the zone is detached,it is left in the configured state. If you try to install or clone to a configured zone that has been detached, you will receive an error message and install or clone process will fail.
  • Ensure that target server, dat02, is at the same OS patch level as source server, dat01.

  • Create the zone named db1Zone on target server
Copy db1Zone.cfg and db1Zone.zfs files to dat02 server
Make any required changes to db1Zone.cfg file. The network information will remain the same. Update any disk related info
Create the zone issuing the following command
zonecfg -z db1Zone -f db1Zone.cfg
Attach the source zone to this zone
  • zoneadm -z db1Zone attach -U -a /export/home/oracle/db1Zone.zfs
Additional info:
Errors

  • ERROR: Argument db1Zone.zfs is not a regular file
root@dat02:/export/home/oracle# zoneadm -z db2Zone attach -a db1Zone.zfs
ERROR: Argument db1Zone.zfs is not a regular file

Specify the complete path of the archive file. If the problem still exist, verify that target system is on the same OS patch level as the source system.


  • cannot receive: stream has unsupported feature, feature flags = 0

If the log file has the following info:

   Installing: This may take several minutes...
[Tue Jun  5 12:01:14 PDT 2012] gzcat /tmp/db1Zone.zfs.gz | zfs receive -F -u -x zoned rpool/zonespool/zones/db1Zone/installtmp/ds
cannot receive: stream has unsupported feature, feature flags = 0
[Tue Jun  5 12:01:14 PDT 2012] ERROR: Error: Command <zfs receive -F -u -x zoned rpool/zonespool/zones/db1Zone/installtmp/ds> exited with status 1

Verify that the target system is on the same OS patch level as the source system.