Wednesday, 30 November 2011

Replace a Corrupt OCR Mirror File

$ ocrcheck

Status of Oracle Cluster Registry is as follows :
                                Version                            :                                2
                                Total space (kbytes)         :                      130067
                                Used space (kbytes)         :                          3752
                                Available space (kbytes)   :                      126299
                                ID                                    :                561894456
                                Device/File Name             :    /s104/app/oradata/ocr01_data
                                                                             Device/File integrity check succeeded

                                Device/File Name             :    /s104/app/oradata/ocr02_data
                                                                            Device/File integrity check succeeded
                                                                            Cluster registry integrity check succeeded



2. Let me corrupt mirrored OCR for testing purpose:
$ dd if=/dev/zero of=/s104/app/oradata/ocr02_data bs=1024k

3. Now check the synchronization between two copies (OCR):

$ ocrcheck

Status of Oracle Cluster Registry is as follows :
                                Version                                       :                              2
                                Total space (kbytes)                   :                     130067
                                Used space (kbytes)                   :                         3752
                                Available space (kbytes)             :                     126299
                                ID                                              :               561894456
                                Device/File Name                       :           /s104/app/oradata/ocr01_data
                                                                                              Device/File integrity check succeeded

                                Device/File Name                       :           /s104/app/oradata/ocr02_data
                                          Device/File needs to be synchronized with the other device

4. Using ocrconfig with -replace ocrmirror option:
$ ocrconfig -replace ocrmirror /s104/app/oradata/ocr02_data

Now check for the OCR status:

$ ocrcheck
Status of Oracle Cluster Registry is as follows :
                                 Version                                :                             2
                                 Total space (kbytes)             :                   130067
                                  Used space (kbytes)            :                       3752
                                 Available space (kbytes)       :                   126299
                                 ID                                        :             561894456
                                 Device/File Name                 :             /s104/app/oradata/ocr01_data
                                                                                           Device/File integrity check succeeded

                                  Device/File Name                :             /s104/app/oradata/ocr02_data
                                                                                       Device/File integrity check succeeded
                                                                                       Cluster registry integrity check succeeded
Now we have both OCR files in the correct state.

DBCA Silent Mode Installation

dbca -silent -createDatabase -templateName New_Database.dbt
   -gdbName PROD123 -sid PROD123 -SysPassword sys8tem2 -SystemPassword sys8tem2  
      -emConfiguration LOCAL -dbsnmpPassword sys8tem2 -sysmanPassword sys8tem2
         -characterSet UTF8 -nationalCharacterSet AL16UTF16 -memoryPercentage 40
            -continueOnNonFatalErrors true


----Before that, goto

$cd $ORACLE_HOME/assistants/dbca/templates

Edit the datafile locations, and select the required oracle components also,

$vi New_Database.dbt


Tuesday, 29 November 2011

To find the dba_segment for schema's in the database

SQL> select owner,sum(bytes)/1024/1024 MB from dba_segments group by owner order by MB;

To find the no of objects are running in the database

SQL> select count(object_name), object_type  from dba_objects group by object_type;

(or)

SQL> select count(object_name), object_type  from all_objects where owner='LIMS_ADMIN' group by object_type;(finding schema vice).

Saturday, 19 November 2011

Recover a deleted datafile on linux using symbolic link when database is up

On Linux and other unix box , when a datafile is accidently dropped , using process (PID) belong to the datafile we can recover the data.



Note : If the process lost , it is not possible to recover using symbolic link.

To have a look let us create a tablespace called DEMO,

SQL> create tablespace demo datafile '/u01/app/oracle/oradata/SABA1/demo01.dbf' size 10M;

Tablespace created.

SQL> create table test tablespace demo as select * from dba_users;


Table created.


SQL> select count(*) from test;


COUNT(*)
------------
34

SQL> select name from v$datafile;


NAME
--------------------------------------------------
/u01/app/oracle/oradata/SABA1/system01.dbf
/u01/app/oracle/oradata/SABA1/sysaux01.dbf
/u01/app/oracle/oradata/SABA1/undotbs01.dbf
/u01/app/oracle/oradata/SABA1/users01.dbf
/u01/app/oracle/oradata/SABA1/encrypted_ts01.dbf
/u01/app/oracle/oradata/SABA1/demo01.dbf


6 rows selected.

[oracle@11G dbs]$ cd /u01/app/oracle/oradata/SABA1/


Let me go ahead and drop demo01.dbf (datafile) manually from OS,
[oracle@11G SABA1]$ ls -lrt demo01.dbf
-rw-r----- 1 oracle oinstall 10493952 Aug 28 21:31 demo01.dbf


[oracle@11G SABA1]$ rm demo01.dbf
[oracle@11G SABA1]$ ls -lrt demo01.dbf
ls: demo01.dbf: No such file or directory


Let me connect to the database,

[oracle@11G ~]$ export ORACLE_SID=SABA1
[oracle@11G ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 28 22:15:52 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:


Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select count(*) from test;

COUNT(*)
----------
34

Opps .. Still I am able to see the records.


SQL> Alter system flush shared_pool;


System altered.


SQL> ALTER SYSTEM FLUSH BUFFER_CACHE;


System altered.


Disconnect the session and open a new terminal and start a new session
[oracle@11G ~]$ export ORACLE_SID=SABA1
[oracle@11G ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 28 22:15:52 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:


Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select * from test;
select * from test
*
ERROR at line 1:
ORA-01116: error in opening database file 6
ORA-01110: data file 6: '/u01/app/oracle/oradata/SABA1/demo01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3


Yes … Now I am not able to see my records
At the OS let us check the process


[oracle@11G ~]$ ps -edf
grep dbw
oracle 4488 1 0 21:24 ? 00:00:01 ora_dbw0_SABA1
oracle 5269 5231 0 21:40 pts/1 00:00:00 grep dbw
[oracle@11G ~]$ ls -l /proc/4488/fd/
grep demo
lrwx------ 1 oracle oinstall 64 Aug 28 21:42 27 -> /u01/app/oracle/oradata/SABA1/demo01.dbf (deleted)
You will see the above message saying the file is deleted.

[oracle@11G ~]$ ls -l /proc/4488/fd/27
lrwx------ 1 oracle oinstall 64 Aug 28 21:45 /proc/4488/fd/27 -> /u01/app/oracle/oradata/SABA1/demo01.dbf (deleted)


To make sure let me check whether demo datafile is available at the OS level


[oracle@11G ~]$ cd /u01/app/oracle/oradata/SABA1
[oracle@11G SABA1]$ ls
control01.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
encrypted_ts01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf


Right i dont see demo01.dbf file. Now let us create a symbolic link using PID so that oracle can see it as it was before the delete


[oracle@11G SABA1]$ ln -s /proc/4488/fd/27 /u01/app/oracle/oradata/SABA1/demo01.dbf
[oracle@11G SABA1]$ ls
control01.ctl redo01.log sysaux01.dbf undotbs01.dbf
demo01.dbf redo02.log system01.dbf users01.dbf
encrypted_ts01.dbf redo03.log temp01.dbf


Yes, Symbolic link is created.


Let me connect to the database,


[oracle@11G ~]$ export ORACLE_SID=SABA1
[oracle@11G ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 28 22:15:52 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:


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


SQL> select count(*) from test;

COUNT(*)
----------
34


Now then data is accessible, but that will be lost if dbwriter closes it file handle (i.e if the database is closed)
However we can now set the tablespace read only so that it is checkpointed, and no writes occurs on it.


SQL> alter tablespace demo read only;

Tablespace altered.


Drop the symbolic link.


[oracle@11G ~]$ rm /u01/app/oracle/oradata/SABA1/demo01.dbf

Copy the data from PID to demo01.dbf


[oracle@11G ~]$ cp -p /proc/6264/fd/30 /u01/app/oracle/oradata/SABA1/demo01.dbf


SQL> alter tablespace demo read write;


Tablespace altered.


SQL> select count(*) from test;


COUNT(*)
----------
34

Replace a Corrupt OCR Mirror File

$ ocrcheck


Status of Oracle Cluster Registry is as follows :

Version : 2

Total space (kbytes) : 130067

Used space (kbytes) : 3752

Available space (kbytes) : 126299

ID : 561894456

Device/File Name : /s104/app/oradata/ocr01_data

Device/File integrity check succeeded

Device/File Name : /s104/app/oradata/ocr02_data

Device/File integrity check succeeded

Cluster registry integrity check succeeded

2. Let me corrupt mirrored OCR for testing purpose:

$ dd if=/dev/zero of=/s104/app/oradata/ocr02_data bs=1024k

3. Now check the synchronization between two copies (OCR):

$ ocrcheck


Status of Oracle Cluster Registry is as follows :

Version : 2

Total space (kbytes) : 130067

Used space (kbytes) : 3752

Available space (kbytes) : 126299

ID : 561894456

Device/File Name : /s104/app/oradata/ocr01_data

Device/File integrity check succeeded

Device/File Name : /s104/app/oradata/ocr02_data

Device/File needs to be synchronized with the other device

4. Using ocrconfig with -replace ocrmirror option:

$ ocrconfig -replace ocrmirror /s104/app/oradata/ocr02_data

Now check for the OCR status:

$ ocrcheck

Status of Oracle Cluster Registry is as follows :

Version : 2

Total space (kbytes) : 130067

Used space (kbytes) : 3752

Available space (kbytes) : 126299

ID : 561894456

Device/File Name : /s104/app/oradata/ocr01_data

Device/File integrity check succeeded

Device/File Name : /s104/app/oradata/ocr02_data

Device/File integrity check succeeded

Cluster registry integrity check succeeded

Now we have both OCR files in the correct state.

Query to find RMAN job status

SQL> select OPERATION, START_TIME, END_TIME, OBJECT_TYPE, STATUS from


v$RMAN_STATUS order by START_TIME;

ORA-00064: object is too large to allocate on this O/S (1,18576200)

SOLUTION:



Increase 'maxuproc' limit to a higher value (work with system administrator to accomplish this) and try again to startup the database with PROCESSES set to MAX.

If action from point 1 still result in ORA-00064 error, increase the following parameter at database level:

_ksmg_granule_size=33554432


This parameter needs to be set in PFILE/SPFILE manually.

CRSCTL & SRVCTL command/references (RAC Administration)

You can use the following commands only in an Oracle RAC environment:


crsctl add crs administrator
crsctl add css votedisk
crsctl add serverpool
crsctl check cluster
crsctl check crs
crsctl check resource
crsctl check ctss
crsctl config crs
crsctl delete crs administrator
crsctl delete css votedisk
crsctl delete node
crsctl delete serverpool
crsctl disable crs
crsctl discover dhcp
crsctl enable crs
crsctl get clientid dhcp
crsctl get css
crsctl get css ipmiaddr
crsctl get nodename
crsctl getperm serverpool
crsctl lsmodules
crsctl modify serverpool
crsctl pin css
crsctl query crs administrator
crsctl query crs activeversion
crsctl query crs releaseversion
crsctl query crs softwareversion
crsctl query css ipmiconfig
crsctl query css ipmidevice
crsctl query css votedisk
crsctl query dns
crsctl release dhcp
crsctl relocate resource
crsctl relocate server
crsctl replace discoverystring
crsctl replace votedisk
crsctl request dhcp
crsctl set css
crsctl set css ipmiaddr
crsctl set css ipmiadmin
crsctl setperm serverpool
crsctl start cluster
crsctl start crs
crsctl start ip
crsctl start testdns
crsctl status ip
crsctl status server
crsctl status serverpool
crsctl status testdns
crsctl stop cluster
crsctl stop crs
crsctl stop ip
crsctl stop testdns
crsctl unpin css
crsctl unset css
crsctl unset css ipmiconfig

crsctl check has
crsctl config has
crsctl disable has
crsctl enable has
crsctl query has releaseversion
crsctl query has softwareversion
crsctl start has
crsctl stop has
crsctl check has



SRVCTL Commands for Reference:




CRS RESOURCE STATUS


srvctl status database -d [-f] [-v] [-S ]
srvctl status instance -d -i >[,]
[-f] [-v] [-S ]
srvctl status service -d -s [,]
[-f] [-v] [-S ]
srvctl status nodeapps [-n ]
srvctl status asm -n

EXAMPLES:

Status of the database, all instances and all services.
srvctl status database -d ORACLE -v


Status of named instances with their current services.
srvctl status instance -d ORACLE -i RAC01, RAC02 -v

Status of a named services.
srvctl status service -d ORACLE -s ERP -v


Status of all nodes supporting database applications.
srvctl status node


START CRS RESOURCES

srvctl start database -d [-o < start-options>]
[-c -q]
srvctl start instance -d -i
[,] [-o ] [-c -q]
srvctl start service -d [-s [,]]
[-i ] [-o ] [-c -q]
srvctl start nodeapps -n
srvctl start asm -n [-i ] [-o ]


EXAMPLES:


Start the database with all enabled instances.
srvctl start database -d ORACLE


Start named instances.
srvctl start instance -d ORACLE -i RAC03, RAC04


Start named services. Dependent instances are started as needed.
srvctl start service -d ORACLE -s CRM

Start a service at the named instance.

srvctl start service -d ORACLE -s CRM -i RAC04


Start node applications.
srvctl start nodeapps -n myclust-4



STOP CRS RESOURCES

srvctl stop database -d [-o ]
[-c -q]
srvctl stop instance -d -i [,]
[-o ][-c -q]
srvctl stop service -d [-s [,]]
[-i ][-c -q] [-f]
srvctl stop nodeapps -n
srvctl stop asm -n [-i ] [-o ]




EXAMPLES:




Stop the database, all instances and all services.
srvctl stop database -d ORACLE


Stop named instances, first relocating all existing services.
srvctl stop instance -d ORACLE -i RAC03,RAC04


Stop the service.
srvctl stop service -d ORACLE -s CRM


Stop the service at the named instances.
srvctl stop service -d ORACLE -s CRM -i RAC04


Stop node applications. Note that instances and services also stop.
srvctl stop nodeapps -n myclust-4


ADD CRS RESOURCES


srvctl add database -d -o [-m ] [-p ]
[-A ip>/ netmask] [-r {PRIMARY PHYSICAL_STANDBY LOGICAL_STANDBY}]
[-s ] [-n ]


srvctl add instance -d -i -n
srvctl add service -d -s -r
[-a ] [-P ] [-u]
srvctl add nodeapps -n -o
[-A ip>/netmask[/if1[if2...]]]
srvctl add asm -n -i -o


OPTIONS:


-A vip range, node, and database, address specification. The format of


address string is:


[]//[/
host interface2
..]>] [,] []//
[/]


-a for services, list of available instances, this list cannot include


preferred instances
-m domain name with the format “us.mydomain.com”
-n node name that will support one or more instances
-o $ORACLE_HOME to locate Oracle binaries
-P for services, TAF preconnect policy - NONE, PRECONNECT
-r for services, list of preferred instances, this list cannot include


available instances.
-s spfile name
-u updates the preferred or available list for the service to support the
specified instance. Only one instance may be specified with the -u
switch. Instances that already support the service should not be
included.


EXAMPLES:

Add a new node:
srvctl add nodeapps -n myclust-1 -o $ORACLE_HOME –A
139.184.201.1/255.255.255.0/hme0


Add a new database.
srvctl add database -d ORACLE -o $ORACLE_HOME


Add named instances to an existing database.
srvctl add instance -d ORACLE -i RAC01 -n myclust-1
srvctl add instance -d ORACLE -i RAC02 -n myclust-2
srvctl add instance -d ORACLE -i RAC03 -n myclust-3


Add a service to an existing database with preferred instances (-r) and
available instances (-a). Use basic failover to the available instances.
srvctl add service -d ORACLE -s STD_BATCH -r RAC01,RAC02 -a RAC03,RAC04


Add a service to an existing database with preferred instances in list one and
available instances in list two. Use preconnect at the available instances.
srvctl add service -d ORACLE -s STD_BATCH -r RAC01,RAC02 -a RAC03,RAC04 -P PRECONNECT


REMOVE CRS RESOURCES


srvctl remove database -d
srvctl remove instance -d [-i ]
srvctl remove service -d -s [-i ]
srvctl remove nodeapps -n

EXAMPLES:


Remove the applications for a database.
srvctl remove database -d ORACLE


Remove the applications for named instances of an existing database.
srvctl remove instance -d ORACLE -i RAC03
srvctl remove instance -d ORACLE -i RAC04


Remove the service.
srvctl remove service -d ORACLE -s STD_BATCH


Remove the service from the instances.
srvctl remove service -d ORACLE -s STD_BATCH -i RAC03,RAC04


Remove all node applications from a node.
srvctl remove nodeapps -n myclust-4

MODIFY CRS RESOURCES

srvctl modify database -d [-n ] [-m ]
[-p ] [-r {PRIMARY PHYSICAL_STANDBY LOGICAL_STANDBY}]
[-s ]
srvctl modify instance -d -i -n
srvctl modify instance -d -i {-s -r}
srvctl modify service -d -s -i
-t [-f]
srvctl modify service -d -s -i
-r [-f]
srvctl modify nodeapps -n [-A ] [-x]


OPTIONS:


-i -t the instance name (-i) is replaced by the instance name (-t)
-i -r the named instance is modified to be a preferred instance
-A address-list for VIP application, at node level
-s add or remove ASM dependency


EXAMPLES:

Modify an instance to execute on another node.
srvctl modify instance -d ORACLE -n myclust-4


Modify a service to execute on another node.
srvctl modify service -d ORACLE -s HOT_BATCH -i RAC01 -t RAC02


Modify an instance to be a preferred instance for a service.
srvctl modify service -d ORACLE -s HOT_BATCH -i RAC02 –r

RELOCATE SERVICES
srvctl relocate service -d -s [-i ]-t [-f]


EXAMPLES:


Relocate a service from one instance to another
srvctl relocate service -d ORACLE -s CRM -i RAC04 -t RAC01


ENABLE CRS RESOURCES (The resource may be up or down to use this function)
srvctl enable database -d
srvctl enable instance -d -i [,]
srvctl enable service -d -s ] [, ] [-i ]


EXAMPLES:


Enable the database.
srvctl enable database -d ORACLE


Enable the named instances.
srvctl enable instance -d ORACLE -i RAC01, RAC02


Enable the service.
srvctl enable service -d ORACLE -s ERP,CRM


Enable the service at the named instance.
srvctl enable service -d ORACLE -s CRM -i RAC03


DISABLE CRS RESOURCES (The resource must be down to use this function)


srvctl disable database -d
srvctl disable instance -d -i [,]
srvctl disable service -d -s ] [,] [-i ]


EXAMPLES:


Disable the database globally.
srvctl disable database -d ORACLE


Disable the named instances.
srvctl disable instance -d ORACLE -i RAC01, RAC02


Disable the service globally.
srvctl disable service -d ORACLE -s ERP,CRM


Disable the service at the named instance.
srvctl disable service -d ORACLE -s CRM -i RAC03,RAC04

To Know the Database Current SETUP

sql>    select instance_name,host_name from v$instance;
sql>    select name from v$database;

sql>   CLEAR
SET HEAD ON
SET VERIFY OFF
SPOOL file
COL tspace form a25 Heading "Tablespace"
COL tot_ts_size form 99999999999999 Heading "Size (Mb)"
COL free_ts_size form 99999999999999 Heading "Free (Mb)"
COL ts_pct form 9999 Heading "% Free"
COL ts_pct1 form 9999 Heading "% Used"
BREAK on report
COMPUTE sum of free_ts_size on report
COMPUTE sum of tot_ts_size on report
SELECT                                                                             /* + RULE */
                  df.tablespace_name tspace, df.BYTES / (1024 * 1024) tot_ts_size,
                  SUM (fs.BYTES) / (1024 * 1024) free_ts_size,
                  NVL (ROUND (SUM (fs.BYTES) * 100 / df.BYTES), 1) ts_pct,
                  ROUND ((df.BYTES - SUM (fs.BYTES)) * 100 / df.BYTES) ts_pct1
           FROM dba_free_space fs,
                 (SELECT tablespace_name, SUM (BYTES) BYTES
                       FROM dba_data_files
                 GROUP BY tablespace_name) df
          WHERE fs.tablespace_name(+) = df.tablespace_name
GROUP BY df.tablespace_name, df.BYTES
UNION ALL
SELECT                                                                              /* + RULE */
                 df.tablespace_name tspace, fs.BYTES / (1024 * 1024) tot_ts_size,
                 SUM (df.bytes_free) / (1024 * 1024) free_ts_size,
                 NVL (ROUND ((SUM (fs.BYTES) - df.bytes_used) * 100 / fs.BYTES),
                           1
                            ) ts_pct,
                ROUND ((SUM (fs.BYTES) - df.bytes_free) * 100 / fs.BYTES) ts_pct1
        FROM dba_temp_files fs,
              (SELECT tablespace_name, bytes_free, bytes_used
                       FROM v$temp_space_header
              GROUP BY tablespace_name, bytes_free, bytes_used) df
        WHERE fs.tablespace_name(+) = df.tablespace_name
GROUP BY df.tablespace_name, fs.BYTES, df.bytes_free, df.bytes_used
ORDER BY 4 DESC
/
SPOOL off;

sql>    set linesize 500;
sql>    select instance_name,host_name from v$instance;

sql>    select value from NLS_DATABASE_PARAMETERS where parameter='NLS_CHARACTERSET';

sql>    select value from NLS_DATABASE_PARAMETERS where parameter='NLS_NCHAR_CHARACTERSET';

sql>    col member format a50;
sql>    select * from v$logfile;

sql>    archive log list;

sql>    col name format a50;
sql>    select * from v$dbfile;

sql>    select tablespace_name, extent_management from dba_tablespaces;

sql>    select tablespace_name, contents from dba_tablespaces;

sql>    select tablespace_name, sum(bytes)/1024/1024 mb from dba_temp_files group by tablespace_name;

sql>    select tablespace_name, sum(bytes_cached)/1024/1024 mb from v$temp_extent_pool group by tablespace_name;

sql>    set linesize 500;
sql>    show parameter background_dump_dest

sql>    col value format a50;
sql>    select name,value from v$parameter where value is not null;


Point-in-time Recovery in Oracle 10g RAC

point-in-time recovery till Nov 26th 2011 00:00:00

First:
Take a controlfile trace backup,

SQL> alter database backup controlfile to trace as '/tmp/control01.ctl';

1.shutdown immediate


2.olsnodes --> to check the number of nodes
 
3.crs_stat -t          -->to find status on both nodes running processes

Name Type Target State Host

------------------------------------------------------------
ora....X1.inst application ONLINE ONLINE sekiazu0140
ora....X2.inst application ONLINE ONLINE sekiazu0141
ora.Q0153X.db application ONLINE ONLINE sekiazu0140
ora....40.lsnr application ONLINE ONLINE sekiazu0140
ora....140.gsd application ONLINE ONLINE sekiazu0140
ora....140.ons application ONLINE ONLINE sekiazu0140
ora....140.vip application ONLINE ONLINE sekiazu0140
ora....41.lsnr application ONLINE ONLINE sekiazu0141
ora....141.gsd application ONLINE ONLINE sekiazu0141
ora....141.ons application ONLINE ONLINE sekiazu0141
ora....141.vip application ONLINE ONLINE sekiazu0141

4.srvctl stop database -d P0158X -->to stop the database in both nodes

5.srvctl stop nodeapps -n

6.srvctl stop nodeapps -n

7.removed all datafiles

8.startup nomount

rman target / catalog username/password@recoverycatalog;

9.restore the controlfile

RMAN>run {

              allocate channel t1 type 'SBT_TAPE' parms 'ENV=(TDPO_OPTFILE=/u001/app/TDP/P0158X/tdpo.opt)';
              restore controlfile to '/s106/oradata/control01.ctl' from 'P0158X_inc0_i2mq1hm6_1_1.rbck';
              }

RMAN> sql 'startup mount'


RMAN>run {

allocate channel t1 type 'SBT_TAPE';
SET UNTIL TIME "to_date('2011-10-26:00:00:00','YYYY-MM-DD:hh24:mi:ss')";
restore database;
recover database;
release channel t1;
}

11.checked the last archive sequence number with sequence number in alertlog 26th Nov 00:00:00 , it's matched.

12.sql>alter database open resetlogs;

13.srvctl start database -d P0158X -->to start the database in both nodes

14.srvctl start nodeapps -n

15.srvctl start nodeapps -n


*******************************************************************************************

Resetting RMAN to a Previous Incarnation:
The following scenario makes an old incarnation of database trgt current again:


# step 1: obtain the primary key of old incarnation
LIST INCARNATION OF DATABASE trgt;


List of Database Incarnations


DB Key Inc Key DB Name DB ID CUR Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 2 TRGT 1334358386 NO 154381 OCT 30 2001 16:02:12
1 116 TRGT 1334358386 YES 154877 OCT 30 2001 16:37:39

# step 2: start instance and reset database to incarnation key 2
STARTUP FORCE NOMOUNT;


RESET DATABASE TO INCARNATION 2;


# step 3: restore control file from previous incarnation, then shut down instance


# and mount control file
RESTORE CONTROLFILE;


STARTUP FORCE MOUNT;


# step 4: restore and recover the database to a point before the RESETLOGS
RESTORE DATABASE UNTIL SCN 154876;


RECOVER DATABASE UNTIL SCN 154876;


# step 5: make this incarnation the current incarnation and then list incarnations:
ALTER DATABASE OPEN RESETLOGS;


LIST INCARNATION OF DATABASE trgt;


List of Database Incarnations


DB Key Inc Key DB Name DB ID CUR Reset SCN Reset Time
------ ------- -------- ---------------- --- ---------- ----------
1 2 TRGT 1334358386 NO 154381 OCT 30 2001 16:02:12
1 116 TRGT 1334358386 NO 154877 OCT 30 2001 16:37:39
1 311 TRGT 1334358386 YES 154877 OCT 30 2001 17:17:03




Resetting the Database After Incomplete Recovery: Example
This example
assumes that an incomplete recovery or recovery with a backup control file was
performed in NOCATALOG mode. Later, RMAN is started in CATALOG mode, but the
RESYNC command fails because the incarnation has not been reset in the catalog.

% rman target / catalog rman/rman@catdb


Recovery Manager: Release 10.2.0.0.0 - Production
(c) Copyright 2001 Oracle Corporation. All rights reserved.

connected to target database: TRGT (DBID=1334531173)


connected to recovery catalog database


RMAN> RESYNC CATALOG;


RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of resync command on default channel at 11/01/2001 12:00:43
RMAN-20003: target database incarnation not found in recovery catalog

RMAN> RESET DATABASE;
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete






Tuesday, 15 November 2011

ADDM Report in Oracle 10g

 To generate a snap id with intervel:

sql>BEGIN DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS
           (retention => 10080,Interval => 15);END;

To check the intervels:

SQL> select * from dba_hist_wr_control;


DB Id             SNAP_INTERVAL      RETENTION             TOPNSQL
4195071208    +00000 01:00:00.0      +00007 00:00:00.0      DEFAULT

 
Listout generated snap id's with begin & end time intervals:

sql>SELECT snap_id, begin_interval_time, end_interval_time FROM dba_hist_snapshot ORDER BY 1;

Snap Id        BEGIN_INTERVAL_TIME           END_INTERVAL_TIME
    "                          "                "                                  "               "
    "                          "                "                                  "               "
10516         14-NOV-11 11.00.41.374 PM       15-NOV-11 12.00.46.449 AM
10517         15-NOV-11 12.00.46.449 AM       15-NOV-11 01.00.15.087 AM
10517         15-NOV-11 12.00.46.514 AM       15-NOV-11 01.00.15.019 AM
10518         15-NOV-11 01.00.15.087 AM       15-NOV-11 02.00.24.045 AM
10518         15-NOV-11 01.00.15.019 AM       15-NOV-11 02.00.23.991 AM
10519         15-NOV-11 02.00.23.991 AM       15-NOV-11 03.00.34.669 AM
10519         15-NOV-11 02.00.24.045 AM       15-NOV-11 03.00.34.739 AM
10520         15-NOV-11 03.00.34.739 AM       15-NOV-11 04.00.07.950 AM
10520         15-NOV-11 03.00.34.669 AM       15-NOV-11 04.00.07.999 AM

To take ADDM report:

Run the below script:
 
SQL>@$ORACLE_HOME/rdbms/admin/addmrpt.sql


Output like ...
Instance      DB_Name      Snap_Id      Snap_Started               Level
P0158X2     P0158X          10524        15 Nov 2011 08:00           1
                                       10525        15 Nov 2011 09:00           1
                                       10526        15 Nov 2011 10:00           1
                                       10527        15 Nov 2011 11:00           1

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap:________________

Friday, 11 November 2011

How To Drop, Create And Recreate DB Control In A 10g Database

In this Document
  Purpose
  Scope and Application
  How To Drop, Create And Recreate DB Control In A 10g Database
     DB Control options:
     A.  Delete DB Control Objects:
     B.  Create DB Control Objects
     C.  Recreate/ReConfig DB Control
  References



Applies to:

Enterprise Manager Grid Control - Version: 10.1 to 11.1
Information in this document applies to any platform.
DBConsole

Purpose

This article provides detailed instructions on how to 1) create, 2) drop and 3)recreate the repository and configuration files for the DB Control application used to manage a single 10g Database.

Scope and Application

The steps in this article are written for a DBA or System Administrator who needs to create, drop or reconfigure the DB Control Application. 

The format of the document will include steps for both 10.1 and 10.2 EMCA because the commands changed between the two releases.

For detailed instructions on DB Control 10.2 for RAC, please consult also:
Note 395162.1 How to manage DB Control 10.2 for RAC Database with emca

How To Drop, Create And Recreate DB Control In A 10g Database

DB Control options:


A.  Delete DB Control Objects:

Option 1.  Delete DB Control Configuration Files using EMCA scripts
Option 2.  Delete DB Control Configuration Files Manually:
Option 3.  Delete DB Control Repository Objects using RepManager
Option 4.  Delete DB Control Repository Objects Manually
Option 5.  Delete DB Control Configuration Files and Repository Objects using EMCA

Option 1. Delete DB Control Configuration Files using EMCA scripts:
For DB Control 10.1.x, run the command: /bin/emca -x 
For DB Control 10.2.x, run the command: bin/emca -deconfig dbcontrol db

Option 2. Delete DB Control Configuration Files Manually:
Remove the following directories from your filesystem:
/
/oc4j/j2ee/OC4J_DBConsole__

NOTE: 
On Windows you also need to delete the DB Console service:
- run regedit
- navigate to HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services
- locate the OracleDBConsole entry and delete it

Alternatively on Windows XP and Windows Server 2003 you can run the following from the command line:
'sc delete '

- where is the DB Control service name (typically: OracleDBConsole)

Also available from Microsoft is the delsrv.exe command.   (Free download from Microsoft)


Option 3. Delete DB Control Repository using RepManager:
This option is not as complete as the other options.  You may find that dropping the repository using the commandline options is a better solution.  Also note, RepManager is not used to create a DB Control Repository.
In both 10g R1 and R2 run: 
/sysman/admin/emdrep/bin/RepManager    -action drop

Warning: this command puts the database in Quiesce Mode.
Please consult the Note 375946.1 Running EMCA Results in Database quiesce And No
New Connections or Operations Can Be Performed During the DB Control Repository Creation

Option 4. Delete DB Control Repository Objects Manually
Step 1: Drop AQ related objects in the SYSMAN schema
Logon SQLPLUS as user SYSMAN
SQL>
exec DBMS_AQADM.DROP_QUEUE_TABLE(queue_table=>'MGMT_NOTIFY_QTABLE',force =>TRUE);

Step 2: Drop the DB Control
Repository Objects
Logon SQLPLUS as user SYS or SYSTEM, and drop the sysman account and management objects:
SQL> SHUTDOWN
IMMEDIATE;
SQL> STARTUP RESTRICT;
SQL> EXEC sysman.emd_maintenance.remove_em_dbms_jobs;
SQL> EXEC sysman.setEMUserContext('',5);
SQL>
REVOKE dba FROM sysman;
SQL> DECLARE
CURSOR c1 IS
SELECT owner, synonym_name name
FROM dba_synonyms
WHERE table_owner
= 'SYSMAN';
BEGIN
FOR r1 IN c1 LOOP
IF r1.owner = 'PUBLIC' THEN
EXECUTE IMMEDIATE 'DROP PUBLIC SYNONYM '||r1.name;
ELSE
EXECUTE
IMMEDIATE 'DROP SYNONYM '||r1.owner||'.'||r1.name;
END IF;
END LOOP;
END;
/
SQL> DROP USER mgmt_view CASCADE;
SQL> DROP ROLE mgmt_user;
SQL> DROP USER sysman CASCADE;
SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;
Note: The above will completely delete the DB Control repository from the database; under certain circumstances (e.g. you want to recreate the repository later on) the following statements may be sufficient to remove the repository:

Logon SQLPLUS as user SYS or SYSTEM, and drop the sysman account and management objects:
SQL> drop user
sysman cascade;
SQL> drop role MGMT_USER;
SQL> drop user MGMT_VIEW cascade;
SQL> drop public synonym MGMT_TARGET_BLACKOUTS;
SQL> drop public synonym SETEMVIEWUSERCONTEXT;

Option 5. Delete DB Control Configuration Files and Repository Objects using EMCA
For DB Control 10.1.x, dropping both the configuration files and the repository objects is a two step process.  Run the following two commands:
/bin/emca -x 
/sysman/admin/emdrep/bin/RepManager    -action drop

For DB Control 10.2.x, both configuration files and repository objects can be deleted with a single command.  Run the command:
/bin/emca -deconfig dbcontrol db -repos drop

Warning: this command puts the database in Quiesce Mode.
Please consult the Note 375946.1 Running EMCA Results in Database quiesce And No
New Connections or Operations Can Be Performed During the DB Control Repository Creation

B. Create DB Control Objects

Option 1.  Create the DB Control Configuration Files
Option 2.  Create the DB Control Repository Objects and Configuration Files

Option 1.  Create the DB Control Configuration Files
To create only the DB Control configuration files, skipping the repository creation (this would be done for instance if you dropped only the files and left the repository in place):
For DB Control 10.1.x, run the command: /bin/emca -r
For DB Control 10.2.x, run the command: /bin/emca -config dbcontrol db


Option 2. Create the DB Control Repository Objects and Configuration Files
For DB Control 10.1.x, run the command: /bin/emca
For DB Control 10.2.x, run the command: bin/emca -config dbcontrol db -repos create

Warning: this command puts the database in Quiesce Mode.
Please consult the Note 375946.1 Running EMCA Results in Database quiesce And No
New Connections or Operations Can Be Performed During the DB Control Repository Creation

C.  Recreate/ReConfig DB Control

Option 1.  Recreate the DB Control Configuration Files only (leave Repository intact)
Option 2.  Recreate the DB Control Configuration Files and Repository

In 10.2, the EMCA commands can be used to reconfigure the existing installs without removing them first.

Option 1. Recreate the DB Control Configuration Files only (leave Repository intact):
For DB Control 10.2.x, run the command:
/bin/emca -config dbcontrol db

Option 2. Recreate the DB Control Configuration Files and Repository

For DB Control 10.2.x, run the command:
/bin/emca -config dbcontrol db -repos recreate

Warning: this command puts the database in Quiesce Mode.
Please consult the Note 375946.1 Running EMCA Results in Database quiesce And No
New Connections or Operations Can Be Performed During the DB Control Repository Creation

For additional information on EMCA commandline options, please see the Oracle Enterprise Manager 10g Advanced Configuration Guide or see Note 330130.1 Overview Of The EMCA Commands Available for DB Control 10.2

References

Note 375946.1 - Problem: Running EMCA Results in Database quiesce And No New Connections or Operations Can Be Performed During the DB Control Repository Creation
Note 395162.1 - How to manage DB Control 10.2 for RAC Database with emca
Note 456437.1 - Ora-24005 Error Trying To Drop User Sysman Cascade

Keywords

EMCA; REPMANAGER; QUIESCE; DB~CONTROL; DBCONSOLE; DBMS_AQADM.DROP_QUEUE_TABLE; REPMANAGER;