Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate SPATIAL data from Oracle to Postgresql

I am trying my best to migrate a spatial database from Oracle to Postgresql and failing miserably.

I have tried many different avenues as you can see from my previous question on here and none are working. Can someone please tell me of a relatively painless way of doing this as I am now clueless with it.

I have tried using 3rd party software such as SwisSQL but this failed with a multitude of errors. I have tried creating files full of insert statements and then creating a C# program to parse these and replace the oracle spatial types with relevant postgis ones and that failed with an out of memory exception on the most basic replaces due to the sheer size of these files. Some of the tables have over 2 million records in them so you can imagine the size of the file containing inserts for each of those.

I am getting pretty desperate for a solution to this as it is seriously hampering progress on this project. I need the data in Postgresql because I am writing software that needs to be database agnostic which means it has to be tested on real data on each database.

Any ideas whatsoever would be welcomed with open arms. If it wasnt for the spatial aspect of this it would have been far more simple and most likely done by now.

EDIT:

Here is an example of an insert produced by Toad for Oracle to give an idea of data complexity.

Insert into CLUSTER_1000M
(CLUSTER_ID, CELL_GEOM, CELL_CENTROID)
Values
(4410925, 
"MDSYS"."SDO_GEOMETRY"(2003,81989,NULL,
"MDSYS"."SDO_ELEM_INFO_ARRAY"(1,1003,3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
"MDSYS"."SDO_ORDINATE_ARRAY"(80000,103280,81000,104280,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)), 
"MDSYS"."SDO_GEOMETRY"(2001,81989,
"MDSYS"."SDO_POINT_TYPE"(80500,103780,NULL),NULL,NULL));
like image 805
CSharpened Avatar asked Jan 18 '23 04:01

CSharpened


1 Answers

There are two popular options: open source ogr2ogr or a commercial offering from Safe Software.

Here is how I'd approach the ogr2ogr solution.

First, you need to have the right tools: GDAL/OGR. If you are on Unix, compile using the right libraries to get Oracle support (not enabled by default). But I'm going to assume you are on Windows. The simplest way to get open source geospatial tools is with OSGeo4W. To enable Oracle support for GDAL/OGR, you need to also select the gdal-oracle10g package in setup.exe with the "Advanced Install" mode. More info about the Oracle package is at this page, and note that you also need to supply the non-free OCI.DLL. When working, you should see the driver name appear with ogr2ogr --formats.

Your basic command from the OSGeo4W Shell should look something like:

ogr2ogr -f "PostgreSQL" PG:"host=localhost user=someuser dbname=somedb password=password port=5432" OCI:someuser/password layername

Here is more info on GDAL/OGR:

  • ogr2ogr command usage: http://www.gdal.org/ogr2ogr.html
  • Oracle Driver: http://www.gdal.org/drv_oci.html
  • PostgreSQL/PostGIS driver: http://www.gdal.org/drv_pg.html
like image 68
Mike T Avatar answered Jan 31 '23 00:01

Mike T