Tuesday, February 18, 2014

Export and Importing data using Oracle 11


In the era of oracle 9-10, I usually does export and imports data using exp and imp utility. Using oracle 11g, things aren't as smooth as it used to be.

Problem A - Exp doesn't export empty tables

Exp no longer exports empty tables. The cause are, exp utility is processing data segments, creating export dump. The Oracle 11g has a new feature, called 'Deferred segment creation'. It means that tables with no data will occupy no segments. And these tables will be missing from the exp result. The symptom of this problem is simple, we have missing tables in the destination system whose row count in the source system are zero.

Solution A-1 - Allocate segment for empty tables

Alter table allocate extent;

This is not so ideal, we must execute the SQL above for each empty table before doing exp command.

Solution A-2 - Disable deferred segment creation


This need to be done before we even create our empty tables.

Solution A-3 - Don't use exp/imp, use expdp/impdp instead

If we have access to the source database server and destination database server's respective filesystems, administrator-like OS level access, Oracle Data Pump (expdp/impdp) is a good solution. Impdp and Expdp are faster than imp and exp. But both are not without problems as we shall see.

Problem B - Expdp in oracle 11 are buggy

Some of the installed Oracle 11 still have buggy expdp routines. The symptoms are ORA-14102 error when we're doing impdp. It seems that a bug in the expdp causes the import SQL contains the clause 'NOLOGGING NOCOMPRESS LOGGING'. Such clause cannot be correct. Makes me wonder what all oracle QA guys are doing. 

Solution B-1 Install Oracle Patch 8795792

You need to log on to Oracle Metalink and download patch 8795792. After shutting down your oracle database, install the patch, start the database, and execute the post-install steps. I forgot to do the post install steps (missed it in the readme file) and takes us 3x export-import cycles to realize that the patch were not effective (yet). But of course you need an active Oracle support contract. IMHO, if you don't have Oracle support contract, you would be better running MariaDB or MongoDB or other open source database.

Problem C - Error importing partitioned data 

One of the destination database is an Oracle Express 11g, which doesn't have Enterprise features. But the source database were Oracle 11g enterprise. When tables using partitioning were imported, we have ORA-00439 feature not enabled : Partitioning error. Fortunately Oracle 11g's impdp have a merge partition option.

Solution C-1 Use merge partition option when importing

Just insert partition_options=merge to impdp's command line. Beware that the partitions would be gone from table's DDL in the destination system.

impdp system TABLES=sh.sales PARTITION_OPTIONS=merge 
DIRECTORY=dpump_dir1 DUMPFILE=sales.dmp

No comments: