Changes between Initial Version and Version 1 of OracleToPg


Ignore:
Timestamp:
03/26/14 12:44:56 (11 years ago)
Author:
niles
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OracleToPg

    v1 v1  
     1 
     2= Porting from an Oracle database to a Postgres database = 
     3 
     4The task of porting an Oracle database to a Postgres database is best done using the perl-based ora2pg tool, which at the time of writing is available from [http://ora2pg.darold.net/install.html]. Installation is straightforward and initial configuration involves logging in as the superuser and editing ora2pg's configuration file as follows : 
     5 
     6{{{ 
     7cd /etc/ora2pg/ 
     8cp ora2pg.conf.dist ora2pg.conf 
     9vi ora2pg.conf 
     10}}} 
     11 
     12'''This has already been done on the machine vso.''' It is documented here for other users. 
     13 
     14The file is a list of key/value pairs, with the key and value separated by a tab. For instance the line in /etc/ora2pg/ora2pg.conf : 
     15 
     16{{{ 
     17ORACLE_HOME  /usr/local/oracle/10g 
     18}}} 
     19would set the ORACLE_HOME value to "/usr/local/oracle/10g". 
     20 
     21 
     22Typically the following settings need to be changed : 
     23 
     241. ORACLE_HOME - While I'm not 100% certain that this needs to be set, it can't hurt, and it's easy to do - go to the machine on which Oracle is installed and look at the file /etc/oratab 
     251. ORACLE_DSN  - Typically set to "dbi:Oracle:" 
     261. ORACLE_USER needs to be set to the user who accesses the database 
     271. ORACLE_PWD needs to be set to their password 
     281. The line reading "#WHERE 1=1" needs to be un-commented so it reads "WHERE 1=1" (ie. delete the "#") 
     291. Depending on your version of postgres, you may need to set PG_SUPPORTS_MVIEW to "0", although this may not be very relevant for our work 
     30 
     31While it is theoretically possible to dump all the contents of an Oracle database, in practice it's probably best done one part at a time, because that allows for more stringent checks to be done. It also allows for tables that are continually being updated in Oracle to be moved to postgres as the means to update them in postgres becomes available. This is done with the '''--allow''' argument when running ora2pg (see the bash script below). 
     32 
     33For example, in Oracle there is a table named "'''NOAA_ACTIVE_REGION_LOCATIONS'''". There are also three Oracle procedures that are used to update this table, somewhat unimaginatively named "'''UPDATE_ACTIVE_REGION'''", "'''UPDATE_ACTIVE_REGION2'''" and "'''UPDATE_ACTIVE_REGION3'''". To extract this into the postgres database, we use ora2pg to extract the SQL to create the table, then the SQL to populate the table using '''INSERT''' statements (which can be a large SQL file) and finally the three procedures. This can be done in a bash script as follows : 
     34 
     35{{{ 
     36#!/bin/bash 
     37 
     38echo Dumping table scheme 
     39ora2pg --debug --allow NOAA_ACTIVE_REGION_LOCATIONS --out activeRegionSchema.psql --type TABLE 
     40echo 
     41 
     42echo Dumping table data 
     43ora2pg --debug --allow NOAA_ACTIVE_REGION_LOCATIONS --out activeRegionData.psql --type INSERT 
     44echo 
     45 
     46echo Dumping procedures 
     47ora2pg --debug --plsql --allow UPDATE_ACTIVE_REGION  --out activeRegionProc1.psql --type PROCEDURE 
     48ora2pg --debug --plsql --allow UPDATE_ACTIVE_REGION2 --out activeRegionProc2.psql --type PROCEDURE 
     49ora2pg --debug --plsql --allow UPDATE_ACTIVE_REGION3 --out activeRegionProc3.psql --type PROCEDURE 
     50echo 
     51 
     52exit 
     53 
     54}}} 
     55 
     56This writes a set of five files with the .psql extension. We can then read them into postgres with a bash script as follows : 
     57 
     58{{{ 
     59#!/bin/bash 
     60 
     61dropdb export_test 
     62createdb export_test 
     63createlang -d export_test plpgsql 
     64 
     65cat activeRegionSchema.psql | psql export_test 
     66cat activeRegionData.psql | psql export_test 
     67 
     68cat activeRegionProc1.psql | psql export_test 
     69cat activeRegionProc2.psql | psql export_test 
     70cat activeRegionProc3.psql | psql export_test 
     71 
     72exit 
     73 
     74}}} 
     75 
     76This creates the table in postgres. Any cron-driven scripts that were updating that table in realtime - "spiders" - must also be modified so that they use the postgres database rather than the Oracle one.