15 November, 2010

"SET TIME ON" in RMAN

"SET TIME ON" in SQLPlus is a SQLPlus client command. It displays the system time from the SQLPlus client program.

If you want RMAN to display "time" you can use NLS_DATE_FORMAT as below :

[oracle@localhost ~]$ env |grep NLS
[oracle@localhost ~]$ NLS_DATE_FORMAT=DD_MON_YYYY_HH24:MI:SS;export NLS_DATE_FORMAT
[oracle@localhost ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Nov 15 06:45:50 2010

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

connected to target database: ORCL (DBID=1229390655)

RMAN> backup database;

Starting backup at 15_NOV_2010_06:45:55
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=54 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=47 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=00004 name=/addtl/oracle/oradata/orcl/users01.dbf
input datafile file number=00002 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00003 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00005 name=/home/oracle/app/oracle/oradata/orcl/example01.dbf
input datafile file number=00006 name=/home/oracle/app/oracle/oradata/orcl/FLOW_1046101119510758.dbf
input datafile file number=00007 name=/home/oracle/app/oracle/oradata/orcl/FLOW_1146416395631714.dbf
input datafile file number=00008 name=/home/oracle/app/oracle/oradata/orcl/FLOW_1170420963682633.dbf
channel ORA_DISK_1: starting piece 1 at 15_NOV_2010_06:45:58
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00014 name=/addtl/oracle/oradata/orcl/hemant01.dbf
input datafile file number=00015 name=/addtl/oracle/oradata/orcl/hemant02.dbf
input datafile file number=00016 name=/addtl/oracle/oradata/orcl/hemant03.dbf
input datafile file number=00009 name=/home/oracle/app/oracle/oradata/orcl/FLOW_1194425963955800.dbf
input datafile file number=00010 name=/home/oracle/app/oracle/oradata/orcl/FLOW_1218408858999342.dbf
input datafile file number=00011 name=/home/oracle/app/oracle/oradata/orcl/FLOW_1242310449730067.dbf
input datafile file number=00012 name=/home/oracle/app/oracle/oradata/orcl/FLOW_1266412439758696.dbf
input datafile file number=00013 name=/home/oracle/app/oracle/oradata/orcl/APEX_1295922881855015.dbf
channel ORA_DISK_2: starting piece 1 at 15_NOV_2010_06:45:58
channel ORA_DISK_2: finished piece 1 at 15_NOV_2010_06:46:01
piece handle=/addtl/oracle/flash_recovery_area/ORCL/backupset/2010_11_15/o1_mf_nnndf_TAG20101115T064557_6g2kx70g_.bkp tag=TAG20101115T064557 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_2: starting piece 1 at 15_NOV_2010_06:46:03
channel ORA_DISK_2: finished piece 1 at 15_NOV_2010_06:46:06
piece handle=/addtl/oracle/flash_recovery_area/ORCL/backupset/2010_11_15/o1_mf_ncnnf_TAG20101115T064557_6g2kxcc6_.bkp tag=TAG20101115T064557 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_2: starting piece 1 at 15_NOV_2010_06:46:07
channel ORA_DISK_2: finished piece 1 at 15_NOV_2010_06:46:08
piece handle=/addtl/oracle/flash_recovery_area/ORCL/backupset/2010_11_15/o1_mf_nnsnf_TAG20101115T064557_6g2kxh4q_.bkp tag=TAG20101115T064557 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:02
...



Notice how the RMAN output shows the Tmestamp in DD_MON_YYYY_HH24:MI:SS format. You could specify an alternate format as well.

[oracle@localhost ~]$ NLS_DATE_FORMAT=DD/MM/YYYY_HH24_MI_SS;export NLS_DATE_FORMAT
[oracle@localhost ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Nov 15 06:50:47 2010

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

connected to target database: ORCL (DBID=1229390655)

RMAN> backup datafile 1 ;

Starting backup at 15/11/2010_06_50_53
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=47 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=49 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=/home/oracle/app/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: starting piece 1 at 15/11/2010_06_50_56
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_2: starting piece 1 at 15/11/2010_06_51_00
channel ORA_DISK_2: finished piece 1 at 15/11/2010_06_51_16
piece handle=/addtl/oracle/flash_recovery_area/ORCL/backupset/2010_11_15/o1_mf_ncnnf_TAG20101115T065055_6g2l6obt_.bkp tag=TAG20101115T065055 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:16
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_2: starting piece 1 at 15/11/2010_06_51_17
channel ORA_DISK_1: finished piece 1 at 15/11/2010_06_51_32
piece handle=/addtl/oracle/flash_recovery_area/ORCL/backupset/2010_11_15/o1_mf_nnndf_TAG20101115T065055_6g2l6jdx_.bkp tag=TAG20101115T065055 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:36
channel ORA_DISK_2: finished piece 1 at 15/11/2010_06_51_32
piece handle=/addtl/oracle/flash_recovery_area/ORCL/backupset/2010_11_15/o1_mf_nnsnf_TAG20101115T065055_6g2l763s_.bkp tag=TAG20101115T065055 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:15
Finished backup at 15/11/2010_06_51_32

RMAN>


Thus, I can change the format of the time display with NLS_DATE_FORMAT.

I can also display backup timestamps etc in the desired format :

[oracle@localhost ~]$ NLS_DATE_FORMAT=DD_MON_RR_HH24_MI_SS
[oracle@localhost ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Nov 15 06:54:15 2010

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

connected to target database: ORCL (DBID=1229390655)

RMAN> list backup of datafile 1;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ------------------
21 Full 666.52M DISK 00:00:48 26_OCT_10_07_17_31
BP Key: 21 Status: AVAILABLE Compressed: NO Tag: TAG20101026T071642
Piece Name: /addtl/oracle/flash_recovery_area/ORCL/backupset/2010_10_26/o1_mf_nnndf_TAG20101026T071642_6dfrpcdn_.bkp
List of Datafiles in backup set 21
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------ ----
1 Full 5323127 26_OCT_10_07_16_43 /home/oracle/app/oracle/oradata/orcl/system01.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ------------------
27 Full 953.77M DISK 00:04:42 26_OCT_10_07_23_15
BP Key: 27 Status: AVAILABLE Compressed: YES Tag: TAG20101026T071833
Piece Name: /addtl/oracle/flash_recovery_area/ORCL/backupset/2010_10_26/o1_mf_nnndf_TAG20101026T071833_6dfrst78_.bkp
List of Datafiles in backup set 27
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------ ----
1 Full 5323217 26_OCT_10_07_18_33 /home/oracle/app/oracle/oradata/orcl/system01.dbf

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ------------------
34 Full 668.63M DISK 00:00:34 15_NOV_10_06_51_30
BP Key: 34 Status: AVAILABLE Compressed: NO Tag: TAG20101115T065055
Piece Name: /addtl/oracle/flash_recovery_area/ORCL/backupset/2010_11_15/o1_mf_nnndf_TAG20101115T065055_6g2l6jdx_.bkp
List of Datafiles in backup set 34
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------ ----
1 Full 5442510 15_NOV_10_06_50_56 /home/oracle/app/oracle/oradata/orcl/system01.dbf

RMAN>


This is useful when you are looking for backups within a particular time range and yo uhave had multiple backups done on the same day. The format can be modified to show Hours_Minutes_Seconds as well.
.
.
.

01 November, 2010

Most Popular Posts - Oct 10

Blogger's "Stats" feature shows that the 3 most popular posts in the past 30 days have been :

3. AUTOEXTEND ON Next Size : 198 pageviews

.
.
.

20 October, 2010

How the Optimizer can use Constraint Definitions

A simple demonstration of how properly defined Referential Integrity constraints can be used by the Optimizer.....

If two tables (say SALES and SALES_LINES) have a Parent-Child relationship but the proper R.I. constraint is not defined, it is possible (either through faulty application code that uses two separate transactions for an INSERT {or a DELETE} against the two tables OR through erroneous adhoc updates to the data) to have "dangling" child records.
For example, an INSERT into SALES errors out (for lack of space in that tablespace) but the corresponding INSERT into SALES_LINES succeeds and commits, when executed as a separate transaction.
Or an adhoc "data-fix" operation deletes rows from the SALES table without having deleted them from the SALES_LINES table first.

Having UNIQUE Indexes on the two tables will not prevent the occurrence of "parent-less children" !

When querying the SALES_LINES table, it might be necessary to validate that the corresponding SALES row exists. This could be done as a join between the two tables, explicitly included in every query against the SALES_LINES table.

Assuming that the two tables have 100,000 rows (each sale having only 1 line), with proper Unique Indexes, a query for one PROD_ID of 10 different products may execute as :


SQL> -- Query for Total Sales for PROD_ID=5
SQL> select sum(l.quantity), sum(l.quantity*l.price)
2 from sales_lines l, sales s
3 where
4 -- join code is used to validate that the sale_id is legitimate
5 l.sale_id = s.sale_id
6 and l.prod_id=5
7 and l.sale_id between 25000 and 35000
8 /

SUM(L.QUANTITY) SUM(L.QUANTITY*L.PRICE)
--------------- -----------------------
2441786 48892118.9


Execution Plan
----------------------------------------------------------
Plan hash value: 146457679

------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 39 | 139 (0)| 00:00:02 |
| 1 | SORT AGGREGATE | | 1 | 39 | | |
| 2 | NESTED LOOPS | | 984 | 38376 | 139 (0)| 00:00:02 |
|* 3 | TABLE ACCESS BY INDEX ROWID| SALES_LINES | 984 | 33456 | 139 (0)| 00:00:02 |
|* 4 | INDEX RANGE SCAN | SALES_LINES_UK | 10000 | | 24 (0)| 00:00:01 |
|* 5 | INDEX UNIQUE SCAN | SALES_UK | 1 | 5 | 0 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------


3 - filter("L"."PROD_ID"=5)
4 - access("L"."SALE_ID">=25000 AND "L"."SALE_ID"<=35000)

5 - access("L"."SALE_ID"="S"."SALE_ID")
filter("S"."SALE_ID"<=35000 AND "S"."SALE_ID">=25000)

Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
281 consistent gets
0 physical reads
0 redo size
523 bytes sent via SQL*Net to client
419 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed

However, if I were to define the Constraints as :

SQL> REM REM ######################################
SQL> REM Now add the Constraint Definitions !
SQL> alter table SALES add constraint SALES_PK primary key (sale_id);

Table altered.

SQL> alter table SALES_LINES add constraint SALES_LINES_FK foreign key (sale_id) references SALES (sale_id);

Table altered.

SQL> REM REM ######################################

and I re-run the query :

SQL> select sum(l.quantity), sum(l.quantity*l.price)
2 from sales_lines l, sales s
3 where
4 -- join code is used to validate that the sale_id is legitimate
5 l.sale_id = s.sale_id
6 and l.prod_id=5
7 and l.sale_id between 25000 and 35000
8 /

SUM(L.QUANTITY) SUM(L.QUANTITY*L.PRICE)
--------------- -----------------------
2441786 48892118.9


Execution Plan
----------------------------------------------------------
Plan hash value: 2517766180

-----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 34 | 139 (0)| 00:00:02 |
| 1 | SORT AGGREGATE | | 1 | 34 | | |
|* 2 | TABLE ACCESS BY INDEX ROWID| SALES_LINES | 984 | 33456 | 139 (0)| 00:00:02 |
|* 3 | INDEX RANGE SCAN | SALES_LINES_UK | 10000 | | 24 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - filter("L"."PROD_ID"=5)
3 - access("L"."SALE_ID">=25000 AND "L"."SALE_ID"<=35000)


Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
139 consistent gets
0 physical reads
0 redo size
523 bytes sent via SQL*Net to client
419 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed

Oracle can simply eliminate the lookup on the SALES table and do much fewer consistent gets.
The presence of the constraint ensures that every SALE_ID in the (child) SALES_LINES table *does* have corresponding SALE_ID in the (parent) SALES table. Since I am not fetching any columns from the SALES table, the join is now unnecessary and the optimizer (smartly) eliminates the join.

.

UPDATE : See the Optimizer team's blog post on Table (Join) Elimination.

.

.
.