Search My Oracle Blog

Custom Search

23 February, 2014

RMAN Image Copy File Names

RMAN provides a convenient way to name Image Copies (backups) of datafiles to retain the same file name without the path.  This is possible with the "%b" FORMAT modifier.

Here's a demo :

[oracle@localhost ~]$ cd /IMA*/ORCL*
[oracle@localhost ORCL_DB]$ pwd
/IMAGE_BACKUP/ORCL_DB
[oracle@localhost ORCL_DB]$ rman target /

Recovery Manager: Release 11.2.0.2.0 - Production on Sun Feb 23 23:24:55 2014

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

connected to target database: ORCL (DBID=1229390655)

RMAN> backup as copy database format '/IMAGE_BACKUP/ORCL_DB/%b';


Starting backup at 23-FEB-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf
output file name=/IMAGE_BACKUP/ORCL_DB/sysaux01.dbf tag=TAG20140223T232527 RECID=3 STAMP=840324368
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/home/oracle/app/oracle/oradata/orcl/system01.dbf
output file name=/IMAGE_BACKUP/ORCL_DB/system01.dbf tag=TAG20140223T232527 RECID=4 STAMP=840324400
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/home/oracle/app/oracle/oradata/orcl/users01.dbf
output file name=/IMAGE_BACKUP/ORCL_DB/users01.dbf tag=TAG20140223T232527 RECID=5 STAMP=840324414
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00011 name=/home/oracle/app/oracle/oradata/orcl/ORCL/datafile/o1_mf_hemant_8pnowslc_.dbf
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 02/23/2014 23:26:55
ORA-01276: Cannot add file /IMAGE_BACKUP/ORCL_DB/o1_mf_hemant_8pnowslc_.dbf.  File has an Oracle Managed Files file name.
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf
output file name=/IMAGE_BACKUP/ORCL_DB/undotbs01.dbf tag=TAG20140223T232527 RECID=6 STAMP=840324420
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/home/oracle/app/oracle/oradata/orcl/example01.dbf
output file name=/IMAGE_BACKUP/ORCL_DB/example01.dbf tag=TAG20140223T232527 RECID=7 STAMP=840324428
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
copying current control file
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 02/23/2014 23:27:12
ORA-19715: invalid format b for generated name
ORA-27302: failure occurred at: slgpn
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 23-FEB-14
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 02/23/2014 23:27:12
ORA-19715: invalid format b for generated name
ORA-27302: failure occurred at: slgpn

RMAN> 
RMAN> quit


Recovery Manager complete.
[oracle@localhost ORCL_DB]$ pwd
/IMAGE_BACKUP/ORCL_DB
[oracle@localhost ORCL_DB]$ pwd
/IMAGE_BACKUP/ORCL_DB
[oracle@localhost ORCL_DB]$ ls -l
total 2641496
-rw-rw---- 1 oracle oracle   85991424 Feb 23 23:27 example01.dbf
-rw-rw---- 1 oracle oracle 1320165376 Feb 23 23:26 sysaux01.dbf
-rw-rw---- 1 oracle oracle  881860608 Feb 23 23:26 system01.dbf
-rw-rw---- 1 oracle oracle  178266112 Feb 23 23:27 undotbs01.dbf
-rw-rw---- 1 oracle oracle  235937792 Feb 23 23:26 users01.dbf
[oracle@localhost ORCL_DB]$ 


However, this fails with OMF files and controlfile auto backups.

Also, you have to be careful to check that you do not have two datafiles with the same name in two different folders. RMAN recognises the presence of the first datafile copied and raises an error on the second datafile

For example :

SQL> create tablespace test_tbs datafile '/home/oracle/app/oracle/oradata/orcl/test_tbs_01.dbf' size 100M;

Tablespace created.

SQL> alter tablespace test_tbs add datafile '/tmp/test_tbs_01.dbf' size 50M;

Tablespace altered.

SQL> 
SQL> !ls -l /home/oracle/app/oracle/oradata/orcl/test_tbs_01.dbf
-rw-rw---- 1 oracle oracle 104865792 Feb 23 23:34 /home/oracle/app/oracle/oradata/orcl/test_tbs_01.dbf

SQL> !ls -l /tmp/test_tbs_01.dbf
-rw-rw---- 1 oracle oracle 52436992 Feb 23 23:34 /tmp/test_tbs_01.dbf

SQL> exit

RMAN> backup as copy tablespace test_tbs format '/IMAGE_BACKUP/ORCL_DB/%b';

Starting backup at 23-FEB-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=47 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/home/oracle/app/oracle/oradata/orcl/test_tbs_01.dbf
output file name=/IMAGE_BACKUP/ORCL_DB/test_tbs_01.dbf tag=TAG20140223T233608 RECID=8 STAMP=840324970
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/tmp/test_tbs_01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 02/23/2014 23:36:13
ORA-19504: failed to create file "/IMAGE_BACKUP/ORCL_DB/test_tbs_01.dbf"
ORA-27038: created file already exists
Additional information: 1

RMAN> 

The %b format for datafiles is also supposed to be usable with the SET NEWNAME clause in a RESTORE run.

.
.
.

22 February, 2014

20 February, 2014

An SQL Performance Quiz

Markus Winand has written a very small SQL Performance Quiz.  (I scored 5 out of 5 on Oracle).
He has published a review of the results.  A very large number of visitors have failed.

.
.
.


12 February, 2014

login.sql does not require a login

Oracle's sqlplus can use a login.sql file to execute commands -- e.g. setup options.
This file is read and executed when you start sqlplus, even without having logged in to a database.

Here's a quick demo :

I start an sqlplus session without a login.sql

[oracle@localhost ~]$ pwd
/home/oracle
[oracle@localhost ~]$ ls -l login.sql
ls: login.sql: No such file or directory
[oracle@localhost ~]$ sqlplus hemant/hemant

SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 12 08:01:43 2014

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show pagesize 
pagesize 14
SQL> show linesize
linesize 80
SQL> show sqlprompt
sqlprompt "SQL> "
SQL> 

Now, I create a login.sql and invoke sqlplus without logging in to the database.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost ~]$ vi login.sql
[oracle@localhost ~]$ cat login.sql
set pagesize 60
set linesize 132
set sqlprompt 'HemantSQL>'
[oracle@localhost ~]$ 
[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 12 08:05:24 2014

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

HemantSQL>show pagesize
pagesize 60
HemantSQL>show linesize
linesize 132
HemantSQL>show user
USER is ""
HemantSQL>

Without having connected to a database (and created a database session), the login.sql was executed.

I can also have it dynamically use a variable --- e.g. the sqlprompt changing based on my login username.

HemantSQL>exit
[oracle@localhost ~]$ vi login.sql
[oracle@localhost ~]$ cat login.sql
set pagesize 60
set linesize 132
set sqlprompt '_USER>'
[oracle@localhost ~]$ 
[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 12 08:08:12 2014

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

>
>show user
USER is ""
>connect hemant/hemant
Connected.
HEMANT>show user
USER is "HEMANT"
HEMANT>connect hr/oracle
Connected.
HR>show user
USER is "HR"
HR>
HR>exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost ~]$ 

Notice how the sqlprompt was simply ">" when no user was logged in ? On the "HEMANT" and "HR" logins, the prompt did change.

.
.
.

08 February, 2014

06 February, 2014

The difference between SELECT ANY DICTIONARY and SELECT_CATALOG_ROLE

I've seen some DBAs confused about these two "privileges" or "roles".

SELECT ANY DICTIONARY is a System Privilege.

SELECT_CATALOG_ROLE is a Role you would see in DBA_ROLES.  However, querying DBA_SYS_PRIVS does NOT show what privileges are granted to this role.

SELECT_CATALOG_ROLE predates the SELECT ANY DICTIONARY privilege.

The SELECT ANY DICTIONARY privilege grants Read access on Data Dictionary tables owned by SYS.  The SELECT_CATALOG_ROLE role grants Read access to Data Dictionary (DBA_%) and Performance (V$%) views.

Here is a short demo :


SQL*Plus: Release 11.2.0.2.0 Production on Thu Feb 6 07:48:15 2014

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

Enter user-name: / as sysdba

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create user sad identified by sad;

User created.

SQL> grant create session, select any dictionary to sad;

Grant succeeded.

SQL> create user scr identified by scr;

User created.

SQL> grant create session, select_catalog_role to scr;

Grant succeeded.

SQL> 
SQL> connect sad/sad
Connected.
SQL> select count(*) from sys.user$;

  COUNT(*)
----------
       115

SQL> select count(*) from dba_users;

  COUNT(*)
----------
        53

SQL> connect scr/scr
Connected.
SQL> select count(*) from sys.user$;
select count(*) from sys.user$
                         *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select count(*) from dba_users;

  COUNT(*)
----------
        53

SQL> 

If you needed to grant a new / junior DBA or a Consultant the privilege to query the Data Dictionary and Performance views, which would you grant ?

.
.
.

Aggregated by orafaq.com

Aggregated by orafaq.com
This blog is being aggregated by orafaq.com