Saturday, August 28, 2010

dbForge Data Compare for Oracle

I had a chance to test about dbForge Data Compare for Oracle from Devart (@DevartSoftware). This is a good software for Oracle data comparison and synchronization and free.
Key Features
- Wide support of Oracle versions: 11g, 10g, XE, 9i, 8i, 7.3
- High-speed comparison
- Comparison of all schema tables at once
- Comparing data with different structures
- Custom mapping of tables
- Full or partial Oracle data synchronization
- Generating SQL*Plus-compatible synchronization script
- Saving data comparison settings as comparison projects for the next usage
- Start page with the latest comparisons
- Convenient UI

We can watch "dbForge Data Compare for Oracle Tutorial" for this tool.

Tuesday, August 24, 2010

Compiled new oci8(1.4.3) in PHP(5.3.3)

How to compile new oci8 in PHP source?
oci8(PHP) is extension for Oracle Database allows you to access Oracle databases. It can be built with PHP 4.3.9 to 5.x. It can be linked with Oracle 9.2, 10.2, 11.1, or 11.2 client libraries.
When we find new version (oci8) and want to upgrade in PHP, How?
If we want to use oci8 1.4.3. we may wait PHP version 6.0.0 or older (but OCI8 1.4.2 is included in PHP 5.3.3).
So, download oci8 1.4.3 and compile in php 5.3.3:
- check PHP source path.
# pwd
/SRC/php-5.3.3
- check old configuration.
# cat config.nice

#! /bin/sh
#
# Created by configure

'./configure' \
'--with-apxs2=/usr/local/apache/bin/apxs' \
'--with-oci8=instantclient,/u01/app/instantclient_11_2' \
"$@"
- move old oci8 and use new oci8 (1.4.3)
# mv ext/oci8 ext/oci8-org
# ls ../oci8-1.4.3.tgz
../oci8-1.4.3.tgz
# tar zxvf ../oci8-1.4.3.tgz -C ext/
# mv ext/oci8-1.4.3 ext/oci8
# make clean && make
# /usr/local/apache/bin/apachectl stop
# make install
# /usr/local/apache/bin/apachectl start
- check again.
we will see new version(oci8).

Monday, August 16, 2010

ORA-00600: internal error code, arguments: [kck_rls_check must use (11,0,0,0,0) or lower], [kdt.c], [9486], [11.2.0.1.0]

I tested some about spfile and then found.
ORA-00600: internal error code, arguments: [kck_rls_check must use (11,0,0,0,0) or lower]
found out Oracle Support [ID 1064264.1] and they told it relates to an internal check on the compression compatibility(default -> 11.2.0.1). then test:
SQL> select value from v$parameter where name='_compression_compatibility';

no rows selected

SQL> create pfile='/tmp/pfile' from memory;

File created.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup pfile='/tmp/pfile';
ORA-00600: internal error code, arguments: [kck_rls_check must use (11,0,0,0,0) or lower], [kdt.c], [9486], [11.2.0.1.0], [], [], [], [], [], [], [], []
checked and solved (_compression_compatibility='11.2.0.1' -> _compression_compatibility='11.2.0')
$ grep compression_compatibility /tmp/pfile
_compression_compatibility='11.2.0.1'

$ grep compression_compatibility /tmp/pfile
_compression_compatibility='11.2.0'

SQL> startup pfile='/tmp/pfile';
ORACLE instance started.

Total System Global Area 790941696 bytes
Fixed Size 1339428 bytes
Variable Size 222302172 bytes
Database Buffers 557842432 bytes
Redo Buffers 9457664 bytes
Database mounted.
Database opened.

SQL> select value from v$parameter where name='_compression_compatibility';

VALUE
------------------------------
11.2.0
Actually we can remove '_compression_compatibility' from parameter file and start database.

Sunday, August 15, 2010

How to change Segment Space Management of a tablespace from MANUAL to AUTO?

That's a good question? If we find out solution. we'll find:
- Backup the tablespace
- Export the tablespace data
- Drop and re-allocate the tablespace
- Import the tablespace
Old Tablespace:
SQL> select tablespace_name, segment_space_management from dba_tablespaces where tablespace_name='TBS_TEST';

TABLESPACE_NAME SEGMEN
------------------------------ ------
TBS_TEST MANUAL

SQL> select * from dba_ts_quotas where tablespace_name='TBS_TEST';

TABLESPACE_NAME USERNAME BYTES MAX_BYTES BLOCKS MAX_BLOCKS DRO
------------------------------ ------------------------------ ---------- ---------- ---------- ---------- ---
TBS_TEST SURACHART 9437184 -1 1152 -1 NO

SQL> select owner, table_name, tablespace_name, num_rows from all_tables where tablespace_name='TBS_TEST';

OWNER TABLE_NAME TABLESPACE_NAME NUM_ROWS
------------------------------ ------------------------------ ------------------------------ ----------
SURACHART TB_TEST TBS_TEST 73189
Solution:
- Backup the tablespace
RMAN> backup tablespace TBS_TEST;

Starting backup at 15-AUG-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=64 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00008 name=/oracle/oradata/ORCL/datafile/o1_mf_tbs_test_66hmvb4p_.dbf
channel ORA_DISK_1: starting piece 1 at 15-AUG-10
channel ORA_DISK_1: finished piece 1 at 15-AUG-10
piece handle=/oracle/oradata/flashback_area/ORCL/backupset/2010_08_15/o1_mf_nnndf_TAG20100815T183444_66hn6nld_.bkp tag=TAG20100815T183444 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-AUG-10
- Export the tablespace data
$ expdp TABLESPACES=TBS_TEST DIRECTORY=DATA_PUMP_DIR DUMPFILE=tbs_test.dmp LOGFILE=tbs_test.log
Export: Release 11.2.0.1.0 - Production on Sun Aug 15 18:39:42 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLESPACE_01": /******** AS SYSDBA TABLESPACES=TBS_TEST DIRECTORY=DATA_PUMP_DIR DUMPFILE=tbs_test.dmp LOGFILE=tbs_test.log
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 9 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SURACHART"."TB_TEST" 7.074 MB 73189 rows
Master table "SYS"."SYS_EXPORT_TABLESPACE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLESPACE_01 is:
/oracle/admin/orcl/dpdump/tbs_test.dmp
Job "SYS"."SYS_EXPORT_TABLESPACE_01" successfully completed at 18:40:12
- Drop and re-allocate the tablespace
SQL> drop tablespace tbs_test including contents and datafiles;

Tablespace dropped.

SQL> select tablespace_name, segment_space_management from dba_tablespaces where tablespace_name='TBS_TEST';

no rows selected

SQL> create tablespace tbs_test datafile size 10M autoextend on next 1M segment space management auto;

Tablespace created.

SQL> select tablespace_name, segment_space_management from dba_tablespaces where tablespace_name='TBS_TEST';

TABLESPACE_NAME SEGMEN
------------------------------ ------
TBS_TEST AUTO
SQL> select owner, table_name, tablespace_name, num_rows from all_tables where tablespace_name='TBS_TEST';

no rows selected
- Import the tablespace
$ impdp TABLESPACES=TBS_TEST DIRECTORY=DATA_PUMP_DIR DUMPFILE=tbs_test.dmp LOGFILE=tbs_test.log

Import: Release 11.2.0.1.0 - Production on Sun Aug 15 18:43:14 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."SYS_IMPORT_TABLESPACE_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_TABLESPACE_01": /******** AS SYSDBA TABLESPACES=TBS_TEST DIRECTORY=DATA_PUMP_DIR DUMPFILE=tbs_test.dmp LOGFILE=tbs_test.log
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SURACHART"."TB_TEST" 7.074 MB 73189 rows
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYS"."SYS_IMPORT_TABLESPACE_01" successfully completed at 18:43:23
Check:
SQL> select tablespace_name, segment_space_management from dba_tablespaces where tablespace_name='TBS_TEST';

TABLESPACE_NAME SEGMEN
------------------------------ ------
TBS_TEST AUTO

SQL> select * from dba_ts_quotas where tablespace_name='TBS_TEST';

TABLESPACE_NAME USERNAME BYTES MAX_BYTES BLOCKS MAX_BLOCKS DRO
------------------------------ ------------------------------ ---------- ---------- ---------- ---------- ---
TBS_TEST SURACHART 9437184 -1 1152 -1 NO

SQL> select owner, table_name, tablespace_name, num_rows from all_tables where tablespace_name='TBS_TEST';

OWNER TABLE_NAME TABLESPACE_NAME NUM_ROWS
------------------------------ ------------------------------ ------------------------------ ----------
SURACHART TB_TEST TBS_TEST 73189
This is just an example. However... change from UNIFORM SIZE to AUTOALLOCATE, we can use this solution.

Wednesday, August 11, 2010

How to find maximum number of third?

I hope to hear your idea from this question. I learned to find maximum number of third by using ROWNUM.

I learned to use ROW_NUMBER function as well.
ROW_NUMBER is an analytic function. It assigns a unique number to each row to which it is applied (either each row in the partition or each row returned by the query), in the ordered sequence of rows specified in the order_by_clause, beginning with 1.
Create Table:
SQL> create table test as select * from all_objects;

Table created.
1. Use ROWNUM
SQL> select object_name ,object_id from test;
.
.
.
V_1 56532
V_2 56533
V_3 56534
TEST 56535

SQL> select * from (select object_name, object_id from test order by object_id desc) where rownum <=3 ;

OBJECT_NAME OBJECT_ID
------------------------------ ----------
TEST 56535
V_3 56534
V_2 56533

SQL> select * from (select object_name, object_id from test order by object_id desc) where rownum <=3 order by object_id;

OBJECT_NAME OBJECT_ID
------------------------------ ----------
V_2 56533
V_3 56534
TEST 56535

SQL> select * from (select * from (select object_name, object_id from test order by object_id desc) where rownum <=3 order by object_id) where rownum <=1;

OBJECT_NAME OBJECT_ID
------------------------------ ----------
V_2 56533
- Check Execution Plan
----------------------------------------------------------
Plan hash value: 627665718
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 30 | | 852 (2)| 00:00:11 |
|* 1 | COUNT STOPKEY | | | | | | |
| 2 | VIEW | | 3 | 90 | | 852 (2)| 00:00:11 |
|* 3 | SORT ORDER BY STOPKEY | | 3 | 90 | 1648K| 852 (2)| 00:00:11 |
|* 4 | COUNT STOPKEY | | | | | | |
| 5 | VIEW | | 41621 | 1219K| | 507 (2)| 00:00:07 |
|* 6 | SORT ORDER BY STOPKEY| | 41621 | 1219K| 1648K| 507 (2)| 00:00:07 |
| 7 | TABLE ACCESS FULL | TEST | 41621 | 1219K| | 163 (2)| 00:00:02 |
-------------------------------------------------------------------------------------------

2. use ROW_NUMBER function
SQL> select object_name, object_id from (select object_id, object_name, row_number () over (order by object_id desc) id from test) x where id=3;

OBJECT_NAME OBJECT_ID
------------------------------ ----------
V_2 56533
- Check Execution Plan
----------------------------------------------------------
Plan hash value: 1795822849
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 41621 | 1747K| | 507 (2)| 00:00:07 |
|* 1 | VIEW | | 41621 | 1747K| | 507 (2)| 00:00:07 |
|* 2 | WINDOW SORT PUSHED RANK| | 41621 | 1219K| 1648K| 507 (2)| 00:00:07 |
| 3 | TABLE ACCESS FULL | TEST | 41621 | 1219K| | 163 (2)| 00:00:02 |
-----------------------------------------------------------------------------------------

These show the same result, but spent the different Cost.

Thursday, August 05, 2010

Error - netca: line 190: 18852 Aborted

On some test server...
$ netca

Oracle Net Services Configuration:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (0xb) at pc=0xf7e76b33, pid=18852, tid=4158679248
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_14-b05 mixed mode)
# Problematic frame:
# C [libc.so.6+0x6fb33] index+0x63
#
# An error report file with more information is saved as hs_err_pid18852.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
/oracle/product/10.2.0/db_1/bin/netca: line 190: 18852 Aborted $JRE -mx64m $SRVM_PROPERTY_DEFS -Dsun.java2d.font.DisableAlgorithmicStyles=true -classpath $CLASSPATH oracle.net.ca.NetCA $*

Then check "hostname" command-line and /etc/hosts file and add hostname in file.
1. check hostname command-line:
$ hostname
host01.surachartopun.com
2. /etc/hosts file:
127.0.0.1 localhost.localdomain localhost
Then changed:
127.0.0.1 localhost.localdomain localhost
10.10.10.100 host01.surachartopun.com
Try again:
$ netca

Oracle Net Services Configuration:
Configuring Listener:LISTENER
Default local naming configuration complete.
Listener configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Oracle Net Services configuration successful. The exit code is 0

OK...

Tuesday, August 03, 2010

Audit SQL with audit_trail db,extended

Nothing new on this article, I just want to post about audit_trail=db_extended. Because I want to audit SQL statements and find out it.
db,extended - Enables database auditing and directs all audit records to the database audit trail (the SYS.AUD$ table). In addition, populates the SQLBIND and SQLTEXT CLOB columns of the SYS.AUD$ table.
SQL> alter system set audit_trail=db_extended scope=spfile;

System altered.

SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area 786759680 bytes
Fixed Size 1339400 bytes
Variable Size 633343992 bytes
Database Buffers 146800640 bytes
Redo Buffers 5275648 bytes
Database mounted.
Database opened.

SQL> show parameter audit_trail

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
audit_trail string DB_EXTENDED

SQL> AUDIT ALL BY surachart BY ACCESS;

Audit succeeded.

SQL> AUDIT SELECT TABLE, UPDATE TABLE, INSERT TABLE, DELETE TABLE BY surachart BY ACCESS;

Audit succeeded.
Login user and do something:
SQL> connect surachart
<Operations>
.
.
.
Then Check...
SQL> show user;
USER is "SYS"

SQL> select sqltext from aud$ where userid='SURACHART';
select * from tab
delete from sdo_geor_ddl__table$$
select count(*) from test
delete from test where rownum <=1
I saw SQL statements from sqltext column in aud$ table.

Monday, August 02, 2010

Oracle 11g R1/R2 Real Application Clusters Handbook Book

Oracle Real Application Cluster(RAC) provides unbeatable fault tolerance, performance, and scalability with no application changes necessary. Oracle RAC is a cluster database with a shared cache architecture that overcomes the limitations of traditional shared-nothing and shared-disk approaches to provide a highly scalable and available database solution for all our business applications.
I mentions a book... Oracle 11g R1/R2 Real Application Clusters Handbook written by Ben Prusinski (blog), Guenadi Jilevski (blog) and Syed Jaffar Hussain (blog). They have had a lot of experience about Oracle Database, Applications and Oracle Real Application Clusters.

This book is helpful about designation, implementation, administration and management for someone who interest in Oracle RAC DBA as well as It explains new features for Oracle 11g R1/R2 RAC and ASM.

What we will learn from this book :
- Administer, implement, and manage Oracle 11g RAC environments for real-world deployments
- Understand the high availability concepts and solutions that are available for Oracle 11g RAC
- Discover the key architectural design and installation techniques required to successfully deploy Oracle 11g RAC
- Add functionality to your RAC environment by incorporating new RAC features such as Automatic Storage Management
- Effectively manage the complex 11g Clusterware, using key troubleshooting tips and techniques.
- Successfully implement database creation methods, manage the RAC database, and handle workload in your RAC environment efficiently
- Plan your backup and recovery strategy appropriately
- Know when and how to upgrade your RAC environment effectively
- Deploy Oracle 11g RAC with complex standard-off-the-shelf systems like Oracle EBS
- Understand key new features for 11g R1/R2 RAC and ASM

If you have plan to begin Oracle RAC DBA, I believe this book can help you to learn and improve.