My blog has moved!

You should be automatically redirected in 5 seconds. If not, visit
http://www.oraexplorer.com
and update your bookmarks.

Friday, July 4, 2008

WOT - Web of Trust

Yesterday I just downloaded Firefox 3, which just set the Guinness World Records for the most software downloads in a day, and started looking around for its add-ons. This one is interesting and useful.

WOT (Web of Trust) is the free Internet security add-on for web browsers. The reputation ratings are categorized into four – trustworthiness, vendor reliability, privacy, and child safely. These ratings are ranked by the WOT web community. The goal is to helps make the Internet safer by sharing experiences.

The nice thing is the visual icons in different colors (green is good, red is bad) showing the web site’s ratings on search web sites like Google. This definitely helps me to proceed to the low-ranking web site cautiously.

clip_image002[5]

Have a safe surf.

Tuesday, June 24, 2008

A Million Thanks to Mom

My kid found this e-card on the Hallmark web site for the Mother's day. We really like the voices of hoops and yoyo - two cartoon characters. Since the card says, "A Million Thanks to Mom", we initially thought it'd probably be done by one million. But apparently it is not. So for fun, we let it run, and it keeps going and going. We've decided to let it continue to see how far it can go. Please note that it takes about one whole day to reach 1M on my desktop machine.




If you want to try out, here is the link, select "A Million Thanks for Mom".

Let me know how far you make it.

[Updated 6/3] Reached 3 millions and still going...
 


[Updated 6/4] Wow 4 millions now. Umm.. I don't know whether or not I should stop it, or let it continue.

 

[Updated 6/10] Now I'm reaching the 10 million “Thanks”. I can’t believe this thing can go on and on. I'm tempted to let it continue and see how far it can go.

[Updated 6/20] After about twenty days of this journey, I just reached 20 million Thanks. Wow..

My daughter urged me to continue. Well, let’s do it.

ThankYou20M_0620

[Update 6/23] Somehow, my XP desktop was rebooted unexpectedly over weekend :-( Well, I guess my 20-day “FUN” trip has to come to the end. It is sad but I feel relief because finally I can use my computer without annoying noises.

Sunday, June 15, 2008

Oracle SQL Developer Migration Workbench

The Oracle SQL developer is not only a great tool for SQL development, with its migration workbench, it is an excellent tool for database migration. Did I also mention it is free?

To get it started, you will need to download the latest version of the tool which is version 1.5.1. Also it is recommended to install the latest updates. The current release of update as of 6/15 is 1.5.1.54.40.

Next, you will need to create a repository. An database account, which has CREATE SESSION, RESOURCE, and CREATE VIEW must be created first. Then logon into SQL Developer as that account. From the tool, create a repository from Migration menu > Repository Management > Create Repository. This process creates a bunch of MD* and MIGR* tables and packages.

To connect to other non-Oracle databases, you will need to create connections through provided JDBC drivers. If somehow, your SQL Developer does not show these 3-rd party connection tabs, you will have to configure it. Instruction is clearly documented on Oracle site here.

image

In my case, I migrate one of our legacy applications on MS SQL to Oracle. Unfortunately this application contains column name named “rowid”, which is Oracle’s reserved word, in most of tables. The tool has a mechanism to append a suffix “_” (with no quotes) if it encounters these reserved words. So “rowid” will be converted to “rowid_”. To see the list of all reserved words, you can just query “KEYWORD” column in MIGRATION_RESERVEDW_WORDS table under the repository schema. Unfortunately, the “rowid” is not really in this table, I have to insert this manually. I added a keyword “privilege” as well because, again, there is a column named “privilege” used in application.

insert into migration_reserved_words values ('rowid');
insert into migration_reserved_words values ('privilege');
I encountered a bug (which Turloch O'Tierney pointed out - thanks) when using version 1.5.1 without the latest patch. In the function “first_char_check” under MIGRATION_TRANSFER package, a number “4” is missing. The impact of this is that If the column name is numeric prefix, for example, 3Q2008, a letter “A” will be prefixed into it to be “A3Q2008”. But due to this bug, it won’t do it with, for example, 4Q2008, resulting in a failure when trying to create table. With the latest patch, it seems like it was fixed already because I now see number 4.

v_allowed := C_DISALLOWED_CHARS || '012356789_$';

The process of migration is straight-forward. You will start with capture then convert. You can capture and convert the whole database at once. But I would not recommend that because if error is encountered, it might be difficult to troubleshoot.

You can just capture only the table first, this will create a converted script. Before running it, please inspect it first and comment un-needed sections especially CREATE default USER syntax and CONNECT using default user. By running the converted script, it will create the definitions of tables, sequences, triggers and constraints. If there is no error, then you can run to move data.

Once data is there, repeat the steps with stored procedures and views. Obviously, you will just need to run the converted script – there is no need for data movement.

Monday, June 9, 2008

Statistic Calculation - DBMS_STAT_FUNCS

Currently I'm working on a project dealing with lot of statistic calculations particularly that of quartiles. First, I have no idea what it is. Thanks to Wiki for explanation. Now the tough part is to do the actual calculation. Fortunately, Oracle provides DBMS_STAT_FUNCS which is exactly what I'm looking for.

List of available calculations -

TYPE summaryType IS RECORD (
count NUMBER,
min NUMBER,
max NUMBER,
range NUMBER,
mean NUMBER,
cmode num_table,
variance NUMBER,
stddev NUMBER,
quantile_5 NUMBER,
quantile_25 NUMBER,
median NUMBER,
quantile_75 NUMBER,
quantile_95 NUMBER,
plus_x_sigma NUMBER,
minus_x_sigma NUMBER,
extreme_values num_table,
top_5_values n_arr,
bottom_5_values n_arr);
Sample -
set serveroutput on;
DECLARE
sfsumtype dbms_stat_funcs.summaryType;
BEGIN
dbms_stat_funcs.summary(p_ownername=>'SCHEMA_NAME',
p_tablename=>'TABLE_NAME',
p_columnname=>'COLUMN_NAME',
s=>sfsumtype);
dbms_output.put_line('Quantile 5 => ' || sfsumtype.quantile_5);
dbms_output.put_line('Quantile 25 => ' || sfsumtype.quantile_25);
dbms_output.put_line('Median => ' || sfsumtype.median);
dbms_output.put_line('Quantile 75 => ' || sfsumtype.quantile_75);
dbms_output.put_line('Quantile 95 => ' || sfsumtype.quantile_95);
END;
/

Saturday, March 15, 2008

11g SQL*Plus

In 11g SQL*Plus, when session is terminated, somehow it displays the process ID, SID and Serial#. Not quite sure what is really for? I guess it is for debugging purpose.

10g Client

user @db10w1> select * from dual;
select * from dual
*
ERROR at line 1:
ORA-01012: not logged on

11g Client
user @db10w1> select * from dual;
select * from dual
*
ERROR at line 1:
ORA-01012: not logged on
Process ID: 0
Session ID: 135 Serial number: 29158

show spparameters

I found one of the interesting features in SQL*Plus 11g for Oracle11g database when doing “help show” from the tool.

SHOW  SPPARAMETERS [parameter_name]
This is similar to what we’re all familiar with but for spfile parameters instead.

Show specific parameters -
SYSTEM @db11r1> show spparameters sga

SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
* lock_sga boolean
* pre_page_sga boolean
* sga_max_size big integer
* sga_target big integer

Show all parameters -
SYSTEM @db11r1> show spparameters

SID NAME TYPE VALUE
-------- ----------------------------- ----------- ------------------
* O7_DICTIONARY_ACCESSIBILITY boolean
* active_instance_count integer
* aq_tm_processes integer 2
* archive_lag_target integer
* asm_diskgroups string
* asm_diskstring string
* asm_power_limit integer
* asm_preferred_read_failure_gr string
:
:
:
* use_indirect_data_buffers boolean
* user_dump_dest string
* utl_file_dir string
* workarea_size_policy string
* xml_db_events string
Originally I thought it is a feature of SQL*Plus 11g, but if I connect to the 10g database, it does not display anything. Note that error indicates that Server version too low for this feature.
SYSTEM @db10w1> show spparameters
SP2-0614: Server version too low for this feature
SP2-0735: unknown SHOW option beginning "lege'@'_co..."
SP2-0158: unknown SHOW option """
If database is started up with pfile, all values of “show spparameters” will be empty.

Tuesday, February 12, 2008

What is the current status of Data Guard?

While working in one of Data Guard projects, I was asked about the current sync status of standby. I started talking about gap, SCN, or applied and received archive log numbers, and so on, which obviously did not make sense to business users. The only thing they'd like to know is whether or not data at standby is up-to-date with that of primary, or if not, what date/time of standby data it is at right now.

All existing scripts we do have in house are just checking the received or applied SCNs or thread# of archive logs. In order to make sense out of these numbers for business users or managers, I will need to convert them into date and time. Fortunately, I recalled the "scn_to_timestamp" function which allows me to convert the SCN number to its corresponding timestamp.

I can get the current_scn from v$database of the standby. However, in the case of physical standby, when database is being mounted (recovery mode), this function does not work. It should work fine with the logical standby which is opened all the time.

SQL> select scn_to_timestamp(current_scn) from v$database;
select scn_to_timestamp(current_scn) from v$database
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-01219: database not open: queries allowed on fixed tables/views only
To resolve this, once getting the current_scn on standby, I can log on to the primary and get the time stamp corresponding to the SCN number.

Sample below is the KSH script to obtain the date/time based on a SCN. Note that the syntax to check the gap is added as well. The account connecting to primary just needs SELECT_CATALOG_ROLE.

# Get SCN number from DR
DRSCN=/tmp/drscn$$.log
${SQLPLUS} -s /nolog <<EOF
connect / as sysdba
set heading off
set feedback off
col current_scn format 999999999999999999999999
spool ${DRSCN}
select current_scn from v\$database;
spool off
exit
EOF
DR_SCN=`cat ${DRSCN}`

rm ${DRSCN}

# Get Timestamp from Primary
TSDR=/tmp/tsdr$$.log
TSSTAT=/tmp/tsstat$$.log
${SQLPLUS} -s /nolog &lt&ltEOF
connect user/password@PRIMARY
set heading off
set feedback off
spool ${TSDR}
select
to_char(scn_to_timestamp(${DR_SCN}),'MM/DD/YYYY HH24:MI')
from dual;
spool off
spool ${TSSTAT}
select
case
when
scn_to_timestamp(${DR_SCN}) > systimestamp - interval '1' hour
then 'OK'
when
scn_to_timestamp(${DR_SCN}) > systimestamp - interval '2' hour
then 'WARNING'
else 'CRITICAL'
end "STATUS"
from dual;
spool off
exit
EOF

rm ${TSDR}
rm ${TSSTAT}

Thursday, January 3, 2008

Unconventional way to create an Oracle database

This is so funny. It probably takes longer for the guy to create a database if he has a cold or flu.

http://www.youtube.com/watch?v=CHzV4LZnvHc

BTW, I like the name of database, "nosejob".

Friday, December 28, 2007

Select-only-privileged user can lock table

This is an interesting post by Tanel Poder on "Your read only accounts aren't that read only". Basically a read-only account with the select privilege only on a table can issue the lock on that table even though it does not have any DML privileges. This means that it could prevent any further DMLs (causing denial of service) to other valid sessions. This behavior is not new. But explanation, examples and work-around/semi-solution by Tanel are clear. Good Job!!!

Tuesday, December 4, 2007

SQL Plus Copy

The SQL*Plus COPY command can copy data between two databases via SQL*Net.

Syntax:

USER1 @srcdb> copy
usage: COPY FROM [db] TO [db] [opt] [table] { ([cols]) } USING [sel]
[db] : database string, e.g., hr/your_password@d:chicago-mktg
[opt] : ONE of the keywords: APPEND, CREATE, INSERT or REPLACE
[table]: name of the destination table
[cols] : a comma-separated list of destination column aliases
[sel] : any valid SQL SELECT statement
A missing FROM or TO clause uses the current SQL*Plus connection.
Sample:
@Target database, the table initially does not exist.
USER1 @targetdb> select * from rep_tab;
select * from rep_tab
*
ERROR at line 1:
ORA-00942: table or view does not exist
@Source database, run copy command within SQL Plus.
USER1 @srcdb> copy from user1/user1@srcdb -
> to user1/user1@target_host:1521/target_sid -
> create rep_tab -
> using -
> select * from rep_tab;

Array fetch/bind size is 15. (arraysize is 15)
Will commit when done. (copycommit is 0)
Maximum long size is 80. (long is 80)
Table REP_TAB created.

1 rows selected from user1@SRCDB.
1 rows inserted into REP_TAB.
1 rows committed into REP_TAB at user1@host1:1521/targetsid.

@Target database, now table is copied here.
USER1 @targetdb> select * from rep_tab;

A
----------
1

This is a quick and easy way to copy data between two databases especially on where the usage of database link is restricted. It only requires SQL*Net service name (or host/port/service) and proper privileges.