Showing posts with label RMAN. Show all posts
Showing posts with label RMAN. Show all posts

Saturday, August 18, 2012

RMAN report / list in Oracle

In our previous post we configured RMAN to disk base backup and cleared SBT.
Let's run some report and list commands to see the status of backups. Verify the FRA configuration.
 
01RMAN> list backup;
02
03
04RMAN> report obsolete;
05
06RMAN retention policy will be applied to the command
07RMAN retention policy is set to redundancy 1
08no obsolete backups found
09
10RMAN> report need backup;
11
12RMAN retention policy will be applied to the command
13RMAN retention policy is set to redundancy 1
14Report of files with less than 1 redundant backups
15File #bkps Name
16---- ----- -----------------------------------------------------
171 0 /u02/oradata/orcl/system01.dbf
182 0 /u02/oradata/orcl/sysaux01.dbf
193 0 /u02/oradata/orcl/undotbs01.dbf
204 0 /u02/oradata/orcl/users01.dbf
215 0 /u02/oradata/orcl/example01.dbf
22
23RMAN>
There no backups yet for our database. We'll create some backups after urning on the backup optimization.
 
1RMAN> configure backup optimization on;
2
3new RMAN configuration parameters:
4CONFIGURE BACKUP OPTIMIZATION ON;
5new RMAN configuration parameters are successfully stored
6
7RMAN>
From the output of list archive log we can see that logs are being archived to FRA.
 
01RMAN> list archivelog all;
02
03List of Archived Log Copies for database with db_unique_name ORCL
04=====================================================================
05
06Key Thrd Seq S Low Time
07------- ---- ------- - ---------
081 1 3 A 07-JUN-12
09 Name: /u02/flash_recovery_area/ORCL/archivelog/2012_06_07/o1_mf_1_3_7x2q7cyp_.arc
10
112 1 4 A 07-JUN-12
12 Name: /u02/flash_recovery_area/ORCL/archivelog/2012_06_08/o1_mf_1_4_7x34qzvx_.arc
13
143 1 5 A 08-JUN-12
15 Name: /u02/flash_recovery_area/ORCL/archivelog/2012_06_08/o1_mf_1_5_7x3z3p7x_.arc
16
174 1 6 A 08-JUN-12
18 Name: /u02/flash_recovery_area/ORCL/archivelog/2012_06_08/o1_mf_1_6_7x4xh6c6_.arc
19
205 1 7 A 08-JUN-12
21 Name: /u02/flash_recovery_area/ORCL/archivelog/2012_06_08/o1_mf_1_7_7x5dlngn_.arc
22
236 1 8 A 08-JUN-12
24 Name: /u02/flash_recovery_area/ORCL/archivelog/2012_06_09/o1_mf_1_8_7x5rm6jw_.arc
25
267 1 9 A 09-JUN-12
27 Name: /u02/flash_recovery_area/ORCL/archivelog/2012_06_09/o1_mf_1_9_7x6c78bg_.arc
28
29
30RMAN>

RMAN reporting & configuration in Oracle on AWS

Initiated an Oracle instance on AWS. In this posts I'll review some of the reporting and backup/recover using RMAN.
Log into to the instance (AWS/Oracle) using password. Start RMAN and let's investigate.
 
01login as: oracle
02oracle@ec2-23-22-205-159.compute-1.amazonaws.com's password:
03oracle@domU-12-31-39-00-7C-94:[/home/oracle]
04$
05oracle@domU-12-31-39-00-7C-94:[/home/oracle]
06$
07oracle@domU-12-31-39-00-7C-94:[/home/oracle]
08$ rman target=orcl
09
10Recovery Manager: Release 11.1.0.7.0 - Production on Fri Jun 8 18:01:12 2012
11
12Copyright (c) 1982, 2007, Oracle. All rights reserved.
13
14target database Password:
15connected to target database: ORCL (DBID=1313137175)
16
17RMAN> list backup;
18
19using target database control file instead of recovery catalog
20
21RMAN>
Now, we are in RMAN and realize there are no backups.
Let's check of the database's configuration like, archivelog mode, FRA configureation etc...
 
01$ sqlplus / as sysdba
02
03SQL*Plus: Release 11.1.0.7.0 - Production on Fri Jun 8 18:01:43 2012
04
05Copyright (c) 1982, 2008, Oracle. All rights reserved.
06
07
08Connected to:
09Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
10With the Partitioning, OLAP, Data Mining and Real Application Testing options
11
12SQL> show user;
13USER is "SYS"
14SQL> archive log list;
15Database log mode Archive Mode
16Automatic archival Enabled
17Archive destination USE_DB_RECOVERY_FILE_DEST
18Oldest online log sequence 5
19Next log sequence to archive 7
20Current log sequence 7
21SQL>
Well the database is in archivelog mode; Let's check the RMAN configuration...
 
01RMAN> show all;
02
03using target database control file instead of recovery catalog
04RMAN configuration parameters for database with db_unique_name ORCL are:
05CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
06CONFIGURE BACKUP OPTIMIZATION OFF; # default
07CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';
08CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
09CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F'; # default
10CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
11CONFIGURE DEVICE TYPE SBT_TAPE PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
12CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
13CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default
14CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
15CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default
16CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
17CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/u02/admin/orcl/osbws/libosbws11.so';
18CONFIGURE MAXSETSIZE TO UNLIMITED; # default
19CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
20CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
21CONFIGURE COMPRESSION ALGORITHM 'BZIP2'; # default
22CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO 'TAPE';
23CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.1.0/db_1/dbs/snapcf_orcl.f'; # default
24
25RMAN>
This instance is designed for OSB (Oracle Secure Backup) with SBT as default, with channel defined for SBT. We'll change the default to disk.
 
1RMAN> configure default device type to disk;
2
3old RMAN configuration parameters:
4CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';
5new RMAN configuration parameters:
6CONFIGURE DEFAULT DEVICE TYPE TO DISK;
7new RMAN configuration parameters are successfully stored
8
9RMAN>
Now we'll CLEAR the tape related configurations...
 
1RMAN> configure default device type to disk;
2
3old RMAN configuration parameters:
4CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';
5new RMAN configuration parameters:
6CONFIGURE DEFAULT DEVICE TYPE TO DISK;
7new RMAN configuration parameters are successfully stored
8
9RMAN>
Notice with the TAPE CLEAR... all values are set to #default
 
01RMAN> CONFIGURE DEVICE TYPE SBT_TAPE clear;
02
03RMAN configuration parameters are successfully reset to default value
04
05RMAN> show all;
06
07RMAN configuration parameters for database with db_unique_name ORCL are:
08CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
09CONFIGURE BACKUP OPTIMIZATION OFF; # default
10CONFIGURE DEFAULT DEVICE TYPE TO DISK;
11CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
12CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
13CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F'; # default
14CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
15CONFIGURE DEVICE TYPE SBT_TAPE PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
16CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
17CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default
18CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
19CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; # default
20CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS 'SBT_LIBRARY=/u02/admin/orcl/osbws/libosbws11.so';
21CONFIGURE MAXSETSIZE TO UNLIMITED; # default
22CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
23CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
24CONFIGURE COMPRESSION ALGORITHM 'BZIP2'; # default
25CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO 'TAPE';
26CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.1.0/db_1/dbs/snapcf_orcl.f'; # default
27
28RMAN>
Now we are set to default (for SBT) and configured RMAN for disk backup.

In next post we'll expolre additional RAN backup reporting.

Friday, August 17, 2012

Loss of TEMP file(s) in Oracle DB

Scenario 1: Recovery from loss of Temp File(s) in Temporary Tablespace
In Oracle Temporary Tablespace is used for sort / merge operations that cannot be done within memory. When some datafile for Temporary Tablespace (Tempspace) is lost or inaccessible, database will perform normally, however certain user queries that require the use of Tempspace will return error.

In 11g Oracle can re-create missing TEMP files at the start of instance. Also you can manually create the missing / damaged Temp Files. This entry describes the steps for the same.
Set up for testing recovery from loss of temp files…

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE    11.1.0.7.0      Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production

SQL> col name format a60;
SQL> select file#, bytes, blocks, name from v$tempfile;
     FILE#      BYTES     BLOCKS NAME
---------- ---------- ---------- -----------------------------------------------
         1  105906176      12928 /u02/oradata/orcl/temp01.dbf

SQL>

 Let us quickly check the sort area allocated in memory in our instance

SQL> show parameter sort_area;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sort_area_retained_size              integer     0
sort_area_size                       integer     65536
SQL>

 We’ll reduce it to small size so that SORT operation will be forced to go to disk.

SQL> alter session set sort_area_size=50;

Session altered.

SQL> show parameter sort_area;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sort_area_retained_size              integer     0
sort_area_size                       integer     50
SQL>

 Now we’ll create a table and issue query with Order By clause to force the use of Tempspace.

SQL> set autotrace off;
SQL> create table t1 as select * from all_objects;

Table created.

SQL> insert into t1 select * from all_objects;

68938 rows created.

SQL> /

68938 rows created.

… REPEAT REPEAT …

SQL> /

68938 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from t1;

  COUNT(*)
----------
    620442

SQL>
SQL> set autotrace traceonly statistics;
SQL> select * from t1 order by 1 desc, 2, 3 desc, 4, 5 desc;

620442 rows selected.

Statistics
----------------------------------------------------------
         77  recursive calls
          4  db block gets
       9179  consistent gets
      12609  physical reads
          0  redo size
   11896316  bytes sent via SQL*Net to client
     455402  bytes received via SQL*Net from client
      41364  SQL*Net roundtrips to/from client
          0  sorts (memory)
          1  sorts (disk)
     620442  rows processed

SQL>

Now we have a query, which ensures the use of Tempspace;
We’ll remove the temp file at OS level, and reissue the query. We’ll get an error.

Automatic re-creation (recovery) of TEMP datafiles on instance restart

SQL> select name from v$tempfile;
NAME
------------------------------------------------------------
/u02/oradata/orcl/temp01.dbf

SQL> !rm /u02/oradata/orcl/temp01.dbf;

SQL> !ls /u02/oradata/orcl/temp01.dbf;
ls: /u02/oradata/orcl/temp01.dbf: No such file or directory
Note: In UNIX/Linux environment the deletion of file is NOT reflected immediately or rerunning the same query may use the DB Cache and the rerun of the query may still continue successfully.

SQL>  select * from t1 order by 1 desc, 2, 3 desc, 4, 5 desc,6,7,8;
 select * from t1 order by 1 desc, 2, 3 desc, 4, 5 desc,6,7,8
               *
ERROR at line 1:
ORA-01565: error in identifying file '/u02/oradata/orcl/temp01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3


SQL>
In Oracle 11g the instance startup will re-create the Temporary datafiles. If require they can be created manually as well.
Since this is a test instance, I am going to restart the instance to see re-creation of Tempfiles.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Database mounted.
Database opened.
SQL> !ls /u02/oradata/orcl/temp01.dbf;
/u02/oradata/orcl/temp01.dbf

SQL> show parameter sort_area;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sort_area_retained_size              integer     0
sort_area_size                       integer     65536
SQL> alter session set sort_area_size=50;

Session altered.

SQL> show parameter sort_area;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sort_area_retained_size              integer     0
sort_area_size                       integer     50
SQL>
SQL>  set autotrace traceonly statistics;
ERROR:
ORA-24315: illegal attribute type


SP2-0619: Error while connecting
SP2-0611: Error enabling STATISTICS report
SQL> exit;


I noticed, after restart of the database, the existing SQLPlus session had some problem in setting autotrace. However exiting and restarting SQLPlus session resolved this issue.



Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
oracle@domU-12-31-39-00-7C-94:[/home/oracle]
$ sqlplus  / as sysdba

SQL*Plus: Release 11.1.0.7.0 - Production on Sat Jul 14 11:41:03 2012

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


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

SQL> show parameter sort_area;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sort_area_retained_size              integer     0
sort_area_size                       integer     65536
SQL> alter session set sort_area_size=50;

Session altered.

SQL> show parameter sort_area;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sort_area_retained_size              integer     0
sort_area_size                       integer     50
SQL> set autotrace traceonly statistics;
SQL>
Note that upon restart of the instance the temporary Datafile was recreated.

SQL>  !ls /u02/oradata/orcl/temp01.dbf;
/u02/oradata/orcl/temp01.dbf

SQL> select * from t1 order by 1 desc, 2, 3 desc, 4, 5 desc,6,7,8;

827256 rows selected.


Statistics
----------------------------------------------------------
       1549  recursive calls
        441  db block gets
      12452  consistent gets
      24801  physical reads
          0  redo size
   14888276  bytes sent via SQL*Net to client
     607070  bytes received via SQL*Net from client
      55152  SQL*Net roundtrips to/from client
         37  sorts (memory)
          1  sorts (disk)
     827256  rows processed

SQL>

Manual re-creation (recovery) of TEMP datafiles when database is open
Alternatively, if the database cannot be restarted (which probably will be the case most of the time), we can manually recreate the temporary datafile when the database is open.
Note however, ever after removal of the tempfile, Oracle is actually performing sort on the disk.
Where is Oracle actually doing the disk sort operation?

SQL> !rm  /u02/oradata/orcl/temp01.dbf;

SQL>  !ls /u02/oradata/orcl/temp01.dbf;
ls: /u02/oradata/orcl/temp01.dbf: No such file or directory

SQL> select * from t1 order by 1 desc, 2, 3 desc, 4, 5 desc,6,7;

827256 rows selected.


Statistics
----------------------------------------------------------
        102  recursive calls
          6  db block gets
      12204  consistent gets
      24550  physical reads
          0  redo size
   14888276  bytes sent via SQL*Net to client
     607070  bytes received via SQL*Net from client
      55152  SQL*Net roundtrips to/from client
          0  sorts (memory)
          1  sorts (disk)
     827256  rows processed

SQL> select * from t1 order by 1 desc, 2, 3 desc, 4, 5 desc,6,7,8,9 desc,10;

827256 rows selected.


Statistics
----------------------------------------------------------
        102  recursive calls
          6  db block gets
      12204  consistent gets
      24574  physical reads
          0  redo size
   14888276  bytes sent via SQL*Net to client
     607070  bytes received via SQL*Net from client
      55152  SQL*Net roundtrips to/from client
          0  sorts (memory)
          1  sorts (disk)
     827256  rows processed

SQL>
It seems, as long as the result set remains the same Oracle is resilient enough to perform required operations to return the correct result set (probably still using DB_CACHE) and not actually accessing the sort area.
SQL> delete from t1 where rownum < 10;

9 rows deleted.

SQL> commit;

Commit complete.

SQL> select * from t1 order by 11,1 desc, 2, 3 desc, 4, 5 desc,6,7,8,9 desc,10;

827247 rows selected.


Statistics
----------------------------------------------------------
        102  recursive calls
          6  db block gets
      12204  consistent gets
      24574  physical reads
          0  redo size
   14886464  bytes sent via SQL*Net to client
     607059  bytes received via SQL*Net from client
      55151  SQL*Net roundtrips to/from client
          0  sorts (memory)
          1  sorts (disk)
     827247  rows processed

SQL>
Though when I add more row to the table (actually changing the result set) the disk-sort-area is actually used again.

SQL> !ls /u02/oradata/orcl/temp01.dbf;
ls: /u02/oradata/orcl/temp01.dbf: No such file or directory

SQL> insert into t1 select * from all_objects;
68938 rows created.

SQL> commit;

Commit complete.

SQL>  select * from t1 order by 11,1 desc, 2, 3 desc, 4, 5 desc,6,7,8,9 desc,10;
 select * from t1 order by 11,1 desc, 2, 3 desc, 4, 5 desc,6,7,8,9 desc,10
               *
ERROR at line 1:
ORA-01565: error in identifying file '/u02/oradata/orcl/temp01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

We can MANUALLY add tempfile to temp tablespace.

SQL> alter tablespace temp add tempfile '/u02/oradata/orcl/temp01.dbf';
alter tablespace temp add tempfile '/u02/oradata/orcl/temp01.dbf'
*
ERROR at line 1:
ORA-01537: cannot add file '/u02/oradata/orcl/temp01.dbf' - file already part
of database


SQL> alter tablespace temp drop tempfile  '/u02/oradata/orcl/temp01.dbf';
alter tablespace temp drop tempfile  '/u02/oradata/orcl/temp01.dbf'
*
ERROR at line 1:
ORA-03261: the tablespace TEMP has only one file


SQL>  alter tablespace temp add tempfile '/u02/oradata/orcl/temp02.dbf';
 alter tablespace temp add tempfile '/u02/oradata/orcl/temp02.dbf'
*
ERROR at line 1:
ORA-01119: error in creating database file '/u02/oradata/orcl/temp02.dbf'
ORA-17610: file '/u02/oradata/orcl/temp02.dbf' does not exist and no size
specified
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3


SQL> alter tablespace temp add tempfile '/u02/oradata/orcl/temp02.dbf' size 100m;

Tablespace altered.

SQL> select file#, bytes, blocks, name from v$tempfile;

     FILE#      BYTES     BLOCKS
---------- ---------- ----------
NAME
--------------------------------------------------------------------------------
         1  103809024      12672
/u02/oradata/orcl/temp01.dbf

         2  104857600      12800
/u02/oradata/orcl/temp02.dbf


SQL> alter tablespace temp drop tempfile '/u02/oradata/orcl/temp01.dbf';

Tablespace altered.

SQL> ALTER DATABASE TEMPFILE '/u02/oradata/orcl/temp02.dbf' AUTOEXTEND ON MAXSIZE 500M;

Tablespace altered.

SQL>

We are back to normal business.