Pages

Tuesday, July 30, 2013

How to create a pluggable database by cloning an existing local PDB

Using the CREATE PLUGGABLE DATABASE ... FROM command you can clone an existing pluggable database (the source pdb) to create a new pdb (the clone pdb).
The source pdb could be in the current local container or it can be located in a remote container (in a next post): during a clone of a remote pdb you need to use a database link referencing the remote container in the FROM clause.

Let's start cloning a local pluggable database. Be sure the current container is the root
SQL> show con_name;

CON_NAME
------------------------------
CDB$ROOT
Here are my current pluggable databases and I want to clone PDB001 which contains the user MARCOV and the table T1 (with 100 rows)
SQL> select name, open_mode from V$PDBS;

NAME          OPEN_MODE
------------------------------ ----------
PDB$SEED         READ ONLY
PDB001          READ WRITE
PDB002          READ WRITE

SQL> alter session set container=PDB001;

Session altered.

SQL> create user marcov identified by marcov quota unlimited on users;

User created.

SQL> grant create session to marcov;

Grant succeeded.

SQL> grant create table to marcov;

Grant succeeded.

SQL> connect marcov/marcov@PDB001
Connected.
SQL> show user
USER is "MARCOV"
SQL> show con_name

CON_NAME
------------------------------
PDB001

SQL> create table T1 (a number);

Table created.

SQL> create table T1 (a number);

Table created.

SQL> insert into T1 select level from dual connect by level < 101;

100 rows created.

SQL> commit;

Commit complete.

SQL> connect / as sysdba
Connected.
SQL> show user
USER is "SYS"
SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT
Here is the content of my tnsnames.ora file
CDB001 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = CDB001)
    )
  )

PDB001 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PDB001)
    )
  )
To clone the source pluggable database PDB001 I need to open it in READ ONLY mode
SQL> select name, open_mode from v$pdbs;

NAME          OPEN_MODE
------------------------------ ----------
PDB$SEED         READ ONLY
PDB001          READ WRITE
PDB002          READ WRITE

SQL> alter pluggable database PDB001 open read only force;

Pluggable database altered.
On my file system I have the following directories and files.
[oracle@localhost CDB001]$ pwd
/app/oracle/oradata/CDB001
[oracle@localhost CDB001]$ ll
total 2163224
-rw-r-----. 1 oracle oinstall  17973248 Jul 30 13:12 control01.ctl
drwxr-x---. 2 oracle oinstall      4096 Jul 20 15:29 PDB001
drwxr-x---. 2 oracle oinstall      4096 Jul 20 16:22 PDB002
drwxr-x---. 2 oracle oinstall      4096 Jul 15 22:07 pdbseed
-rw-r-----. 1 oracle oinstall  52429312 Jul 30 13:12 redo01.log
-rw-r-----. 1 oracle oinstall  52429312 Jul 29 22:06 redo02.log
-rw-r-----. 1 oracle oinstall  52429312 Jul 30 02:32 redo03.log
-rw-r-----. 1 oracle oinstall 817897472 Jul 30 13:11 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 817897472 Jul 30 13:06 system01.dbf
-rw-r-----. 1 oracle oinstall  76554240 Jul 30 13:11 temp01.dbf
-rw-r-----. 1 oracle oinstall 325066752 Jul 30 13:10 undotbs01.dbf
-rw-r-----. 1 oracle oinstall   5251072 Jul 30 02:37 users01.dbf
Here is the content of PDB001 directory.
[oracle@localhost CDB001]$ ll PDB001/
total 922516
-rw-r-----. 1 oracle oinstall   5251072 Jul 30 13:08 PDB001_users01.dbf
-rw-r-----. 1 oracle oinstall 665853952 Jul 30 13:08 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 272637952 Jul 30 13:08 system01.dbf
-rw-r-----. 1 oracle oinstall  20979712 Jul 21 17:51 temp01.dbf
I'm going to create a new pluggable database called PDB003, cloning PDB001. The command to clone a pluggable database locally is the following:
SQL> create pluggable database PDB003 from PDB001 file_name_convert=('/app/oracle/oradata/CDB001/PDB001','/app/oracle/oradata/CDB001/PDB003');

Pluggable database created.
New files and directories are created. Note also the same name of the datafile PDB001_users01.dbf used as default tablespace for PDB003.
[oracle@localhost CDB001]$ ll
total 2163228
-rw-r-----. 1 oracle oinstall  17973248 Jul 30 13:19 control01.ctl
drwxr-x---. 2 oracle oinstall      4096 Jul 20 15:29 PDB001
drwxr-x---. 2 oracle oinstall      4096 Jul 20 16:22 PDB002
drwxr-x---. 2 oracle oinstall      4096 Jul 30 13:17 PDB003
drwxr-x---. 2 oracle oinstall      4096 Jul 15 22:07 pdbseed
-rw-r-----. 1 oracle oinstall  52429312 Jul 30 13:18 redo01.log
-rw-r-----. 1 oracle oinstall  52429312 Jul 29 22:06 redo02.log
-rw-r-----. 1 oracle oinstall  52429312 Jul 30 02:32 redo03.log
-rw-r-----. 1 oracle oinstall 817897472 Jul 30 13:18 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 817897472 Jul 30 13:17 system01.dbf
-rw-r-----. 1 oracle oinstall  76554240 Jul 30 13:18 temp01.dbf
-rw-r-----. 1 oracle oinstall 325066752 Jul 30 13:16 undotbs01.dbf
-rw-r-----. 1 oracle oinstall   5251072 Jul 30 02:37 users01.dbf
[oracle@localhost CDB001]$ ll PDB003
total 921688
-rw-r-----. 1 oracle oinstall   5251072 Jul 30 13:18 PDB001_users01.dbf
-rw-r-----. 1 oracle oinstall 665853952 Jul 30 13:18 sysaux01.dbf
-rw-r-----. 1 oracle oinstall 272637952 Jul 30 13:18 system01.dbf
-rw-r-----. 1 oracle oinstall  20979712 Jul 30 13:17 temp01.dbf
After the command is sucessfully completed the status and the open mode of the new pluggable database are NEW and MOUNTED.
SQL> select PDB_NAME, STATUS from CDB_PDBS;

PDB_NAME   STATUS
---------- -------------
PDB$SEED   NORMAL
PDB001    NORMAL
PDB002    NORMAL
PDB003    NEW

SQL> select name, open_mode from V$PDBS;

NAME          OPEN_MODE
------------------------------ ----------
PDB$SEED         READ ONLY
PDB001          READ ONLY
PDB002          READ WRITE
PDB003          MOUNTED
A new service is created too.
SQL> select name, pdb from V$SERVICES order by creation_date;

NAME       PDB
-------------------- ------------------------------
CDB001XDB      CDB$ROOT
SYS$BACKGROUND      CDB$ROOT
CDB001       CDB$ROOT
SYS$USERS      CDB$ROOT
pdb001       PDB001
pdb002       PDB002
pdb003       PDB003
You can now open both pluggable databases with one simply command (have a look at this post for more information about the syntax and examples)
SQL> alter pluggable database PDB001,PDB003 open READ WRITE FORCE;

Pluggable database altered.

SQL> select name, open_mode from V$PDBS;

NAME       OPEN_MODE
-------------------- ----------
PDB$SEED      READ ONLY
PDB001       READ WRITE
PDB002       READ WRITE
PDB003       READ WRITE

SQL> select PDB_NAME, STATUS from CDB_PDBS;

PDB_NAME   STATUS
---------- -------------
PDB$SEED   NORMAL
PDB001    NORMAL
PDB002    NORMAL
PDB003    NORMAL
Add the following entry on the tnsnames.ora file.
PDB003 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PDB003)
    )
  )
Let's see my data on PDB003 and on PDB001
SQL> connect marcov/marcov@PDB003
Connected.
SQL> show con_name

CON_NAME
------------------------------
PDB003
SQL> select count(*) from marcov.T1;

  COUNT(*)
----------
       100

SQL> connect marcov/marcov@PDB001
Connected.
SQL> show con_name

CON_NAME
------------------------------
PDB001
SQL> select count(*) from marcov.T1;

  COUNT(*)
----------
       100
It is not possible to create a new pdb cloning a local or a remote seed: to create a new pdb from the seed you have to follow this post. If you try to clone from the seed template you will receive the ORA-65000 error, described below:
SQL> create pluggable database PDB004 from PDB$SEED file_name_convert=('/app/oracle/oradata/CDB001/pdbseed','/app/oracle/oradata/CDB001/PDB004');
create pluggable database PDB004 from PDB$SEED file_name_convert=('/app/oracle/oradata/CDB001/pdbseed','/app/oracle/oradata/CDB001/PDB004')
                          *
ERROR at line 1:
ORA-65000: missing or invalid pluggable database name

[oracle@localhost pdbseed]$ oerr ora 65000
65000, 00000, "missing or invalid pluggable database name"
// *Cause:  A valid pluggable database name was not present where required 
//     by the syntax of a CREATE PLUGGABLE DATABASE, ALTER PLUGGABLE
//          DATABASE or DROP PLUGGABLE DATABASE statement.
// *Action: Reissue the statement with a valid pluggable database name.

That's all.

How to change the open mode of all pluggable databases

When you need to modify the open mode of all your PDBs at the same time (look at this post if you want to change the open mode of only a specific pluggable database) you can use ALTER PLUGGABLE DATABASE command and the ALL option.
As usual you have to ensure that the current container is the root.
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;

SYS_CONTEXT('USERENV','CON_NAME')
--------------------------------------------------------------------------------
CDB$ROOT
The following statement for example changes the open mode of all your pluggable databases at the same time.
SQL>ALTER PLUGGABLE DATABASE ALL CLOSE IMMEDIATE;

Pluggable database altered.

SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          MOUNTED     3
PDB002          MOUNTED     4
When you need to change the open mode of all pluggable database except for listed ones you can include also the EXCEPT option as in the following example:
SQL> ALTER PLUGGABLE DATABASE ALL EXCEPT PDB001 OPEN READ WRITE;

Pluggable database altered.

SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          MOUNTED     3
PDB002          READ WRITE    4
To open all my pluggable databases I can simply execute the following command. It doesn't take care that PDB002 is already open in READ WRITE mode: any error is returned because the pluggable databases are in different open mode.
SQL> ALTER PLUGGABLE DATABASE ALL OPEN READ WRITE;

Pluggable database altered.

SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ WRITE    3
PDB002          READ WRITE    4
However, if any of your pluggable databases are in READ ONLY mode, then the statement returns the error "ORA-65019: pluggable database PDB001 already open" as you can see:
SQL> ALTER PLUGGABLE DATABASE ALL CLOSE IMMEDIATE;

Pluggable database altered.

SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          MOUNTED     3
PDB002          MOUNTED     4

SQL> ALTER PLUGGABLE DATABASE PDB001 OPEN READ ONLY;

Pluggable database altered.

SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ ONLY    3
PDB002          MOUNTED     4

SQL> ALTER PLUGGABLE DATABASE ALL OPEN READ WRITE;
ALTER PLUGGABLE DATABASE ALL OPEN READ WRITE
*
ERROR at line 1:
ORA-65019: pluggable database PDB001 already open
Even if the statement fails for pluggable database PDB001 it was able to open PDB002 as requested:
SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ ONLY    3
PDB002          READ WRITE    4
To avoid the error ORA-65019 you can include the FORCE option in your command:
SQL> ALTER PLUGGABLE DATABASE ALL OPEN READ WRITE FORCE;

Pluggable database altered.

SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ WRITE    3
PDB002          READ WRITE    4
To shutdown all your pluggable databases except one you can use the following command:
SQL> alter pluggable database all except PDB002 close immediate;

Pluggable database altered.

SQL> select name, open_mode from V$PDBS;

NAME          OPEN_MODE
------------------------------ ----------
PDB$SEED         READ ONLY
PDB001          MOUNTED
PDB002          READ WRITE
To list some of your pluggable databases you can use the comma as in the following example where I need to open all my pluggable databases (PDB001 and PDB002) except those listed (just PDB001 and PDB002!!). Nothing happens of course.
SQL> alter pluggable database all except PDB002,PDB001 open;

Pluggable database altered.

SQL> select name, open_mode from V$PDBS;

NAME          OPEN_MODE
------------------------------ ----------
PDB$SEED         READ ONLY
PDB001          MOUNTED
PDB002          READ WRITE
That's all.

Monday, July 29, 2013

Pluggable database: limitations of the open mode of the CDB imposed on the open mode of PDBs

The open mode of the container database imposes limitations on the open mode of PDBs.
For example, the root must be open before any PDBs can be open. Therefore, you might need to change the open mode of the root before changing the open mode of a PDB. Let's start.

Verify you are connected to the root container.
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;

SYS_CONTEXT('USERENV','CON_NAME')
--------------------------------------------------------------------------------
CDB$ROOT
Verify the open mode from the V$DATABASE view.
SQL> select name, con_id, open_mode from v$database;

NAME       CON_ID OPEN_MODE
--------- ---------- --------------------
CDB001     0 READ WRITE
I've two pluggable databases in the current container: I want to close the pluggable database called PDB001.
SQL> alter pluggable database PDB001 close immediate;

Pluggable database altered.
Verify the open mode from the V$PDBS view.
One of my pluggable databases (PDB002) is available in READ WRITE mode, the second (PDB001) is in MOUNTED mode. The seed (PDB$SEED) is a template that you can use to create new PDBs and is always in READ ONLY mode.
SQL> select name, con_id, open_mode from v$pdbs;

NAME       CON_ID OPEN_MODE
------------------------------ ---------- ----------
PDB$SEED    2 READ ONLY
PDB001     3 MOUNTED
PDB002     4 READ WRITE
What does it happen to pluggable databases when you shutdown the root container and open it again in MOUNT mode ?
SQL> shutdown immediate;    
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  626327552 bytes
Fixed Size      2291472 bytes
Variable Size    473958640 bytes
Database Buffers   146800640 bytes
Redo Buffers      3276800 bytes
Database mounted.
The root container is in MOUNTED mode as expected.
SQL> select name, con_id, open_mode from v$database;

NAME       CON_ID OPEN_MODE
--------- ---------- --------------------
CDB001     0 MOUNTED

SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;

SYS_CONTEXT('USERENV','CON_NAME')
--------------------------------------------------------------------------------
CDB$ROOT
The three pluggable databases are all in MOUNTED mode too.
SQL> select name, con_id, open_mode from v$pdbs;

NAME       CON_ID OPEN_MODE
------------------------------ ---------- ----------
PDB$SEED    2 MOUNTED
PDB001     3 MOUNTED
PDB002     4 MOUNTED
You cannot open a pluggable database if the container is not open.
SQL> alter pluggable database PDB001 open read write;
alter pluggable database PDB001 open read write
*
ERROR at line 1:
ORA-01109: database not open
Open first the CDB instance containing the root, the seed and its pluggable databases.
SQL> alter database open;

Database altered.

SQL> select name, con_id, open_mode from v$database;

NAME       CON_ID OPEN_MODE
--------- ---------- --------------------
CDB001     0 READ WRITE
The seed database is now put in READ ONLY mode; the other two pluggable databases are still in MOUNTED mode. So they don't start automatically and you have to take care of this.
SQL> select name, con_id, open_mode from v$pdbs;    

NAME       CON_ID OPEN_MODE
------------------------------ ---------- ----------
PDB$SEED    2 READ ONLY
PDB001     3 MOUNTED
PDB002     4 MOUNTED
You can now open pluggable databases as you want. I'm going to open a pluggable database, PDB001, in READ ONLY mode and then PDB002 in READ WRITE mode.
SQL> alter pluggable database pdb001 open read only;

Pluggable database altered.

SQL> alter pluggable database pdb002 open;          

Pluggable database altered.

SQL> select name, con_id, open_mode from v$pdbs;

NAME       CON_ID OPEN_MODE
------------------------------ ---------- ----------
PDB$SEED    2 READ ONLY
PDB001     3 READ ONLY
PDB002     4 READ WRITE
As you can see I didn't specify to open the pluggable database PDB002 in READ WRITE mode: as usual when you don't specify a valid option the READ WRITE is the default mode.

To open also the PDB001 pluggable database in READ WRITE mode you can use the following command and the FORCE option.
SQL> alter pluggable database PDB001 open read write force;

Pluggable database altered.

SQL> select name, con_id, open_mode from v$pdbs;

NAME       CON_ID OPEN_MODE
------------------------------ ---------- ----------
PDB$SEED    2 READ ONLY
PDB001     3 READ WRITE
PDB002     4 READ WRITE

That's all.

Sunday, July 28, 2013

How to change the open mode of listed PDBs

The clauses of the ALTER PLUGGABLE DATABASE statement that modify the mode of a PDB are:
- OPEN READ WRITE [RESTRICTED] [FORCE]: it opens the PDB in read/write mode;
- OPEN READ ONLY [RESTRICTED] [FORCE]: it opens the PDB in read-only mode;
- OPEN UPGRADE [RESTRICTED]: it opens the PDB in migrate mode;
- CLOSE [IMMEDIATE]: it places the PDB in mounted mode and it is the PDB equivalent of the SQL*Plus SHUTDOWN command;

When using the RESTRICTED option, only users with RESTRICTED SESSION privilege can log into the PDB: all other sessions connected to the PDB without RESTRICTED SESSION privilege are terminated and their transactions rolled back.
When FORCE is specified, the statement opens a PDB that is currently closed and changes the open mode as specified.

To modify the open mode of one or more PDBs you have to ensure that the current container is the root:
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;

SYS_CONTEXT('USERENV','CON_NAME')
--------------------------------------------------------------------------------
CDB$ROOT
Let's get information about current pluggable databases querying the V$PDBS view:
SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ WRITE    3
PDB002          READ WRITE    4
I want to "shutdown" the pluggable database identified as PDB001: all current connected sessions will be terminated and their transaction rolled back.
You need to use the alter pluggable database command:
SQL> alter pluggable database pdb001 close immediate;

Pluggable database altered.
The specified pluggable database is put in MOUNTED mode:
SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          MOUNTED     3
PDB002          READ WRITE    4
If you want to open the pluggable database PDB001 in READ ONLY mode you can use again the alter pluggable database command:
SQL> alter pluggable database pdb001 open read only;

Pluggable database altered.
It's now open in READ ONLY mode.
SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ ONLY    3
PDB002          READ WRITE    4
What does it happen when you try to open it in READ WRITE mode ?
SQL> alter pluggable database pdb001 open read write;
alter pluggable database pdb001 open read write
*
ERROR at line 1:
ORA-65019: pluggable database PDB001 already open
Oracle throws the following exception:
[oracle@localhost trace]$ oerr ora 65019
65019, 00000, "pluggable database %s already open"
// *Cause:  An attempt was made to open a pluggable database that was already
//          opened.
// *Action: Check V$PLUGGABLE_DATABASE.STATE.
If you want to open in READ WRITE mode your pluggable database, currently in READ ONLY mode, you have to add the FORCE option to the previous command:
SQL> alter pluggable database pdb001 open read write force;

Pluggable database altered.
The pluggable database is now open in READ WRITE mode again:
SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ WRITE    3
PDB002          READ WRITE    4

In the next post I will decribe the limitations of the open mode of the root imposed on the open mode of PDBs.

That's all.

Sunday, July 21, 2013

How to create a pluggable database PDB in a multitenant container database CDB using the files of the seed PDB$SEED

The new architecture provided by Oracle Database 12c enables an Oracle database to function as a multitenant container database (CDB):
it can include zero, one, or many pluggable databases (PDBs), that is a portable collection of schemas, schema objects and nonschema objects.

A multitenant container database (CDB) is formed by the following components:
- the root container (and exactly one root) named CDB$ROOT that stores Oracle-supplied metadata and common users (a database user known in every container);
- the seed template (and exactly one seed) named PDB$SEED used, if you want, to create new PDBs. It's not possible to add objects to or modify objects in the seed: it works only in READ ONLY mode;
- pluggable databases (zero, one, or many PDBs) named as you prefer that are your "old idea of databases" before Oracle Database 12c. A pluggable database contains the data and code required by your software application and is fully backward compatible with Oracle Database releases before Oracle Database 12c.

The options for creating a pluggable database (the so called PDB) fall into two main categories: copying and plugging in as you will see in this post and in the next posts.

Talking about copying, you have two options to copy a pluggable database:
  • create a pluggable database (PDB) in a multitenant container database (CDB) using the files of the seed (PDB$SEED);
  • create it by cloning a source PDB and plugging the clone into the CDB (bear in mind that the source PDB can be in the local CDB or in a remote CDB). 

Today I'm going to describe how to copy a pluggable database using the files of the seed from the SQL*Plus command line.

If you want to see how to create a pluggable database copying the files of the seed using DBCA you can simply watch the following video (I will create a post about it using screenshot as soon as possible).

To create a new pluggable database copying the files of the seed you have to ensure that the current container is the root:
SQL> SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;

SYS_CONTEXT('USERENV','CON_NAME')
--------------------------------------------------------------------------------
CDB$ROOT
and your multitenant container database CDB must be also in read/write mode. My CDB is called CDB001:
SQL> select NAME, CDB, CON_ID, OPEN_MODE from V$DATABASE;

NAME   CDB   CON_ID OPEN_MODE
--------- --- ---------- --------------------
CDB001   YES        0 READ WRITE
Your script must include the CREATE PLUGGABLE DATABASE statement and eventually some other clauses, such as the following I used in my script:
- STORAGE: specify the limit of the amount of storage the PDB can use. Omitting this clause is equivalent to specify an unlimited amount;
- DEFAULT TABLESPACE: specify a default permanent tablespace for non-SYSTEM users. When you omit this clause the SYSTEM tablespace will be used as default permanent tablespace for non-SYSTEM users and this is not recommended;
- FILE_NAME_CONVERT: specify the target locations of the data files whereas the source files are those associated with the seed. This parameter is required when Oracle Managed Files is not enabled and the PDB_FILE_NAME_CONVERT initialization parameter is not set
- other clauses you can use are: ROLES, TEMPFILE REUSE and PATH_PREFIX.
SQL> CREATE PLUGGABLE DATABASE PDB002 
  2  ADMIN USER PDB002_ADMIN IDENTIFIED BY oracle
  3  storage (maxsize 5G MAX_SHARED_TEMP_SIZE 500M)
  4  DEFAULT TABLESPACE "USERS" DATAFILE '/app/oracle/oradata/CDB001/PDB002/PDB002_users01.dbf' SIZE 5M REUSE AUTOEXTEND ON 
  5  file_name_convert=('/app/oracle/oradata/CDB001/pdbseed/system01.dbf','/app/oracle/oradata/CDB001/PDB002/system01.dbf','/app/oracle/oradata/CDB001/pdbseed/sysaux01.dbf','/app/oracle/oradata/CDB001/PDB002/sysaux01.dbf','/app/oracle/oradata/CDB001/pdbseed/temp01.dbf','/app/oracle/oradata/CDB001/PDB002/temp01.dbf');

Pluggable database created.
From the alert log (vi /app/oracle/diag/rdbms/cdb001/CDB001/trace/alert_CDB001.log):
Sat Jul 20 16:21:48 2013
CREATE PLUGGABLE DATABASE PDB002 ADMIN USER PDB002_ADMIN IDENTIFIED BY * storage (maxsize 5G MAX_SHARED_TEMP_SIZE 500M) DEFAULT TABLESPACE "USERS" DATAFILE '/app/oracle/oradata/CDB001/PDB002/PDB002_users01.dbf' SIZE 5M REUSE AUTOEXTEND ON file_name_convert=('/app/oracle/oradata/CDB001/pdbseed/system01.dbf','/app/oracle/oradata/CDB001/PDB002/system01.dbf','/app/oracle/oradata/CDB001/pdbseed/sysaux01.dbf','/app/oracle/oradata/CDB001/PDB002/sysaux01.dbf','/app/oracle/oradata/CDB001/pdbseed/temp01.dbf','/app/oracle/oradata/CDB001/PDB002/temp01.dbf')
Sat Jul 20 16:22:35 2013
****************************************************************
Pluggable Database PDB002 with pdb id - 4 is created as UNUSABLE.
If any errors are encountered before the pdb is marked as NEW,
then the pdb must be dropped
****************************************************************
Deleting old file#2 from file$ 
Deleting old file#4 from file$ 
Adding new file#10 to file$(old file#2) 
Adding new file#11 to file$(old file#4) 
Successfully created internal service pdb002 at open
CREATE TABLESPACE USERS DATAFILE  '/app/oracle/oradata/CDB001/PDB002/PDB002_users01.dbf' SIZE 5M REUSE AUTOEXTEND ON  SEGMENT SPACE MANAGEMENT AUTO
Completed: CREATE TABLESPACE USERS DATAFILE  '/app/oracle/oradata/CDB001/PDB002/PDB002_users01.dbf' SIZE 5M REUSE AUTOEXTEND ON  SEGMENT SPACE MANAGEMENT AUTO
Sat Jul 20 16:22:49 2013
ALTER SYSTEM: Flushing buffer cache inst=0 container=4 local
****************************************************************
Post plug operations are now complete.
Pluggable database PDB002 with pdb id - 4 is now marked as NEW.
****************************************************************
Completed: CREATE PLUGGABLE DATABASE PDB002 ADMIN USER PDB002_ADMIN IDENTIFIED BY * storage (maxsize 5G MAX_SHARED_TEMP_SIZE 500M) DEFAULT TABLESPACE "USERS" DATAFILE '/app/oracle/oradata/CDB001/PDB002/PDB002_users01.dbf' SIZE 5M REUSE AUTOEXTEND ON file_name_convert=('/app/oracle/oradata/CDB001/pdbseed/system01.dbf','/app/oracle/oradata/CDB001/PDB002/system01.dbf','/app/oracle/oradata/CDB001/pdbseed/sysaux01.dbf','/app/oracle/oradata/CDB001/PDB002/sysaux01.dbf','/app/oracle/oradata/CDB001/pdbseed/temp01.dbf','/app/oracle/oradata/CDB001/PDB002/temp01.dbf')
As you can see when you create a pluggable database from the SQL*Plus command line it is open in MOUNTED mode. This is a different behaviour compared with the same operation performed by DBCA: in the final step DBCA is able to open the new pluggable database in READ WRITE mode.
SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ WRITE    3
PDB002          MOUNTED     4
To open your new pluggable database in READ WRITE mode execute the following alter pluggable database command:
SQL> alter pluggable database pdb002 open read write;

Pluggable database altered.
Now query again the V$PDBS view: your pluggable database is now available to the application.
SQL> select NAME, OPEN_MODE, CON_ID from V$PDBS;

NAME          OPEN_MODE      CON_ID
------------------------------ ---------- ----------
PDB$SEED         READ ONLY    2
PDB001          READ WRITE    3
PDB002          READ WRITE    4
That's all.

Wednesday, July 17, 2013

Installing Oracle Database 12c as Container Database with three Pluggable Databases

Here is a video recorded during the creation of the first database. Go on if you want to see all the screenshots.

So we have already installed the software of the Oracle Database 12c release 1 (have a look at this post) and now we want to create a database using dbca.
So let's run dbca from the oracle user.
[oracle@vsi08devpom ~]$ dbca &


Select the operation you want to perform using dbca. Because I've already created an Oracle Database all the options are available. Anyway I want to create another database so I'm going to select Create Database.
During the Creation Mode screen you have two options:
1. you can create a database with default configuration. It's possible to create it as Container Database and create also one Pluggable Database.


I'm not going to click the finish button right now. I want to use the second option to create a database.

2. So choose Advanced Mode in which you configure your own database structure. This option enables you to perform more complex installations, such as creating individual passwords for different accounts, creating specific types of starter databases (for example, for transaction processing or data warehouse systems), using different language groups, specifying email notifications, and so on.






During the Advanced Mode screens you can choose to create the database as Container Database.
Select the Create as Container database option to create the database as a multitenant container database (CDB) that can support one pluggable database (PDB). If you want Oracle Universal Installer to create a PDB when it creates the CDB, specify the PDB name in the Pluggable Database Name field. The PDB name must be unique. If you need to create more than one PDB you have to provide a PDB Name Prefix.

The next Advanced Mode screen asks you how you want to manage your database: configuring the EM Database Express or registering it with EM Cloud Control.


The next screen asks you to specify passwords for SYS, SYSTEM and PDBADMIN or use the same password for all accounts.


The next screen asks you to select a listener or create a new one.

The next screen asks you to specify the storage locations for database files (storage type: File System or Automatic Storage Management) and for recovery related files (you can specify a Fast Recovery Area and enable archiving)


The next screen shows you the several database components you are going to configure like Oracle Database Vault or Label Security.
The next screen asks you to configure Database Vault and Label Security (I didn't select them during this installation).


The next screen let you specify settings about memory, default database block size and the maximum number of operating system user processes simultaneously connected to the database, character sets and the connection mode (dedicated server mode or shared server mode).Select the Enable Automatic Memory Management option to allow the database to automatically distribute memory between SGA and PGA. If you do not select this option, then the SGA and PGA must be sized manually.

The next screen asks you to select the Creation Options for the database (create, save as database template, generate database creation scripts).
The pre requisite checks are all satisfied.
Creation of the database configuration summary.
Database configuration summary created. So click finish button to begin the installation process.
 The database creation is in progress... still 36%.
 The database is finally created as well as the EM Database Express. In my case I was running another EM Database Express so the next available port was used (5501 instead of the "already in use" 5500). If you want to change the port number of your EM Database Express have a look at this post.

 Some screenshots from the EM Database Express.



























That's all.


Tuesday, July 16, 2013

How to configure the HTTPS Port for EM Database Express 12c

Configuring the HTTPS Port for EM Database Express 12c

If you used dbca to configure your database and enabled to configure also the EM Express you can find the EM Express URL provided by DBCA in the latest GUI screen.
If you forget the URL you can use the following SQL statement to find the port for EM Express:
[oracle@vsi08devpom ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Tue Jul 16 13:31:31 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> select dbms_xdb_config.gethttpsport() from dual;

DBMS_XDB_CONFIG.GETHTTPSPORT()
------------------------------
              5500
In your web browser enter the EM Express URL in this format to go to the login page: https://hostname:portnumber/em/
When EM Express prompts you for your username and password, log in as a user with DBA privilege (such as SYSTEM or SYS). 

If you want to change the default HTTPS Port for EM Express, that is 5500, you can proceed following these steps (as seen on Oracle documentation):

1. Configure and start the Oracle Net Listener (the listener). You can use lsnrctl to start, stop, and view the status of the listener

2. If the listener is running on a nonstandard port (for example, not 1521), then the init.ora file for the database you want to manage using EM Express must contain a local_listener entry so that the HTTPS port can register with the correct listener. The local_listener entry references a TNSNAMES entry that points to the correct listener. For example:
local_listener=inst1
where inst1 is a TNSNAMES entry defined in tnsnames.ora that points to the listener. For example:
inst1= (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host_name)(PORT=1234))
(CONNECT_DATA=(SERVICE_NAME=service_name)(SERVER=DEDICATED)))
In this example, 1234 is the nonstandard port on which the listener has been configured to listen.

3. Enable the TCP dispatcher by adding the following entry to the init.ora file for the database you want to manage using EM Express:
dispatchers="(PROTOCOL=TCP)(SERVICE=XDB)"
In my case, because the database SID is CDB001 I have:
SQL> show parameter dispatchers

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
dispatchers                 string     (PROTOCOL=TCP) (SERVICE=CDB001
                         XDB)
max_dispatchers              integer

4. Restart the database so that the changes made in the init.ora file take effect.

5. Use the PL/SQL procedure DBMS_XDB_CONFIG.SETHTTPSPORT to set the HTTPS port for EM Express. This will update the HTTPS port in the xdbconfig.xml file in the Oracle XML DB Repository. You must connect as SYS / AS SYSDBA to run the procedure. In my case I'm going to change the default port 5500 to 5555:
SQL> exec DBMS_XDB_CONFIG.SETHTTPSPORT(5555);

PL/SQL procedure successfully completed.

6. To access EM Express, enter a URL in the following format in a Web browser: https://hostname:portnumber/em/

Have a look at the following picture:

When prompted for your username and password, log in as a user with DBA privilege (such as SYSTEM).
 
Simply executes the same procedure to set again the default port number to 5500.


That's all.









Sunday, July 14, 2013

How to install Oracle Instant Client 12c and Oracle SQL Plus on Ubuntu

So you want to use your Ubuntu distribution and connect to an Oracle database.
Here you can find the steps to install and configure the Oracle Instant Client on Ubuntu 12.04.

First of all you need to go to the following link http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html and choose the Instant Client for your platform (in my case it is "Instant Client for Linux x86").

On the next web page select "Accept License Agreement" so you can download some rpm packets of the latest available Instant Client version (today is Version 12.1.0.1.0).

Click on oracle-instantclient12.1-basic-12.1.0.1.0-1.i386.rpm (Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications), oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.i386.rpm (Instant Client Package - SQL*Plus: Additional libraries and executable for running SQL*Plus with Instant Client) and oracle-instantclient12.1-devel-12.1.0.1.0-1.i386.rpm (Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client).

To be available to download those rpm packets you have also to sign in into the Oracle website.

Next step is to install alien on your distribution.
From the man page "alien is a program that converts between Red Hat rpm, Debian deb, Stampede slp, Slackware tgz, and Solaris pkg file formats. If you want to use a package from another linux distribution than the one you have installed on your system, you can use alien to convert it to your preferred package format and install it."

ubuntu@ubuntu-VirtualBox:~$ sudo apt-get install alien
Then go to your download directory and list the available rpm packets.
ubuntu@ubuntu-VirtualBox:~$ cd Downloads/
ubuntu@ubuntu-VirtualBox:~/Downloads$ ls
oracle-instantclient12.1-basic-12.1.0.1.0-1.i386.rpm
oracle-instantclient12.1-devel-12.1.0.1.0-1.i386.rpm
oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.i386.rpm
Let's install all of them using alien command:
ubuntu@ubuntu-VirtualBox:~/Downloads$ sudo alien -i oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.i386.rpm
    dpkg --no-force-overwrite -i oracle-instantclient12.1-sqlplus_12.1.0.1.0-2_i386.deb
Selecting previously unselected package oracle-instantclient12.1-sqlplus.
(Reading database ... 142987 files and directories currently installed.)
Unpacking oracle-instantclient12.1-sqlplus (from oracle-instantclient12.1-sqlplus_12.1.0.1.0-2_i386.deb) ...
Setting up oracle-instantclient12.1-sqlplus (12.1.0.1.0-2) ...
Now it's time for the Instant Client Basic Package:
ubuntu@ubuntu-VirtualBox:~/Downloads$ sudo alien -i oracle-instantclient12.1-basic-12.1.0.1.0-1.i386.rpm
    dpkg --no-force-overwrite -i oracle-instantclient12.1-basic_12.1.0.1.0-2_i386.deb
Selecting previously unselected package oracle-instantclient12.1-basic.
(Reading database ... 143000 files and directories currently installed.)
Unpacking oracle-instantclient12.1-basic (from oracle-instantclient12.1-basic_12.1.0.1.0-2_i386.deb) ...
Setting up oracle-instantclient12.1-basic (12.1.0.1.0-2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
And finally it's time for Instant Client SDK Package:
ubuntu@ubuntu-VirtualBox:~/Downloads$ sudo alien -i oracle-instantclient12.1-devel-12.1.0.1.0-1.i386.rpm
    dpkg --no-force-overwrite -i oracle-instantclient12.1-devel_12.1.0.1.0-2_i386.deb
Selecting previously unselected package oracle-instantclient12.1-devel.
(Reading database ... 143016 files and directories currently installed.)
Unpacking oracle-instantclient12.1-devel (from oracle-instantclient12.1-devel_12.1.0.1.0-2_i386.deb) ...
Setting up oracle-instantclient12.1-devel (12.1.0.1.0-2) ...
Let's try to issue the sqlplus command
ubuntu@ubuntu-VirtualBox:~$ sqlplus / as sysdba
sqlplus: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
Ops.. it fails because of a missing shared object file: libaio.so.1 So install libaio1 using the usual apt-get command.
ubuntu@ubuntu-VirtualBox:~$ sudo apt-get install libaio1
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following NEW packages will be installed:
  libaio1
0 upgraded, 1 newly installed, 0 to remove and 608 not upgraded.
Need to get 6,648 B of archives.
After this operation, 53.2 kB of additional disk space will be used.
Get:1 http://it.archive.ubuntu.com/ubuntu/ precise/main libaio1 i386 0.3.109-2ubuntu1 [6,648 B]
Fetched 6,648 B in 0s (12.5 kB/s)
Selecting previously unselected package libaio1.
(Reading database ... 143067 files and directories currently installed.)
Unpacking libaio1 (from .../libaio1_0.3.109-2ubuntu1_i386.deb) ...
Setting up libaio1 (0.3.109-2ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Let's try to run sqlplus again.
ubuntu@ubuntu-VirtualBox:~/Downloads$ sqlplus / as sysdba
sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory
sqlplus complains about missing libraries. You can solve creating/editing the oracle.conf file issuing the following command and simply adding a line (the path where were installed all the libraries of the Instant Client packages: /usr/lib/oracle/12.1/client/lib):
ubuntu@ubuntu-VirtualBox:~/Downloads$sudo vi /etc/ld.so.conf.d/oracle.conf
/usr/lib/oracle/12.1/client/lib
Now update the information of all the shared libraries on your system.
ubuntu@ubuntu-VirtualBox:~/Downloads$sudo ldconfig
Run sqlplus again... and as you can see it works...
ubuntu@ubuntu-VirtualBox:~$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Sun Jul 14 20:01:37 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

ERROR:
ORA-12162: TNS:net service name is incorrectly specified
... even if there's no database to connect to...
On the next post a new Oracle Database 12c will be finally available.

That's all.

Friday, July 12, 2013

Oracle Database 12c: pictures from Rome


Few pictures taken during the Oracle Database 12c presentation in Rome.






















Wednesday, July 10, 2013

Software only installation of Oracle Database 12c release 1

In this post I'm going to install only the software of the Oracle Database 12c release 1.

Download from Oracle website and extract it into the home directory of the oracle user.
[oracle@localhost ~]$ pwd
/home/oracle
[oracle@localhost ~]$ cd database/
[oracle@localhost database]$ ./runInstaller &
The GUI of the installer is similar to the previous version.

On the first step "Configure Security Update" you have to specify your email to be informed on security issue;
on next step "Software Updates" it asks to download any PSU available;
on next step "Installation Option" it asks what kind of installation you want to perform. I'm going to choose "Install database software only";
on next step "Grid Installation Options" it asks if you want to install a single instance, a RAC or a RAC One Node database installation. I'm selecting "Single instance database installation";
on next step "Product Languages" choose the one you need or leave the English default language like I do;
on next step "Database Edition" I'm going to choose "Enterprise Edition" instead of "Standard Edition" or "Standard Edition One";

Before proceeding on next step execute the following commands:
[root@localhost /]# mkdir -p /app/oracle
[root@localhost /]# chonw oracle.oinstall /app/oracle
[root@localhost /]# chown oracle.oinstall /app/oracle
on next step "Installation Location" I'm going to use "/app/oracle/" as Oracle base and "/app/oracle/product/12.1.0/dbhome_1" as software location;

Before proceeding on next step execute the following commands:
[root@localhost /]# mkdir -p /app/oraInventory
[root@localhost /]# chown oracle.oinstall /app/oraInventory
on next step "Create Inventory" I'm going to use "/app/oraInventory" as Inventory Directory and oinstall as oraInventory Group Name;

on next step "Operating Sytem Groups" I selected dba group;
on the next step "Summary" I first saved the response file and the clicked the Install button.

When asked execute the suggested scripts as root user: /app/oraInventory/orainstRoot.sh and /app/oracle/product/12.1.0/dbhome_1/root.sh
[root@localhost /]# /app/oraInventory/orainstRoot.sh
Changing permissions of /app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /app/oraInventory to oinstall.
The execution of the script is complete.
[root@localhost /]# /app/oracle/product/12.1.0/dbhome_1/root.sh
Performing root user operation for Oracle 12c 

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /app/oracle/product/12.1.0/dbhome_1

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
The installation of Oracle Database was successful.

That's all.

Tuesday, July 9, 2013

How to avoid kernel-uek is needed by oracle-rdbms-server-12cR1-preinstall on CentOS while installing Oracle Database 12c release 1

So as you should know Oracle Database Server 12c release 1 is finally out there and this is my first post about it.
I've just finished to download some fundamental documents from Oracle website such as "2 Day DBA", "New Features Guide", "Concepts Guide", "Upgrade Guide", "Administrator's Guide" (1360 pages!!!), "Backup and Recovery User's Guide" (684 pages) and "Database Installation Guide for Linux".

I'm starting to read the "Database Installation Guide for Linux" guide, setting up a running virtual CentOS machine and, of course, preparing to install the new Oracle Database 12cR1:
I want to use the so useful rpm package provided by Oracle for automatically complete default operating system configurations. There are many options described on the documentation to configure your Oracle Linux distribution with Oracle RDBMS pre-install rpm... but you can find some difficulties while using a different release such as "RedHat like" distribution like that one I'm going to use: the latest CentOS 6.4 distribution.
Do not use the following instruction on a production environment because they won't be supported by Oracle guys: this post is only for testing purpose.

So open a terminal and use wget command to get the requested rpm package from Oracle public yum repository:
[root@localhost ~]$ wget http://public-yum.oracle.com/repo/OracleLinux/OL6/latest/x86_64/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64.rpm
--2013-07-04 10:15:03--  http://public-yum.oracle.com/repo/OracleLinux/OL6/latest/x86_64/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64.rpm
While installing the rpm package, it fails because some dependencies were not satisfied. I indeed installed the default minimal CentOS distribution.
[root@localhost ~] rpm -Uvh oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64.rpm 
warning: oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
error: Failed dependencies:
 bind-utils is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 compat-libcap1 is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 compat-libstdc++-33 is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 gcc-c++ is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 kernel-uek is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 ksh is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 libaio is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 libaio-devel is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 libstdc++-devel is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 nfs-utils is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 smartmontools is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
 sysstat is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
Execute a yum install command with the previous missing packages and one of them would not be available from the public CentOS repository. Just try to guess which one...
[root@localhost database]# yum -y install compat-libcap1 compat-libstdc++-33 gcc-c++ kernel-uek ksh libaio libaio-devel libstdc++-devel nfs-utils smartmontools sysstats smartmontools
Indeed when you issue again the command to install Oracle RDBMS pre-install package it discovers kernel-uek is still needed: UEK stands for Unbreakable Enterprise Kernel.
[root@localhost ~]# rpm -Uvh oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64.rpm 
warning: oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
error: Failed dependencies:
 kernel-uek is needed by oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.x86_64
I don't want to use a different kernel just to install a configuration package in a testing environment so why do not recompile that package instead and exclude that dependency ?
I loved to recompile packages when I studied at the university: it was time of Red Hat 4.0 and I should still have a CD-ROM to install it at home.
So the first things you must have are the packages to rebuild a rpm package.
[root@localhost ~]# yum -y install rpm-build rpmdevtools
To avoid a rpmbuild error you have to create also the same user Oracle used to compile its package. It was called "mockbuild". So simply create it using useradd command and then set a password for him.
[root@localhost ~]# useradd mockbuild -m -s /bin/bash
[root@localhost ~]# passwd mockbuild
Changing password for user mockbuild.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
Login with the new mockbuild user and download the rpm package containing all the source information that you have to modify.
[root@localhost ~]# su - mockbuild
[mockbuild@localhost ~]$ wget http://public-yum.oracle.com/repo/OracleLinux/OL6/latest/x86_64/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.src.rpm
--2013-07-04 10:39:37--  http://public-yum.oracle.com/repo/OracleLinux/OL6/latest/x86_64/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.src.rpm
Resolving public-yum.oracle.com... 137.254.56.43
Connecting to public-yum.oracle.com|137.254.56.43|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13332 (13K) [application/x-rpm]
Saving to: “oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.src.rpm”

100%[=============================================================>] 13,332      44.7K/s   in 0.3s    

2013-07-04 10:39:37 (44.7 KB/s) - “oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.src.rpm” saved [13332/13332]
Under the home directory of the mockbuild user create the RPM build environment using rpmdev-setuptree:
[mockbuild@localhost ~]$ pwd
/home/mockbuild
[mockbuild@localhost ~]$ rpmdev-setuptree 
[mockbuild@localhost ~]$ ll
total 20
-rw-rw-r--. 1 mockbuild mockbuild 13332 Apr 24 03:26 oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.src.rpm
drwxrwxr-x. 7 mockbuild mockbuild  4096 Jul  4 10:40 rpmbuild
[mockbuild@localhost ~]$ ll rpmbuild
total 20
drwxrwxr-x. 2 mockbuild mockbuild 4096 Jul  4 10:40 BUILD
drwxrwxr-x. 2 mockbuild mockbuild 4096 Jul  4 10:40 RPMS
drwxrwxr-x. 2 mockbuild mockbuild 4096 Jul  4 10:40 SOURCES
drwxrwxr-x. 2 mockbuild mockbuild 4096 Jul  4 10:40 SPECS
drwxrwxr-x. 2 mockbuild mockbuild 4096 Jul  4 10:40 SRPMS
Install the source rpm:
[mockbuild@localhost ~]$ rpm -ivh oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.src.rpm 
warning: oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.src.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
   1:oracle-rdbms-server-12c########################################### [100%]
Edit the oracle-rdbms-server-12cR1-preinstall.spec file removing the kernel-uek dependency (delete or comment that line)
[mockbuild@localhost ~]$ vi rpmbuild/SPECS/oracle-rdbms-server-12cR1-preinstall.spec 
...
#System requirement
Requires:procps module-init-tools ethtool initscripts
Requires:bc bind-utils nfs-utils util-linux-ng pam
Requires:xorg-x11-utils xorg-x11-xauth
Requires:kernel-uek
Requires:smartmontools
...
Once you have removed the kernel-uek dependency you can rebuild the rpm issuing the following command:
[mockbuild@localhost ~]$ rpmbuild -ba rpmbuild/SPECS/oracle-rdbms-server-12cR1-preinstall.spec
warning: line 18: prereq is deprecated: PreReq:/etc/redhat-release
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.UzkCll
+ umask 022
+ cd /home/mockbuild/rpmbuild/BUILD
+ echo RPM_BUILD_ROOT=/home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386
RPM_BUILD_ROOT=/home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386
+ cd /home/mockbuild/rpmbuild/BUILD
+ rm -rf oracle-rdbms-server-12cR1-preinstall-1.0
+ /bin/tar -xf -
+ /usr/bin/gzip -dc /home/mockbuild/rpmbuild/SOURCES/oracle-rdbms-server-12cR1-preinstall-1.0.tar.gz
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd oracle-rdbms-server-12cR1-preinstall-1.0
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.FUjBhi
+ umask 022
+ cd /home/mockbuild/rpmbuild/BUILD
+ cd oracle-rdbms-server-12cR1-preinstall-1.0
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.Qq9rxf
+ umask 022
+ cd /home/mockbuild/rpmbuild/BUILD
+ cd oracle-rdbms-server-12cR1-preinstall-1.0
+ rm -rf /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386
+ mkdir -p -m 755 /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/etc/sysconfig/oracle-rdbms-server-12cR1-preinstall
+ mkdir -p -m 755 /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/usr/bin
+ mkdir -p -m 755 /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/etc/rc.d/init.d
+ mkdir -p -m 755 /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/etc/security/limits.d
+ mkdir -p -m 700 /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/var/log/oracle-rdbms-server-12cR1-preinstall/results
+ install -m 700 oracle-rdbms-server-12cR1-preinstall-verify /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/etc/sysconfig/oracle-rdbms-server-12cR1-preinstall
+ install -m 700 oracle-rdbms-server-12cR1-preinstall-verify /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/usr/bin
+ install -m 600 oracle-rdbms-server-12cR1-preinstall.param /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/etc/sysconfig/oracle-rdbms-server-12cR1-preinstall
+ install -m 700 oracle-rdbms-server-12cR1-preinstall-firstboot /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/etc/rc.d/init.d
+ touch /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/etc/security/limits.d/oracle-rdbms-server-12cR1-preinstall.conf
+ ln -f -s /etc/sysconfig/oracle-rdbms-server-12cR1-preinstall/oracle-rdbms-server-12cR1-preinstall-verify /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386/usr/bin/oracle-rdbms-server-12cR1-preinstall-verify
+ /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386
warning: File listed twice: /etc/sysconfig/oracle-rdbms-server-12cR1-preinstall/oracle-rdbms-server-12cR1-preinstall-verify
warning: File listed twice: /etc/sysconfig/oracle-rdbms-server-12cR1-preinstall/oracle-rdbms-server-12cR1-preinstall.param
Provides: config(oracle-rdbms-server-12cR1-preinstall) = 1.0-8.el6 oracle-rdbms-server-12cR1-preinstall = 1.0
Requires(interp): /bin/sh /bin/sh /bin/sh /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(VersionedDependencies) <= 3.0.3-1
Requires(pre): /bin/sh /etc/redhat-release
Requires(post): /bin/sh
Requires(preun): /bin/sh /etc/redhat-release
Requires(postun): /bin/sh
Requires: /bin/bash
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386
Wrote: /home/mockbuild/rpmbuild/SRPMS/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.src.rpm
Wrote: /home/mockbuild/rpmbuild/RPMS/i386/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.t2jJoi
+ umask 022
+ cd /home/mockbuild/rpmbuild/BUILD
+ cd oracle-rdbms-server-12cR1-preinstall-1.0
+ rm -rf /home/mockbuild/rpmbuild/BUILDROOT/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386
+ exit 0
Here is my new RPM file.
[mockbuild@localhost ~]$ ls rpmbuild/RPMS/i386/
oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386.rpm
Log out the mockbuild user and as root issue the yum localinstall command:
[mockbuild@localhost ~]$ exit
logout
[root@localhost ~]# pwd
/root
[root@localhost ~]# yum localinstall /home/mockbuild/rpmbuild/RPMS/i386/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386.rpm 
Loaded plugins: fastestmirror, refresh-packagekit
Setting up Local Package Process
Examining /home/mockbuild/rpmbuild/RPMS/i386/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386.rpm: oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386
Marking /home/mockbuild/rpmbuild/RPMS/i386/oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386.rpm to be installed
Loading mirror speeds from cached hostfile
 * base: centos.intergenia.de
 * extras: centos.copahost.com
 * updates: centos.bio.lmu.de
Resolving Dependencies
--> Running transaction check
---> Package oracle-rdbms-server-12cR1-preinstall.i386 0:1.0-8.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
 Package                     Arch Version   Repository                                            Size
=======================================================================================================
Installing:
 oracle-rdbms-server-12cR1-preinstall
                             i386 1.0-8.el6 /oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386  37 k

Transaction Summary
=======================================================================================================
Install       1 Package(s)

Total size: 37 k
Installed size: 37 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386                                 1/1 
  Verifying  : oracle-rdbms-server-12cR1-preinstall-1.0-8.el6.i386                                 1/1 

Installed:
  oracle-rdbms-server-12cR1-preinstall.i386 0:1.0-8.el6                                                

Complete!
The oracle-rdbms-server-12cR1-preinstall.i386 0:1.0-8.el6 rpm package is finally installed and I can see it creates a new user in my machine.
[root@localhost ~]# cd /home/
[root@localhost home]# ls
mockbuild  oracle

In the next post I will continue the installation of the Oracle Database 12c relase 1.

That's all.