Sunday, 19 February 2017

Session level parallelism setting to run scripts


alter session enable parallel ddl;
alter session force parallel ddl parallel 20;
alter session set db_file_multiblock_read_count = 256;
alter session set "_px_max_granules_per_slave"=3000;
alter session set "_px_index_sampling"=3000;
alter session set "_px_dynamic_sample_size"=3000;
ALTER SESSION ENABLE RESUMABLE TIMEOUT 3600;
alter session set parallel_force_local=TRUE;

Monday, 13 February 2017

DROP Database in RAC

Steps to drop database

srvctl stop database -d TEST

sqlplus / as sysdba

SQL>startup nomount

SQL> alter system set cluster_database=FALSE scope=spfile sid='*';

SQL> shutdown abort;

SQL> startup mount exclusive restrict

SQL>  select logins,parallel from v$instance;

SQL> drop database;



Or

SQL> alter system set cluster_database=FALSE scope=spfile sid='*';

srvctl stop database -d TEST

SQL> startup mount exclusive restrict

SQL>  select logins,parallel from v$instance;

SQL> drop database;


Saturday, 11 February 2017

Manual DB creation

###Command##

CREATE DATABASE JOSHI
USER SYS IDENTIFIED BY abc#1234
USER SYSTEM IDENTIFIED BY 
abc#1234
LOGFILE GROUP 1 ('/u03/oracle/JOSHI/redo01a.log','/u03/oracle/JOSHI/redo01b.log') SIZE 1000M BLOCKSIZE 512,
GROUP 2 ('/u03/oracle/JOSHI/redo02a.log','/u03/oracle/JOSHI/redo02b.log') SIZE 1000M BLOCKSIZE 512,
GROUP 3 ('/u03/oracle/JOSHI/redo03a.log','/u03/oracle/JOSHI/redo03b.log') SIZE 1000M BLOCKSIZE 512
MAXLOGHISTORY 1
MAXLOGFILES 32
MAXLOGMEMBERS 3
MAXDATAFILES 1024
CHARACTER SET US7ASCII
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DATAFILE '/u03/oracle/JOSHI/system01.dbf' SIZE 800M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SYSAUX DATAFILE '/u03/oracle/JOSHI/sysaux01.dbf' SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
DEFAULT TABLESPACE USERS DATAFILE '/u03/oracle/JOSHI/users01.dbf'SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/u03/oracle/JOSHI/temp01.dbf'SIZE 200M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE UNDOTBS1 DATAFILE '/u03/oracle/JOSHI/undotbs01.dbf'SIZE 280M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED;

OR

CREATE DATABASE JOSHI
   USER SYS IDENTIFIED BY ora123$
   USER SYSTEM IDENTIFIED BY ora123$
   LOGFILE GROUP 1 ('+DATA','+FLASH') SIZE 1000M BLOCKSIZE 512,
           GROUP 2 ('+DATA','+FLASH') SIZE 1000M BLOCKSIZE 512,
           GROUP 3 ('+DATA','+FLASH') SIZE 1000M BLOCKSIZE 512
   MAXLOGHISTORY 1
   MAXLOGFILES 16
   MAXLOGMEMBERS 3
   MAXDATAFILES 1024
   CHARACTER SET US7ASCII
   NATIONAL CHARACTER SET AL16UTF16
   EXTENT MANAGEMENT LOCAL
   DATAFILE '+DATA'
     SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
   SYSAUX DATAFILE '+DATA'
     SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
   DEFAULT TABLESPACE users
      DATAFILE '+DATA'
      SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
   DEFAULT TEMPORARY TABLESPACE tempts1
      TEMPFILE '+DATA'
      SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
   UNDO TABLESPACE undotbs1
      DATAFILE '+DATA'
      SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED;

             On WINDOWS

oradim -NEW -SID test -STARTMODE MANUAL -PFILE E:\pfiletest.ora

startup nomount;
CREATE DATABASE TEST
USER SYS IDENTIFIED BY sys1234
USER SYSTEM IDENTIFIED BY sys1234
LOGFILE GROUP 1 ('E:\test\REDO01.LOG') SIZE 100M,
GROUP 2 ('E:\test\REDO02.LOG') SIZE 100M,
GROUP 3 ('E:\test\REDO03.LOG') SIZE 100M
MAXLOGHISTORY 1
MAXLOGFILES 32
MAXLOGMEMBERS 3
MAXDATAFILES 1024
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16
NLS_LENGTH_SEMANTICS CHAR
EXTENT MANAGEMENT LOCAL
DATAFILE 'E:\TEST\SYSTEM01.DBF' SIZE 800M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SYSAUX DATAFILE 'E:\TEST\SYSAUX01.DBF' SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
DEFAULT TABLESPACE USERS DATAFILE 'E:\TEST\USERS01.DBF'SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE 'E:\TEST\TEMP01.DBF'SIZE 200M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE UNDOTBS1 DATAFILE 'E:\TEST\UNDOTBS01.DBF'SIZE 280M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED;

###Once DB created run below###

@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql


alter user system account unlock;
connect system/manager;

@?/sqlplus/admin/pupbld.sql

a)catalog.sql =>Creates dictionary tables and views
b)catproc.sql =>Creates PL/SQL procedures,functions and packages necessary.
c)pupbld.sql  =>Creates user profiles.

Thursday, 26 January 2017

Creating an Oracle ACFS File System 12c

Create a volume

RECO is the Disk Group name.

ASMCMD [+] > volcreate -G RECO -s 200G u02


Check the volume device name 

ASMCMD [+] > volinfo -G RECO u02
Diskgroup Name: RECO

         Volume Name: U02
         Volume Device: /dev/asm/u02-93
         State: ENABLED
         Size (MB): 204800
         Resize Unit (MB): 64
         Redundancy: HIGH
         Stripe Columns: 8
         Stripe Width (K): 1024
         Usage:
         Mountpath:

or

SELECT volume_name, volume_device FROM V$ASM_VOLUME WHERE volume_name ='U02';

Create a file system with the Oracle ACFS mkfs command. Create a file system using an existing volume device.


[grid@RAC1 ~]$ /sbin/mkfs -t acfs /dev/asm/u02-93
mkfs.acfs: version                   = 12.1.0.2.0
mkfs.acfs: on-disk version           = 39.0
mkfs.acfs: volume                    = /dev/asm/u02-93
mkfs.acfs: volume size               = 214748364800  ( 200.00 GB )
mkfs.acfs: Format complete.

Optionally register the file system as a root user

[grid@RAC1 ~]$ /sbin/acfsutil registry -a /dev/asm/u02-93 /u02
PRCN-2018 : Current user grid is not a privileged user
acfsutil registry: ACFS-03111: unable to add ACFS mount /u02 within Oracle Registry

[grid@RAC1 ~]$ sudo su - root
[sudo] password for grid:
[root@RAC1 ~]# /sbin/acfsutil registry -a /dev/asm/u02-93 /u02
acfsutil registry: mount point /u02 successfully added to Oracle Registry



[root@RAC1 ~]# df -h /u02
Filesystem       Size  Used Avail Use% Mounted on
/dev/asm/u02-93  200G  483M  200G   1% /u02
[root@RAC1 ~]#

Check status
ASMCMD> volinfo -G RECO u02
Diskgroup Name: RECO

         Volume Name: U02
         Volume Device: /dev/asm/u02-93
         State: ENABLED
         Size (MB): 204800
         Resize Unit (MB): 64
         Redundancy: HIGH
         Stripe Columns: 8
         Stripe Width (K): 1024
         Usage: ACFS
         Mountpath: /u02



Mount the file system with the Oracle ACFS mount command. You can mount a file system before or after registering the file system. If the file system has been registered, you can wait for the file system to be mounted automatically. Issue the following command on each node to mount it if not mounted already.

/bin/mount -t acfs /dev/asm/u02-93 /u02



https://docs.oracle.com/database/121/OSTMG/GUID-4C98CF06-8CCC-45F1-9316-C40FB3EFF268.htm#OSTMG94787

Tuesday, 24 January 2017

CTAS Method to Create Table

##Shell Script##


export ORACLE_SID=joshi
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4

sqlplus -s '/ as sysdba' << EOF

set lines 200
set pages 50
Set echo on
set serveroutput on
set timing on
set time on
spool /home/oracle/CTAS_TABLE.log

alter session set db_file_multiblock_read_count=128;
alter session set sort_multiblock_read_count=128;
alter session set parallel_force_local=true;

exec dbms_application_info.set_module ('CTAS_TABLE_TMP',null);

CREATE TABLE SCOTT.TMP AS SELECT * FROM HR.DEPT;


spool off
exit;
EOF


#########


#Sample CTAS statement:
CREATE TABLE emp2 AS SELECT * FROM emp;

#Specifying a tablespace:
CREATE TABLE emp3 TABLESPACE users AS SELECT * FROM emp;

#Parallel CTAS with nologging for faster performance
CREATE TABLE emp4 NOLOGGING PARALLEL 4 AS SELECT * FROM emp;

Thursday, 19 January 2017

ASM Disk configuration

[root@localhost backup]# rpm -Uvih oracleasm-support-2.1.7-1.el5.x86_64.rpm
warning: oracleasm-support-2.1.7-1.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...                ########################################### [100%]
   1:oracleasm-support      ########################################### [100%]

[root@localhost backup]# rpm -Uvih oracleasm-2.6.18-308.el5-2.0.5-1.el5.x86_64.rpm
warning: oracleasm-2.6.18-308.el5-2.0.5-1.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...                ########################################### [100%]
   1:oracleasm-2.6.18-308.el########################################### [100%]

[root@localhost backup]# rpm -qa|grep oracleasm
oracleasm-support-2.1.7-1.el5
oracleasm-2.6.18-308.el5-2.0.5-1.el5

[root@localhost backup]# rpm -Uvih oracleasmlib-2.0.4-1.el5.i386.rpm
warning: oracleasmlib-2.0.4-1.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...                ########################################### [100%]
   1:oracleasmlib           ########################################### [100%]

[root@localhost backup]# /etc/init.d/oracleasm configure
Configuring the Oracle ASM library driver.

This will configure the on-boot properties of the Oracle ASM library
driver.  The following questions will determine whether the driver is
loaded on boot and what permissions it will have.  The current values
will be shown in brackets ('[]').  Hitting <ENTER> without typing an
answer will keep that current value.  Ctrl-C will abort.

Default user to own the driver interface []: oracle
Default group to own the driver interface []: oinstall
Start Oracle ASM library driver on boot (y/n) [n]: y
Scan for Oracle ASM disks on boot (y/n) [y]:
Writing Oracle ASM library driver configuration: done
Initializing the Oracle ASMLib driver:                     [  OK  ]
Scanning the system for Oracle ASMLib disks:
                                                           [  OK  ]
[root@localhost backup]#
[root@localhost backup]# /etc/init.d/oracleasm status
Checking if ASM is loaded: yes
Checking if /dev/oracleasm is mounted: yes
[root@localhost backup]# ls -ltrh /dev/sd*
brw-r----- 1 root disk 8,  0 Jan 19 01:01 /dev/sda
brw-r----- 1 root disk 8,  2 Jan 19 01:01 /dev/sda2
brw-r----- 1 root disk 8, 80 Jan 19 01:01 /dev/sdf
brw-r----- 1 root disk 8, 48 Jan 19 01:02 /dev/sdd
brw-r----- 1 root disk 8, 64 Jan 19 01:02 /dev/sde
brw-r----- 1 root disk 8, 32 Jan 19 01:02 /dev/sdc
brw-r----- 1 root disk 8, 16 Jan 19 01:02 /dev/sdb
brw-r----- 1 root disk 8,  1 Jan 19 01:02 /dev/sda1
[root@localhost backup]# cat /proc/partitions
major minor  #blocks  name

   8        0   31457280 sda
   8        1     104391 sda1
   8        2   31350847 sda2
   8       16   10485760 sdb
   8       32   10485760 sdc
   8       48   10485760 sdd
   8       64   52428800 sde
   8       80   52428800 sdf
 253        0   27295744 dm-0
 253        1    4030464 dm-1
[root@localhost backup]# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 6527.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6527, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-6527, default 6527):
Using default value 6527

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost backup]# cat /proc/partitions
major minor  #blocks  name

   8        0   31457280 sda
   8        1     104391 sda1
   8        2   31350847 sda2
   8       16   10485760 sdb
   8       32   10485760 sdc
   8       48   10485760 sdd
   8       64   52428800 sde
   8       80   52428800 sdf
   8       81   52428096 sdf1
 253        0   27295744 dm-0
 253        1    4030464 dm-1
[root@localhost backup]# /etc/init.d/oracleasm createdisk DATA1 /dev/sdf1
Marking disk "DATA1" as an ASM disk:                       [  OK  ]
[root@localhost backup]# /etc/init.d/oracleasm listdisks
DATA1
[root@localhost backup]#

Configure Mount Point on Linux

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       26G  2.6G   22G  11% /
/dev/sda1              99M   24M   71M  25% /boot
tmpfs                 978M     0  978M   0% /dev/shm

[root@localhost ~]# cat /proc/partitions
major minor  #blocks  name

   8        0   31457280 sda
   8        1     104391 sda1
   8        2   31350847 sda2
   8       16   10485760 sdb
 253        0   27295744 dm-0
 253        1    4030464 dm-1

[root@localhost ~]# ls -ltrh /dev/sd*
brw-r----- 1 root disk 8,  2 Jan 19 00:09 /dev/sda2
brw-r----- 1 root disk 8,  0 Jan 19 00:09 /dev/sda
brw-r----- 1 root disk 8, 16 Jan 19 00:09 /dev/sdb
brw-r----- 1 root disk 8,  1 Jan 19 00:10 /dev/sda1

[root@localhost ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3916    31350847+  8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/dm-0: 27.9 GB, 27950841856 bytes
255 heads, 63 sectors/track, 3398 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 4127 MB, 4127195136 bytes
255 heads, 63 sectors/track, 501 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-1 doesn't contain a valid partition table

[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

[root@localhost ~]# cat /proc/partitions
major minor  #blocks  name

   8        0   31457280 sda
   8        1     104391 sda1
   8        2   31350847 sda2
   8       16   10485760 sdb
   8       17   10482381 sdb1
 253        0   27295744 dm-0
 253        1    4030464 dm-1

[root@localhost ~]# cat /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0


[root@localhost ~]# mkfs.ext3 -b 4096 /dev/sdb
mke2fs 1.39 (29-May-2006)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1310720 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@localhost ~]# cat /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0

[root@localhost ~]# vi /etc/fstab
[root@localhost ~]# cat /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
/dev/sdb                /u01                    ext3    defaults        1 1
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
[root@localhost ~]# mkdir -p /u01
[root@localhost ~]# mount /dev/sdb /u01

[root@localhost ~]# df -h /u01
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb              9.9G  151M  9.2G   2% /u01
[root@localhost ~]#