Top Banner
Reduce resource consumption and clone in seconds your oracle virtual environment on your laptop using linux containers and btrfs Bertrand Drouvot
27

Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Jul 14, 2015

Download

Technology

BertrandDrouvot
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Reduce resource consumption and clone in seconds your oracle virtual environment on

your laptop using linux containers and btrfs

Bertrand Drouvot

Page 2: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Oracle DBA since 1999

OCP 9i,10g,11g

Rac certified Expert

Exadata certified implementation specialist

Blogger since 2012

@bertranddrouvot

BasketBall fan

About Me

Page 3: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Linux containers (LXC)

btfrs FileSystem

Use case to minimise resource consumption on your laptop

From an oracle DBA point of view

Use case 1: Clone a database software home to apply cpu october on it

Use case 2: Clone a database to apply cpu october on it

Use cases 1 and 2: Without and With LXC

Use case 3: Clone a PDB

Disable COW on a subvolume (Performance reason) and Snap it

Will present

Page 4: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

In depth Linux containers (LXC)

In depth btfrs FileSystem

Will not present

Page 5: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

1. Linux Containers (LXC) allow running multiple isolated Linux instances (containers) on the same host.

2. A way to isolate a group of processes from the others on a running Linux system.

3. Resource management and resource isolation features (Cgroups and name spaces).

4. Processes can have their own private view of the operating system with its own process ID (PID) space, file system structure and network interfaces.

LXC

Page 6: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

LXC (http://www.oracle.com/technetwork/server-storage/linux/technologies/oracle-linux-containers-1898044.html)

Page 7: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

1. Supports large files and file systems.

2. Offers integrated volume management.

3. Has built-in RAID functionality.

4. Keeps data secure using copy-on-write (COW) and checksumming techniques.

5. Provides writable snapshots.

6. COW comes with some advantages, but can negatively affect performance with large files that have small random writes. It is recommended to disable COW for database files and virtual machine images.

btrfs

Page 8: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Copy on write (COW) snapshot

Page 9: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

How does it help?

We can clone in seconds (and using few disk space):

Linux containers

Oracle software

Oracle databases (Non CDB, CDB and PDB)

Only on playground environment! (btrfs not officially supported by oracle see 236826.1& 1601759.1)

Page 10: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Let’s setup the VM, LXC and btrfs (1/7)

Let’s create a OEL 6.5 virtual machine (named lxc) using virtualbox. This virtual machine will host our Linux containers, oracle software and databases

Install lxc and btrfs into the virtual machine created previously

Page 11: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Let’s setup the VM, LXC and btrfs (2/7)

Install a btrfs file system into the virtual machine (this file system will receive the oracle software and databases). To do so, add a disk to your virtualbox machine, start the machine and launch the fs creation:

Page 12: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Let’s setup the VM, LXC and btrfs (3/7)

Add a btrfs file system into the virtual machine (this file system will receive the linux containers). To do so, add a disk to your virtualbox machine, start the machine and launch the fs creation:

Page 13: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Let’s setup the VM, LXC and btrfs (4/7)

Create 2 btrfs subvolumes for the database software and databases:

Page 14: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Let’s setup the VM, LXC and btrfs (5/7)

Add into /etc/hosts the machine (VM) name (LXC in our case):

Page 15: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Let’s setup the VM, LXC and btrfs (6/7)

Install the 12cR1 database software with:

Create a simple database with datafiles, redologs and controlfile located into the /btrfs/databases folder:

Page 16: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Let’s setup the VM, LXC and btrfs (7/7)

Create a linux container (using oracle template) that will be the source of all our new containers:

lxc-create --name cont_source -B btrfs --template oracle -- --

url http://public-yum.oracle.com -R 6.latest -r "perl sudo

oracle-rdbms-server-12cR1-preinstall"

Look at the “-B btrfs” argument to specify that the linux container is created on a BTRFS file system (and then would be able to use the snapshot capability during LXC clone creation).

Page 17: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Use case 1: clone db software + install CPU October

Check FS size: btrfs filesystem df /btrfs

Create a snapshot of the /btrfs/u01 subvolume: btrfs su snapshot /btrfs/u01 /btrfs/u01_patch

Check FS size: btrfs filesystem df /btrfs

Install CPU October 2014

Check FS size: btrfs filesystem df /btrfs

Page 18: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Use case 2: clone database + install CPU October

Check FS size: btrfs filesystem df /btrfs

Clone the database directory: btrfs su snapshot

/btrfs/databases /btrfs/databases_patch

Check FS size: btrfs filesystem df /btrfs

Apply the CPU on the cloned database BDTDB_CPU:

Check FS size: btrfs filesystem df /btrfs

Page 19: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Use cases 1 and 2: with LXC (1/4)

Clone the cont_source linux container machine: lxc-clone -s -t btrfs -o cont_source -n cpu_oct

Clone the database software: btrfs su snapshot /btrfs/u01 /btrfs/u01_cpu_oct

Clone the database directory: btrfs su snapshot /btrfs/databases /btrfs/databases_cpu_oct

Link the cloned subvolumes to the cloned linux container FS (so that everything match the source environment)

Page 20: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Use cases 1 and 2: with LXC (2/4)

Copy oratab, oraenv, dbhome + create mount point directory into the linux container:

cp -p /usr/local/bin/coraenv /usr/local/bin/dbhome

/usr/local/bin/oraenv

/container/cpu_oct/rootfs/usr/local/bin

cp -p /etc/oratab /container/cpu_oct/rootfs/etc/

mkdir -p /container/cpu_oct/rootfs/btrfs/u01

mkdir -p /container/cpu_oct/rootfs/btrfs/databases

mkdir -p

/container/cpu_oct/rootfs/home/oracle/19121550

Start the cloned linux container: lxc-start -n cpu_oct

Page 21: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Use cases 1 and 2: with LXC (3/4)Patch de database software:

Page 22: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Use cases 1 and 2: with LXC (4/4)Patch the database:

Page 23: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

With / without LXC comparisonSoftware cloning:

No need to create a new oratab entry with LXC (simply copy the oratab to the LXC directory).

No need to update the cloned inventory.

Database cloning:

No need to create a new oratab entry with LXC (simply copy the oratab to the LXC directory).

No need to recreate the control file of the duplicated database with LXC.

The config file of the cloned LXC machine just need to ensure that the cloned subvolumes are mounted at the right location.

Page 24: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Use case 3: Duplicate a PDBPut PDB1 in read only mode

alter pluggable database PDB1 open read only;

Generate the PDB1 xml file

alter session set container=PDB1;

exec

dbms_pdb.describe(pdb_descr_file=>’/home/oracle/pdb1.xml');

Create the btrfs clone

btrfs su snapshot /btrfs/databases/oradata/BDTPDB/PDB1

/btrfs/databases/oradata/BDTPDB/PDB2

Create and open the PDB2 PDB

create pluggable database PDB2 AS CLONE using

'/home/oracle/pdb1.xml'

source_file_name_convert=('/btrfs/databases/oradata/BDTPDB/PD

B1','/btrfs/databases/oradata/BDTPDB/PDB2') nocopy tempfile

reuse;

alter pluggable database PDB2 open;

Page 25: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Disable COW on a subvolume (Performance reason) and Snap it (1/2)

Create a new subvolume

btrfs subvolume create /btrfs/databases_cowoff

Disable COW and chown oracle:dba

chattr +C /btrfs/databases_cowoff

chown oracle:dba /btrfs/databases_cowoff

Create a new database (not cloned)

Check new database is not COW

lsattr /btrfs/databases_cowoff/oradata/COWOFF/datafile/*

Page 26: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Disable COW on a subvolume (Performance reason) and Snap it (2/2)

Create a snap

btrfs su snapshot /btrfs/databases_cowoff

/btrfs/databases_cowoff_snap

Create a cloned database

Check cloned database is not COW

lsattr /btrfs/databases_cowoff_snap/oradata/COWOFF/datafile/*

Page 27: Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environment on your Laptop using Linux Containers and BTRFS

Questions?