Tuesday, February 23, 2010

Using "sys_context" function

We were planning to restrict an DB user so that it can
a. only create session
b. have insert only into a table MYTABLE
c. Can insert on that table(MYTABLE) only from several selected servers

Point a & b are easy to resolve. But for pint c we had to do some this extra.
In order to implement point c we created a trigger on table MYTABLE which used function sys_context to collect & IP from the session and use these information for authentication. My trigger was as below:

create or replace trigger mytrg
before insert on MYTABLE
for each row
declare
var_ip varchar2(50);
var_count_ip number;
var_user varchar2(50);
begin
select sys_context('USERENV', 'IP_ADDRESS') into var_ip from dual;
select count(*) into var_count_ip from servers where ip = var_ip;
select user into var_user from dual;
if var_user = 'ALERTSENDER' and (var_ip is null or var_count_ip <>
RAISE_APPLICATION_ERROR(-20001,
'ERROR:' || var_ip ||
':NOT AN AUTHENTICATED IP');
else
--OTHER NORMAL OPERATIONS
end if;
end;


Detailed List of Locked Object

I order to find details of all locked object at any moment we can use below query:

select c.USERNAME,b.owner,b.object_name,b.object_type,
decode(a.LOCKED_MODE,
0,
'none',
1,'null',
2,'Row- Share',
3,'Row-exclusive',
4,'Share',
5,'Share /Row- exclusive',
6,'exclusive') LOCKED_MODE,
c.SID, c.SERIAL#,d.SPID, c.OSUSER,c.PROGRAM,c.MACHINE
from v$locked_object a, dba_objects b, v$session c, v$process d
where a.OBJECT_ID = b.object_id
and a.SESSION_ID = c.SID
and c.PADDR = d.ADDR;

Tuesday, February 16, 2010

Foreign Key Constraints Referencing to a Table

We had a table to purge with primary key.
Problem is we need to backup purged data which includes data from all the child tables referencing with foreign keys to that table.
Now I had to find all the child tables and their foreign key columns. I used below query to resolve this problem:

select a.owner,
a.constraint_name,
a.constraint_type,
a.table_name,
b.column_name,
a.r_owner,
a.r_constraint_name
from dba_constraints a, dba_cons_columns b
where a.owner = 'MYUSER'
and a.owner = b.owner
and a.constraint_name = b.constraint_name
and a.r_constraint_name in
(select constraint_name
from dba_constraints
where table_name = 'MYTABLE'
and owner = 'MYUSER');


http://bytes.com/topic/oracle/answers/644008-query-find-primary-foreign-keys
http://www.databasejournal.com/features/oracle/article.php/3665591/Finding-Foreign-Key-Constraints-in-Oracle.htm

Monday, February 15, 2010

Execution Plan & Estimate Temporary Tablespace Usages

One of our developer was informing that he need extra space on temporary tablespace as one of his adhoc query is running for 2 hours (and may run for 10 hours) and consuming huge amount of temp space.

Database was Oracle 11gR2 on RHEL5.
Now problem is how can I estimate that how much space should I add ? I tried with execution plan
as below:

sqlplus user/pass@DB

sql> delete from myuser.plan_table;

sql> commit;

sql> explain plan for
select * from .....


sql> select * from myuser.plan_table;


But I could not find any field that said about Temp Usage.
Then searching the web I became know that Older version of plan table(I found default) don't have that field. It should be created manually and than explain the a query:

cd /ORAIN/oracle/product/11.2.0/dbhome_1/rdbms/admin/


sqlplus user/pass@DB

sql> drop myuser.plan_table purge;

sql> @utlxplan.sql

Table created.

sql> delete from myuser.plan_table;

sql> commit;

sql> explain plan for
select * from .....


sql> select * from myuser.plan_table;

Here TEMP_SPACE column will show the estimated space usage. Then I added the extra Temp space according to the value [added more than estimated for safety purpose] showed by column TEMP_SPACE and it worked.


Recent optimizer statistics should be gathered for Tables and Indexes used the query for which plan is being generated in order to get more accurate result.

http://oradbatips.blogspot.com/2008/02/tip-69-estimate-temp-usage-without.html
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:12519780526076

Wednesday, January 20, 2010

LOCAL LISTENER & ORA-00119 & ORA-00132

Oracle's PMON by default checks for listeners on the default port 1521.
If any listener on port 1521 is running PMON will register the database with tnat listener.Otherwise it will try every possible port.

In order to help PMON to find LISTENER(if not running on 1521) and initialization parameter needs to be configured. The parameter is "local_listener".
If "local_listener" has any value then an entry in tnsnames.ora is needed specifying that local listener port. Please follow below:

if local_listener is set as below:

SQL> show parameter local_listener

NAME TYPE VALUE
-------------- ------- ---------------------
local_listener string LISTENER_MYDB

An entry in tnsnames.ora will be as below (PORT should be the listener port created to serve the target DB):

LISTENER_MYDB =
(ADDRESS = (PROTOCOL = TCP)(HOST = myservername_or_ip)(PORT = 1522))

Now if init parameter local_listener is set (not null) and there is no corresponding enrtry in tnsnames.ora then below will be shown:

ORA-00119: invalid specification for system parameter LOCAL_LISTENER
ORA-00132: syntax error or unresolved network name 'LISTENER_MYDB'

http://www.orafaq.com/node/30
http://www.shutdownabort.com/errors/ORA-00119.php

Tuesday, January 19, 2010

WFMLRSVCApp.ear file missing 11g Installation

Last week I was installing oracle 11gR2.

There were row zip files:

linux_11gR2_database_1of2.zip
linux_11gR2_database_2of2.zip

First time they were extracted in two different folder Disk1 and Diks2.
Then all the contents of one folder were copied to another folder.
Under this condition I started my installation.
After some time i got an error like


File not found .......... WFMLRSVCApp.ear


I stopped installation and tried as below:

Without unzipping into two different folders I copied those two installation zip files to a single folder and unzip them in the same folder as below:

unzip linux_11gR2_database_1of2.zip
unzip linux_11gR2_database_2of2.zip

At this time my installation was running perfectly.
thanks to link



sqlplus Permission denied!!

Last week I installed a new 11gR2 database on RHEL5.4
Installation was completed and I was about to run sqlplus for the first time.

On a terminal I typed sqlplus /nolog
but I got error like below:
error while loading shared libraries: /lib/lib.....so: cannot restore segment prot after reloc: Permission denied

The reason is that SELinux is running and it is in enforcing mode
To solve this problem please request your system admin
or if you have root password then do below:

# getenforce (to see the current mode)
Enforcing

# setenforce 0 (to change the mode to )

# getenforce (to see the current mode)
Permissive


You will find more info here