Tuesday, October 29, 2013

Oracle 12c: cloning a PDB

Out here I create a clone of testdb1(PDB). The clone testdb2(PDB) is on the same CDB(testdb)

SQL> alter pluggable database testdb1 close;

Pluggable database altered.

SQL> alter pluggable database testdb1 open read only;

Pluggable database altered.


SQL>
SQL> create pluggable database testdb2 from testdb1 FILE_NAME_CONVERT=('/u02/app/oracle/oradata/testdb/testdb1','/u02/app/oracle/oradata/testdb/testdb2');
create pluggable database testdb2 from testdb1 FILE_NAME_CONVERT=('/u02/app/oracle/oradata/testdb/testdb1','/u02/app/oracle/oradata/testdb/testdb2')
*
ERROR at line 1:
ORA-65005: missing or invalid file name pattern for file -
/u02/app/oracle/product/12.1.0/dbhome_1/dbs/soe.dbf

The above error was due to the fact that I had not added the datafile soe.dbf from SOE tablespace into the FILE_NAME_CONVERT list. By adding it as shown below, resolved the issue.

 The below operation not allowed from within a pluggable database, and needs to be executed from within the CDB. If we execute it withing testdb1, we will get the following error message: ORA-65040: operation not allowed from within a pluggable database.


SQL> create pluggable database testdb2 from testdb1 FILE_NAME_CONVERT=('/u02/app/oracle/oradata/testdb/testdb1','/u02/app/oracle/oradata/testdb/testdb2','/u02/app/oracle/product/12.1.0/dbhome_1/dbs/soe.dbf','/u02/app/oracle/oradata/testdb/testdb2/soe.dbf');

Pluggable database created.

SQL>

We see below that the datafiles have been added to the directory testdb2

-bash-3.2$ pwd
/u02/app/oracle/oradata/testdb/testdb2
-bash-3.2$ ls
soe.dbf  sysaux01.dbf  system01.dbf  temp01.dbf  testdb1_users01.dbf
-bash-3.2$ ls -lrt
total 4397364
-rw-r----- 1 oracle oinstall   20979712 Oct 29 22:50 temp01.dbf
-rw-r----- 1 oracle oinstall    5251072 Oct 29 22:50 testdb1_users01.dbf
-rw-r----- 1 oracle oinstall  272637952 Oct 29 22:50 system01.dbf
-rw-r----- 1 oracle oinstall  650125312 Oct 29 22:50 sysaux01.dbf
-rw-r----- 1 oracle oinstall 3570409472 Oct 29 22:50 soe.dbf
-bash-3.2$

Below we open the newly created clone database testdb2

SQL> alter pluggable database testdb2 open;

Pluggable database altered.

SQL>

 Next, we close testdb1 which is in read only node and re-open it again.

SQL> alter pluggable database testdb1 close;


Pluggable database altered.

SQL> SQL> alter pluggable database testdb1 open ;

Pluggable database altered.

SQL>

Below we connect to the CDB (testdb) and see that datafiles for the clone PDB (testdb2) now shows up when listing the datafiles.

-bash-3.2$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Tue Oct 29 22:55:05 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> show con_name

CON_NAME
------------------------------
CDB$ROOT
SQL> show con_id

CON_ID
------------------------------
1
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/system01.dbf
/u02/app/oracle/oradata/testdb/sysaux01.dbf
/u02/app/oracle/oradata/testdb/undotbs01.dbf
/u02/app/oracle/oradata/testdb/pdbseed/system01.dbf
/u02/app/oracle/oradata/testdb/users01.dbf
/u02/app/oracle/oradata/testdb/pdbseed/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb1/system01.dbf
/u02/app/oracle/oradata/testdb/testdb1/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb1/testdb1_users01.dbf
/u02/app/oracle/product/12.1.0/dbhome_1/dbs/soe.dbf
/u02/app/oracle/oradata/testdb/testdb2/system01.dbf

NAME
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/testdb2/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb2/testdb1_users01.dbf
/u02/app/oracle/oradata/testdb/testdb2/soe.dbf

14 rows selected.

SQL>

Oracle 12c: control, data, redo log, and temp files in CDB and PDB

After creating the PDB as shown in the previous post, I created the Order Entry schema using Swingbench.
Below we will see the how the control files, data files, redo log files, and the temp files are used by the CDB (testdb) and the PDB (testdb1) 

-bash-3.2$ echo $ORACLE_SID
testdb
-bash-3.2$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Tue Oct 29 09:22:28 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>
SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT
SQL> show con_id

CON_ID
------------------------------
1
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/system01.dbf
/u02/app/oracle/oradata/testdb/sysaux01.dbf
/u02/app/oracle/oradata/testdb/undotbs01.dbf
/u02/app/oracle/oradata/testdb/pdbseed/system01.dbf
/u02/app/oracle/oradata/testdb/users01.dbf
/u02/app/oracle/oradata/testdb/pdbseed/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb1/system01.dbf
/u02/app/oracle/oradata/testdb/testdb1/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb1/testdb1_users01.dbf
/u02/app/oracle/product/12.1.0/dbhome_1/dbs/soe.dbf

10 rows selected.

SQL> select con_id,name from v$tempfile;

    CON_ID
----------
NAME
--------------------------------------------------------------------------------
         1
/u02/app/oracle/oradata/testdb/temp01.dbf

         2
/u02/app/oracle/oradata/testdb/pdbseed/pdbseed_temp01.dbf

         3
/u02/app/oracle/oradata/testdb/testdb1/temp01.dbf


SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/control01.ctl
/u02/app/oracle/fast_recovery_area/testdb/control02.ctl

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/redo03.log
/u02/app/oracle/oradata/testdb/redo02.log
/u02/app/oracle/oradata/testdb/redo01.log

SQL>

Next we change the session container to the PDB (testdb1).

SQL> ALTER SESSION SET CONTAINER =testdb1;

Session altered.

SQL> show con_name

CON_NAME
------------------------------
TESTDB1
SQL> show con_id

CON_ID
------------------------------
3
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/undotbs01.dbf
/u02/app/oracle/oradata/testdb/testdb1/system01.dbf
/u02/app/oracle/oradata/testdb/testdb1/sysaux01.dbf
/u02/app/oracle/oradata/testdb/testdb1/testdb1_users01.dbf
/u02/app/oracle/product/12.1.0/dbhome_1/dbs/soe.dbf

SQL> select con_id,name from v$tempfile;

    CON_ID
----------
NAME
--------------------------------------------------------------------------------
         3
/u02/app/oracle/oradata/testdb/testdb1/temp01.dbf


SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/control01.ctl
/u02/app/oracle/fast_recovery_area/testdb/control02.ctl

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u02/app/oracle/oradata/testdb/redo03.log
/u02/app/oracle/oradata/testdb/redo02.log
/u02/app/oracle/oradata/testdb/redo01.log

SQL>

Monday, October 28, 2013

Creating an Oracle 12c database using dbca

The screen shots below show the creation of an Oracle 12c database using dbca as user oracle.















Installing Oracle 12c R1 on Linux

Below are the screen shots of installing Oracle 12c (12.1.0.1.0) Single Instance on RedHat Linux

Below are the screens see on running runInstaller as user oracle.















Friday, October 25, 2013

Getting started with Python

I had Python 2.4.3 on my Red Hat 4.1.2-54 box, but decided to install Python 3.2 as some of the newer scripts were breaking.

Here is what I did to install Pyton 3 on my RedHat box(source: http://www.hosting.com/support/linux/installing-python-3-on-centosredhat-5x-from-source/)

[root@isvx7 ~]# wget http://www.python.org/ftp/python/3.2/Python-3.2.tar.bz2
[root@isvx7 ~]# tar -xjf Python-3.2.tar.bz2
[root@isvx7 ~]# cd Python-3.2


[root@isvx7 Python-3.2]# ./configure --prefix=/opt/python3
[root@isvx7 Python-3.2]# make
[root@isvx7 Python-3.2]# sudo make install

[root@isvx7 Python-3.2]# /opt/python3/bin/python3 -V
Python 3.2


Update the path to python3 in the scripts as shown below.

[root@isvx3 mypython]# cat hello.py
#!/opt/python3/bin/python3

print ('Hello World!')


Unlike most programming and scripting languages, python relies on indentation as oposed to curly brackets
So to avoid errors like “inconsistent use of tabs and spaces in indentation”, it would be best
to setup autoindentation properly.

Below is a sample to setup vim autoindentation(source: http://stackoverflow.com/questions/65076/how-to-setup-vim-autoindentation-properly-for-editing-python-files-py):

$ cat ~/.vimrc
syntax on
set showmatch
set ts=4
set sts=4
set sw=4
set autoindent
set smartindent
set smarttab
set expandtab
set number

or

$ cat ~/.vimrc
" configure expanding of tabs for various file types
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.c set noexpandtab
au BufRead,BufNewFile *.h set noexpandtab
au BufRead,BufNewFile Makefile* set noexpandtab

" --------------------------------------------------------------------------------
" configure editor with tabs and nice stuff...
" --------------------------------------------------------------------------------
set expandtab           " enter spaces when tab is pressed
set textwidth=120       " break lines when line length increases
set tabstop=4           " use 4 spaces to represent tab
set softtabstop=4
set shiftwidth=4        " number of spaces to use for auto indent
set autoindent          " copy indent from current line when starting a new line

" make backspaces more powerfull
set backspace=indent,eol,start

set ruler                           " show line and column number
syntax on               " syntax highlighting
set showcmd             " show (partial) command in status line

Even better than using vim would be to sue an IDE for python. This would particularly useful in
debugging the scripts, by setting break points, etc.

Wing IDE 101 is a good free Python IDE.
http://wingware.com/downloads/wingide-101