Dec 16, 2009

rank

RANK and its mates can be useful functions to use when you need to order a list of records.

For example, I needed to transform a database from OMF (oracle managed files) to OSF (oracle standard files). As you may know, OMF bear no resemblance to the datafile standard most corporates seem to run, a typical omf data file might look like o1_mf_ts_ofsaa_2gt2g1hr_.dbf, while a osf might look like user_01.dbf

Being a good dba I wanted to script and automate the CREATE CONTROLFILE statement. My soltion to the above problem was to use the rank function.

So something like -

select tablespace_name, file_name, rank() over (PARTITION BY tablespace_name order by file_id) "id"

solved my problem and produced an output something like -

tablespace1 somefile1 1
tablespace1 somefile2 2
tablespace2 somefile1 1
...

I was then able to use the above statement to generate the datafile section of the create controlfile file.

Dec 4, 2009

EXIT from PL/SQL procedure block

A simple method to EXIT from a PL/SQL block is to use the RETURN keyword. You should also be able to return an EXIT status.

So if we run something like -

1 BEGIN
2 dbms_output.put_line('one.');
3 return;
4 dbms_output.put_line('two.');
5* end;
n990538@edrtst> /
one.

PL/SQL procedure successfully completed.

Oct 28, 2009

instr, substr

A couple of usefull oracle functions for manipulating strings.

instr(string1, string2, start position, nth appearance) returns the position where the string exists.

where
string1 is the original string to search from
string2 is the string to search in string 1
start posititon is optional and is the start position to start searching from
nth appearance is optional and is the number of occurances of string2 in string1.

instr('Tech on the net', 'e', 1, 3) would return 14.

substr(string1, start position, length) returns a string.

where
string1 is the string to check.
start position is the position in the string to start the substring from
length is optional and the length of the position.

substr('Tech on the net',1,5) would return 'Tech '

Often using a combination of the above functions is useful.

substr('Tech on the net',1, instr('Tech on the net', 'e', 1, 3)) would return ''Tech on the ne'

Oct 21, 2009

bug - 2942857 - OERI:12327 from complex view merging

Bug 2942857 - OERI:12327 from complex view merging
DOC ID 2942857.8

Fixed: 9.2.05, 10.1.0.2

Complex view merging may fail with ORA-600[12327] if an COUNT(*) is used and the query has a subquery predicate against the COUNT(*) .

Workaround: Set "_complex_view_merging"=false

Affects EDR, EDMT, DWH.

sed & awk script - find num SID entries in oratab

sed and awk command to
- remove blank lines from the start of each line
- Find entries based on input parameter - SID.
- find the number of entries.

cat oratab sed -e 's/^[ \t]*//' awk -F: '/^'"$SID"'/ { print $1 }' wc -l

truss

Truss is a command that enables you to trace a unix program. The truss output will show the libraries, executables, log files etc the command is touching including the return code.

Use the following commands -
truss -ae -o truss.txt -p 123456

truss -f -o truss.txt abc

where

truss.txt is the output file.
123456 is the process id that the truss will run on.
abc is the program that truss will run on.

Oct 13, 2009

SGA

SGA is made up of the following -

Fixed - Small and always constant depending on platform, os and database version
Variable (large pool, shared pool, java pool)
Database Buffer
Redo Log Buffer

10G
Oracle introduced memory management. Basically you set the following parameters and oracle manages the memory for you. The theory is the database will adjust the memory components as on a as required basis.

sga_taget <> 0
statistics_level = TYPICAL

Jul 22, 2009

zfs parameters

Parameters -

Show Parameters

zpool get
zfs get

There are many parameters that can be used, some which may prove useful are:

compression: Turn compress on at the file system level. Could be useful for staging area.

acl

ACL - Fine grain permissions -

Scenario 1:

databases like oracle, can create files etc on the database server. The os account that starts the database needs to have write permission on the directory structure. The ability that the database has should be conducted as part of the application and therefore it will depend on where these application directories are located. Best practice would suggest that these files should be available and even owned by a application owner.

Use ACL's to resolve this issue. In a nutshell, the owner and group of the file generated by the database is owned by an application owner and group. Give the oracle user or an oracle group read/write/execute permission on the underlying directory. In unix, ensusure setid for group is set. This ensures that dependent files adopt the permissions of the directory.

unix> chmod g+s dirname
unix> chmod A+group:grpname:read_data/write_data/execute:allow dirname

where grpname is the name of the group that is owned by the database owner.

When dealing with a hierarchical file structure, all directories up to parent should be included.

Warning 1:

if you chmod group permissions, then ACL's may be changed.

ls

ls -V - shows acl attributes for a file.

May 29, 2009

TNS Basics

If you are getting TNS-03505 when using tnsping or sqlplus then check the following -

sqlnet.ora - NAMES.DEFAULT_DOMAIN = world

then ensure your entry in the tnsnames.ora file has either a .world fixed to the ens of the database alias or there is an extention.

i.e. -

RISST01P.WORLD = ...

May 15, 2009

SQLPLUS Reports

Use some of the following guidelines when writing SQLPLUS Reports

Compute - use perform computations on groups of data. Types of computiations include AVG, MAX, MIN, STD, SUM, VAR.

break on tablespace_name skip 2
compute sum label "SIZE (M) " of size on tablespace_name

use multiple columns to perform multiple computionation and grand computations etc.

May 1, 2009

datapump

Use the following as a guide when using datapump to extract data and load data into a 10 or above oracle database.

1. create datapump directory and give read, write privilege to required users.

2. Use the following examples to unload and load data from an oracle database.

expdp scott/tiger@db10g tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log

impdp scott/tiger@db10g tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log

Refer to the following link for more details.

http://www.oracle-base.com/articles/10g/OracleDataPump10g.php

Apr 14, 2009

MAX_DUMP_FILE_SIZE

Limit the size of alert log files with this parameter.

Parameter can be changed at system or session level.
i.e. - alter system or alter session

Options are UNLIMITED or a number with size attributes, i.e.: - K, M, G.

To make life easier set this parameter to UNLIMITED.


http://download.oracle.com/docs/cd/B28359_01/server.111/b28320/initparams129.htm

Mar 30, 2009

Defaut Attributes

To change default attributes for partitioned tables and indexes - so tablespace or pctfree is set correctly for new partitions, use the following -

alter table owner . table modify default attributes attribute ...

Subpartitions are slightly different, try -

alter index "owner" . "index" modify default attributes for partition "partition name" ...

where attribute can be -
pctfree, tablespace, pctused etc

Mar 17, 2009

scp

Use the following for using scp:

Assumptions - ssh to server has been setup correctly - see note on setting up ssh.

scp -prvqC files
user@host target directory

options:
-p --> preserve time stamps
-r --> copy subsdirectories
-v --> verbose mode
-q --> quiet - don't include progress counter.
-C --> compress. Note: When running in compress mode, scp runs at a slower rate.

Jan 22, 2009

java thin client

JAVA Thin Client is used by some development / reporting tools to connect to multiple databases.

One such example is dbvisualizer.

The thin driver is useful as it allows users to connect to oracle databases without the requirement of any oracle client software to be installed on desktop / client etc.

Steps:

1. Download the oracle thin driver - http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/winsoft.html

2. Copy into software location or application may load load (and copy to correct location. DBVisualizer does this for you).

3. Create a connection string, something like - jdbc:oracle:thin:@servername:dbport:dbname

Once done, you should be able to connect.