Tuesday, March 29, 2016

Bind Variables

This example, tested on Oracle 11, shows how you can define bind variables in SQL*Plus, assign values to them in PL/SQL then display those values afterwards back in SQL*Plus:

SQL> variable bv1 varchar2(3)
SQL> variable bv2 number
SQL> begin
  2  select 'ABC' into :bv1 from dual;
  3  select 123 into :bv2 from dual;
  4  end;
  5  /

PL/SQL procedure successfully completed.

SQL> print bv1

BV1
--------------------------------
ABC

SQL> print bv2

       BV2
----------
       123

SQL> execute :bv1 := 'XYZ';

PL/SQL procedure successfully completed.

SQL> execute :bv2 := 456;

PL/SQL procedure successfully completed.

SQL> print bv1

BV1
--------------------------------
XYZ

SQL> print bv2

       BV2
----------
       456

SQL>

Friday, March 11, 2016

RMAN Backup With Compression

I repeated the test from the previous post but this time I tried to compress the backup. At this stage I need your help. I believe I have used the free compression which does not require an extra licence. If somebody who knows more about this than me could add a comment below, telling me if I am right or wrong, that would be very helpful. I backed up the database as before:

C:\Users\AJ0294094>rman nocatalog target=andrew/reid

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Mar 11 19:19:38 2016

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: DEBELDV2 (DBID=4080010922, not open)
using target database control file instead of recovery catalog

RMAN> backup as compressed backupset database;

Starting backup at 11-MAR-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=156 device type=DISK
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=E:\ORACLE\ORADATA\DEBELDV2\SYSTEM01.DBF
input datafile file number=00003 name=E:\ORACLE\ORADATA\DEBELDV2\UNDOTBS01.DBF
input datafile file number=00002 name=E:\ORACLE\ORADATA\DEBELDV2\SYSAUX01.DBF
input datafile file number=00004 name=E:\ORACLE\ORADATA\DEBELDV2\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 11-MAR-16
channel ORA_DISK_1: finished piece 1 at 11-MAR-16
piece handle=E:\ORACLE\FLASH_RECOVERY_AREA\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_1
1\O1_MF_NNNDF_TAG20160311T192012_CG632XB5_.BKP tag=TAG20160311T192012 comment=NO
NE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 11-MAR-16
channel ORA_DISK_1: finished piece 1 at 11-MAR-16
piece handle=E:\ORACLE\FLASH_RECOVERY_AREA\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_1
1\O1_MF_NCSNF_TAG20160311T192012_CG6359MJ_.BKP tag=TAG20160311T192012 comment=NO
NE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-MAR-16

RMAN> exit


Recovery Manager complete.

C:\Users\AJ0294094>

... and when I checked the size of the backup on disk, it was roughly a quarter of the size of the backup I did before:

E:\oracle\flash_recovery_area\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_11>dir
Volume in drive E is Seagate Backup Plus Drive
Volume Serial Number is 6E45-7AAF

Directory of E:\oracle\flash_recovery_area\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_
11

03/11/2016  07:21 PM    <DIR>          .
03/11/2016  07:21 PM    <DIR>          ..
03/11/2016  07:21 PM         1,097,728 O1_MF_NCSNF_TAG20160311T192012_CG6359MJ_.
BKP
03/11/2016  07:21 PM       235,659,264 O1_MF_NNNDF_TAG20160311T192012_CG632XB5_.
BKP
               2 File(s)    236,756,992 bytes
               2 Dir(s)  579,868,397,568 bytes free

E:\oracle\flash_recovery_area\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_11>

RMAN Backup Without Compression

I wanted to test the effect of RMAN backup compression on an Oracle 11.2.0.1 database running on Windows. I configured the flash recovery area, closed the database and mounted it. Then I did a backup without compression:

C:\Users\AJ0294094>rman nocatalog target=andrew/reid

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Mar 11 18:42:42 2016

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: DEBELDV2 (DBID=4080010922)
using target database control file instead of recovery catalog

RMAN> shutdown

database closed
database dismounted
Oracle instance shut down

RMAN> startup mount

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area    1043886080 bytes

Fixed Size                     2182344 bytes
Variable Size                612369208 bytes
Database Buffers             423624704 bytes
Redo Buffers                   5709824 bytes

RMAN> backup database;

Starting backup at 11-MAR-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=156 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=E:\ORACLE\ORADATA\DEBELDV2\SYSTEM01.DBF
input datafile file number=00003 name=E:\ORACLE\ORADATA\DEBELDV2\UNDOTBS01.DBF
input datafile file number=00002 name=E:\ORACLE\ORADATA\DEBELDV2\SYSAUX01.DBF
input datafile file number=00004 name=E:\ORACLE\ORADATA\DEBELDV2\USERS01.DBF
channel ORA_DISK_1: starting piece 1 at 11-MAR-16
channel ORA_DISK_1: finished piece 1 at 11-MAR-16
piece handle=E:\ORACLE\FLASH_RECOVERY_AREA\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_1
1\O1_MF_NNNDF_TAG20160311T184324_CG60XXJ6_.BKP tag=TAG20160311T184324 comment=NO
NE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 11-MAR-16
channel ORA_DISK_1: finished piece 1 at 11-MAR-16
piece handle=E:\ORACLE\FLASH_RECOVERY_AREA\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_1
1\O1_MF_NCSNF_TAG20160311T184324_CG610XWY_.BKP tag=TAG20160311T184324 comment=NO
NE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 11-MAR-16

RMAN>

I checked the size of the backup. It was just under 1 gigabyte (N.B. this was an empty database just created by dbca):

E:\oracle\flash_recovery_area\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_11>dir
Volume in drive E is Seagate Backup Plus Drive
Volume Serial Number is 6E45-7AAF

Directory of E:\oracle\flash_recovery_area\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_
11

03/11/2016  06:45 PM    <DIR>          .
03/11/2016  06:45 PM    <DIR>          ..
03/11/2016  06:45 PM         9,830,400 O1_MF_NCSNF_TAG20160311T184324_CG610XWY_.
BKP
03/11/2016  06:44 PM       981,147,648 O1_MF_NNNDF_TAG20160311T184324_CG60XXJ6_.
BKP
               2 File(s)    990,978,048 bytes
               2 Dir(s)  579,413,495,808 bytes free

E:\oracle\flash_recovery_area\DEBELDV2\DEBELDV2\BACKUPSET\2016_03_11>

I did not need to keep this backup so I deleted it:

C:\Users\AJ0294094>rman nocatalog target=andrew/reid

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Mar 11 19:08:46 2016

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: DEBELDV2 (DBID=4080010922, not open)
using target database control file instead of recovery catalog

RMAN> delete backup;

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=156 device type=DISK

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
1       1       1   1   AVAILABLE   DISK        E:\ORACLE\FLASH_RECOVERY_AREA\DE
BELDV2\DEBELDV2\BACKUPSET\2016_03_11\O1_MF_NNNDF_TAG20160311T184324_CG60XXJ6_.BK
P
2       2       1   1   AVAILABLE   DISK        E:\ORACLE\FLASH_RECOVERY_AREA\DE
BELDV2\DEBELDV2\BACKUPSET\2016_03_11\O1_MF_NCSNF_TAG20160311T184324_CG610XWY_.BK
P

Do you really want to delete the above objects (enter YES or NO)? YES
deleted backup piece
backup piece handle=E:\ORACLE\FLASH_RECOVERY_AREA\DEBELDV2\DEBELDV2\BACKUPSET\20
16_03_11\O1_MF_NNNDF_TAG20160311T184324_CG60XXJ6_.BKP RECID=1 STAMP=906230605
deleted backup piece
backup piece handle=E:\ORACLE\FLASH_RECOVERY_AREA\DEBELDV2\DEBELDV2\BACKUPSET\20
16_03_11\O1_MF_NCSNF_TAG20160311T184324_CG610XWY_.BKP RECID=2 STAMP=906230701
Deleted 2 objects


RMAN>

I checked at the OS level that the backup files had disappeared (they had).

Continued in the next post.