You are on page 1of 8

###Resize standby datafile if disk runs out of space on standby site.

PURPOSE: TO AVOID RECREATION OF STANDBY DATABASE IN CASE FILE IS NOT RESIZED ON


STANDBY :
ITLINUXDEVBLADE07-PRIMARY
Database is DGTEST9i
[oracle@itlinuxdevblade07 dgtest9i]$ df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 25G 21G 2.0G 92% /opt
[oracle@itlinuxdevblade07 dgtest9i]$
2 gb freespace on disk on PRIMARY.
ITLINUXDEVBLADE08
[oracle@itlinuxdevblade08 oradata]$ df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 25G 23G 550M 98% /opt
[oracle@itlinuxdevblade08 oradata]$
The corresponding disk on the standby site as in db_file_name_convert has only 5
50 mb free.
Now create a new tablespace for the testing purpose..
SQL> create tablespace dropme datafile /opt/oracle/oradata/dgtest9i/dropme.dbf siz
e 200m;
Tablespace created.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
[oracle@itlinuxdevblade07 dgtest9i]$ df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 25G 22G 1.8G 93% /opt
[oracle@itlinuxdevblade07 dgtest9i]$
On STANDBY
[oracle@itlinuxdevblade08 dgtest9i]$ df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 25G 23G 350M 99% /opt
[oracle@itlinuxdevblade08 dgtest9i]$
Space available reduced from 550 mb to 350 mb
The logs were succesfully applied on STANDBY disk as there was enough space.
Now add a sum of more than the amount available on the standby disk by RESIZING
the file on PRIMARY to the tablespace.
PRIMARY site..
SQL> Alter database datafile /opt/oracle/oradata/dgtest9i/dropme.dbf RESIZE 1024M;
Database altered.
SQL> SQL>
SQL> alter system switch logfile;
System altered.
Go to STANDBY
[oracle@itlinuxdevblade08 dgtest9i]$ df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 25G 23G 350M 99% /opt
[oracle@itlinuxdevblade08 dgtest9i]$ ls -lrt
total 801848
-rw-r 1 oracle dba 209723392 May 10 14:23 dropme.dbf
-rw-r 1 oracle dba 7544832 May 10 14:23 control01.ctl
[oracle@itlinuxdevblade08 dgtest9i]$
The file has not been resized.as there was not enough space
Now check the logs for errors..
On standby alert log shows media recovery failed as the datafile could not be res
ized and media recovery stops
The standby database cannot be opened now as the files need recovery..
Media Recovery Log /opt/oracle/dgtest9i/arch/arch59.log
MRP0: Background Media Recovery terminated with error 1237

Wed May 10 14:23:04 2006


Errors in file /opt/oracle/admin/dgtest9i/bdump/dgtest9i_mrp0_10198.trc:
ORA-01237: cannot extend datafile 3
ORA-01110: data file 3: /opt/oracle/dgtest9i/dropme.dbf
ORA-19502: write error on file /opt/oracle/dgtest9i/dropme.dbf, blockno 71297 (blo
cksize=8192)
ORA-27072: skgfdisp: I/O error
Linux-x86_64 Error: 2: No such file or directory
Additional information: 71296
Some recovered datafiles maybe left media fuzzy
Media recovery may continue but open resetlogs may fail
MRP0: Background Media Recovery process shutdown
STEPS to solve this problem.
1. Shutdown both databases.
2. Create a new db_file_name_convert path as the file in question has to be move
d to different disks where space exists.
*.db_file_name_convert=/opt/oracle/dgtest9i/, /opt/oracle/oradata/dgtest9i/, /tmp/d
gtest9i/, /tmp/dgtest9i/both machines.
3. Copy dropme.dbf to /tmp/dgtest9i on both machines from original area.
4. Startup mount;..PRIMARY DATABASE
5. alter database rename file /opt/oracle/oradata/dgtest9i/dropmedbf to /tmp/dgtest
9i/dropme.dbf;
6. alter database open;
7. alter database create standby controlfile as /tmp/control01.ctl .primary site.
8. ftp the standby controlfile to /opt/oracle/dgtest9i on standby.controlfile are
a in standby spfile.
9.startup nomount;.STANDBY site.
SQL> show parameter convert;
NAME TYPE VALUE

db_file_name_convert string /opt/oracle/oradata/dgtest9i/, /opt/oracle/dgtest9i/
, /tmp/dgtest9i/, /tmp/dgtest9i/
log_file_name_convert string /opt/oracle/oradata/dgtest9i/, /opt/oracle/dgtest9i
/
SQL> alter database mount standby database;
Database altered.
SQL> select name from v$datafile;
/opt/oracle/dgtest9i/system01.dbf
/opt/oracle/dgtest9i/undotbs01.dbf
/tmp/dgtest9i/dropme.dbf
Primary site : Switch a few logfiles.
Now start managed recovery on standby.
SQL>recover managed standby database disconnect;
Alert log below
Completed: ALTER DATABASE RECOVER managed standby database d
Wed May 10 14:54:30 2006
RFS: Possible network disconnect with primary database
Wed May 10 14:54:38 2006
Fetching gap sequence for thread 1, gap sequence 59-63
Trying FAL server: DGTEST9I_BLADE07
Wed May 10 14:54:41 2006
RFS: Successfully opened standby logfile 4: /opt/oracle/dgtest9i/st01.log
Wed May 10 14:54:56 2006
Media Recovery Log /opt/oracle/dgtest9i/arch/arch59.log
Media Recovery Log /opt/oracle/dgtest9i/arch/arch60.log
Media Recovery Log /opt/oracle/dgtest9i/arch/arch61.log
Media Recovery Log /opt/oracle/dgtest9i/arch/arch62.log
Media Recovery Log /opt/oracle/dgtest9i/arch/arch63.log
Media Recovery Log /opt/oracle/dgtest9i/arch/arch64.log
Media Recovery Log /opt/oracle/dgtest9i/arch/arch65.log

Media Recovery Waiting for thread 1 seq# 66 (in transit)


Go to /tmp/dgtest9i on STANDBY and make sure file is resized to 1 gb..
[oracle@itlinuxdevblade08 dgtest9i]$ ls -lrt
total 1049612
-rw-r 1 oracle dba 1073750016 May 10 14:55 dropme.dbf
###Schema Refresh
I m refreshing TESTDB by taking Data from PRODB,here only one schema is refreshe
d.
Source side:
Preparatory Steps:
Create directory or use an exiting directory by giving read and write permission
for system Database user to use that direcotry(TEST_MIG).
SQL> grant read,write on directory TEST_MIG to system;
Grant succeeded.
SQL> alter user system identified by TESTDBdba account unlock;
PRODDB:
Step 1:Exporting the Data from the source Database(PRODDB in our case)
vi expdp_refresh_schema_sep27.sh
$ expdp system/PRODDB@PRODDB DUMPFILE=REFRESH_SCHEMA.DMP DIRECTORY=DATA_PUMP_DIR
SCHEMAS=REFRESH_SCHEMA LOGFILE=REFRESH_SCHEMA.log
$ nohup sh expdp_refresh_schema_sep27.sh>refresh_schema.out &
Step 2:Copying the dump file(Source Data) to Target Database server
We can use winscp tool(A graphical utility for copying files from windows to l
inux or viceversa) or ftp or scp or tar or rsync for coping Data from source ser
ver to target server.
Step 3:Moving Data into the target Database.
$ impdp system/TESTDBdba@TESTDB DUMPFILE=REFRESH_SCHEMA.DMP DIRECTORY=TEST_MIG R
EMAP_SCHEMA=REFRESH_SCHEMA:REFRESH_SCHEMA LOGFILE=REFRESH_SCHEMA.log
Step 4:Verify the Data in Source and Target Databases.
Note:
In oracle 11g rel2,version:11.2.0.1.0 there are about 44 Distinct object_types c
omparing to previous versions this number is huge.
SQL> select *from v$version;
BANNER
-------------------------------------------------------------------------------Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production

NLSRTL Version 11.2.0.1.0 - Production


SQL> select distinct object_type from dba_objects;
OBJECT_TYPE
------------------EDITION
INDEX PARTITION
CONSUMER GROUP
SEQUENCE
TABLE PARTITION
SCHEDULE
QUEUE
RULE
JAVA DATA
PROCEDURE
OPERATOR
OBJECT_TYPE
------------------LOB PARTITION
DESTINATION
WINDOW
SCHEDULER GROUP
DATABASE LINK
LOB
PACKAGE
PACKAGE BODY
LIBRARY
PROGRAM
RULE SET
OBJECT_TYPE
------------------CONTEXT
TYPE BODY
JAVA RESOURCE
XML SCHEMA
TRIGGER
JOB CLASS
UNDEFINED
DIRECTORY
MATERIALIZED VIEW
TABLE
INDEX
OBJECT_TYPE
------------------SYNONYM
VIEW
FUNCTION
JAVA CLASS
JAVA SOURCE
INDEXTYPE
CLUSTER
TYPE
RESOURCE PLAN
JOB
EVALUATION CONTEXT

44 rows selected.
Source Database:
PRODDB:
--------SQL> select count(*) from dba_objects
where owner= REFRESH_SCHEMA ;
COUNT(*)
---------132
SQL> select count(*) from dba_tables
where owner= REFRESH_SCHEMA ;
COUNT(*)
---------34
SELECT COUNT(*) FROM DBA_OBJECTS
WHERE OWNER= REFRESH_SCHEMA
AND OBJECT_TYPE IN( TABLE , JOB , VIEW , PACKAGE , TRIGGER , SYNONYM , FUNCTION
, PROCEDURE , TYPE )
ORDER BY OBJECT_TYPE;
SQL> SELECT COUNT(*) FROM DBA_OBJECTS
WHERE OWNER= REFRESH_SCHEMA
AND OBJECT_TYPE IN( TABLE , JOB , VIEW , PACKAGE , TRIGGER , SYNONYM , FUNCTION
, PROCEDURE , TYPE )
ORDER BY OBJECT_TYPE;
2 3 4
COUNT(*)
---------62
SELECT COUNT(*) FROM DBA_OBJECTS
WHERE OWNER= REFRESH_SCHEMA
AND OBJECT_TYPE IN
TARGET DATABASE:
TESTDB:
------------SQL> select count(*) from dba_objects
where owner= REFRESH_SCHE ; 2
COUNT(*)
---------131
SQL> select count(*) from dba_tables
where owner= APEX4_DEV ; 2
COUNT(*)
----------

34
SQL> SELECT COUNT(*) FROM DBA_OBJECTS
WHERE OWNER= REFRESH_SCHEMA
AND OBJECT_TYPE IN( TABLE , JOB , VIEW , PACKAGE , TRIGGER , SYNONYM , FUNCTION
, PROCEDURE , TYPE )
ORDER BY OBJECT_TYPE;
COUNT(*)
---------62
###Active Session History (ASH)
How to run ASHRPT.SQL script
To generate a text report of ASH information, run the ashrpt.sql script at the S
QL prompt:
@$ORACLE_HOME/rdbms/admin/ashrpt.sql
First, you need to specify whether you want an HTML or a text report.
Enter value for report_type: text
Specify the time frame to collect ASH information by first specifying the begin
time in minutes prior to the system date.
Enter value for begin_time: -10
Note: here you have to just put number in minutes eg: 10 for 10 minutes
Next, enter the duration in minutes that the report for which you want to captur
e ASH information from the begin time. The default duration of system date minus
begin time is accepted in the following example:
Enter value for duration:
Note: left blank for default value. Default value is SYSDATE
The report in this example will gather ASH information beginning from 10 minutes
before the current time and ending at the current time. Next, accept the defaul
t report name or enter a report name. The default name is accepted in the follow
ing example:
Enter value for report_name:
Using the report name ashrpt_1_0310_0131.txt
Note: Left it blank for default value.
The session history report is generated.
Purpose of ASH
ASH is way of sampling the state of sessions connected to an Oracle database in
order to monitory database load as well as drill down into any performance issue
s that may arise. Any session that is connected to the database and is waiting f
or an event that does not belong to the Idle wait class is considered as an acti
ve session.ASH maintains a fixed sized circular buffer in the database System Gl
obal Area (SGA). The fixed
sized circular buffer will be allocated during database start-up time. ASH by de
fault on an Oracle database, samples once every second and logs some 30 to 60 (d
epending on version) pieces of information on any session that is active at the

time of sampling.Each session sample is a set of rows and the V$ACTIVE_SESSION_H


ISTORY view returns one row for each active session per sample, returning the la
test session sample rows first. Because the active session samples are stored in
a Fixed Sized circular buffer in SGA, the greater the system activity, the smal
ler the number of seconds of session activity that can be stored in the Fixed Si
zed circular buffer. This means that the duration for which a session sample app
ears in the V$ view, or the number of seconds of session activity that is displa
yed in the V$ view, is completely dependent on the database activity.
ASH Analysis
1.Online Analysis
2.Offline Analysis
Let start with ONLINE analysis
========================
I have open two session. first one (SID 16) is running the DML like
SQL> delete test where rowid= AAAKB9AAEAAAAAiAAA ;
From second session (SID 15) run the same DML, and it is obvious that second
session will wait for first session to commit.
Lets check the info in V$ACTIVE_SESSION_HISTORY.
-----------------------------------------------Run the following script.
SQL> select SESSION_ID,NAME,P1,P2,P3,WAIT_TIME,CURRENT_OBJ#,CURRENT_FILE#,CURR
ENT_BLOCK#
from v$active_session_history ash, v$event_name enm
where ash.event#=enm.event# and SESSION_ID=&SID and SAMPLE_TIME>=(sysdate
-&minute/(24*60)); Input is
Enter value for sid: 15
Enter value for minute: 1 /* How many minutes activity you want to see */
output is 59 lines as it is wiatting more than 1 minute more than 1 minute
SESSION_ID NAME
P1
P2
P3 WAIT
_TIME CURRENT_OBJ# CURRENT_FILE# CURRENT_BLOCK#
---------- ------------------------------ ---------- ---------- ---------- --------- ------------ ------------- -------------15 enq: TX - row lock contention 1415053318
589825
143
0
41085
4
34
15 enq: TX - row lock contention 1415053318
589825
143
0
41085
4
34
15 enq: TX - row lock contention 1415053318
589825
143
0
41085
4
34
continue .............
15 enq: TX - row lock contention 1415053318
589825
143
0
41085
4
34
15 enq: TX - row lock contention 1415053318
589825
143
0
41085
4
34
15 enq: TX - row lock contention 1415053318
589825
143
0
41085
4
34
So you have object details with problem info.
Lets do the OFFLINE analysis of ASH
==============================
So if your are not able to find the problem online, you can dump the ASH to a tr
ace.
Command would be like below: where level means minute. lets dump for 10 minutes
history
1. SQL> alter session set events immediate trace name ashdump level 10 ;
or
2. SQL> alter system set events immediate trace name ashdump level 10 ;
or
3. SQL> oradebug setmypid

SQL> oradebug dump ashdump 10;


So you will get the trace file in udump.
ASH Contains
* SQL identifier of SQL statement(SQL_ID-SQL identifier of the SQL statement tha
t the session was executing at the time of sampling)
* Object number, file number, and block number(CURRENT_OBJ#-Object ID of the obj
ect that the session is referencing,CURRENT_FILE#-File number of the file contai
ning the block that the session is referencing,CURRENT_BLOCK#-ID of the block th
at the session is referencing)
* Wait event identifier (EVENT_ID-Identifier of the resource or event for which
the session is waiting or for which the session last waited)
* Session identifier and session serial number(sid,serial#-Session serial number
(used to uniquely identify a session s objects))
* Module and action name(module-name of executing module when sampled,action-nam
e of executing module when sampled)
* Client identifier of the session(client id)
* Service hash identifier (service_hash-hash that identifies the service)

You might also like