Oracle Database Experts

By Charles Kim

October 28th, 2007

RMAN Database Backup Copy and Merge with Incremental Backups

First, enable BCT (Block Change Tracking). For syntax, please refer to: http://dbaexpert.com/blog/?p=33

One time only to establish the baseline full database backup, you need to perform a level 0 backup of the database using the AS COPY syntax to the FRA:
backup incremental level 0 AS COPY tag DBATOOLS_backup_cp_full_102607 format ‘/u01/app/oracle/admin/DBATOOLS/bkups/%U’ (database);
backup AS COPY skip inaccessible format ‘/u01/app/oracle/admin/DBATOOLS/bkups/%U’ (archivelog all delete input) ;

Now, perform a level 1 incremental backup of the database and archivelogs. Please pay particular attention to the TAGs. It will serve as the essence to performing the merge:
BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG ‘DBATOOLS_backup_cp1_full_102607′ format ‘/u01/app/oracle/admin/DBATOOLS/bkups/%U’ DATABASE;
backup AS COPY skip inaccessible format ‘/u01/app/oracle/admin/DBATOOLS/bkups/%U’ (archivelog all delete input) ;


The level 1 backup from the previous night will be merged with the level 0 backup using the TAG syntax prior to performing the new level 1 backup:
recover copy of database with tag ‘DBATOOLS_backup_cp1_full_102607′;
BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG ‘DBATOOLS_backup_cp1_full_102707′ DATABASE;
backup AS COPY skip inaccessible (archivelog all delete input) ;

Posted by Charles Kim @ DBAExpert.com

October 24th, 2007

Basic RAC configuration

Oracle Real Application Cluster (RAC) is the successor to Oracle Parallel Server (OPS) and allows multiple instances to access the same database (storage) accessing and modifying the same data at the same time.

RAC provides fault tolerance, load balancing, and performance benefits by allowing the system to scale out, and at the same time since all nodes access the same database, the failure of one instance will not cause the loss of access to the database.

At the heart of Oracle10g RAC is the OCR and Voting Disk. All the nodes in the cluster must be able to access all of the data, redo log files, control files and spfile. At each instance level exist redo log file(s) and UNDO tablespace. All the instances in the RAC cluster must be able to access the controlfiles, redo logs and UNDO tablespaces to recover a node in the event of a system failure.

As of Oracle Database 10g RAC, data files, redo log files, control files, and archivelog files can reside on shared storage. Shared storage can be on raw-disk devices, NAS, ASM, or a clustered file system. At a minimum, a 1GB bandwidth for Oracle Interconnect and public network is required to successfully implement RAC. Typically, the networks cards (NICs) are aggregated to provide 2-4GBit bandwidth. Likewise, the network bandwidth for the public network is often aggregated to provide 2-4GBit bandwidth. With technologies such as Infiniband, the bandwidth can be amplified upto 10Gbit per second.

We recommend having at a minimum: 3 voting disks and mirroring the OCR. The voting disks must have at least 50% survivability for the RAC cluster to stay up. For example, if you have two voting disks and lose one of the two voting disks, you will only have 50% of the voting disks. In this particular case, the entire RAC cluster will crash.

Posted by: Charles Kim @ DBAExpert.com

October 24th, 2007

ocfs

ocfs V1 - allows database files ONLY to be located shared storage

1. datafiles

2. control files

3. redo logs

4. archived redo logs

5. OCR

6. Voting Disk


  • does NOT support storage of oracle binaries
  • does NOT support storage of scripts


Recommended backup and recovery tool is RMAN

If you want to access the files while the database is up, and want to use cp,dd,mv,tar the file system must support Direct I/O


http://oss.oracle.com - Oracle Open Source Support Website


ocfs2

Introduced in 2005

Is a POSIX compliant file system

Support ALL types of files including Oracle Binaries

Must be running Linux Kernel 2.6


Available on Windows and Linux

Oracle has plans to port to Sun Solaris. Date is still not published.


Ice Rocket :

October 24th, 2007

Oradebug

Trace SQL statements with bind variables
> oradebug setospid 10121
Oracle pid: 91, Unix process pid: 10121, image: oracleorcl
> oradebug EVENT 10046 trace name context forever, level 12
Statement processed.
> ! vi /app/oracle/admin/orcl/bdump/ora_10121.trc

Trace Process Statistics
> oradebug setorapid 2
Unix process pid: 1436, image: ora_pmon_orcl
> oradebug procstat
Statement processed.
> oradebug TRACEFILE_NAME
/app/oracle/admin/orcl/bdump/pmon_1436.trc

List semaphores and shared memory segments in use
> oradebug ipc

Dump Error Stack
> oradebug setospid <pid>
> oradebug event immediate trace name errorstack level 3

October 24th, 2007

Simple Script to rename redo logs to ASM

select ‘alter database rename file ‘||chr(39)||
member||chr(39)||’ to ‘||chr(39)||
‘+DATA/DBATOOLS/onlinelog/’||
substr(member, instr(member, ‘/’, -1)+1)||chr(39)||’;’
from v$logfile
/

October 24th, 2007

Create a RMAN repository and register a database

First, create the rman schema:
1 create user rman identified by rman123
2* default tablespace rman_d temporary tablespace temp
SQL> /

User created.

SQL> grant RECOVERY_CATALOG_OWNER to rman;

Grant succeeded.

SQL> grant connect, resource to rman;

Grant succeeded.

Next, connect to the recovery catalog database:
scadmin > rman target rman/rman123 catalog rman/rman123

Recovery Manager: Release 10.2.0.3.0 – Production on Wed Oct 1 13:14:20 2007

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

connected to target database: RMANPROD (DBID=999586748)
connected to recovery catalog database

Finally create the catalog:
RMAN> create catalog

recovery catalog created

Register each database (from each client server):
rman catalog rman/rman123@DBATOOLS target /

Recovery Manager: Release 10.2.0.3.0 – Production on Wed Oct 1 13:24:55 2007

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

connected to target database: DBATOOLS (DBID=2955690999)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

October 24th, 2007

Check CRS Status

crsctl query css votedisk
——————————————————–
0. 0 /dev/dba_vote_disk

crsctl check crs
——————————————————–
CSS appears healthy
CRS appears healthy
EVM appears healthy

Check CRS version being used:
——————————————————–
crsctl query crs softwareversion [<nodename>] – lists the version of CRS software installed
crsctl query crs activeversion – lists the CRS software operating version

When are these commands useful? Rolling upgrades

CRS State Dumps
—————
crsctl debug statedump crs –> output generated to $ORA_CRS_HOME/log/[hostname]/crsd.log

CRS > ./crsctl debug statedump crs
Dumping State for crs objects
crsctl debug statedump css –> ../cssd/ocssd.log
crsctl debug statedump evm –> ../evmd/evmd.log

October 24th, 2007

Remove files with find

In this example, we will remove all files that have not been modified in 30 days.
find . -mtime +30 -exec rm -f {} \;

If you have a ton of files in the directory, the find command used above will spit out errors. In this case, you may want to try the find command piped to xargs:

find . -mtime +30 |xargs rm -f

rhct-logo

Posted by: Charles Kim @ DBAExpert.com

October 24th, 2007

Setting the 10046 Event for performance diagnostic

exec dbms_system.set_bool_param_in_session(8,5,’timed_statistics’,true);

PL/SQL procedure successfully completed.

 

SQL> exec dbms_system.set_int_param_in_session(8,5,’max_dump_file_size’,10000000);

PL/SQL procedure successfully completed.

 

SQL> execute sys.dbms_system.set_ev(8,5,10046,8, ‘ ‘);

PL/SQL procedure successfully completed.

 

To Turn Off Tracing:

******* run all of your processing here *******

SQL> execute sys.dbms_system.set_ev(&&SID, &&SERIAL, 10046, 0, ‘ ‘);

— disables extended SQL tracing.

 

Another alternative:

The DBMS_SUPPORT package is preferred and fully supported by Oracle but the above DBMS_SYSTEM works just fine. You will have to install this package and it is not available on all platforms. To install run the dbmssupp.sql script as sysdba located in $ORACLE_HOME/rdbms/admin directory.

SQL> execute sys.dbms_support.start_trace_in_session(&&SID, &&SERIAL, waits=>true, binds=>false);

— equivalent to level 8 tracing, bind=>true would be equivalent to level 12 tracing.

******* run all of your processing here *******

SQL> execute sys.dbms_support.stop_trace_in_session(&&SID, &&SERIAL); — end tracing.

Set you local session:

alter session set events ‘10046 trace name context forever, level 12′;

October 23rd, 2007

RAC Tracing

Srvctl tracing:

Vi $ORACLE_HOME/bin/racgwrap

Uncomment out this line:

#_USR_ORA_DEBUG=1 && export _USR_ORA_DEBUG

 

export SRVM_TRACE=TRUE

October 23rd, 2007

Srvctl helpful commands

Most common commands:

srvctl start database d database-name

srvctl stop database d database-name

srvctl start asm n node-name

srvctl stop asm n node-name

srvctl start nodeapps n node-name

srvctl stop nodeapps n node-name

srvctl status service -d <db_name> -s <service_name>

 

For help with all commands:

srvctl -h

Note: From this, you can derive where to get help for other commands

For Detailed Help:

srvctl start database -h

srvctl add service -h

srvctl relocate service –h

 

Check out current configuration information:

srvctl config database

Displays the configuration information of the cluster database.

srvctl config service

Displays the configuration information for the services.

srvctl config nodeapps

Displays the configuration information for the node applications.

srvctl config asm

Displays the configuration for the ASM instances on the node.

Example to look for all the registered services for a database:

srvctl config service -d DBATOOLS

To get VIP information:

o srvctl config nodeapps -n xxxx708 -a

VIP exists.: /xxxx708-vip/10.999.99.99/255.255.255.0/eth4

or

o ifconfig -a

Look for interface with two IPs!

When node 1 comes back up, it will start it’s CRS stack. It will take back

it’s VIP. In order to fail the service back, you would need to run srvctl

relocate. The following example is relocating the service from node 2 back to

node 1:

srvctl relocate service -d V10SN -s SRV_AVAIL -i V10SN2 -t V10SN1

 

To Forcefully remove a database from the OCR, use srvctl remove database with -f (force option):

Then use srvctl add database -d DB -o $ORACLE_HOME
again.

October 23rd, 2007

Finding the Bind Values in a Query

Extended SQL trace is one of the oldest and most complete methods for capturing the values of bind variables used in SQL statements. You can enable extended SQL trace in your own session with the following statement:

ALTER SESSION SET EVENTS ‘10046 trace name context forever, level 4′;

You can enable extended SQL trace in another user’s session using one of the following procedure calls:

SYS.dbms_system.set_ev (sid, serial#, 10046, 4, ”)
SYS.dbms_support.start_trace_in_session (sid, serial#, waits=>FALSE, binds=>TRUE)
SYS.dbms_monitor.session_trace_enable (sid, serial#, waits=>FALSE, binds=>TRUE)

The dbms_monitor package is new in Oracle 10g. Any of these will cause Oracle to write a trace file on the database server in the directory specified by the user_dump_dest instance parameter. The trace file will contain text like:

PARSING IN CURSOR #1 len=116 dep=0 uid=77 oct=3 lid=77 tim=4528731877418 hv=3407
047714 ad=’b8cd9050′
SELECT e.*
FROM emp e,
dept d
WHERE e.deptno = d.deptno AND
d.deptno = :l_deptno AND
e.sal > :l_sal
END OF STMT
PARSE #1:c=0,e=1644,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=4528731877382
BINDS #1:
bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=03 oacfl2=c000000000000000
size=48 offset=0 bfp=800003fb800697f0 bln=22 avl=02 flg=05 value=10
bind 1: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=03 oacfl2=c000000000000000
size=0 offset=24 bfp=800003fb80069808 bln=22 avl=02 flg=01 value=300
EXEC #1:c=0,e=810,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=4528731879874
FETCH #1:c=10000,e=14607,p=3,cr=6,cu=0,mis=0,r=1,dep=0,og=4,tim=4528731894755
FETCH #1:c=0,e=154,p=0,cr=0,cu=0,mis=0,r=2,dep=0,og=4,tim=4528731898231

In the above example, “BINDS #1″ indicates values bound into the bind variables of the statement in cursor #1. (See the previous “PARSING IN CURSOR #1″ entry for the text of the statement in cursor #1.) Below “BINDS #1″, the “bind 0″ entry corresponds to the first bind variable in the statement i.e. :l_deptno. Similarly, “bind 1″ corresponds to the second bind variable, :l_sal. The last item on the “bind 0″ and “bind 1″ entries shows the value of the bind variable at the time of binding. If a statement is executed multiple times in a traced session, there will be additional “BINDS” entries as new values are bound.

Beginning in Oracle 10g, it is also possible to monitor bind variable values in your own session or other sessions witho
ut performing an extended SQL trace. A new v$ view called v$sql_bind_capture shows bind variable data across all sessions. There are a few important restrictions on v$sql_bind_capture: Only simple-type bind variables that appear in the WHERE a nd HAVING clauses are captured. (Thus it is not possible to obtain the values used in INSERT statements or SET clauses of UPDATE statements, or LOBs or LONGs.) Also, to reduce overhead, bind variable information is captured no more frequently than once every 15 minutes for a given cursor. Finally, this view is only populated when the statistics_level parameter is set to TYPICAL or ALL.

For example, we can retrieve bind variable information for all statements parsed by us with a query such as:

SELECT b.name, b.value_string, sq.sql_text
FROM v$sql_bind_capture b, v$sql sq, v$session s
WHERE sq.sql_id = b.sql_id
AND sq.address = b.address
AND sq.child_address = b.child_address
AND sq.parsing_user_id = s.user#
AND s.username = USER
ORDER BY sq.sql_id, sq.address, sq.child_address, b.position;

This might produce results such as:

NAME VALUE_STRING SQL_TEXT
———– —————– ———————————————————-
:L_DEPTNO 10 SELECT e.* FROM emp e, dept d WHERE e.deptno = d.deptno…
:L_SAL 300 SELECT e.* FROM emp e, dept d WHERE e.deptno = d.deptno…

Even though the data collected in v$sql_bind_capture is only sampled periodically, it can still help DBAs track down performance issues in code they are not familiar with. For example, since v$sql_bind_capture indicates the data type of thebind variables, it is possible to use the view to discover statements that have performance problems due to implicit type conversions. Recently we were asked by a development group why the following statement would not use an index on the image_no column:

SELECT * FROM images WHERE image_no = :B1;

By comparing the data type of the bind variable against the data type of the image_no column, it was straightforward to show a type conversion was taking place that was defeating the index. When the developer changed the bind variable datatype from numeric to character, the query began using the index.

Extended SQL trace allows you to see all bind variable values for all executions of SQL statements captured in the tracefile. Beginning in Oracle 10g, the v$sql_bind_capture view allows you to see sampled bind variable information for all sessions without having to use tracing. Both tools can be extremely useful to the Oracle DBA.