Sunday 15 November 2015

DB level size and free space

col hostname for a30
select (select host_name from v$instance)hostname,GB_DB_SIZE  , (select sum(BYTES)/1024/1024/1024 from dba_free_space) free from
(
select sum(physical_bytes)/1024/1024/1024 GB_DB_SIZE  from
(
select
      sum(bytes) physical_bytes
    from
      dba_data_files
    union all
select
      sum(bytes)
    from
      dba_temp_files
union all
select sum(BYTES) from v$log
) );

Thursday 20 August 2015

Rman duplicate database skip tablespace

RMAN - Duplicate database with skip tablespace.

This scenario when any table got dropped and user just need those table data. Duplicate database by skipping unrequited tablespace. Export required table from duplicate  database.

We can use point in time recovery too.

Source DB - orcl
Temp Db   - test2

SYS@clone> select name from v$tablespace;

NAME
------------------------------
SYSTEM
TEMP
SYSAUX
SYS_UNDOTS


6 rows selected.



C:\Windows\system32>rman auxiliary / target sys/orcl@clone

Recovery Manager: Release 11.1.0.6.0 - Production on Fri Aug 21 01:42:46 2015

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

connected to target database: CLONE (DBID=939948083)
connected to auxiliary database: TEST2 (not mounted)

RMAN> run
2> {
3> ##SET NEWNAME FOR DATABASE TO 'C:\APP\DILIP\ORADATA\backup_clone\test2\%b';  11.2.0 feature
4> ###set until time "to_date('13-apr-2014 00:37:26', 'dd-mon-yyyy hh24:mi:ss')";
5> set newname for tempfile 1 to 'C:\APP\DILIP\ORADATA\backup_clone\test2\TEMP01.DBF';
6> DUPLICATE TARGET DATABASE TO test2 SKIP TABLESPACE tt1,tt
7> LOGFILE
8>   GROUP 1 ('C:\APP\DILIP\ORADATA\backup_clone\test2\t_log1.f')  SIZE 10m,
9>   GROUP 2 ('C:\APP\DILIP\ORADATA\backup_clone\test2\t_log2.f') SIZE 10m;
10> }

executing command: SET NEWNAME
using target database control file instead of recovery catalog

Starting Duplicate Db at 21-AUG-15
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=98 device type=DISK
Datafile 4 skipped by request
Datafile 5 skipped by request

contents of Memory Script:
{
   set until scn  325074;
   set newname for datafile  1 to
 "C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSTEM01.DBF";
   set newname for datafile  2 to
 "C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSAUX01.DBF";
   set newname for datafile  3 to
 "C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2UNDOTBS01.DBF";
   restore
   clone database
   skip tablespace  "TT1",
 "TT"   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 21-AUG-15
using channel ORA_AUX_DISK_1

skipping datafile 3; already restored to file C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2UNDOTBS01.DBF
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00002 to C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSAUX01.DBF
channel ORA_AUX_DISK_1: reading from backup piece C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_21_20150821_2JQF46C1_1_1
channel ORA_AUX_DISK_1: piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_21_20150821_2JQF46C1_1_1 tag=TAG20150821T005108
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSTEM01.DBF
channel ORA_AUX_DISK_1: reading from backup piece C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_21_20150821_2IQF46BS_1_1
channel ORA_AUX_DISK_1: piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_21_20150821_2IQF46BS_1_1 tag=TAG20150821T005108
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 21-AUG-15
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TEST2" RESETLOGS ARCHIVELOG
  MAXLOGFILES     32
  MAXLOGMEMBERS      2
  MAXDATAFILES       32
  MAXINSTANCES    16
  MAXLOGHISTORY     1752
 LOGFILE
  GROUP  1 ( 'C:\APP\DILIP\ORADATA\backup_clone\test2\t_log1.f' ) SIZE 10 M ,
  GROUP  2 ( 'C:\APP\DILIP\ORADATA\backup_clone\test2\t_log2.f' ) SIZE 10 M
 DATAFILE
  'C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSTEM01.DBF'
 CHARACTER SET US7ASCII


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=888284617 file name=C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSAUX01.DBF
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=888284617 file name=C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2UNDOTBS01.DBF

contents of Memory Script:
{
   set until scn  325074;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 21-AUG-15
using channel ORA_AUX_DISK_1
datafile 4 not processed because file is offline
datafile 5 not processed because file is offline

starting media recovery

archived log for thread 1 with sequence 3 is already on disk as file C:\APP\DILIP\PRODUCT\11.1.0\DB_1\RDBMS\ARC00003_0888274922.001
archived log file name=C:\APP\DILIP\PRODUCT\11.1.0\DB_1\RDBMS\ARC00003_0888274922.001 thread=1 sequence=3
media recovery complete, elapsed time: 00:00:01
Finished recover at 21-AUG-15

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount ;
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     209235968 bytes

Fixed Size                     1332188 bytes
Variable Size                 71306276 bytes
Database Buffers             130023424 bytes
Redo Buffers                   6574080 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TEST2" RESETLOGS ARCHIVELOG
  MAXLOGFILES     32
  MAXLOGMEMBERS      2
  MAXDATAFILES       32
  MAXINSTANCES    16
  MAXLOGHISTORY     1752
 LOGFILE
  GROUP  1 ( 'C:\APP\DILIP\ORADATA\backup_clone\test2\t_log1.f' ) SIZE 10 M ,
  GROUP  2 ( 'C:\APP\DILIP\ORADATA\backup_clone\test2\t_log2.f' ) SIZE 10 M
 DATAFILE
  'C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSTEM01.DBF'
 CHARACTER SET US7ASCII


contents of Memory Script:
{
   set newname for tempfile  1 to
 "C:\APP\DILIP\ORADATA\backup_clone\test2\TEMP01.DBF";
   switch clone tempfile all;
   catalog clone datafilecopy  "C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSAUX01.DBF";
   catalog clone datafilecopy  "C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2UNDOTBS01.DBF";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to C:\APP\DILIP\ORADATA\backup_clone\test2\TEMP01.DBF in control file

cataloged datafile copy
datafile copy file name=C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSAUX01.DBF RECID=1 STAMP=888284634

cataloged datafile copy
datafile copy file name=C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2UNDOTBS01.DBF RECID=2 STAMP=888284634

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=888284634 file name=C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2SYSAUX01.DBF
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=888284634 file name=C:\APP\DILIP\ORADATA\BACKUP_CLONE\TEST2UNDOTBS01.DBF

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened

contents of Memory Script:
{
# drop offline and skipped tablespaces
sql clone 'drop tablespace  "TT1" including contents cascade constraints';
# drop offline and skipped tablespaces
sql clone 'drop tablespace  "TT" including contents cascade constraints';
}
executing Memory Script

sql statement: drop tablespace  "TT1" including contents cascade constraints

sql statement: drop tablespace  "TT" including contents cascade constraints
Finished Duplicate Db at 21-AUG-15

RMAN>


RMAN> exit

duplicate db---test2 no tt and tt1 tablespace.

SYS@test2> select name from v$tablespace;

NAME
------------------------------
SYSTEM
TEMP
SYSAUX
SYS_UNDOTS

4 rows selected.

RMAN read only open scenario before resetlogs

Resetlog always somewhat risky option, while opening database after incomplete recovery with resetlog option or point in time recovery and open db in resetlog. So its good to check db can open in ready only and check data is correct as per requirement and resetlog and then attempt it open in reset log.


level 0 backup:

run{
allocate channel c1 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U' maxpiecesize 8G;
allocate channel c2 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U' maxpiecesize 8G;
backup as compressed backupset incremental level=0 database plus archivelog  tag='Full_backup_level0';
}

level 1 backup:

sql "alter session set nls_date_format=''dd-Mon-yy hh24:mi:ss''";

run{
allocate channel c1 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U' maxpiecesize 8G;
allocate channel c2 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U' maxpiecesize 8G;
backup as compressed backupset incremental level=1 database plus archivelog  tag='%tag%';
}


backup as compressed backupset incremental level=1 database include current controlfile filesperset=50 tag='db_level_0';


sql "alter session set nls_date_format=''dd-Mon-yy hh24:mi:ss''";

run{
allocate channel c1 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U' maxpiecesize 8G;
allocate channel c2 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U' maxpiecesize 8G;
backup as compressed backupset incremental level=0 database include current controlfile filesperset=50 tag='db_level_0';
backup archivelog all delete all input filesperset=4 tag='arch_level_0';
}

run{
allocate channel c1 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U' maxpiecesize 8G;
allocate channel c2 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U' maxpiecesize 8G;
backup as compressed backupset incremental level=1 database include current controlfile filesperset=50 tag='db_level_1';
backup archivelog all delete all input filesperset=4 tag='arch_level_1';
}

RMAN> recover database until time "to_date('20-AUG-2015 22:28:11','dd-mon-yyyy hh24:mi:ss')";

Starting recover at 20-AUG-15
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=9
channel ORA_DISK_1: reading from backup piece C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_27QF3U0M_1_1
channel ORA_DISK_1: piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_27QF3U0M_1_1 tag=ARCH_LEVEL_0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=C:\APP\DILIP\PRODUCT\11.1.0\DB_1\RDBMS\ARC00009_0888271172.001 thread=1 sequence=9
media recovery complete, elapsed time: 00:00:01
Finished recover at 20-AUG-15

RMAN> exit


SYS@clone> /

FUZ STATUS  ERROR                                                             REC CHECKPOINT_CHANGE# CHECKPOINT_TIME
--- ------- ----------------------------------------------------------------- --- ------------------ ----------------------- ---
NO  ONLINE                                                                                    298348 20-AUG-2015 10:28:11 pm
NO  ONLINE                                                                                    298349 20-AUG-2015 10:28:11 pm

2 rows selected.

SYS@clone> alter database open read only;

Database altered.

SYS@clone> select open_mode from v$database;

OPEN_MODE
----------
READ ONLY

1 row selected.

SYS@clone> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            C:\app\Dilip\product\11.1.0\db_1\RDBMS
Oldest online log sequence     9
Next log sequence to archive   10
Current log sequence           10
SYS@clone> desc level1
ERROR:
ORA-04043: object level1 does not exist


SYS@clone> desc level10
ERROR:
ORA-04043: object level10 does not exist


SYS@clone>
SYS@clone>
SYS@clone> desc level10
ERROR:
ORA-04043: object level10 does not exist


SYS@clone> desc tab
 Name

 -------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
 TNAME

 TABTYPE

 CLUSTERID


SYS@clone> select * from tab where tname like 'LEVEL%';

TNAME                          TABTYPE         CLUSTERID
------------------------------ ------- -----------------
LEVEL_0                        TABLE
LEVEL_1                        TABLE

2 rows selected.


RMAN> recover database until sequence 11;

Starting recover at 20-AUG-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=99 device type=DISK
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: C:\APP\DILIP\ORADATA\CLONE_TEST\SYSTEM01.DBF
destination for restore of datafile 00005: C:\APP\DILIP\ORADATA\CLONE_TEST\TT1.DBF
channel ORA_DISK_1: reading from backup piece C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_28QF3
channel ORA_DISK_1: piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_28QF3U4A_1_1 tag=D
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: C:\APP\DILIP\ORADATA\CLONE_TEST\SYSAUX01.DBF
destination for restore of datafile 00003: C:\APP\DILIP\ORADATA\CLONE_TEST\UNDOTBS01.DBF
destination for restore of datafile 00004: C:\APP\DILIP\ORADATA\CLONE_TEST\TT.DBF
channel ORA_DISK_1: reading from backup piece C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_29QF3
channel ORA_DISK_1: piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_29QF3U4A_1_1 tag=D
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

starting media recovery

unable to find archived log
archived log thread=1 sequence=10
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/20/2015 22:56:59
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 10 and starting SCN of 29

RMAN> exit


Recovery Manager complete.

C:\Windows\system32>sqlplus / as sysdba

SQL*Plus: Release 11.1.0.6.0 - Production on Thu Aug 20 22:57:47 2015

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


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


SYS@clone> alter database open read only;

Database altered.

SYS@clone> desc level10
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 OWNER                                              VARCHAR2(30)
 SEGMENT_NAME                                       VARCHAR2(81)
 PARTITION_NAME                                     VARCHAR2(30)
 SEGMENT_TYPE                                       VARCHAR2(18)
 SEGMENT_SUBTYPE                                    VARCHAR2(10)
 TABLESPACE_NAME                                    VARCHAR2(30)
 HEADER_FILE                                        NUMBER
 HEADER_BLOCK                                       NUMBER
 BYTES                                              NUMBER
 BLOCKS                                             NUMBER
 EXTENTS                                            NUMBER
 INITIAL_EXTENT                                     NUMBER
 NEXT_EXTENT                                        NUMBER
 MIN_EXTENTS                                        NUMBER
 MAX_EXTENTS                                        NUMBER
 MAX_SIZE                                           NUMBER
 RETENTION                                          VARCHAR2(7)
 MINRETENTION                                       NUMBER
 PCT_INCREASE                                       NUMBER
 FREELISTS                                          NUMBER
 FREELIST_GROUPS                                    NUMBER
 RELATIVE_FNO                                       NUMBER
 BUFFER_POOL                                        VARCHAR2(7)

SYS@clone>
### Bingo :)


Or

again try for something

Creating Backups in Default Location Rather than using Format Rman

Solution:
Use below format while disk channel.

RMAN> run{
2> allocate channel c1 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U';
3> allocate channel c2 type disk format 'C:\app\Dilip\oradata\backup_clone\backup_clone\_%D_%T_%U';
4> backup database plus archivelog ;
5> }

allocated channel: c1
channel c1: SID=99 device type=DISK

allocated channel: c2
channel c2: SID=77 device type=DISK


Starting backup at 20-AUG-15
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=13 STAMP=888263407
input archived log thread=1 sequence=8 RECID=14 STAMP=888263640
input archived log thread=1 sequence=9 RECID=15 STAMP=888263680
input archived log thread=1 sequence=10 RECID=16 STAMP=888263953
input archived log thread=1 sequence=11 RECID=17 STAMP=888264014
channel c1: starting piece 1 at 20-AUG-15
channel c2: starting archived log backup set
channel c2: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=7 STAMP=888263082
input archived log thread=1 sequence=2 RECID=8 STAMP=888263086
input archived log thread=1 sequence=3 RECID=9 STAMP=888263089
input archived log thread=1 sequence=4 RECID=10 STAMP=888263217
input archived log thread=1 sequence=5 RECID=11 STAMP=888263344
input archived log thread=1 sequence=6 RECID=12 STAMP=888263362
channel c2: starting piece 1 at 20-AUG-15
channel c1: finished piece 1 at 20-AUG-15
piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_0RQF3LD5_1_1 tag=TAG20150820T200140 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=12 RECID=18 STAMP=888264100
channel c1: starting piece 1 at 20-AUG-15
channel c1: finished piece 1 at 20-AUG-15
piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_0TQF3LD6_1_1 tag=TAG20150820T200140 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c2: finished piece 1 at 20-AUG-15
piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_0SQF3LD5_1_1 tag=TAG20150820T200140 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:02
Finished backup at 20-AUG-15

Starting backup at 20-AUG-15
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=C:\APP\DILIP\ORADATA\CLONE_TEST\SYSTEM01.DBF
input datafile file number=00005 name=C:\APP\DILIP\ORADATA\CLONE_TEST\TT1.DBF
channel c1: starting piece 1 at 20-AUG-15
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00003 name=C:\APP\DILIP\ORADATA\CLONE_TEST\UNDOTBS01.DBF
input datafile file number=00002 name=C:\APP\DILIP\ORADATA\CLONE_TEST\SYSAUX01.DBF
input datafile file number=00004 name=C:\APP\DILIP\ORADATA\CLONE_TEST\TT.DBF
channel c2: starting piece 1 at 20-AUG-15
channel c1: finished piece 1 at 20-AUG-15
piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_0UQF3LD9_1_1 tag=TAG20150820T200144 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:26
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
channel c2: finished piece 1 at 20-AUG-15
piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_0VQF3LD9_1_1 tag=TAG20150820T200144 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:25
including current control file in backup set
channel c1: starting piece 1 at 20-AUG-15
channel c1: finished piece 1 at 20-AUG-15
piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_10QF3LE3_1_1 tag=TAG20150820T200144 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 20-AUG-15

Starting backup at 20-AUG-15
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=19 STAMP=888264134
channel c1: starting piece 1 at 20-AUG-15
channel c1: finished piece 1 at 20-AUG-15
piece handle=C:\APP\DILIP\ORADATA\BACKUP_CLONE\BACKUP_CLONE\_20_20150820_11QF3LE6_1_1 tag=TAG20150820T200214 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 20-AUG-15
released channel: c1
released channel: c2

RMAN>

Sunday 24 May 2015

ASM files db wise

ASM files db wise to see all list of files in db


---for ar database
column path format a70
column file_type format a15


select concat('+'||gname, sys_connect_by_path(aname, '/')) path,
       system_created, alias_directory, file_type
from ( select b.name gname, a.parent_index pindex, a.name aname,
              a.reference_index rindex , a.system_created, a.alias_directory,
              c.type file_type
       from v$asm_alias a, v$asm_diskgroup b, v$asm_file c
       where a.group_number = b.group_number
             and a.group_number = c.group_number(+)
             and a.file_number = c.file_number(+)
             and a.file_incarnation = c.incarnation(+)
     )
start with (mod(pindex, power(2, 24))) = 0
            and rindex in
                ( select a.reference_index
                  from v$asm_alias a, v$asm_diskgroup b
                  where a.group_number = b.group_number
                        and (mod(a.parent_index, power(2, 24))) = 0
                        and a.name = '&dbname'
                )
connect by prior rindex = pindex;


---
emca -DBCONSOLE_HTTP_PORT 5500 -RMI_PORT 5520 -JMS_PORT 5540
-AGENT_PORT 1830


emca -config dbcontrol db -repos create

emca -config dbcontrol db -repos recreate

Friday 15 May 2015

Running script on all database

If we have multiple instances running on one servers and some script we need to run on all db's, then its good we use below script to set ORACLE_SID and login and run the script.

This specially used for below scenario:
  1. DB level patching in one go.
  2. While patching take snap of before and after patch.
  3. Some DB level script for reporting.



for i in `ps -aef | grep pmon |awk '{print $8}' |  egrep -i -v 'grep|asm' | cut -d "_" -f3`
do
  echo "ORACLE_SID $i : `hostname`"
  export ORACLE_SID=$i
  sqlplus -s / as sysdba <<EOF
  set lin 180
  select instance_name,host_name from v\$instance;
  srvctl status database -d $i
  exit
EOF
done


awk index = oracle instr

[oracle@node1 ~]$ cat /etc/oratab | egrep node | grep -v '#B' | awk -F ':' '{print substr($1,1,index($1,"1")-1)}'
node
[oracle@node1 ~]$

Filter blank lines


cat /etc/oratab | grep -v '^$'

Check before RMAN resetlogs.

 ---Check before resetlogs

 alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS' ;


 SYS@FAKE> select fuzzy, status, error, recover, checkpoint_change#, checkpoint_time, count(*) from v$datafile_header group by fuzzy, status, error, recover, checkpoint_change#, checkpoint_time ;

FUZ STATUS  ERROR                                                             REC CHECKPOINT_CHANGE# CHECKPOINT_TIME               COUNT(*)
--- ------- ----------------------------------------------------------------- --- ------------------ -------------------- -----------------
YES ONLINE                                                                                    267865 15-MAY-2015 14:45:25                 4
YES ONLINE                                                                                    269515 15-MAY-2015 15:19:13                 1

2 rows selected.

5 rows selected.

SYS@FAKE> select file#,status, error, recover,fuzzy from v$datafile_header where fuzzy='YES';

            FILE# STATUS  ERROR                                                             REC FUZ
----------------- ------- ----------------------------------------------------------------- --- ---
                1 ONLINE                                                                        YES
                2 ONLINE                                                                        YES
                3 ONLINE                                                                        YES
                4 ONLINE                                                                        YES
                5 ONLINE                                                                        YES

5 rows selected.


SYS@FAKE> recover database using backup controlfile;
ORA-00279: change 267865 generated at 05/15/2015 14:45:25 needed for thread 1
ORA-00289: suggestion : C:\APP\DILIP\PRODUCT\11.1.0\DB_1\RDBMS\ARC00004_0741132407.001
ORA-00280: change 267865 for thread 1 is in sequence #4


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
C:\APP\DILIP\ORADATA\clone_test\O1_MF_2_6MP1X3CM_.log
Log applied.
Media recovery complete.
SYS@FAKE> select file#,status, error, recover,fuzzy from v$datafile_header where fuzzy='YES';  ---NO fuzzy

no rows selected

SYS@FAKE>


SYS@FAKE> select fuzzy, status, error, recover, checkpoint_change#, checkpoint_time, count(*) from v$datafile_header group by fuzzy, status, error, recover, checkpoint_change#, checkpoint_time ;

FUZ STATUS  ERROR                                                             REC CHECKPOINT_CHANGE# CHECKPOINT_TIME               COUNT(*)
--- ------- ----------------------------------------------------------------- --- ------------------ -------------------- -----------------
NO  ONLINE                                                                                    272859 15-MAY-2015 16:51:48                 5

1 row selected.

SYS@FAKE>

---Good to go for resetlogs

SYS@FAKE> alter database open resetlogs;

Database altered.

SYS@FAKE>

Thursday 7 May 2015

RMAN cataloging tape backup piece

Catalog Backset backup on Symantec 

1.
Activate automatic rman configuration
catalog device type 'sbt_tape' backuppiece '668ghi8_1_1';

2.
DECLARE 
v_dev varchar2(50); 
v_fullname varchar2(900); 
recid number; 
stamp number
BEGIN v_dev:=sys.dbms_backup_restore.deviceAllocate(type=>'sbt_tape', ident=>'test'); sys.dbms_backup_restore.inspectBackupPiece('hggfddhgf_1_1',v_fullname,recid,stamp); sys.dbms_backup_restore.deviceDeallocate; 
END;
 /