Archive

Posts Tagged ‘DBA’

How to find out Schema Passwords in a 10gAS Application Server

May 26th, 2009 sam No comments

There are two basic methods to find out the schema passwords in a Oracle 10gAS Application Server:-

A) Steps (through the ODM tool):-

1)   Log onto the host that hosts the infrastructure tier (e.g. host is – ausable) using x-windows like Hummingbird.

2)    Log on as user “oracle” – the user that did the install.

3)   Source the infrastructure tier environment file (if
you have one created that sets all the env. vars) as below:-

a.   $ cd bin – location of the environment file.

b.   $ . <as_infra> – environment file name.

4)   Open up oidadmin – Oracle Directory Manager tool as:-

a.   $ oidadmin

b.   Log in as orcladmin/<pwd> user.

5)   Follow the navigation path as below:-

Oracle Internet Directory Services -> orcladm@ausable.rfsuny.org:389 ->
Entry Management  -> Cn=OracleContext -> Cn=Products
->Cn=IAS -> Cn=IAS Infrastructure Databases ->
OrclReferenceName=<infra.rfsuny.org>  ->
OrclResourceName=<PORTAL> – The schema name you want the password
for.

6)   On the right hand side window-pane, you should see a
property called “orclpasswordattribute” on the
“Properties” tab.

7)   The Properties Tab would contain the password for the schema as shown in Figure A below:-

Figure A

8)   When logging in through SQL*Plus, the password is case in-sensitive as usual. 

B) Steps (through the command line):-

1)Log onto the host that hosts the infrastructure tier (ausable).

2)Log on as user “oracle” – the user that did the install.

3)  Source the infrastructure tier environment file as below:-

a.   $ cd bin – location of the environment file.

b.   $ . <as_infra> – environment file name.

4)  $ ldapsearch -D cn=orcladmin -w inadm02 -p 389 -h ausable
-b “cn=IAS,cn=Products,cn=OracleContext”  -s sub -v
OrclresourceName=<Schema Name> 

5)  You should see the O/P like this below on the host:-

ldap_init( ausable, 389 )filter pattern: OrclresourceName=PORTAL

returning: ALL

filter is: (OrclresourceName=PORTAL)

OrclResourceName=PORTAL,orclReferenceName=infra.rfsuny.org,cn=IAS Infrastructure Databases,cn=IAS,cn=Products,cn=OracleContext

orclflexattribute1=true

orclresourcename=PORTALobjectclass=orclResourceDescriptor

objectclass=top orclpasswordattribute=<Schema Password> 

OrclResourceName=PORTAL,orclReferenceName=infra2.rfsuny.org,cn=IAS
Infrastructure
Databases,cn=IAS,cn=Products,cn=OracleContextorclpasswordattribute=<Schema Password>orclflexattribute1=trueorclresourcename=PORTALobjectclass=orclResourceDescriptorobjectclass=top

2 matches 

6) From the above pick the password from the instance you are interested in finding out the password.  

Categories: Oracle Tags:

Moving Statistics from One Database to Other Database

May 10th, 2009 sam No comments

I had recently upgraded the Database from 10.1.0.4 to 10.2.0.4, I had saved the statistics in table sys.dictstattab. I want to test the statistics on the Test Database.

There are four basic steps to copy the statistics from one database to another database using DBMS_STATS:

1) Create a table in your database to hold the statistics. 
2) Move the statistics from the data dictionary to the table you created in step 1. 
3) Use the Oracle export/import tools to move the data (statistics) from the holding table in your database to a second database. 
4) Populate the data dictionary of the second database with the statistics from the holding table that were copied from the original database.
Categories: DBA, Oracle Tags:

Recovery using RMAN

March 15th, 2009 sam No comments

You lost the RMAN recovery catalog and controlfile. Restored controlfile from backup for example using dbms_backup_restore
package and then restored and recovered the whole database with RMAN in nocatalog mode. When you register the database in a new recovery
catalog, old backups in the controlfile are now inaccessible using the new RMAN catalog.
A: 1. After restoring the controlfile, make a copy to control.bak
before mounting the database.
2. Mount database
3. Start rman and connect to the new recovery catalog
4. register database
5. resync catalog from controlfilecopy ‘/path/control.bak’
6. Restore/recover and open database
7. reset database
Explanation: When you register the database after opening with resetlogs, resync of catalog from
controlfile does not include information about backups from previous incarnations

Categories: DBA, Oracle Tags:

Steps for Changing Report Server Name

March 3rd, 2009 sam No comments

1. Stop your mid-tier
$OHopmnbinopmnctl stopall
Note: If the infrastructure and middle tier are installed on the same machine then ORACLE_HOME mentioned above is ORACLE_HOME of your mid-tier.

2. Stop EM Website
$OHbinemctl stop
Note: If the infrastructure and middle tier are installed on the same machine then stop Infrastructure EM, and if the infrastructure and middle tier are installed on separate machines then stop Middle Tier EM.

3. Rename $OHreportsconfrep_<hostname>.conf file to something else.
Note: ORACLE_HOME mentioned above is ORACLE_HOME of your mid-tier.

4. Rename $OHreportsserverrep_<hostname>.dat file to something else.
Note: ORACLE_HOME mentioned above is ORACLE_HOME of your mid-tier.

5. Edit $OHreportsconfrwservlet.properties file and change the SERVER parameter to the new in-process reports server name you want (this new name has to be a unique name), e.g. myRepSrv.
Note: ORACLE_HOME mentioned above is ORACLE_HOME of your mid-tier.

6. Create a backup copy of the $OHsysmanemdtargets.xml file.

7. Open $OHsysmanemdtargets.xml file and edit the below tag to reflect new in-process Report server name (myRepSrv) :
<Target TYPE=”oracle_repserv” NAME=”iAS902.shgoel-us.us.oracle.com_Reports:myRepSrv” DISPLAY_NAME=”Reports:myRepSrv” VERSION=”1.0″ ON_HOST=”shgoel-us.us.oracle.com”>
<Property NAME=”OracleHome” VALUE=”D:OracleSWiAS902″/>
<Property NAME=”UserName” VALUE=”orcladmin”/>
<Property NAME=”Servlet” VALUE=”http://shgoel-us.us.oracle.com:7780/reports/rwservlet”/>
<Property NAME=”Server” VALUE=”myRepSrv”/>
<Property NAME=”Password” VALUE=”7c857d418cf91dc7″ ENCRYPTED=”TRUE”/>
<Property NAME=”host” VALUE=”shgoel-us.us.oracle.com”/>
<CompositeMembership>
<MemberOf TYPE=”oracle_ias” NAME=”iAS902.shgoel-us.us.oracle.com” ASSOCIATION=”null”/>
</CompositeMembership>
</Target>

8. Save the targets.xml file

9. Start EM Website
$OHbinemctl start

10. Start your mid-tier
$OHopmnbinopmnctl startall

Categories: DBA, Oracle Tags:

Oracle Identity Management(OIM) How to reset OID cn=orcladmin password

March 2nd, 2009 sam No comments

Oracle Identity Management(OIM) How to reset OID cn=orcladmin password

If you wonder what is the password for Oracle Internet Directory(OID) user cn=orcladmin after OIM installation, well, it is exactly the same as ias_admin password specified during installation of OIM. If you really want to reset the password, use included utility resetiASpasswd.sh in $ORACLE_HOMEbin as follows:

First make sure your environment is setup properly for OIM home. (ORACLE_HOME param.)
$ORACLE_HOME/bin/resetiASpasswd.sh cn=orcladmin your_new_pass $ORACLE_HOME

To reset the password to a new randomly generated password, execute the following command in the Oracle home of the application server instance whose password you would like to change:

(UNIX) ORACLE_HOME/bin/resetiASpasswd.sh cn=orcladmin password ORACLE_HOME
(Windows) ORACLE_HOMEbinresetiASpasswd cn=orcladmin password ORACLE_HOME

password is the orcladmin password.


Categories: DBA, Oracle Tags:

Oracle Locking Survival Guide

March 2nd, 2009 sam No comments


Oracle Locking Survival Guide
—————————–

Overview
In multi-user systems, many users may update the same information at the same time. Locking allows only one user to update a particular data block; another person cannot modify the same data.

The basic idea of locking is that when a user modifies data through a transaction, that data is locked by that transaction until the transaction is committed or rolled back. The lock is held until the transaction is complete – this known as data concurrency.

The second purpose of locking is to ensure that all processes can always access (read) the original data as they were at the time the query began (uncommited modification), This is known as read consistency.

Although locks are vital to enforce database consistency, they can create performance problems. Every time one process issues a lock, another user may be shut out from processing the locked row or table. Oracle allows to lock whatever resources you need – a single row, many rows, an entire table, even many tables. But the larger the scope of the lock, the more processes you potentially shut out.


Oracle provides two different levels of locking: Row Level Lock and Table Level Lock.

Row-Level Locking

With a row-level locking strategy, each row within a table can be locked individually. Locked rows can be updated only by the locking process. All other rows in the table are still available for updating by other processes. Of course, other processes continue to be able to read any row in the table, including the one that is actually being updated. When other processes do read updated rows, they see only the old version of the row prior to update (via a rollback segment) until the changes are actually committed. This is known as a consistent read.

When a process places a row level lock on a record, what really happens?

First, a data manipulation language (DML) lock is placed over the row. This lock prevents other processes from updating (or locking) the row. This lock is released only when the locking process successfully commits the transaction to the database (i.e., makes the updates to that transaction permanent) or when the process is rolled back.

Next, a data dictionary language (DDL) lock is placed over the table to prevent structural alterations to the table. For example, this type of lock keeps the DBA from being able to remove a table by issuing a DROP statement against the table. This lock is released only when the locking process successfully commits the transaction to the database or when the process is rolled back.
Table-Level Locking

With table-level locking, the entire table is locked as an entity. Once a process has locked a table, only that process can update (or lock) any row in the table. None of the rows in the table are available for updating by any other process. Of course, other processes continue to be able to read any row in the table, including the one that is actually being updated.

How does table-level locking work?

The first DML operation that needs to update a row in a table obtains what’s called a Row Share Exclusive lock over the entire table. All other query-only processes needing access to the table are informed that they must use the rollback information for the locking process. The lock is released only when the locking process successfully commits the transaction to the database or when the process is rolled back.

Releasing Locks

Many users believe that they are the only users on the system – at least the only ones who count. Unfortunately, this type of attitude is what causes locking problems. We’ve often observed applications that were completely stalled because one user decided to go to lunch without having committed his or her changes. Remember that all locking (row or table) will prevent other users from updating information. Every application has a handful of central, core tables. Inadvertently locking such tables can affect many other people in a system.

Many users, and some programmers, don’t understand that terminating a process does not always release locks. Switching off your workstation before you go home does not always release locks. Locks are released only when changes are committed or rolled back. A user’s action is the only thing that distinguishes between committing, aborting, and rolling back changes. Make it a priority to train your users to commit or roll back all outstanding changes before leaving their current screens.

Modes of Locking
Oracle uses two modes of locking in a multi-user database:

Exclusive lock mode (X) prevents the associates resource from being shared. This lock mode is obtained to modify data. The first transaction to lock a resource exclusively is the only transaction that can alter the resource until the exclusive lock is released.

Share lock mode (S) allows the associated resource to be shared, depending on the operations involved. Multiple users reading data can share the data, holding share locks to prevent concurrent access by a writer (who needs an exclusive lock). Several transactions can acquire share locks on the same resource.
Exclusive Locks

SQL Statement
Mode of Lock

SELECT … FROM table…
No Lock
INSERT INTO table …
RX
UPDATE table …
RX
DELETE FROM table …
RX
LOCK TABLE table IN ROW EXCLUSIVE MODE
RX
LOCK TABLE table IN SHARE ROW EXCLUSIVE MODE
SRX
LOCK TABLE table IN EXCLUSIVE MODE
X

Share Locks

SQL Statement
Mode of Lock

SELECT … FROM table FOR UPDATE OF … RS
LOCK TABLE table IN ROW SHARE MODE RS
LOCK TABLE table IN SHARE MODE S
LOCK TABLE table IN SHARE ROW EXCLUSIVE MODE SRX

RS: Row Share
RX: Row Exclusive
S: Share
SRX: Share Row Exclusive
X: Exclusive

Description of each Lock Mode
The following sections explain each mode of lock, from least restrictive to most restrictive.

Row Share Table Locks (RS)

A row share table lock (also sometimes called a subshare table lock, SS) indicates that the transaction holding the lock on the table has locked rows in the table and intends to update them. A row share table lock is automatically acquired for a table when one of the following SQL statements is executed:

SELECT … FROM table … FOR UPDATE OF … ;
LOCK TABLE table IN ROW SHARE MODE;

A row share table lock is the least restrictive mode of table lock, offering the highest degree of concurrency for a table.

Permitted Operations:

A row share table lock held by a transaction allows other transactions to:

SELECT (query the table)
INSERT, UPDATE, DELETE
or lock rows concurrently in the same table.

Therefore, other transactions can obtain simultaneous row share, row exclusive, share, and share row exclusive table locks for the same table.

Prohibited Operations:

A row share table lock held by a transaction prevents other transactions from exclusive write access to the same table.

When to Lock with ROW SHARE Mode:

Your transaction needs to prevent another transaction from acquiring an intervening share, share row, or exclusive table lock for a table before the table can be updated in your transaction. If another transaction acquires an intervening share, share row, or exclusive table lock, no other transactions can update the table until the locking transaction commits or rolls back.

Your transaction needs to prevent a table from being altered or dropped before the table can be modified later in your transaction.

Example

We use the EMP table for the next examples.

EMPNO ENAME JOB
———- ———- ———
7369 Smith CLERK
7499 Allen SALESMAN
7521 Ward SALESMAN
7566 Jones MANAGER
7654 Martin SALESMAN
7698 Blake MANAGER
7782 Clark MANAGER
7788 Scott ANALYST
7839 King PRESIDENT
7844 Turner SALESMAN
7876 Adams CLERK
7900 James TEST
7902 Ford ANALYST
7934 Miller CLERK

Session 1
Session 2

select job from emp
where job = ‘CLERK’
for update of empno;
OK
select job from emp
where job = ‘CLERK’
for update of empno;
Waiting ….

select job from emp
where job = ‘MANAGER’
for update of empno;
OK

lock table emp in share mode;
OK

lock table emp in exclusive mode;
Waiting ….

insert into emp (empno,ename)
values (9999,’Test’);
OK

delete from emp where empno = 9999;
OK

delete from emp where empno = 7876;
Waiting …. (Blocked by Session 1)

update emp set job = ‘CLIMBER’
where empno = 7876;
Waiting …. (Blocked by Session 1)

A first look about the locking situation can be found in DBA_LOCKS

SELECT SUBSTR(TO_CHAR(session_id),1,5) “SID”,
SUBSTR(lock_type,1,15) “Lock Type”,
SUBSTR(mode_held,1,15) “Mode Held”,
SUBSTR(blocking_others,1,15) “Blocking?”
FROM dba_locks
/

SID Lock Type Mode Held Blocking?
—– ————— ————— —————
95 Transaction Exclusive Blocking <- This is Session 1
95 DML Row-S (SS) Not Blocking
98 DML Row-X (SX) Not Blocking <- This is Session 2
98 Transaction None Not Blocking
110 Temp Segment Row-X (SX) Not Blocking
111 RS Row-S (SS) Not Blocking
111 Control File Row-S (SS) Not Blocking
111 XR Null Not Blocking
112 Redo Thread Exclusive Not Blocking
113 Media Recovery Share Not Blocking
113 Media Recovery Share Not Blocking
113 Media Recovery Share Not Blocking
113 Media Recovery Share Not Blocking
113 Media Recovery Share Not Blocking
113 Media Recovery Share Not Blocking
113 Media Recovery Share Not Blocking
113 PW Row-X (SX) Not Blocking

Row Exclusive Table Locks (RX)

A row exclusive table lock (also called a subexclusive table lock, SX) generally indicates that the transaction holding the lock has made one or more updates to rows in the table. A row exclusive table lock is acquired automatically for a table modified by the following types of statements:

INSERT INTO table … ;
UPDATE table … ;
DELETE FROM table … ;
LOCK TABLE table IN ROW EXCLUSIVE MODE;

A row exclusive table lock is slightly more restrictive than a row share table lock.

Permitted Operations:

A row exclusive table lock held by a transaction allows other transactions to

SELECT (query the table)
INSERT, UPDATE, DELETE
or lock rows concurrently in the same table.

Therefore, row exclusive table locks allow multiple transactions to obtain simultaneous row exclusive and row share table locks for the same table.

Prohibited Operations:

A row exclusive table lock held by a transaction prevents other transactions from manually locking the table for exclusive reading or writing. Therefore, other transactions cannot concurrently lock the table using the following statements:

LOCK TABLE table IN SHARE MODE;
LOCK TABLE table IN EXCLUSIVE MODE;

When to Lock with ROW EXCLUSIVE Mode:

This is the Default Locking Behaviour of Oracle.

Example

Session 1
Session 2

update emp
set ename = ‘Zahn’;
OK
lock table emp in exclusive mode;
Waiting ….

Share Table Locks (S)

A share table lock is acquired automatically for the table specified in the following statement:

LOCK TABLE table IN SHARE MODE;

Permitted Operations:

A share table lock held by a transaction allows other transactions only to

to SELECT (query the table)
to lock specific rows with SELECT … FOR UPDATE
or to execute LOCK TABLE … IN SHARE MODE

statements successfully. No updates are allowed by other transactions. Multiple transactions can hold share table locks for the same table concurrently. In this case, no transaction can update the table (even if a transaction holds row locks as the result of a SELECT statement with the FOR UPDATE clause). Therefore, a transaction that has a share table lock can update the table only if no other transactions also have a share table lock on the same table.

Prohibited Operations:

A share table lock held by a transaction prevents other transactions from modifying the same table and from executing the following statements:

LOCK TABLE table IN SHARE ROW EXCLUSIVE MODE;
LOCK TABLE table IN EXCLUSIVE MODE;
LOCK TABLE table IN ROW EXCLUSIVE MODE;

When to Lock with SHARE Mode

Your transaction only queries the table, and requires a consistent set of the table’s data for the duration of the transaction.

You can hold up other transactions that try to update the locked table, until all transactions that hold SHARE locks on the table either commit or roll back.

Other transactions may acquire concurrent SHARE table locks on the same table, also allowing them the option of transaction-level read consistency.

Caution:

Your transaction may or may not update the table later in the same transaction. However, if multiple transactions concurrently hold share table locks for the same table, no transaction can update the table (even if row locks are held as the result of a SELECT… FOR UPDATE statement). Therefore, if concurrent share table locks on the same table are common, updates cannot proceed and deadlocks are common. In this case, use share row exclusive or exclusive table locks instead.

Example 1

Session 1
Session 2

lock table emp
in share mode;
OK

update emp
set ename = ‘Zahn’
where empno = 7900;
commit;
OK

lock table emp
in share mode;
OK

This and other Transactions have to wait until Session 2 commits the Transaction.

update emp
set ename = ‘Müller’
where empno = 7900;
Waiting ….
select * from emp;
OK


This and other Transactions have to wait until Session 1 commits the Transaction.

This and other Transactions can
get a Share Lock (Lock Switch).


lock table emp
in share mode;
OK

Example 2

For example, assume that two tables, emp and budget, require a consistent set of data in a third table, dept. For a given department number, you want to update the information in both of these tables, and ensure that no new members are added to the department between these two transactions.

Although this scenario is quite rare, it can be accommodated by locking the dept table in SHARE MODE, as shown in the following example. Because the dept table is rarely updated, locking it probably does not cause many other transactions to wait long.

LOCK TABLE dept IN SHARE MODE; /* Other Transactions have to wait */

UPDATE emp
SET sal = sal * 1.1
WHERE deptno IN
(SELECT deptno FROM dept WHERE loc = ‘DALLAS’);

UPDATE budget
SET Totsal = Totsal * 1.1
WHERE deptno IN
(SELECT deptno FROM dept WHERE Loc = ‘DALLAS’);

COMMIT; /* This releases the lock */

Exclusive Table Locks (X)

An exclusive table lock is the most restrictive mode of table lock, allowing the transaction that holds the lock exclusive write access to the table. An exclusive table lock is acquired for a table as follows:

LOCK TABLE table IN EXCLUSIVE MODE;

Permitted Operations:

Only one transaction can obtain an exclusive table lock for a table. An exclusive table lock permits other transactions only to query the table.

Prohibited Operations:

An exclusive table lock held by a transaction prohibits other transactions from performing any type of DML statement or placing any type of lock on the table.

Be careful to use an EXCLUSIVE lock!

Your transaction requires immediate update access to the locked table. When your transaction holds an exclusive table lock, other transactions cannot lock specific rows in the locked table.

Your transaction also ensures transaction-level read consistency for the locked table until the transaction is committed or rolled back.

You are not concerned about low levels of data concurrency, making transactions that request exclusive table locks wait in line to update the table sequentially.

Example

Session 1
Session 2

lock table emp
in exclusive mode;
OK

update emp
set ename = ‘Zahn’
where empno = 7900;
commit;
OK

lock table emp
in exclusive mode;
OK
select * from emp;
OK


This and other Transactions have to wait until Session 1 commits the Transaction.

This and other Transactions cannot
get any other Lock (No Lock Switch).

lock table emp
in share mode;
Waiting ….

lock table emp
in exclusive mode;
Waiting ….

update emp
set ename = ‘Zahn’
where empno = 7900;
Waiting ….


Data Lock Conversion Versus Lock Escalation
A transaction holds exclusive row locks for all rows inserted, updated, or deleted within the transaction. Because row locks are acquired at the highest degree of restrictiveness, no lock conversion is required or performed.

Oracle automatically converts a table lock of lower restrictiveness to one of higher restrictiveness as appropriate. For example, assume that a transaction uses a SELECT statement with the FOR UPDATE clause to lock rows of a table. As a result, it acquires the exclusive row locks and a row share table lock for the table. If the transaction later updates one or more of the locked rows, the row share table lock is automatically converted to a row exclusive table lock.

Lock escalation occurs when numerous locks are held at one level of granularity (for example, rows) and a database raises the locks to a higher level of granularity (for example, table). For example, if a single user locks many rows in a table, some databases automatically escalate the user’s row locks to a single table. The number of locks is reduced, but the restrictiveness of what is being locked is increased.

Oracle never escalates locks. Lock escalation greatly increases the likelihood of deadlocks.

Deadlocks
A deadlock can occur when two or more users are waiting for data locked by each other. Deadlocks prevent some transactions from continuing to work. The next example illustrates two transactions in a deadlock.

Example

Session 1
Session 2
Time
update emp set
sal = sal * 1.1
where empno = 7369;

1 row updated.

update emp set
sal = sal * 1.1
where empno = 7934;

ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
update emp set
mgr = 1342
where empno = 7934;

1 row updated.

update emp set
mgr = 1342
where empno = 7369;

Waiting …
A

B

C


In the example, no problem exists at time point A, as each transaction has a row lock on the row it attempts to update. Each transaction proceeds without being terminated. However, each tries next to update the row currently held by the other transaction. Therefore, a deadlock results at time point B, because neither transaction can obtain the resource it needs to proceed or terminate. It is a deadlock because no matter how long each transaction waits, the conflicting locks are held.

Automatic Deadlock Detection

Oracle performs automatic deadlock detection for enqueue locking deadlocks. Deadlock detection is initiated whenever an enqueue wait times out, if the resource type required is regarded as deadlock sensitive, and if the lock state for the resource has not changed. If any session that is holding a lock on the required resource in an incompatible mode is waiting directly or indirectly for a resource that is held by the current session in an incompatible mode, then a deadlock exists.

If a deadlock is detected, the session that was unlucky enough to find it aborts its lock request and rolls back its current statement in order to break the deadlock. Note that this is a rollback of the current statement only, not necessarily the entire transaction. Oracle places an implicit savepoint at the beginning of each statement, called the default savepoint, and it is to this savepoint that the transaction is rolled back in the first case. This is enough to resolve the technical deadlock. However, the interacting sessions may well remain blocked.

ORA-60 error in ALERT.LOG

An ORA-60 error is returned to the session that found the deadlock, and if this exception is not handled, then depending on the rules of the application development tool, the entire transaction is normally rolled back, and a deadlock state dump written to the user dump destination directory. This, of course, resolves the deadlock entirely. The enqueue deadlocks statistic in V$SYSSTAT records the number of times that an enqueue deadlock has been detected.

select name, value
from v$sysstat
where name = ‘enqueue deadlocks’;

NAME VALUE
———————————————————— ———-
enqueue deadlocks 1

How to avoid Deadlocks

Application developers can eliminate all risk of enqueue deadlocks by ensuring that transactions requiring multiple resources always lock them in the same order. However, in complex applications, this is easier said than done, particularly if an ad hoc query tool is used. To be safe, you should adopt a strict locking order, but you must also handle the ORA-60 exception appropriately. In some cases it may be sufficient to pause for three seconds, and then retry the statement. However, in general, it is safest to roll back the transaction entirely, before pausing and retrying.

Referential Integrity Locks (RI Locks)
With the introduction of automated referential integrity (RI) came a whole new suite of locking problems. What seems at first to be a DBA’s blessing can turn out to be an absolute nightmare when the DBA doesn’t fully understand the implications of this feature. Why is this so?

RI constraints are validated by the database via a simple SELECT from the dependent (parent) table in question-very simple, very straightforward. If a row is deleted or a primary key is modified within the parent table, all associated child tables need to be scanned to make sure no orphaned records will result. If a row is inserted or the foreign key is modified, the parent table is scanned to ensure that the new foreign key value(s) is valid. If a DELETE CASCADE clause is included, all associated child table records are deleted. Problems begin to arise when we look at how the referential integrity is enforced.

Oracle assumes the existence of an index over every foreign key within a table. This assumption is valid for a primary key constraint or even a unique key constraint but a little presumptuous for every foreign key.

Index or no Index on Foreign Key’s ?

If an index exists on the foreign key column of the child table, no DML locks, other than a lock over the rows being modified, are required.

If the index is not created, a share lock is taken out on the child table for the duration of the transaction.

The referential integrity validation could take several minutes or even hours to resolve. The share lock over the child table will allow other users to simultaneously read from the table, while restricting certain types of modification. The share lock over the table can actually block other normal, everyday modification of other rows in that table.

You can use the script: show_missing_fk_index.sql to check unindexed foreign keys:

SQL> start show_missing_fk_index.sql

Please enter Owner Name and Table Name. Wildcards allowed (DEFAULT: %)

eg.: SCOTT, S% OR %
eg.: EMP, E% OR %

Owner <%>: SCOTT
Tables <%>:

Unindexed Foreign Keys owned by Owner: SCOTT

Table Name 1. Column Constraint Name
———————— ———————— —————
EMP DEPTNO FK_EMP_DEPT

What is so dangerous about a Cascading Delete ?

Oracle allows to enhance a referential integrity definition to included cascading deletion. If a row is deleted from a parent table, all of the associated children will be automatically purged. This behavior obviously will affect an application’s locking strategy, again circumnavigating normal object locking, removing control from the programmer.

What is so dangerous about a cascading delete? A deleted child table might, in turn, have its own child tables. Even worse, the child tables could have table-level triggers that begin to fire. What starts out as a simple, single-record delete from a harmless table could turn into an uncontrollable torrent of cascading deletes and stored database triggers.

DELETE CASCADE constraints can be found with the following script:

SQL> SELECT OWNER,
CONSTRAINT_NAME,
CONSTRAINT_TYPE,
TABLE_NAME,
DELETE_RULE
FROM USER_CONSTRAINTS
WHERE DELETE_RULE IS NOT NULL;

CONSTRAINT_NAME C TABLE_NAME DELETE_RU
—————————— – —————– ———
FK_EMP_DEPT R EMP CASCADE

Blocking Locks
Oracle resolves true enqueue deadlocks so quickly that overall system activity is scarcely affected. However, blocking locks can bring application processing to a standstill. For example, if a long-running transaction takes a shared mode lock on a key application table, then all updates to that table must wait.

There are numerous ways of attempting to diagnose blocking lock situations, normally with the intention of killing the offending session.

Blocking locks are almost always TX (transaction) locks or TM (table) locks . When a session waits on a TX lock, it is waiting for that transaction to either commit or roll back. The reason for waiting is that the transaction has modified a data block, and the waiting session needs to modify the same part of that block. In such cases, the row wait columns of V$SESSION can be useful in identifying the database object, file, and block numbers concerned, and even the row number in the case of row locks. V$LOCKED_OBJECT can then be used to obtain session information for the sessions holding DML locks on the crucial database object. This is based on the fact that sessions with blocking TX enqueue locks always hold a DML lock as well, unless DML locks have been disabled.

It may not be adequate, however, to identify a single blocking session, because it may, in turn, be blocked by another session. To address this requirement, Oracle’s UTLLOCKT.SQL script gives a tree-structured report showing the relationship between blocking and waiting sessions. Some DBAs are loath to use this script because it creates a temporary table, which will block if another space management transaction is caught behind the blocking lock. Although this is extremely unlikely, the same information can be obtained from the DBA_WAITERS view if necessary. The DBA_WAITERS view is created by Oracle’s catblock.sql script.

Some application developers attempt to evade blocking locks by preceding all updates with a SELECT FOR UPDATE NOWAIT or SELECT FOR UPDATE SKIP LOCKED statement. However, if they allow user interaction between taking a sub-exclusive lock in this way and releasing it, then a more subtle blocking lock situation can still occur. If a user goes out to lunch while holding a sub-exclusive lock on a table, then any shared lock request on the whole table will block at the head of the request queue, and all other lock requests will queue behind it.

Diagnosing such situations and working out which session to kill is not easy, because the diagnosis depends on the order of the waiters. Most blocking lock detection utilities do not show the request order, and do not consider that a waiter can block other sessions even when it is not actually holding any locks.

Lock Detection Scripts

The following scripts can be used to track and identify blocking locks. The scripts shows the following lock situation.

Session 1 Session 2
select empno
from emp for update of empno; update emp set ename = ‘Müller’
where empno = 7369;

show_dml_locks.sql

This script shows actual DML-Locks (incl. Table-Name), WAIT = YES means
that users are waiting for a lock.

WAI OSUSER PROCESS LOCKER T_OWNER OBJECT_NAME PROGRAM
— ——- ——– ——- ——– ————- ————–
NO zahn 8935 SCOTT – Record(s) sqlplus@akira
YES zahn 8944 SCOTT – Record(s) sqlplus@akira
NO zahn 8935 SCOTT SCOTT EMP sqlplus@akira
NO zahn 8944 SCOTT SCOTT EMP sqlplus@akira

show_blocking_sessions.sql

This script show users waiting for a lock, the locker and the SQL-Command they are waiting for a lock, the osuser, schema and PIDs are shown as well.

Current Lock-Waits

OS_LOCKER LOCKER_SCHEMA LOCKER_PID OS_WAITER WAITER_SCHEMA WAITER_PID
———- ————– ———- ———– ————— ———-
zahn SCOTT 8935 zahn SCOTT 8944

SQL_TEXT_WAITER
————————————————————————–
TX: update emp set ename = ‘Müller’ where empno = 7369

utllockt.sql

This is the original Oracle script to print out the lock wait-for graph in a tree structured fashion. This script prints the sessions in the system that are waiting for locks, and the locks that they are waiting for. The printout is tree structured. If a sessionid is printed immediately below and to the right of another session, then it is waiting for that session. The session ids printed at the left hand side of the page are the ones that everyone is waiting for (Session 96 is waiting for session 88 to complete):

WAITING_SESSION LOCK_TYPE MODE_REQUESTED MODE_HELD LOCK_ID1 LOCK_ID2 —————– ———— ————– ———- ——— ——– 88 None 96 Transaction Exclusive Exclusive 262144 3206

The lock information to the right of the session id describes the lock that the session is waiting for (not the lock it is holding). Note that this is a script and not a set of view definitions because connect-by is used in the implementation and therefore a temporary table is created and dropped since you cannot do a join in a connect-by.

This script has two small disadvantages. One, a table is created when this script is run. To create a table a number of locks must be acquired. This might cause the session running the script to get caught in the lock problem it is trying to diagnose. Two, if a session waits on a lock held by more than one session (share lock) then the wait-for graph is no longer a tree and the conenct-by will show the session (and any sessions waiting on it) several times.

Distributed Transactions
For distributed transactions, Oracle is unable to distinguish blocking locks and deadlocks, because not all of the lock information is available locally. To prevent distributed transaction deadlocks, Oracle times out any call in a distributed transaction if it has not received any response within the number of seconds specified by the _DISTRIBUTED_LOCK_TIMEOUT parameter. This timeout defaults to 60 seconds. If a distributed transaction times out, an ORA-2049 error is returned to the controlling session. Robust applications should handle this exception in the same way as local enqueue deadlocks.

select name,value
from v$parameter
where name = ‘distributed_lock_timeout’;

NAME VALUE
—————————– ——
distributed_lock_timeout 60

ITL Entry Shortages
There is an interested transaction list (ITL) in the variable header of each Oracle data block. When a new block is formatted for a segment, the initial number of entries in the ITL is set by the INITRANS parameter for the segment. Free space permitting, the ITL can grow dynamically if required, up to the limit imposed by the database block size, or the MAXTRANS parameter for the segment, whichever is less.

Every transaction that modifies a data block must record its transaction identifier and the rollback segment address for its changes to that block in an ITL entry. (However, for discrete transactions, there is no rollback segment address for the changes.) Oracle searches the ITL for a reusable or free entry. If all the entries in the ITL are occupied by uncommitted transactions, then a new entry will be dynamically created, if possible.

If the block does not have enough internal free space (24 bytes) to dynamically create an additional ITL entry, then the transaction must wait for a transaction using one of the existing ITL entries to either commit or roll back. The blocked transaction waits in shared mode on the TX enqueue for one of the existing transactions, chosen pseudo-randomly. The row wait columns in V$SESSION show the object, file, and block numbers of the target block. However, the ROW_WAIT_ROW# column remains unset, indicating that the transaction is not waiting on a row-level lock, but is probably waiting for a free ITL entry.

The most common cause of ITL entry shortages is a zero PCTFREE setting. Think twice before setting PCTFREE to zero on a segment that might be subject to multiple concurrent updates to a single block, even though those updates may not increase the total row length. The degree of concurrency that a block can support is dependent on the size of its ITL, and failing that, the amount of internal free space. Do not, however, let this warning scare you into using unnecessarily large INITRANS or PCTFREE settings. Large PCTFREE settings compromise data density and degrade table scan performance, and non-default INITRANS settings are seldom warranted.

One case in which a non-default INITRANS setting is warranted is for segments subject to parallel DML. If a child transaction of a PDML transaction encounters an ITL entry shortage, it will check whether the other ITL entries in the block are all occupied by its sibling transactions and, if so, the transaction will roll back with an ORA-12829 error, in order to avoid self-deadlock. The solution in this case is to be content with a lower degree of parallelism, or to rebuild the segment with a higher INITRANS setting. A higher INITRANS value is also needed if multiple serializable transactions may have concurrent interest in any one block.

Check ITL Waits

The following SQL-Statement shows the number of ITL-Waits per table (Interested Transaction List). INITRANS and/or PCTFREE for those tables is to small (could also be that MAXTRANS is too small). Note that STATISTICS_LEVEL must be set to TYPICAL or ALL, MAXTRANS has been desupported in Oracle 10g and now is always 255 (maximum).

select name,value
from v$parameter
where name = ‘statistics_level’;

NAME VALUE
———————————— ———–
statistics_level TYPICAL

TTITLE “ITL-Waits per table (INITRANS to small)”
set pages 1000
col owner format a15 trunc
col object_name format a30 word_wrap
col value format 999,999,999 heading “NBR. ITL WAITS”

select owner,
object_name||’ ‘||subobject_name object_name,
value
from v$segment_statistics
where statistic_name = ‘ITL waits’
and value > 0
order by 3,1,2;

col owner clear
col object_name clear
col value clear
ttitle off
/

Conclusion
Exclusive Locks lock a resource exclusively, Share Locks can be acquired by more than one Session as long as the other Session holding a Share Lock have no open Transaction. A Share Lock can be “switched” from one Session to another.

Application developers can eliminate the risk of deadlocks by ensuring that transactions requiring multiple resources always lock them in the same order.

A DELETE CASCADE can start out as a simple, single-record delete from a harmless table could turn into an uncontrollable torrent of cascading deletes and stored database triggers.

Blocking locks are almost always TX (transaction) locks or TM (table) locks. Oracle always performs locking automatically to ensure data concurrency, data integrity, and statement-level read consistency. Usually, the default locking mechanisms should not be overriden.

For distributed transactions, Oracle is unable to distinguish blocking locks and deadlocks.

The most common cause of ITL entry shortages is a zero PCTFREE setting.

Categories: DBA, Oracle Tags:

Oracle RMAN – Restore from any Disk Location

February 24th, 2009 sam No comments

Oracle RMAN – Restore from any Disk Location

RMAN looks for the backupfiles to restore within its catalog and therefore there is no RESTORE DATABASE FROM <Disk-Location> command. You can circumvent this constraint using the RMAN command CATALOG START WITH <Disk-Location>. The following example shows how to restore an Oracle database from any disk location.

ora_rman_catalog_start_with.gif

1. Copy the Backup Set Files to any Disk Location

cp <backupset> /tmp/backup

2. Mount the Database

sqlplus / as sysdba
startup mount;

3. Cleanup RMAN Catalog

rman target /

crosscheck backup;
delete noprompt expired backup of database;
delete noprompt expired backup of controlfile;
delete noprompt expired backup of archivelog all;
list backup;

At this point no backup should be available !

4. Make new Backup Location visible to RMAN Catalog

catalog start with ‘/tmp/backup’;

searching for all files that match the pattern
/tmp/backup

List of Files Unknown to the Database
=====================================
File Name: /tmp/backup/PROD_datafile_14_1.bak
File Name: /tmp/backup/PROD_controlfile_17.bak
File Name: /tmp/backup/PROD_archivelog_16_1.bak
File Name: /tmp/backup/PROD_datafile_15_1.bak

Do you really want to catalog the above files
(enter YES or NO)?
yes

List of Cataloged Files
=======================
File Name: /tmp/backup/PROD_datafile_14_1.bak
File Name: /tmp/backup/PROD_controlfile_17.bak
File Name: /tmp/backup/PROD_archivelog_16_1.bak
File Name: /tmp/backup/PROD_datafile_15_1.bak

list backup;

At this point the backup must be available !

5. Restore and Recover the Database

restore database;
recover database;
alter database open;

Categories: Uncategorized Tags:

Logical Standby Creation

February 20th, 2009 sam No comments

Create a Physical Standby
1. Perform a hot backup of the primary database.
This can be done in several ways depending on what your current
configuration is and where the logical standby database will be placed.
2. Turn this backup of the primary database into a physical standby following
a. Restore the backup to the target area if necessary.
b. Create the standby control file and the standby initialization parameter file
c. Define the standby parameters.
i. FAL_SERVER and FAL_CLIENT
ii. STANDBY_ARCHIVE_DEST
d. Enable redo shipping from the primary database to this new physical standby.
e. Start the Managed Recover Process to start bringing this database up to date.
Once the physical standby is up to date you can continue with the next step.
Prepare for the Logical Standby
From this point you begin to incur downtime of the Primary database.
1. Shutdown the Primary database.
a. SHUTDOWN IMMEDIATE
b. Make sure that the physical standby has applied all of the redo sent to it following the shutdown.
c. Defer any further redo shipping to this physical standby.
i. ALTER SYSTEM SET
LOG_ARCHIVE_DEST_STATE_3=DEFER;
1. Or whatever destination number you used.
2. Startup the production database in the restricted mode and build the dictionary.
a. Start the primary database in the mounted mode.
i. STARTUP MOUNT
b. Create a backup control file.
i. ALTER DATABASE BACKUP CONTROLFILE to ‘<file specification>;
c. Restrict access to the primary database
i. ALTER SYSTEM ENABLE RESTRICTED ESSION;
d. Open the database.
i. ALTER DATABASE OPEN;
e. Ensure that Supplemental logging is enabled and switch logs.
Note – If you have other Physical standbys already created you
need to perform this step on those physical standbys as well in
preparation for future switchovers.
i. ALTER DATABASE ADD SUPPLEMENTAL LOG
DATA (PRIMARY KEY, UNIQUE INDEX)
COLUMNS;
ii. ALTER SYSTEM ARCHIVE LOG CURRENT;
Street Proven Techniques for Deploying Data Guard SQL Apply Page 13
f. Record the checkpoint_change# number from v$database.
i. SELECT checkpoint_change# FROM
V$DATABASE;
g. Execute the dictionary build procedure
i. EXECUTE DBMS_LOGSTDBY.BUILD;
h. Switch log files again.
i. ALTER SYSTEM ARCHIVE LOG CURRENT;
i. Obtain archive logs necessary to start the logical standby.
i. SELECT NAME FROM V$ARCHIVED_LOG
WHERE FIRST_CHANGE# <
(SLECT MAX(*NEXT_CHANGE#*)
FROM V$ARCHIVED_LOG
WHERE DICTIONARY_END = ‘YES’ AND
STANDBY_DEST= ‘NO’)
AND NEXT_CHANGE# >
(SELECT MAX(*FIRST_CHANGE#*)
FROM V$ARCHIVED_LOG
WHERE DICTIONARY_BEGIN = ‘YES’ AND
STANDBY_DEST= ‘NO’) ;
3. At this point you can open the database for general use.
a. ALTER SYSTEM DISABLE RESTRICTED SESSION;
Once these steps are complete the Primary is back up and running.
Finish creating the Logical standby
Primary database has been down only for the amount of time it took to
perform the previous 3 steps. From this point on the rest of the steps are
performed on the new logical standby while production is up.
1. Shutdown the physical standby
a. SHUTDOWN IMMEDIATE
2. Copy over all required files from the Primary database to the future
Logical standby.
a. Copy the archive logs identified in the previous section, which
were created on the primary database from the time you restarted
the database to the point the dictionary build command
completed. You should copy the logs containing the dictionary
build as well as the archive log just prior to the dictionary build.
Put them in the directory where the original incoming archive
logs were placed.
i. For example: “/oracle/standby/arch/”
b. Copy the backup control file.
i. If you use a different name for the backup control file
you will have to fix the initialization parameter file to
reflect this change.
3. Finish up the processing on the soon to be logical standby
Street Proven Techniques for Deploying Data Guard SQL Apply Page 14
a. Using the newly created backup control file, mount the database.
i. STARTUP MOUNT;
b. Rename all of the data files and online redo log files to reflect
their current filename. For example, for each data file and log file:
i. ALTER DATABASE RENAME FILE ‘/primary/arch/system.dbf’
TO ‘/standby/arch/system.dbf’;
c. Perform a point in time recovery to the checkpoint change
number obtained in the previous steps.
i. ALTER DATABASE RECOVER AUTOMATIC FROM ‘/oracle/standby/arch/’
UNTIL CHANGE <checkpoint_change#>
USING BACKUP CONTROLFILE;
d. Turn on the Logical standby guard
i. ALTER DATABASE GUARD ALL;
e. Open the standby database the first time.
i. ALTER DATABASE OPEN RESETLOGS;
f. Shut the database down and run the nid utility to change the
database name and id.
i. SHUTDOWN IMMEDIATE;
ii. STARTUP MOUNT;
iii. nid TARGET=sys/password DBNAME=<new name>
iv. SHUTDOWN IMMEDIATE
v. Create the new password file and correct the init.ora file
with the new DBNAME.
vi. Mount the Logical standby and open reset logs.
1. STARTUP MOUNT;
2. ALTER DATABASE OPEN RESETLOGS;
g. Add the temporary files.
i. ALTER TABLESPACE <temp name> ADD TEMPFILE <filespec> SIZE nn;
h. Register the archive logs you copied over in the previous steps.
For each log file do the following:
i. ALTER DATABASE REGISTER LOGICAL
LOGFILE <filespec>;
i. Start Logical standby apply.
i. ALTER DATABASE START LOGICAL STANDBY
APPLY INITIAL <checkpoint_change#>;
4. Re-enable the redo shipping from the primary to this logical standby.
a. ALTER SYSTEM SET
log_archive_dest_state_3=enable;

Categories: Apps DBA, DBA Tags:

Troubleshooting ORA-1031 Insufficient Privilege

December 31st, 2008 sam No comments

Today I tried to login as sysdba i was given this error “ORA-01031 Insufficeint Privilege”. So I thought to write troubleshooting tips for ORA-01031

Facts About Operating System Authentication

1. The following syntax is used while OS Authentication
sqlplus / as sysdba

2. A SQLNET.AUTHENTICATION_SERVICES controls the operation system authentication.
On unix platforms setting the value of this parameter to ” ALL ” or removing this parameter from SQLNET.ORA will allow the Operating system users to authenticate to the database with out specifying the password in other case[setting the value to NONE] the authentication will fail with ORA- 1031.

eg : SQLNET.AUTHENTICATION_SERVICES=(ALL) will allow the OS authentication

SQLNET.AUTHENTICATION_SERVICES=(NONE) will fail the OS authentication

3. The Operating system user should belong to OSDBA group in order to login as sysdba and the user should belong to OSOPER in order to login a sysoper. On unix based platforms these groups by default would be DBA, OPER and in windows these would be ORA_DBA ,ORA_OPER.

1. Remote sysdba connections attempted with a user name and password uses password file authentication

2. The following syntax is used while using a password file authentication
sqlplus <sysdba user>/<password> as sysdba
The following syntax is used while using a password file authentication connecting to the database as remote user
sqlplus <sysdba user>/<password>@<NET SERVICE NAME> as sysdba

3. Password file authentication is enabled by setting the database parameter remote_login_password file to “shared” or “exclusive”.

SQL> alter system set remote_login_password file=exclusive scope=spfile;

4. On unix based platforms a password file is created by default during database installation with an entry of sys under directory $ORACLE_HOME/dbs/ and on windows the file is created under %ORACLE_HOME%\database\

5. Granting each database user a sysdba or sysoper privilege adds the user to the password file in the background.


Troubleshooting ORA-1031 with OS Authentication

1. Check whether the OS user is part of DBA group and OPER group if not add the user to these groups.

2. Check the SQLNET.AUTHENTICATION_SERVICES parameter in the SQLNET.ORA .
On unix based platforms either this parameter should not be present or should be set to ALL.
On windows this parameter should be set to NTS.

3. If the OS user is a domain user in the windows domain than check whether the database service is started with a domain user , if not start the database service with the
domain user. Check whether the domain is added to the ORA_DBA or ORA_<SID>_DBA group.

Check if a non domain[Local] user can able to login to the database. If so there could be problem with the domain settings ,contact the system administrator and the network
administrator reporting the same.

If the local user is also failing to login than follow the remaining steps specified in this troubleshooting document.

4. If a scheduled script on windows is causing the error than the user calling the script must be a privileged user.The AT command, by default, runs as the NT SYSTEM
account.The SYSTEM account is not a privileged Oracle user.

Categories: DBA Tags:

Operations on Redo Log’s Files

December 24th, 2008 sam No comments

Steps for Renaming Redo Log Members

Shut down the database.

1.             SHUTDOWN

2. Copy the redo log files to the new location.Operating system files, such as redo log members, must be copied using the appropriate operating system commands. See your operating system specific documentation for more information about copying files.

The following example uses operating system commands (UNIX) to move the redo log members to a new location:

mv /diska/logs/log1a.rdo /diskc/logs/log1c.rdo
mv /diska/logs/log2a.rdo /diskc/logs/log2c.rdo

3. Startup the database, mount, but do not open it.

4.             CONNECT / as SYSDBA
5.             STARTUP MOUNT

6. Rename the redo log members.

Use the ALTER DATABASE statement with the RENAME FILE clause to rename the database redo log files.

ALTER DATABASE
  RENAME FILE '/diska/logs/log1a.rdo', '/diska/logs/log2a.rdo'
           TO '/diskc/logs/log1c.rdo', '/diskc/logs/log2c.rdo';

7. Open the database for normal operation.

The redo log alterations take effect when the database is opened.

ALTER DATABASE OPEN;

Dropping Log Groups

To drop a redo log group, you must have the ALTER DATABASE system privilege. Before dropping a redo log group, consider the following restrictions and precautions:

· An instance requires at least two groups of redo log files, regardless of the number of members in the groups. (A group comprises one or more members.)

· You can drop a redo log group only if it is inactive. If you need to drop the current group, first force a log switch to occur.

· Make sure a redo log group is archived (if archiving is enabled) before dropping it. To see whether this has happened, use the V$LOG view.

·                SELECT GROUP#, ARCHIVED, STATUS FROM V$LOG;

·                   GROUP# ARC STATUS
·                --------- --- ----------------
·                        1 YES ACTIVE
·                        2 NO  CURRENT
·                        3 YES INACTIVE
·                        4 YES INACTIVE

Drop a redo log group with the SQL statement ALTER DATABASE with the DROP LOGFILE clause.

The following statement drops redo log group number 3:

ALTER DATABASE DROP LOGFILE GROUP 3;

When a redo log group is dropped from the database, and you are not using the Oracle-managed files feature, the operating system files are not deleted from disk. Rather, the control files of the associated database are updated to drop the members of the group from the database structure. After dropping a redo log group, make sure that the drop completed successfully, and then use the appropriate operating system command to delete the dropped redo log files.

When using Oracle-managed files, the cleanup of operating systems files is done automatically for you.

Dropping Redo Log Members

To drop a redo log member, you must have the ALTER DATABASE system privilege. Consider the following restrictions and precautions before dropping individual redo log members:

· It is permissible to drop redo log files so that a multiplexed redo log becomes temporarily asymmetric. For example, if you use duplexed groups of redo log files, you can drop one member of one group, even though all other groups have two members each. However, you should rectify this situation immediately so that all groups have at least two members, and thereby eliminate the single point of failure possible for the redo log.

· An instance always requires at least two valid groups of redo log files, regardless of the number of members in the groups. (A group comprises one or more members.) If the member you want to drop is the last valid member of the group, you cannot drop the member until the other members become valid. To see a redo log file status, use the V$LOGFILE view. A redo log file becomes INVALID if the database cannot access it. It becomes STALE if the database suspects that it is not complete or correct. A stale log file becomes valid again the next time its group is made the active group.

· You can drop a redo log member only if it is not part of an active or current group. If you want to drop a member of an active group, first force a log switch to occur.

· Make sure the group to which a redo log member belongs is archived (if archiving is enabled) before dropping the member. To see whether this has happened, use the V$LOG view.

To drop specific inactive redo log members, use the ALTER DATABASE statement with the DROP LOGFILE MEMBER clause.

The following statement drops the redo log /oracle/dbs/log3c.rdo:

ALTER DATABASE DROP LOGFILE MEMBER '/oracle/dbs/log3c.rdo';

When a redo log member is dropped from the database, the operating system file is not deleted from disk. Rather, the control files of the associated database are updated to drop the member from the database structure. After dropping a redo log file, make sure that the drop completed successfully, and then use the appropriate operating system command to delete the dropped redo log file.

To drop a member of an active group, you must first force a log switch.

Forcing Log Switches

A log switch occurs when LGWR stops writing to one redo log group and starts writing to another. By default, a log switch occurs automatically when the current redo log file group fills.

You can force a log switch to make the currently active group inactive and available for redo log maintenance operations. For example, you want to drop the currently active group, but are not able to do so until the group is inactive. You may also wish to force a log switch if the currently active group needs to be archived at a specific time before the members of the group are completely filled. This option is useful in configurations with large redo log files that take a long time to fill.

To force a log switch, you must have the ALTER SYSTEM privilege. Use the ALTER SYSTEM statement with the SWITCH LOGFILE clause.

The following statement forces a log switch:

ALTER SYSTEM SWITCH LOGFILE;

Redo Log File Status

To see the status of the redo log file there are two dynamic views are there.
A)V$LOG
B)V$LOGFILE

A)V$LOG:
———-
V$LOG displays redo log file information from the control file.

Status:
——–
1)UNUSED – Online redo log has never been written to. This is the state of a redo log that was just added, or just after a RESETLOGS, when it is not the current redo log.

2)CURRENT – Current redo log. This implies that the redo log is active. The redo log could be open or closed.

3)ACTIVE – Log is active but is not the current log. It is needed for crash recovery. It may be in use for block recovery. It may or may not be archived.

4)CLEARING – Log is being re-created as an empty log after an ALTER DATABASE CLEAR LOGFILE statement. After the log is cleared, the status changes to UNUSED.

5)CLEARING_CURRENT – Current log is being cleared of a closed thread. The log can stay in this status if there is some failure in the switch such as an I/O error writing the new log header.

6)INACTIVE – Log is no longer needed for instance recovery. It may be in use for media recovery. It might or might not be archived.

B)V$LOGFILE:
——————
V$LOGFILE view contains information about redo log files.
1)INVALID – The file is corrupted or missing.
2)STALE -This redo log file member is new and has never been used.
3)DELETED -The file is no longer being used.
4) -The redo log file is in use and is not corrupted.

Categories: DBA Tags: