Thursday, December 9, 2010

DataStage Import Table Definition, ODBC Data Source

It is recommended to use Orchestrate Schema Definitions to import table definitions, which however is not available for MS SQL Server. An example to use orchdbutil GUI to import Oracle table definitions is shown below, which can only import one table at a time. Note the database server is the tnsnames entry configured.



Another way is to configure ODBC data source and use it to import table definitions. The file to configure the ODBC data source is $DSHOME/.odbc.ini:

An example for Oracle ODBC data source:
[Oracle-DSNAME]
QEWSD=2455147
Driver=/u/BASE/IBM/InformationServer/Server/branded_odbc/lib/VMora23.so
Description=DataDirect Oracle Wire Protocol driver
ApplicationUsingThreads=1
ArraySize=60000
CachedCursorLimit=32
CachedDescLimit=0
CatalogIncludesSynonyms=1
CatalogOptions=0
DefaultLongDataBuffLen=1024
DescribeAtPrepare=0
EnableDescribeParam=0
EnableNcharSupport=0
EnableScrollableCursors=1
EnableStaticCursorsForLongData=0
EnableTimestampWithTimeZone=0
HostName=
LocalTimeZoneOffset=
LockTimeOut=-1
LogonID=
Password=
PortNumber=
ProcedureRetResults=0
SID=
UseCurrentSchema=1


An example for SQL Server ODBC data source:
[SQL-DSNAME]
Driver=/u/BASE/IBM/InformationServer/Server/branded_odbc/lib/VMmsss23.so
Description=DataDirect SQL Server Wire Protocol driver
Database=
Address=
QuotedId=No
AnsiNPW=No

And the uvodbc.config file under the project directory need to be configured by referencing the ODBC data sources:
......
[ODBC DATA SOURCES]
<ODBC_DATA_SOURCE>
DBMSTYPE = ODBC

Thursday, October 28, 2010

Oracle 11g Invisible Indexes

SQL> create unique index EMP_UK1 on emp(empno) tablespace users invisible;

Index created.

SQL> select index_name, visibility from user_indexes where table_name='EMP';
INDEX_NAME VISIBILIT
------------------------------ ---------
EMP_UK1 INVISIBLE

SQL> explain plan for
2 select /*+ index(EMP_UK1) */ * from emp where empno=3999;

Explained.

SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
Id     Operation     Name     Rows     Bytes     Cost (%CPU)     Time
--------------------------------------------------------------------------
0  SELECT STATEMENT 1 53 83 (0) 00:00:04
* 1 TABLE ACCESS FULL EMP  1  53  83 (0) 00:00:04
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
1 - filter("EMPNO"=3999)
13 rows selected.

SQL> alter session set optimizer_use_invisible_indexes=true;
Session altered.

SQL> explain plan for
2 select /*+ index(EMP_UK1) */ * from emp where empno=3999;
Explained.

SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2080524269
---------------------------------------------------------------------------------------
Id     Operation     Name     Rows     Bytes     Cost (%CPU)     Time
---------------------------------------------------------------------------------------

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
0  SELECT STATEMENT  1  53  2 (0) 00: 00:01
1  TABLE ACCESS BY INDEX ROWID  EMP  1  53  2 (0)  00:00:01
* 2  INDEX UNIQUE SCAN  EMP_UK1  1  1 (0)  00:00:01
---------------------------------------------------------------------------------------

PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPNO"=3999)

14 rows selected.

Tuesday, October 26, 2010

Query Oracle hidden/underscore parameters

SELECT a.ksppinm "Parameter",
               a.ksppdesc "Description",
               b.ksppstvl "Session Value",
               c.ksppstvl "Instance Value"
FROM x$ksppi a, x$ksppcv b, x$ksppsv c
WHERE a.indx = b.indx
     AND a.indx = c.indx
    AND a.ksppinm LIKE '%%';

Monday, October 18, 2010

Custom JavaSSO logout to return SSO logout page, not the EM welcome page

We had an application deployed to Oracle Application Server. It used JavaSSO for single-signon. When logging out, the application returned to the Enterprise Manager welcome page, not the JavaSSO logout page.

Found the problem was with the jazn.xml file in the container level, there was a entry:

    property name="custom.sso.url.param" value=""

Removing it fixed the issue.

Thursday, October 14, 2010

Linux memory usage

  • Do a free command, see the used, free memory, as well buffers and cached memory
        

  • Do a total of all running procecss memory usage, including init, the kernel is not reported in "ps"
$ ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid|grep -v RSS|awk '{total=total+$3}END{print total}'

2194756
  • How much used for kernel
Total physical RAM - buffers - cached - total running process RAM usage - free:
8175520 - 535184 - 3158588 - 2194756 - 2105836 = 92236KB

Notes:
  • Reference: http://mail.nl.linux.org/linux-mm/2003-03/msg00077.html
  •  Memory Buffers - A page cache for the virtual memory system. The kernel keeps track of frequently accessed memory and stores the pages here.
  • Memory Cached - Any modern operating system will cache files frequently accessed.
  • VSIZE (Virtual memory SIZE) - The amount of memory the process is currently using. This includes the amount in RAM (including buffers/cached) and the amount in swap.
  • RSS (Resident Set Size) - The portion of a process that exists in physical memory (RAM).
  • The kernel - The kernel will consume a couple of MB of memory. The memory that the kernel consumes can not be swapped out to disk. This memory is not reported by commands such as "free" or "ps".

Thursday, October 7, 2010

Kill sessions in Oracle

  • ALTER SYSTEM KILL SESSION 'sid,serial#';
It marks the session as 'killed' in v$session. When client session tries to issue more commands like commit, DMLs, error "ORA-00028: your session has been killed" returned. Then the session is rolled back and removed from v$session
  • ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
The session is rolled back and removed from v$session immediately. When client session tries to issue more commands like commit, DMLs, error "ORA-03113: end-of-file on communication channel" returned.

  • ALTER SYSTEM DISCONNECT SESSION 'sid,serial#' POST_TRANSACTION;
It waits for the client session to finish the transactions and commit. Once committed, when client session tries to issue more commands like DMLs, error "ORA-00028: your session has been killed" returned. Then the session is removed from v$session. There is no rollback as the session has committed.

Tuesday, October 5, 2010

RMAN Notes

  • Compression & algorithm (ZLIB new for 11g, default BZIP2)
          RMAN> CONFIGURE COMPRESSION ALGORITHM ' ZLIB' ;
  • Multiplexed backup
  • Block media recovery: v$backup_corruption
          RMAN> BLOCKRECOVER CORRUPTION LIST;
  • Backup duration & load
        RMAN > backup duration 2:00 minimize load database;
  • Using RMAN to clone database, and clone on the fly with 11g
  • Using RMAN for inter-platform migration
  • Using RMAN to migrate to ASM
  • Test restore
          RMAN> RESTORE VALIDATE DATABASE FROM TAG=' Tag name' ;

Database Cloning on the Fly - 11g

Read and excerpt from the book: Oracle 10g/11g data and database management utilities - haven't got a chance to try:
---------------------------------------------------------------------------------
As you have seen, Oracle 10g required the database to have a backup, and some manual preparation must be done prior to the clone process execution. Starting with 11g the DBA is leveraged from some tasks. With 11g, it is no longer required to have the target spfle created, this can be created on the fly, and there is no need to have a pre-existing backup from the source database. RMAN reads the original database files the same way it reads the datafles for a backup operation and transfers the on-the fly backup to the auxiliary database using an inter-instance network connection. RMAN utilizes an in-memory rman script to perform the cloning tasks at the auxiliary location. Some preparation at the destination site must be still performed prior to the clone process; the cloned environment must be already identifed with a password file, which holds the same password as that defned at the source site.

DUPLI CATE TARGET DATABASE
TO CLONEDB
FROM ACTIVE DATABASE
SPFILE
PARAMETER_VALUE_CONVERT ' /u01' , ' /u02 '
SET LOG_FI LE_NAME_CONVERT ' /u01' , ' /u02 '
SET DB_FILE_NAME_CONVERT ' /u01' , ' /u02 '
SET SGA_MAX_SIZE 512M
SET SGA_TARGET 400M;

Wednesday, September 29, 2010

UNDO Data for a LOB Segment is Kept within the LOB Segment Space

Never realized this before. See metalink note:
How to determine the actual size of the LOB segments and how to free the deleted/unused space above/below the HWM [ID 386341.1] for details.

Using command to free the space:
alter table <tablename> modify lob(<lob_column>) (shrink space [cascade]);

Wednesday, September 22, 2010

Upgrade from Oracle Database 10.2.0.4 to 11.2.0.1

Just upgraded one of our databases from 10.2.0.4 to 11.2.0.1. The following outlines the major steps:
  1. Install Oracle 11.2.0.1 software. Choose 'install database software only' option. Specify a location for Oracle Base that is required for Oracle 11g diagnostic framework        
  2. Perform complete pre-upgrade checklist according to metalink note 870814.1, including:
  3. 1) Identify invalid objects and recompile them.  2) Resolve TIMESTAMP WITH TIMEZONE Datatype. Metalink note 815679.1 provides excellent explanation and solution on this. In my case I don't need to perform any action. 3) Update optimizer statistics, including dictonary and SYS schema 4) Run utlu112i.sql to identify issues and correct them, including free space in the tablespaces, size of some of the pools
  4. !!Backup the database!!
  5.  
  6. Perform the upgrade with dbua
  7. On the first try, I had issue and the upgrade aborted with ORA-0431 error and had to restore the database from the backup. The database uses AMM. However after increasing the sga_target from 700M to 1G, I was able to upgrade to the database successfully on the second try. 
  8. Perform post-upgrade, including
  9. 1) Update some of the init.ora parameters, such as compatible, using memory_target, etc. 2) Update all the scripts, such as backup, start/stop scripts to reflect the new Oracle home  

Tuesday, September 21, 2010

Search, Drill-down History sessions, SQL Text and Execution Plan with Oracle EM Grid Control

As an DBA who has worked with many database administration tools, I often need to be able to find queries that users ran recently, for being able to view the queries and their execution plans, and tune them. Oracle 10g onwards provide views such as  DBA_HIST_SQLTEXT, DBA_HIST_SQL_PLAN that can be queried to find out the queries and their plans.

Oracle 10g EM Grid onwards provide intuitive GUI interface to search and drill-down history sessions, sql text and execution plan.

Go to the database target -> Performance tab -> Search SQL link at the bottom. It can search from Cursor Cache, AWR Snapshots, AWR Baseline, SQL Tuning Set. Note in the search box for SQL Text LIKE, the wildchar % or ? needs to be used, and it is not case-sensitive.

Run a sql statement from sql*plus
SQL> select * from testniej;


Searching with the wildchar returns the query and its SQL ID, click the SQL ID we can drill down to the query: its statistics, plan, etc.
Searching without the wildchar returns nothing

Wednesday, September 15, 2010

Datapump Job Finished without Doing Anything

Helped another DBA to figure out the problem. The datapump finished without doing anything, with a full trace TRACE=1FF0300, there was nothing specific in the trace file.
-------------------------------------
......
KUPM: 13:55:39.631: dropping master since job never started
KUPM: 13:55:39.631: *******OUT DISPATCH  , request type=1004   response type =2041
KUPC: 13:55:39.632: Before ENQ: Sending Type: 2041 ID: RP,KUPC$C_1_20100915135538,MCP,KUPC$A_1_20100915135539,10,Y
KUPM: 13:55:39.632: Exited main loop...
KUPV: 13:55:39.633: Update request for job: SYS.SYS_IMPORT_FULL_01, func: 1
KUPM: 13:55:39.634: Entered state: UNDEFINED
KUPM: 13:55:39.634: In RESPOND_TO_START
KUPM: 13:55:39.634: In check_workers...
KUPM: 13:55:39.634: Job is completing

.......
-------------------------------------------

Searched the alert.log file found an error: ORA-25153: Temporary Tablespace is Empty

Found the temporaory tablespace didn't have any temporary datafile, which was not added back when the DBA recreated the controlfile. After adding the temporary datafile back, the problem was resolved.

Friday, August 27, 2010

Stale Oracle Statistics? Cached Execution Plan?

Today I had a very interesting issue. My Datastage developer had a job that ran forever and eventually out of temp tablespace and the job was aborted. The job was doing a single select query by joining 3 tables. I took the query out to sql*plus and it ran instantly.

By examing the query execution plan when running from the Datastage job and when running from sql*plus, they were different. How could that be? The two queries were exactly the same, why the execation plan were different. Were the execution plan cached somewhere when running from DataStage.

Anyway, updating the statisitcs on the table with 'analyze table ... compute statistics' resolved the issue.

Tuesday, August 10, 2010

Retrieve OID ORASSO Password

The user is orasso in the OID repository database, run ldapsearch from oid server, replacing password with the actual password of orcladmin, and db_service_name with the actual database service name, e.g. orcl.oracle.com
---------------------------------------------------------------
ldapsearch -p 389 -h laoid -D "cn=orcladmin" -w  password -b "orclresourcename=orasso, orclreferencename=db_service_name, cn=IAS Infrastructure Databases,cn=IAS,cn=Products,cn=OracleContext" -s base "objectclass=*" orclpasswordattribute

Tuesday, June 22, 2010

Using Materialized View to Achieve Uniqueness across Tables

Recently I have been working with materialized view (MV) a lot. Some rules I have learned:

- On a fast refresh MV with UNION ALL joins, the MV logs need to be created with ROWID/PRIMARY KEY. And the MV needs to SELECT the ROWID/PRIMARY KEY, and also a UMARKER

- In order to call functions in the MV SELECT clause, the function must be created as DETERMINISTIC

We use an MV with unique index to achieve uniqueness across tables. This appears fine. However we have an issue to perform unit of work commit. The logic is when a product is renamed, its old name is moved to the product_hist table, which has to be an unit of work. However the MV refresh couldn't handle the order of the updates correctly, thus the unique constraint fires to prevent such as an unit of work.

We have to update the product table then commit first; then update the product_hist table, which defeats the application logic. So if anybody has a workaround, please share.

Let me demonstrate here:
-----------------------------------------------
create table product (id number primary key, name varchar2(30));
create table product_hist (hist_id number primary key, id number, name varchar2(30));
create materialized view log on product with rowid, primary key;
create materialized view log on product_hist with rowid, primary key;

create materialized view product_mv build immediate refresh fast on commit as
select rowid rid, id pk_id, name, 'P' umarker from product
union all select rowid rid, hist_id pk_id, name, 'PH' umarker from product_hist;

create unique index product_mv_uq on product_mv(name);

insert into product values(1,'product one');
insert into product_hist values(1,1,'product one old');
commit;
select name from product_mv;

NAME
------------------------------
product one old
product one

update product set name='product one new' where id=1;
insert into product_hist values(2,1,'product one');
commit;

commit
*
ERROR at line 1:
ORA-12008: error in materialized view refresh path
ORA-00001: unique constraint (ABC.PRODUCT_MV_UQ) violated

Thursday, June 10, 2010

Unix/Linux Process Dump - OC4J Process Hanged during Deployment

Our OC4J server process hanged during application deployment. Using 'kill -3 ' we were able to get the process dump into the OC4J log under $OH/opmn/logs. By inspecting the log we were able to find the root cause.

Tuesday, June 8, 2010

Using Bind Variables in SQL*Plus

A quick note:

To define the bind variable
SQL> var :b1 number;

To assign values to the bind variable
SQL > exec :b1 := 8888;
   

Thursday, May 27, 2010

How to Disable On-demand Deployment of WebLogic Console Application

A quick link to:
http://redstack.wordpress.com/2009/07/14/how-to-disable-on-demand-deployment-of-weblogic-console-application/

Just to add: the Admin Server and all the managed servers need to be restarted for the change to take effective.

Manually Adding EM Grid Control Host Targets

I had some hosts cloned from other hosts that have EM Grid Control agent installed and managed by one EM Grid Control server. The new cloned hosts will be managed by the second EM Grid Control server.

In order to add the new cloned host targets into the second EM Grid Control server, we can run EM Grid agent configuration assisstant (agentca) to reconfiure (-f option) or rediscover(-d option). Note EM Grid control doesn't support to add host targets directly from the control console.

 ---------------------------------------------------------------------------
[49] /u/BASE/emgrid_agent/agent10g/bin: ./agentca


Either rediscover(-d) or reconfigure(-f) option is mandatory

[50] /u/BASE/emgrid_agent/agent10g/bin: ./agentca -f
Stopping the agent using /u/BASE/emgrid_agent/agent10g/bin/emctl stop agent
Oracle Enterprise Manager 10g Release 5 Grid Control 10.2.0.5.0.
Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved.
Stopping agent ... stopped.
Running agentca using /u/BASE/emgrid_agent/agent10g/oui/bin/runConfig.sh ORACLE_HOME=/u/BASE/emgrid_agent/agent10g ACTION=Configure MODE=Perform RESPONSE_FILE=/u/BASE/emgrid_agent/agent10g/response_file RERUN=TRUE INV_PTR_LOC=/u/BASE/emgrid_agent/agent10g/oraInst.loc COMPONENT_XML={oracle.sysman.top.agent.10_2_0_1_0.xml}
Perform - mode is starting for action: Configure

Perform - mode finished for action: Configure

You can see the log file: /u/BASE/emgrid_agent/agent10g/cfgtoollogs/oui/configActions2010-05-27_09-26-20-AM.log

Wednesday, May 26, 2010

Using Function instead of In-line View

My developer wrote a query (trimmed below for easy reading) with in-line views, which turned out to be very slow:

SELECT head.time_series_id time_series_id, head.time_series_name name, obs.observation_id vintage, ...
confidentiality_table.coded_value_en_desc boc_confidentiality_en,
confidentiality_table.coded_value_fr_desc boc_confidentiality_fr, ...
FROM time_series_observation obs,time_series_header head, ...
(SELECT time_series_id, wm_concat(confidentiality_status_en_name) coded_value_en_desc,
wm_concat(confidentiality_status_fr_name) coded_value_fr_desc
FROM time_series_header tsh, data_set_confidentiality ds_conf, confidentiality_status_mv conf
WHERE tsh.data_set_id = ds_conf.data_set_id
AND ds_conf.confidentiality_status_code_id = conf.confidentiality_status_code_id
GROUP BY time_series_id) confidentiality_table
WHERE obs.time_series_id = head.time_series_id AND ...
AND head.time_series_id = confidentiality_table.time_series_id (+)
AND obs.observation_id =?

The time_series_header table is large. My developer never thought about full-table scanned for it in the in-line view confidentiality_table, instead he thought it will be retrieved based on the time_series_id joined from the where clause.

Unfortunately Oracle doesn't work like that smart. It builds the in-line view confidentiality_table by doing full-table scan on the table time_series_header and group by on all the time_series_id. The joining to match the specific time_series_id by matching the specific observation_id. Note there is one-to-one relationship between time_series_id and observation_id

By looking at the execution plan together, we confirmed full-table scan happened, which is absolutely unnecessary as it just needs to wm_concat based on specific time_series_id, not all of them, as the entire query is looking for specific time_series_id, not a whole range of them.

It is not possible to move the confidentiality_status_mv out and join with time_series_header directly, as such it would need to group by on all the columns in the select list. Instead I recommended and built a function as following:
--------------------------------------------
CREATE OR REPLACE FUNCTION GET_CONFIDENTIALITY_DESC(in_time_series_id NUMBER, in_desc VARCHAR2 ) RETURN VARCHAR2 AS
v_dec VARCHAR2(2000);
BEGIN
IF (in_desc='EN') THEN
SELECT wm_concat(confidentiality_status_en_name) into v_dec
FROM time_series_header tsh, data_set_confidentiality ds_conf, confidentiality_status_mv conf
WHERE tsh.data_set_id = ds_conf.data_set_id
AND ds_conf.confidentiality_status_code_id = conf.confidentiality_status_code_id
AND tsh.time_series_id=in_time_series_id;
ELSIF (in_desc='FR') THEN
SELECT wm_concat(confidentiality_status_fr_name) into v_dec
FROM time_series_header tsh, data_set_confidentiality ds_conf, confidentiality_status_mv conf
WHERE tsh.data_set_id = ds_conf.data_set_id
AND ds_conf.confidentiality_status_code_id = conf.confidentiality_status_code_id
AND tsh.time_series_id=in_time_series_id;
END IF;

RETURN v_dec;

EXCEPTION ...
END;
/
--------------------------------------------

By incorporating the function into the query and replacing the in-line view, the new query runs and returns results instantly. Problem is resolved.

SELECT head.time_series_id time_series_id, head.time_series_name name, obs.observation_id vintage, ...
GET_CONFIDENTIALITY_DESC(head.time_series_id,'EN') boc_confidentiality_en,
GET_CONFIDENTIALITY_DESC(head.time_series_id,'EN') boc_confidentiality_fr,...
FROM time_series_observation obs,time_series_header head, ...
WHERE obs.time_series_id = head.time_series_id AND ...
AND obs.observation_id =?