Migration From SQL Server To Oracle Using SQL Developer

Migration is the process of copying the schema objects and data from a non-Oracle database, such as MySQL, Microsoft SQL Server, Sybase Adaptive Server, Microsoft Access, or IBM DB2, to an Oracle database.

To migrate a third-party database to Oracle easily, you can choose the following options using SQL Developer:

– Migrating using the Migration Wizard

– Copying tables to Oracle

Migrating Using the Migration Wizard

The Migration wizard provides a screen to manage all the steps needed for the migration to Oracle database. These steps are as follows:

– Capturing the source database (MySQL, Microsoft SQL Server, Sybase Adaptive Server, Microsoft Access, IBM DB2),

– Converting it to Oracle format,

– Generating DDL,

– Performing the conversion.

After a brief explanation about the process of migration, let’s do a simple migration from SQL Server database to Oracle database.

1- I created sample SQL Server database named TALIPTEST.

2- The migration repository is a collection of schema objects that SQL Developer uses to manage metadata for migrations. For a migration repository create a database connection to convenient Oracle database and give following grants.

 CREATE USER MIGRATIONS IDENTIFIED BY “migration”

DEFAULT TABLESPACE USERS

TEMPORARY TABLESPACE TEMP;

grant create session to migrations;

grant resource to migrations;

grant create view to migrations;

For multischema migrations, you must grant the privileges with the ADMIN option as follows.

grant resource to migrations with admin option;

grant create role to migrations with admin option;

grant alter any trigger to migrations with admin option;

grant create user to migrations with admin option;

3- Download SQL Developer from http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html

4- Unzip the file named sqldeveloper-3.2.20.09.87.zip and extract it. Open  sqldeveloper.exe file to open SQL Developer.

5- Right click to the “Connections” and click the “New Connections”.

6-  Create a database connection named Migration_Repository that connects to the MIGRATIONS user.

7- Right-click the Migration_Repository connection, and select “Migration Repository” menu , then “Associate Migration Repository” to create the repository.

8- Schema objects needed for migration will be created in MIGRATIONS schema.

9- To connect to third-party database (MySQL, Microsoft SQL Server, Sybase Adaptive Server,  Microsoft Access, IBM DB2) using SQL Developer, we need jTDS driver. You can download needed jTDS driver from following link. http://sourceforge.net/projects/jtds/files/jtds/1.2/jtds-1.2-dist.zip/download  . Extract the dowloaded zip file named jtds-1.2-dist.zip

10- Click “Tools” and then “Prefenrences”.

11- Select “Third Party JDBC Drivers” and click “Add Entry” button to add jTDS driver for SQL Server.

12- Select jar file located in jTDS driver folder.

13- Click “OK” button.

14- Now you can connect to SQL Server or Sybase database using SQL Developer. Connect to the SQL Server database as follows.

15- And finally, let us create the database connection which we will migrate to.

16- The migration wizard is invoked in a variety of contexts. You can right-click a third-party database connection and select “Migrate to Oracle”  or you can click “Tools>Migration>Migrate…”.

17- Click “Next” button.

18- Select migration repository database connection.

19- Give a name for migration project and select a directory to write output.

20– Select third party database connection. You can migrate database on online or offline mode. If you choose online migration then Migration Wizard will perform all needed operations. If you choose offline migration then Migration Wizard will generate all needed DDL scripts.

21- Select SQL Server database which we want to migrate to Oracle.

22- Specify the conversion options. And click “Advanced Options” link to ensure “Microsoft SQL Server : Is quoted identifier on” option is selected.

23- Select target database connection.

24- If you select offline migration then offline migration script will be generated in the project output directory.

25- Select the connections to be used for online data move.

26- Click “Finish” button so start migration.

27- Migration and conversion process will be perfomed as follows.

Now, Our SQL Server database in Oracle 🙂

Copying tables to Oracle

Right click the table located in third party database and click “Copy To Oracle”

Select destination (Oracle) database connection and click “Apply” button. If you choose “Include Data” check box it will create table structure and move data.

Copy to Oracle database is finished.

Note: This method doesn’t move indexes, triggers, etc. It only moves table structure and data.

Talip Hakan Öztürk

Advertisements

The Backdoor Entry to Oracle Database

Hi Friends,

I want to talk about a situation that happened to me a few days ago. I Logged in to one of my databases and my connection was hanged. My database was not accepting new connections. Now bound to the database server and I checked the status of the listener.

# lsnrctl status

Everything was normal. The listener is listening to my database. So I didn’t get any error from listener. I tried to log in with “sqlplus / as sysdba” but I failed. Connections on the server was also hanging. I checked the background processes.

# ps -ef | grep ora_

Everything was normal. And I learned something I did not know until that day. The backdoor entry of the Oracle database! You can enter to the database through the back door using SQL * Plus tool with “Prelim” parameter:)  Prelim, directly connects to the SGA but it does not open a session.

You can connect to the database with Prelim as following

# sqlplus -prelim / as sysdba
SQL>

Or

# sqlplus /nolog
SQL> set _prelim on
SQL> conn / as sysdba
Prelim connection established

Now, you can analyze the SGA using oradebug command.

SQL> oradebug setmypid
SQL> oradebug hanganalyze 12

A trace file will be produced in the directory configured in user_dump_dest parameter. If we are to sort the files according to time we can get the most recent trace file.

# ls -ltrh

You can also get the trace file name with oradebug command.

SQL> oradebug TRACEFILE_NAME
/oracle/diag/rdbms/dbtalip/TALIPDB/trace/TALIPDB_ora_32739.trc

When we examine the trace file, we see that lines beginning as follows.

*** 2012-06-11 12:14:02.870
================================================
HANG ANALYSIS:
  instances (db_name.oracle_sid): dbtalip.talipdb
  oradebug_node_dump_level: 12
  analysis initiated by oradebug
=================================================

If we continue to examine the trace file We can see the details of the session that caused the problem.
os id: 981
process id: 29, oracle@dbtalip (TNS V1-V3)
session id: 74
session serial #: 47681

When we kill that session from OS, everything will be OK.

# kill -9 981

Talip Hakan Öztürk

What is the ORADEBUG?

What is the ORADEBUG?

ORADEBUG is a command and can be executed from SQL*Plus to view process internal information.

You can see a list of ORADEBUG commands by following command.

SQL> oradebug help

Trace SQL statements with bind variables;

1- Set Process PID number which you want to trace

SQL> oradebug setospid 32318 Oracle pid: 29, Unix process pid: 32318, image: oracle@dbarge (TNS V1-V3)

Or you can trace your own process

SQL> oradebug setmypid

2- Start 10046 trace

SQL> oradebug EVENT 10046 trace name context forever, level 12

3- Analyze your trace file

# vi /oracle/diag/rdbms/dbarge/TEST11G/trace/TEST11G_ora_32318.trc

Trace Process Statistics;

1- Set process PID number which you want to trace. You can see it on PID column in V$PROCESS view. For example; to monitor LGWR process statistics which PID number is 11.

SQL> oradebug setorapid 11 Oracle pid: 11, Unix process pid: 16944, image:oracle@dbarge(LGWR)

2- Get statistics for LGWR process.

SQL> oradebug procstat

3- Write statistics to file.

SQL> oradebug TRACEFILE_NAME /oracle/diag/rdbms/dbarge/TEST11G/trace/TEST11G_lgwr_16944.trc

List used semaphores and shared memory segments;

SQL> oradebug ipc

Dumping error stack;

SQL> oradebug setospid 11301

SQL> oradebug event immediate trace name errorstack level 3

 

Talip Hakan Öztürk

OEM Configuration When the Database Host Name or IP Address Changes

The Enterprise Manager console will not work when database host name and / or IP address changes. We must run EMCA tool for reconfiguring the OEM database console. To do this, use the following commands.

emca -deconfig dbcontrol db -repos drop

emca -config dbcontrol db -repos create

or

emca -deconfig dbcontrol db

emca -config dbcontrol db -repos recreate

TNS konfigürasyonumuz değişir ise (Örneğin dinleyici(listener) portumuz değişirse), bu durumda yine EMCA aracı ile aşağıdaki gibi tekrar konfigürasyonumuzu yapabiliriz.

If our TNS configuration changes (for example, the listener (listener) port is changed), in this case we can still configure with the EMCA tool as follows.

emca -config dbcontrol db

Example: EMCA wants some information during repository drop and create operation. Such as SID, listener port number, SYS and SYSMAN passwords.

talip /oracle/ora11gR2> emctl stop dbconsole

Oracle Enterprise Manager 11g Database Control Release 11.2.0.2.0 Copyright (c) 1996, 2010 Oracle Corporation. All rights reserved.

http://dbtalip:1158/em/console/aboutApplication Stopping Oracle Enterprise Manager 11g Database Control … … Stopped.

talip /oracle/ora11gR2> emca -deconfig dbcontrol db -repos drop

STARTED EMCA at Nov 29, 2011 9:16:31 AM

EM Configuration Assistant, Version 11.2.0.0.2 Production Copyright (c) 2003, 2005, Oracle. All rights reserved.

Enter the following information:

Database SID: TEST11GR2

Listener port number: 1521

Password for SYS user:

Password for SYSMAN user:

———————————————————————- WARNING : While repository is dropped the database will be put in quiesce mode. ———————————————————————-

Do you wish to continue? [yes(Y)/no(N)]: y

Nov 29, 2011 9:16:53 AM oracle.sysman.emcp.EMConfig perform

INFO: This operation is being logged at

/oracle/cfgtoollogs/emca/TEST11GR2/emca_2011_11_29_09_16_30.log.

Nov 29, 2011 9:16:53 AM oracle.sysman.emcp.util.DBControlUtil stopOMS

INFO: Stopping Database Control (this may take a while) …

Nov 29, 2011 9:16:55 AM oracle.sysman.emcp.EMReposConfig invoke

INFO: Dropping the EM repository (this may take a while) …

Nov 29, 2011 9:19:15 AM oracle.sysman.emcp.EMReposConfig invoke

INFO: Repository successfully dropped Enterprise Manager configuration completed successfully FINISHED EMCA at Nov 29, 2011 9:19:18 AM

talip /oracle/ora11gR2> emca -config dbcontrol db -repos create

STARTED EMCA at Nov 29, 2011 9:19:25 AM

EM Configuration Assistant, Version 11.2.0.0.2 Production Copyright (c) 2003, 2005, Oracle. All rights reserved.

Enter the following information:

Database SID: TEST11GR2

Listener port number: 1521

Listener ORACLE_HOME [ /oracle/ora11gR2 ]:

Password for SYS user:

Password for DBSNMP user:

Password for SYSMAN user:

Email address for notifications (optional):

Outgoing Mail (SMTP) server for notifications (optional):

—————————————————————–

You have specified the following settings

Database ORACLE_HOME ……………. /oracle/ora11gR2

Local hostname ……………. dbtalip

Listener ORACLE_HOME ……………. /oracle/ora11gR2

Listener port number ……………. 1521

Database SID ……………. TEST11GR2

Email address for notifications ……………

Outgoing Mail (SMTP) server for notifications ……………

—————————————————————–

Do you wish to continue? [yes(Y)/no(N)]: y

Nov 29, 2011 9:19:46 AM oracle.sysman.emcp.EMConfig perform

INFO: This operation is being logged at

/oracle/cfgtoollogs/emca/TEST11GR2/emca_2011_11_29_09_19_24.log.

Nov 29, 2011 9:19:47 AM oracle.sysman.emcp.EMReposConfig createRepository

INFO: Creating the EM repository (this may take a while) …

Nov 29, 2011 9:26:16 AM oracle.sysman.emcp.EMReposConfig invoke

INFO: Repository successfully created

Nov 29, 2011 9:26:22 AM oracle.sysman.emcp.EMReposConfig uploadConfigDataToRepository

INFO: Uploading configuration data to EM repository (this may take a while) …

Nov 29, 2011 9:27:19 AM oracle.sysman.emcp.EMReposConfig invoke

INFO: Uploaded configuration data successfully

Nov 29, 2011 9:27:21 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole

INFO: Securing Database Control (this may take a while) …

Nov 29, 2011 9:27:31 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole

INFO: Database Control secured successfully.

Nov 29, 2011 9:27:31 AM oracle.sysman.emcp.util.DBControlUtil startOMS

INFO: Starting Database Control (this may take a while) …

Nov 29, 2011 9:28:09 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration

INFO: Database Control started successfully

Nov 29, 2011 9:28:09 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration

INFO: >>>>>>>>>>> The Database Control URL is https://dbtalip:1158/em <<<<<<<<<<<

Nov 29, 2011 9:28:13 AM oracle.sysman.emcp.EMDBPostConfig invoke

WARNING:

************************ WARNING ************************

Management Repository has been placed in secure mode wherein Enterprise Manager data will be encrypted. The encryption key has been placed in th file:

/oracle/ora11gR2/dbtalip_TEST11GR2/sysman/config/emkey.ora. Ensure this file is backed up as the encrypted data will becom unusable if this file is lost.

***********************************************************

Enterprise Manager configuration completed successfully

FINISHED EMCA at Nov 29, 2011 9:28:13 AM

talip /oracle/ora11gR2> emctl status dbconsole

Oracle Enterprise Manager 11g Database Control Release 11.2.0.2.0

Copyright (c) 1996, 2010 Oracle Corporation. All rights reserved. https://dbtalip:1158/em/console/aboutApplication

Oracle Enterprise Manager 11g is running. ——————————————————————

Logs are generated in directory /oracle/ora11gR2/dbtalip_TEST11GR2/sysman/log talip /oracle/ora11gR2>

 

Now, OEM is available.

Talip Hakan Öztürk

Oracle Software Patching Using OPatch – Interim Patches

OPatch is an Oracle utility that assists you to apply interim patches to Oracle’s rdbms software. You can find opatch utility in $ORACLE_HOME/Opatch directory. For example, let’s apply patch number 8943287  to our 10.2.0.5 database.

Applying Patch:

1- Backup Oracle Home directory.

$ tar -cf ora10g.tar ora10g

2- Download patch file p8943287_10205_Linux-x86-64.zip via metalink. And copy it to database server.

3- Unzip the patch file.

$ unzip p8943287_10205_Linux-x86-64.zip

4- Apply patch with opatch utility.

$ cd 8943287

$ ORACLE_HOME/OPatch/opatch apply

To see list of applied patches :

$ORACLE_HOME/OPatch/opatch lsinventory

For example:

$ORACLE_HOME/OPatch/opatch lsinventory

Invoking OPatch 10.2.0.4.9

Oracle Interim Patch Installer version 10.2.0.4.9

Copyright (c) 2009, Oracle Corporation. All rights reserved.

Oracle Home : /oracle/ora10g

Central Inventory : /oracle/oraInventory

from : /etc/oraInst.loc

OPatch version : 10.2.0.4.9

OUI version : 10.2.0.5.0

OUI location : /oracle/ora10g/oui

Log file location : /oracle/ora10g/cfgtoollogs/opatch/opatch2011-10-28_12-14-12PM.log

Patch history file: /oracle/ora10g/cfgtoollogs/opatch/opatch_history.txt

Lsinventory Output file location : /oracle/ora10g/cfgtoollogs/opatch/lsinv/lsinventory2011-10-28_12-14-12PM.txt

——————————————————————————–

Installed Top-level Products (3):

Oracle Database 10g 10.2.0.1.0

Oracle Database 10g Release 2 Patch Set 3 10.2.0.4.0

Oracle Database 10g Release 2 Patch Set 4 10.2.0.5.0

There are 3 products installed in this Oracle Home.

Interim patches (2) :

Patch 8943287 : applied on Fri Oct 21 20:39:46 EEST 2011

Unique Patch ID: 12722995

Created on 23 Aug 2010, 11:45:16 hrs PST8PDT

Bugs fixed:

8943287

——————————————————————————–

Rollback applied patch:

Sometimes a patch is applied to the system may need to take back because of its effect. In this case, rollback is performed as follows.

$ORACLE_HOME/OPatch/opatch rollback -id 8943287

Talip Hakan ÖZTÜRK