Remove ora2pg; now available at <http://www.samse.fr/GPL/ora2pg/>.

This commit is contained in:
Peter Eisentraut 2006-02-25 19:18:58 +00:00
parent 305c82e6bb
commit e6917b1255
8 changed files with 1 additions and 3163 deletions

View File

@ -1,4 +1,4 @@
# $PostgreSQL: pgsql/contrib/Makefile,v 1.62 2006/02/12 03:55:52 momjian Exp $
# $PostgreSQL: pgsql/contrib/Makefile,v 1.63 2006/02/25 19:18:58 petere Exp $
subdir = contrib
top_builddir = ..
@ -38,7 +38,6 @@ WANTED_DIRS = \
# adddepend \ (does not have a makefile)
# mSQL-interface \ (requires msql installed)
# mac \ (does not have a makefile)
# oracle \ (does not have a makefile)
# start-scripts \ (does not have a makefile)
# xml2 \ (requires libxml installed)

View File

@ -98,10 +98,6 @@ oid2name -
Maps numeric files to table names
by B Palmer <bpalmer@crimelabs.net>
oracle -
Converts Oracle database schema to PostgreSQL
by Gilles Darold <gilles@darold.net>
pg_buffercache -
Real time queries on the shared buffer cache
by Mark Kirkwood <markir@paradise.net.nz>

View File

@ -1,93 +0,0 @@
2001 05 09 - Initial version 1.0
2001 05 09 - Version 1.1
- Add table grant extraction based on group. Oracle ROLES are groups in PG
2001 05 11 - Version 1.2
- Views extraction is now really done with the option type=>'VIEW'
- Add indexes extraction on tables.
- Changes name of constraints, default is now used.
- Add debug printing to see that the process is running :-)
- Add extraction of only required tablename.
- Add extraction of only n to n table indice. Indices of extraction can be obtained
with the option showtableid set to 1.
- Fix print of NOT NULL field.
- Complete rewrite of the grant extraction
- Complete rewrite of most things
2001 06 20 - Version 1.3
- Grant/privilege extraction are now done separatly with the option type=>'GRANT'
- Sequence extraction with the option type=>'SEQUENCE'
- Trigger extraction with the option type=>'TRIGGER'
- Function extraction with the option type=>'FUNCTION' and type=>'PROCEDURE'
- Complete rewrite of the foreign key extraction
- Fix incorrect type translation and many other bug fix
- Add schema only extraction by option schema => 'MYSCHEM'
2001 06 27 - Version 1.4
- Add online Oracle data extraction and insertion into PG database.
- Data export as insert statement (type => DATA)
- Data export as copy from stdin statement (type => COPY)
2001 12 28 - Version 1.5
- Fix LongReadLen problem when exporting Oracle data on LONG and LOB types
Thanks to Stephane Schildknecht for reporting and testing the fix.
- Add more precision on NUMBER type conversion
- Add conversion of type LONG, LOB, FILE
- Fix a problem when extracting data, sometime table could need to be prefixed
by the schema name.
- Fix output of Oracle data extraction. It now require a call to the function
export_data().
2002 01 07 - Version 1.6
- Fix problem exporting NULL value. Thanks to Stephane Schildknecht.
2002 02 14 - Version 1.7
- Remove export of OUTLINE object type. Thanks to Jean-Paul ARGUDO.
2002 03 05 - Version 1.8
- Add Oracle type FLOAT conversion to float8.
- Add column alias extraction on view. Thanks to Jean-Francois RIPOUTEAU
- Add PACKAGE extraction (type => DATA).
2002 06 04 - Version 1.9
- Fix a problem export data which fill NULL instead of 0 or empty string.
Thanks to Jan Kester.
- Add time with date when export data [ tochar('YYYY-MM-DD HH24:MI:SS') ].
Thanks to Paolo Mattioli.
2002 07 29 - Version 1.10
- Fix a problem with local settings regarding decimal separator (all ,
are changed to .) Thank to Jan Kester.
2002 09 27 - Version 1.11
- Fix a problem when retrieving package+package body. Thanks to Mike WILHELM-HILTZ
- Set LongReadLen to 100000 when exporting table information. Many users reports
this kind of error: A-01406 LongReadLen too small and/or LongTruncOk not set
This should fix the problem else you must increase the value (around line 422 of Ora2Pg.pm.
- Filtering by owner for better performance when retreiving database schema. Thanks to Jefferson MEDEIROS
2002 12 03 - Version 1.12
I have fixed 2 bugs when using it against Oracle 817R3 on linux.
- Fix problem regarding RI constraints, the owner name was not
getting into the sql statement. Thank to Ian Boston.
- Moved all the RI constraints out of the create table statement.
Thank to Ian Boston for this contribution. This was a major request
from Ora2pg users.
2002 12 26 - Version 2.0
- Clean code.
- Fix COPY output on column value with end of line and add column naming.
- Add support to the PostgreSQL 7.3 schema. So Oracle schema can now be exported.
(see export_schema init option)
- Remove data extraction limit (old default: 10) so each tuple will be dump by default.
Thanks for all congratulation message and bug report+fix I received.
Gilles DAROLD <gilles@darold.net>

File diff suppressed because it is too large Load Diff

View File

@ -1,485 +0,0 @@
NAME
Ora2Pg - Oracle to PostgreSQL database schema converter
SYNOPSIS
BEGIN {
$ENV{ORACLE_HOME} = '/usr/local/oracle/oracle816';
}
use strict;
use Ora2Pg;
# Init the database connection
my $dbsrc = 'dbi:Oracle:host=testdb.samse.fr;sid=TEST;port=1521';
my $dbuser = 'system';
my $dbpwd = 'manager';
# Create an instance of the Ora2Pg perl module
my $schema = new Ora2Pg (
datasource => $dbsrc, # Database DBD datasource
user => $dbuser, # Database user
password => $dbpwd, # Database password
{
PrintError => 0,
RaiseError => 1,
AutoCommit => 0
}
);
# Create the POSTGRESQL representation of all objects in the database
$schema->export_schema("output.sql");
exit(0);
or if you only want to extract some tables:
# Create an instance of the Ora2Pg perl module
my @tables = ('tab1', 'tab2', 'tab3');
my $schema = new Ora2Pg (
datasource => $dbsrc, # Database DBD datasource
user => $dbuser, # Database user
password => $dbpwd, # Database password
tables => \@tables,
or # Tables to extract
tables => [('tab1','tab2')],
debug => 1 # To show somethings when running
);
or if you only want to extract the 10 first tables:
# Create an instance of the Ora2Pg perl module
my $schema = new Ora2Pg (
datasource => $dbsrc, # Database DBD datasource
user => $dbuser, # Database user
password => $dbpwd, # Database password
max => 10 # 10 first tables to extract
);
or if you only want to extract tables 10 to 20:
# Create an instance of the Ora2Pg perl module
my $schema = new Ora2Pg (
datasource => $dbsrc, # Database DBD datasource
user => $dbuser, # Database user
password => $dbpwd, # Database password
min => 10, # Begin extraction at indice 10
max => 20 # End extraction at indice 20
);
To choose a particular Oracle schema to export just set the following
option to your schema name:
schema => 'APPS'
This schema definition can also be needed when you want to export data.
If export failed and complain that the table doesn't exists use this to
prefix the table name by the schema name.
If you want to use PostgreSQL 7.3 schema support activate the init
option 'export_schema' set to 1. Default is no schema export
To know at which indices tables can be found during extraction use the
option:
showtableid => 1
To extract all views set the type option as follow:
type => 'VIEW'
To extract all grants set the type option as follow:
type => 'GRANT'
To extract all sequences set the type option as follow:
type => 'SEQUENCE'
To extract all triggers set the type option as follow:
type => 'TRIGGER'
To extract all functions set the type option as follow:
type => 'FUNCTION'
To extract all procedures set the type option as follow:
type => 'PROCEDURE'
To extract all packages and body set the type option as follow:
type => 'PACKAGE'
Default is table extraction
type => 'TABLE'
To extract all data from table extraction as INSERT statement use:
type => 'DATA'
To extract all data from table extraction as COPY statement use:
type => 'COPY'
and data_limit => n to specify the max tuples to return. If you set this
options to 0 or nothing, no limitation are used. Additional option
'table', 'min' and 'max' can also be used.
When use of COPY or DATA you can export data by calling method:
$schema->export_data("output.sql");
Data are dumped to the given filename or to STDOUT with no argument. You
can also send these data directly to a PostgreSQL backend using the
following method:
$schema->send_to_pgdb($destdatasrc,$destuser,$destpasswd);
In this case you must call export_data() without argument after the call
to method send_to_pgdb().
If you set type to COPY and you want to dump data directly to a PG
database, you must call method send_to_pgdb but data will not be sent
via DBD::Pg but they will be load to the database using the psql
command. Calling this method is istill required to be able to extract
database name, hostname and port information. Edit the $PSQL variable to
match the path of your psql command (nothing to edit if psql is in your
path).
DESCRIPTION
Ora2Pg is a perl OO module used to export an Oracle database schema to a
PostgreSQL compatible schema.
It simply connect to your Oracle database, extract its structure and
generate a SQL script that you can load into your PostgreSQL database.
I'm not a Oracle DBA so I don't really know something about its internal
structure so you may find some incorrect things. Please tell me what is
wrong and what can be better.
It currently dump the database schema (tables, views, sequences,
indexes, grants), with primary, unique and foreign keys into PostgreSQL
syntax without editing the SQL code generated.
It now can dump Oracle data into PostgreSQL DB as online process. You
can choose what columns can be exported for each table.
Functions, procedures and triggers PL/SQL code generated must be
reviewed to match the PostgreSQL syntax. Some usefull recommandation on
porting Oracle to PostgreSQL can be found at
http://techdocs.postgresql.org/ under the "Converting from other
Databases to PostgreSQL" Oracle part. I just notice one thing more is
that the trunc() function in Oracle is the same for number or date so be
carefull when porting to PostgreSQL to use trunc() for number and
date_trunc() for date.
ABSTRACT
The goal of the Ora2Pg perl module is to cover all part needed to export
an Oracle database to a PostgreSQL database without other thing that
provide the connection parameters to the Oracle database.
Features must include:
- Database schema export (tables, views, sequences, indexes),
with unique, primary and foreign key.
- Grants/privileges export by user and group.
- Table selection (by name and max table) export.
- Export Oracle schema to PostgreSQL 7.3 schema.
- Predefined functions/triggers/procedures/packages export.
- Data export.
- Sql query converter (todo)
My knowledge regarding database is really poor especially for Oracle so
contribution is welcome.
REQUIREMENT
You just need the DBI, DBD::Pg and DBD::Oracle perl module to be
installed
PUBLIC METHODS
new HASH_OPTIONS
Creates a new Ora2Pg object.
Supported options are:
- datasource : DBD datasource (required)
- user : DBD user (optional with public access)
- password : DBD password (optional with public access)
- schema : Oracle internal schema to extract
- type : Type of data to extract, can be TABLE,VIEW,GRANT,SEQUENCE,
TRIGGER,FUNCTION,PROCEDURE,DATA,COPY,PACKAGE
- debug : Print the current state of the parsing
- export_schema : Export Oracle schema to PostgreSQL 7.3 schema
- tables : Extract only the given tables (arrayref)
- showtableid : Display only the table indice during extraction
- min : Indice to begin extraction. Default to 0
- max : Indice to end extraction. Default to 0 mean no limits
- data_limit : Number max of tuples to return during data extraction (default 0 no limit)
Attempt that this list should grow a little more because all
initialization is done by this way.
export_data FILENAME
Print SQL data output to a filename or to STDOUT if no file is given.
Must be used only if type option is set to DATA or COPY =cut
sub export_data { my ($self, $outfile) = @_;
$self->_get_sql_data($outfile);
}
export_sql FILENAME
Print SQL conversion output to a filename or simply return these data if
no file is given.
send_to_pgdb DEST_DATASRC DEST_USER DEST_PASSWD
Open a DB handle to a PostgreSQL database
modify_struct TABLE_NAME ARRAYOF_FIELDNAME
Modify a table structure during export. Only given fieldname will be
exported.
PRIVATE METHODS
_init HASH_OPTIONS
Initialize a Ora2Pg object instance with a connexion to the Oracle
database.
_grants
This function is used to retrieve all privilege information.
It extract all Oracle's ROLES to convert them as Postgres groups and
search all users associated to these roles.
Set the main hash $self->{groups}. Set the main hash $self->{grantss}.
_sequences
This function is used to retrieve all sequences information.
Set the main hash $self->{sequences}.
_triggers
This function is used to retrieve all triggers information.
Set the main hash $self->{triggers}.
_functions
This function is used to retrieve all functions information.
Set the main hash $self->{functions}.
_packages
This function is used to retrieve all packages information.
Set the main hash $self->{packages}.
_tables
This function is used to retrieve all table information.
Set the main hash of the database structure $self->{tables}. Keys are
the names of all tables retrieved from the current database. Each table
information compose an array associated to the table_info key as array
reference. In other way:
$self->{tables}{$class_name}{table_info} = [(OWNER,TYPE)];
DBI TYPE can be TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL
TEMPORARY, ALIAS, SYNONYM or a data source specific type identifier.
This only extract TABLE type.
It also get the following informations in the DBI object to affect the
main hash of the database structure :
$self->{tables}{$class_name}{field_name} = $sth->{NAME};
$self->{tables}{$class_name}{field_type} = $sth->{TYPE};
It also call these other private subroutine to affect the main hash of
the database structure :
@{$self->{tables}{$class_name}{column_info}} = $self->_column_info($class_name, $owner);
@{$self->{tables}{$class_name}{primary_key}} = $self->_primary_key($class_name, $owner);
@{$self->{tables}{$class_name}{unique_key}} = $self->_unique_key($class_name, $owner);
@{$self->{tables}{$class_name}{foreign_key}} = $self->_foreign_key($class_name, $owner);
_views
This function is used to retrieve all views information.
Set the main hash of the views definition $self->{views}. Keys are the
names of all views retrieved from the current database values are the
text definition of the views.
It then set the main hash as follow:
# Definition of the view
$self->{views}{$table}{text} = $view_infos{$table};
_get_sql_data
Returns a string containing the entire SQL Schema definition compatible
with PostgreSQL
_get_data TABLE
This function implements a Oracle-native data extraction.
Return a list of array reference containing the data
_sql_type INTERNAL_TYPE LENGTH PRECISION SCALE
This function return the PostgreSQL datatype corresponding to the Oracle
internal type.
_column_info TABLE OWNER
This function implements a Oracle-native column information.
Return a list of array reference containing the following informations
for each column the given a table
[( column name, column type, column length, nullable column, default
value )]
_primary_key TABLE OWNER
This function implements a Oracle-native primary key column information.
Return a list of all column name defined as primary key for the given
table.
_unique_key TABLE OWNER
This function implements a Oracle-native unique key column information.
Return a list of all column name defined as unique key for the given
table.
_foreign_key TABLE OWNER
This function implements a Oracle-native foreign key reference
information.
Return a list of hash of hash of array reference. Ouuf! Nothing very
difficult. The first hash is composed of all foreign key name. The
second hash just have two key known as 'local' and remote' corresponding
to the local table where the foreign key is defined and the remote table
where the key refer.
The foreign key name is composed as follow:
'local_table_name->remote_table_name'
Foreign key data consist in two array representing at the same indice
the local field and the remote field where the first one refer to the
second. Just like this:
@{$link{$fkey_name}{local}} = @local_columns;
@{$link{$fkey_name}{remote}} = @remote_columns;
_get_users
This function implements a Oracle-native users information.
Return a hash of all users as an array.
_get_roles
This function implements a Oracle-native roles information.
Return a hash of all groups (roles) as an array of associated users.
_get_all_grants
This function implements a Oracle-native user privilege information.
Return a hash of all tables grants as an array of associated users.
_get_indexes TABLE OWNER
This function implements a Oracle-native indexes information.
Return hash of array containing all unique index and a hash of array of
all indexes name which are not primary keys for the given table.
_get_sequences
This function implements a Oracle-native sequences information.
Return a hash of array of sequence name with MIN_VALUE, MAX_VALUE,
INCREMENT and LAST_NUMBER for the given table.
_get_views
This function implements a Oracle-native views information.
Return a hash of view name with the SQL query it is based on.
_alias_info
This function implements a Oracle-native column information.
Return a list of array reference containing the following informations
for each alias of the given view
[( column name, column id )]
_get_triggers
This function implements a Oracle-native triggers information.
Return an array of refarray of all triggers informations
_get_functions
This function implements a Oracle-native functions information.
Return a hash of all function name with their PLSQL code
_get_packages
This function implements a Oracle-native packages information.
Return a hash of all function name with their PLSQL code
_table_info
This function retrieve all Oracle-native tables information.
Return a handle to a DB query statement
AUTHOR
Gilles Darold <gilles@darold.net>
COPYRIGHT
Copyright (c) 2001 Gilles Darold - All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
BUGS
This perl module is in the same state as my knowledge regarding
database, it can move and not be compatible with older version so I will
do my best to give you official support for Ora2Pg. Your volontee to
help construct it and your contribution are welcome.
SEE ALSO
the DBI manpage, the DBD::Oracle manpage, the DBD::Pg manpage
ACKNOWLEDGEMENTS
Thanks to Jason Servetar who decided me to implement data extraction.

View File

@ -1,5 +0,0 @@
The following need your contribution :
- SQL queries converter.
- PL/SQL code converter.

View File

@ -1,483 +0,0 @@
<HTML>
<HEAD>
<TITLE>Ora2Pg - Oracle to PostgreSQL database schema converter</TITLE>
</HEAD>
<BODY>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#abstract">ABSTRACT</A></LI>
<LI><A HREF="#requirement">REQUIREMENT</A></LI>
<LI><A HREF="#public methods">PUBLIC METHODS</A></LI>
<UL>
<LI><A HREF="#new hash_options">new HASH_OPTIONS</A></LI>
<LI><A HREF="#export_data filename">export_data FILENAME</A></LI>
<LI><A HREF="#export_sql filename">export_sql FILENAME</A></LI>
<LI><A HREF="#send_to_pgdb dest_datasrc dest_user dest_passwd">send_to_pgdb DEST_DATASRC DEST_USER DEST_PASSWD</A></LI>
<LI><A HREF="#modify_struct table_name arrayof_fieldname">modify_struct TABLE_NAME ARRAYOF_FIELDNAME</A></LI>
</UL>
<LI><A HREF="#private methods">PRIVATE METHODS</A></LI>
<UL>
<LI><A HREF="#_init hash_options">_init HASH_OPTIONS</A></LI>
<LI><A HREF="#_grants">_grants</A></LI>
<LI><A HREF="#_sequences">_sequences</A></LI>
<LI><A HREF="#_triggers">_triggers</A></LI>
<LI><A HREF="#_functions">_functions</A></LI>
<LI><A HREF="#_packages">_packages</A></LI>
<LI><A HREF="#_tables">_tables</A></LI>
<LI><A HREF="#_views">_views</A></LI>
<LI><A HREF="#_get_sql_data">_get_sql_data</A></LI>
<LI><A HREF="#_get_data table">_get_data TABLE</A></LI>
<LI><A HREF="#_sql_type internal_type length precision scale">_sql_type INTERNAL_TYPE LENGTH PRECISION SCALE</A></LI>
<LI><A HREF="#_column_info table owner">_column_info TABLE OWNER</A></LI>
<LI><A HREF="#_primary_key table owner">_primary_key TABLE OWNER</A></LI>
<LI><A HREF="#_unique_key table owner">_unique_key TABLE OWNER</A></LI>
<LI><A HREF="#_foreign_key table owner">_foreign_key TABLE OWNER</A></LI>
<LI><A HREF="#_get_users">_get_users</A></LI>
<LI><A HREF="#_get_roles">_get_roles</A></LI>
<LI><A HREF="#_get_all_grants">_get_all_grants</A></LI>
<LI><A HREF="#_get_indexes table owner">_get_indexes TABLE OWNER</A></LI>
<LI><A HREF="#_get_sequences">_get_sequences</A></LI>
<LI><A HREF="#_get_views">_get_views</A></LI>
<LI><A HREF="#_alias_info">_alias_info</A></LI>
<LI><A HREF="#_get_triggers">_get_triggers</A></LI>
<LI><A HREF="#_get_functions">_get_functions</A></LI>
<LI><A HREF="#_get_packages">_get_packages</A></LI>
<LI><A HREF="#_table_info">_table_info</A></LI>
</UL>
<LI><A HREF="#author">AUTHOR</A></LI>
<LI><A HREF="#copyright">COPYRIGHT</A></LI>
<LI><A HREF="#bugs">BUGS</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
<LI><A HREF="#acknowledgements">ACKNOWLEDGEMENTS</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>Ora2Pg - Oracle to PostgreSQL database schema converter</P>
<P>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
BEGIN {
$ENV{ORACLE_HOME} = '/usr/local/oracle/oracle816';
}</PRE>
<PRE>
use strict;</PRE>
<PRE>
use Ora2Pg;</PRE>
<PRE>
# Init the database connection
my $dbsrc = 'dbi:Oracle:host=testdb.samse.fr;sid=TEST;port=1521';
my $dbuser = 'system';
my $dbpwd = 'manager';</PRE>
<PRE>
# Create an instance of the Ora2Pg perl module
my $schema = new Ora2Pg (
datasource =&gt; $dbsrc, # Database DBD datasource
user =&gt; $dbuser, # Database user
password =&gt; $dbpwd, # Database password
{
PrintError =&gt; 0,
RaiseError =&gt; 1,
AutoCommit =&gt; 0
}
);</PRE>
<PRE>
# Create the POSTGRESQL representation of all objects in the database
$schema-&gt;export_schema(&quot;output.sql&quot;);</PRE>
<PRE>
exit(0);</PRE>
<P>or if you only want to extract some tables:</P>
<PRE>
# Create an instance of the Ora2Pg perl module
my @tables = ('tab1', 'tab2', 'tab3');
my $schema = new Ora2Pg (
datasource =&gt; $dbsrc, # Database DBD datasource
user =&gt; $dbuser, # Database user
password =&gt; $dbpwd, # Database password
tables =&gt; \@tables,
or # Tables to extract
tables =&gt; [('tab1','tab2')],
debug =&gt; 1 # To show somethings when running
);</PRE>
<P>or if you only want to extract the 10 first tables:</P>
<PRE>
# Create an instance of the Ora2Pg perl module
my $schema = new Ora2Pg (
datasource =&gt; $dbsrc, # Database DBD datasource
user =&gt; $dbuser, # Database user
password =&gt; $dbpwd, # Database password
max =&gt; 10 # 10 first tables to extract
);</PRE>
<P>or if you only want to extract tables 10 to 20:</P>
<PRE>
# Create an instance of the Ora2Pg perl module
my $schema = new Ora2Pg (
datasource =&gt; $dbsrc, # Database DBD datasource
user =&gt; $dbuser, # Database user
password =&gt; $dbpwd, # Database password
min =&gt; 10, # Begin extraction at indice 10
max =&gt; 20 # End extraction at indice 20
);</PRE>
<P>To choose a particular Oracle schema to export just set the following option
to your schema name:</P>
<PRE>
schema =&gt; 'APPS'</PRE>
<P>This schema definition can also be needed when you want to export data. If export
failed and complain that the table doesn't exists use this to prefix the table name
by the schema name.</P>
<P>If you want to use PostgreSQL 7.3 schema support activate the init option
'export_schema' set to 1. Default is no schema export</P>
<P>To know at which indices tables can be found during extraction use the option:</P>
<PRE>
showtableid =&gt; 1</PRE>
<P>To extract all views set the type option as follow:</P>
<PRE>
type =&gt; 'VIEW'</PRE>
<P>To extract all grants set the type option as follow:</P>
<PRE>
type =&gt; 'GRANT'</PRE>
<P>To extract all sequences set the type option as follow:</P>
<PRE>
type =&gt; 'SEQUENCE'</PRE>
<P>To extract all triggers set the type option as follow:</P>
<PRE>
type =&gt; 'TRIGGER'</PRE>
<P>To extract all functions set the type option as follow:</P>
<PRE>
type =&gt; 'FUNCTION'</PRE>
<P>To extract all procedures set the type option as follow:</P>
<PRE>
type =&gt; 'PROCEDURE'</PRE>
<P>To extract all packages and body set the type option as follow:</P>
<PRE>
type =&gt; 'PACKAGE'</PRE>
<P>Default is table extraction</P>
<PRE>
type =&gt; 'TABLE'</PRE>
<P>To extract all data from table extraction as INSERT statement use:</P>
<PRE>
type =&gt; 'DATA'</PRE>
<P>To extract all data from table extraction as COPY statement use:</P>
<PRE>
type =&gt; 'COPY'</PRE>
<P>and data_limit =&gt; n to specify the max tuples to return. If you set
this options to 0 or nothing, no limitation are used. Additional option
'table', 'min' and 'max' can also be used.</P>
<P>When use of COPY or DATA you can export data by calling method:</P>
<P>$schema-&gt;export_data(``output.sql'');</P>
<P>Data are dumped to the given filename or to STDOUT with no argument.
You can also send these data directly to a PostgreSQL backend using
the following method:</P>
<P>$schema-&gt;send_to_pgdb($destdatasrc,$destuser,$destpasswd);</P>
<P>In this case you must call <CODE>export_data()</CODE> without argument after the
call to method send_to_pgdb().</P>
<P>If you set type to COPY and you want to dump data directly to a PG database,
you must call method send_to_pgdb but data will not be sent via DBD::Pg but
they will be load to the database using the psql command. Calling this method
is istill required to be able to extract database name, hostname and port
information. Edit the $PSQL variable to match the path of your psql
command (nothing to edit if psql is in your path).</P>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>Ora2Pg is a perl OO module used to export an Oracle database schema
to a PostgreSQL compatible schema.</P>
<P>It simply connect to your Oracle database, extract its structure and
generate a SQL script that you can load into your PostgreSQL database.</P>
<P>I'm not a Oracle DBA so I don't really know something about its internal
structure so you may find some incorrect things. Please tell me what is
wrong and what can be better.</P>
<P>It currently dump the database schema (tables, views, sequences, indexes, grants),
with primary, unique and foreign keys into PostgreSQL syntax without editing the
SQL code generated.</P>
<P>It now can dump Oracle data into PostgreSQL DB as online process. You can choose
what columns can be exported for each table.</P>
<P>Functions, procedures and triggers PL/SQL code generated must be reviewed to match
the PostgreSQL syntax. Some usefull recommandation on porting Oracle to PostgreSQL
can be found at <A HREF="http://techdocs.postgresql.org/">http://techdocs.postgresql.org/</A> under the ``Converting from other
Databases to PostgreSQL'' Oracle part. I just notice one thing more is that the
<CODE>trunc()</CODE> function in Oracle is the same for number or date so be carefull when
porting to PostgreSQL to use <CODE>trunc()</CODE> for number and <CODE>date_trunc()</CODE> for date.</P>
<P>
<HR>
<H1><A NAME="abstract">ABSTRACT</A></H1>
<P>The goal of the Ora2Pg perl module is to cover all part needed to export
an Oracle database to a PostgreSQL database without other thing that provide
the connection parameters to the Oracle database.</P>
<P>Features must include:</P>
<PRE>
- Database schema export (tables, views, sequences, indexes),
with unique, primary and foreign key.
- Grants/privileges export by user and group.
- Table selection (by name and max table) export.
- Export Oracle schema to PostgreSQL 7.3 schema.
- Predefined functions/triggers/procedures/packages export.
- Data export.
- Sql query converter (todo)</PRE>
<P>My knowledge regarding database is really poor especially for Oracle
so contribution is welcome.</P>
<P>
<HR>
<H1><A NAME="requirement">REQUIREMENT</A></H1>
<P>You just need the DBI, DBD::Pg and DBD::Oracle perl module to be installed</P>
<P>
<HR>
<H1><A NAME="public methods">PUBLIC METHODS</A></H1>
<P>
<H2><A NAME="new hash_options">new HASH_OPTIONS</A></H2>
<P>Creates a new Ora2Pg object.</P>
<P>Supported options are:</P>
<PRE>
- datasource : DBD datasource (required)
- user : DBD user (optional with public access)
- password : DBD password (optional with public access)
- schema : Oracle internal schema to extract
- type : Type of data to extract, can be TABLE,VIEW,GRANT,SEQUENCE,
TRIGGER,FUNCTION,PROCEDURE,DATA,COPY,PACKAGE
- debug : Print the current state of the parsing
- export_schema : Export Oracle schema to PostgreSQL 7.3 schema
- tables : Extract only the given tables (arrayref)
- showtableid : Display only the table indice during extraction
- min : Indice to begin extraction. Default to 0
- max : Indice to end extraction. Default to 0 mean no limits
- data_limit : Number max of tuples to return during data extraction (default 0 no limit)</PRE>
<P>Attempt that this list should grow a little more because all initialization is
done by this way.</P>
<P>
<H2><A NAME="export_data filename">export_data FILENAME</A></H2>
<P>Print SQL data output to a filename or
to STDOUT if no file is given.</P>
<P>Must be used only if type option is set to DATA or COPY
=cut</P>
<P>sub export_data
{
my ($self, $outfile) = @_;</P>
<PRE>
$self-&gt;_get_sql_data($outfile);
}</PRE>
<P>
<H2><A NAME="export_sql filename">export_sql FILENAME</A></H2>
<P>Print SQL conversion output to a filename or
simply return these data if no file is given.</P>
<P>
<H2><A NAME="send_to_pgdb dest_datasrc dest_user dest_passwd">send_to_pgdb DEST_DATASRC DEST_USER DEST_PASSWD</A></H2>
<P>Open a DB handle to a PostgreSQL database</P>
<P>
<H2><A NAME="modify_struct table_name arrayof_fieldname">modify_struct TABLE_NAME ARRAYOF_FIELDNAME</A></H2>
<P>Modify a table structure during export. Only given fieldname
will be exported.</P>
<P>
<HR>
<H1><A NAME="private methods">PRIVATE METHODS</A></H1>
<P>
<H2><A NAME="_init hash_options">_init HASH_OPTIONS</A></H2>
<P>Initialize a Ora2Pg object instance with a connexion to the
Oracle database.</P>
<P>
<H2><A NAME="_grants">_grants</A></H2>
<P>This function is used to retrieve all privilege information.</P>
<P>It extract all Oracle's ROLES to convert them as Postgres groups
and search all users associated to these roles.</P>
<P>Set the main hash $self-&gt;{groups}.
Set the main hash $self-&gt;{grantss}.</P>
<P>
<H2><A NAME="_sequences">_sequences</A></H2>
<P>This function is used to retrieve all sequences information.</P>
<P>Set the main hash $self-&gt;{sequences}.</P>
<P>
<H2><A NAME="_triggers">_triggers</A></H2>
<P>This function is used to retrieve all triggers information.</P>
<P>Set the main hash $self-&gt;{triggers}.</P>
<P>
<H2><A NAME="_functions">_functions</A></H2>
<P>This function is used to retrieve all functions information.</P>
<P>Set the main hash $self-&gt;{functions}.</P>
<P>
<H2><A NAME="_packages">_packages</A></H2>
<P>This function is used to retrieve all packages information.</P>
<P>Set the main hash $self-&gt;{packages}.</P>
<P>
<H2><A NAME="_tables">_tables</A></H2>
<P>This function is used to retrieve all table information.</P>
<P>Set the main hash of the database structure $self-&gt;{tables}.
Keys are the names of all tables retrieved from the current
database. Each table information compose an array associated
to the table_info key as array reference. In other way:</P>
<PRE>
$self-&gt;{tables}{$class_name}{table_info} = [(OWNER,TYPE)];</PRE>
<P>DBI TYPE can be TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL TEMPORARY,
ALIAS, SYNONYM or a data source specific type identifier. This only extract
TABLE type.</P>
<P>It also get the following informations in the DBI object to affect the
main hash of the database structure :</P>
<PRE>
$self-&gt;{tables}{$class_name}{field_name} = $sth-&gt;{NAME};
$self-&gt;{tables}{$class_name}{field_type} = $sth-&gt;{TYPE};</PRE>
<P>It also call these other private subroutine to affect the main hash
of the database structure :</P>
<PRE>
@{$self-&gt;{tables}{$class_name}{column_info}} = $self-&gt;_column_info($class_name, $owner);
@{$self-&gt;{tables}{$class_name}{primary_key}} = $self-&gt;_primary_key($class_name, $owner);
@{$self-&gt;{tables}{$class_name}{unique_key}} = $self-&gt;_unique_key($class_name, $owner);
@{$self-&gt;{tables}{$class_name}{foreign_key}} = $self-&gt;_foreign_key($class_name, $owner);</PRE>
<P>
<H2><A NAME="_views">_views</A></H2>
<P>This function is used to retrieve all views information.</P>
<P>Set the main hash of the views definition $self-&gt;{views}.
Keys are the names of all views retrieved from the current
database values are the text definition of the views.</P>
<P>It then set the main hash as follow:</P>
<PRE>
# Definition of the view
$self-&gt;{views}{$table}{text} = $view_infos{$table};</PRE>
<P>
<H2><A NAME="_get_sql_data">_get_sql_data</A></H2>
<P>Returns a string containing the entire SQL Schema definition compatible with PostgreSQL</P>
<P>
<H2><A NAME="_get_data table">_get_data TABLE</A></H2>
<P>This function implements a Oracle-native data extraction.</P>
<P>Return a list of array reference containing the data</P>
<P>
<H2><A NAME="_sql_type internal_type length precision scale">_sql_type INTERNAL_TYPE LENGTH PRECISION SCALE</A></H2>
<P>This function return the PostgreSQL datatype corresponding to the
Oracle internal type.</P>
<P>
<H2><A NAME="_column_info table owner">_column_info TABLE OWNER</A></H2>
<P>This function implements a Oracle-native column information.</P>
<P>Return a list of array reference containing the following informations
for each column the given a table</P>
<P>[(
column name,
column type,
column length,
nullable column,
default value
)]</P>
<P>
<H2><A NAME="_primary_key table owner">_primary_key TABLE OWNER</A></H2>
<P>This function implements a Oracle-native primary key column
information.</P>
<P>Return a list of all column name defined as primary key
for the given table.</P>
<P>
<H2><A NAME="_unique_key table owner">_unique_key TABLE OWNER</A></H2>
<P>This function implements a Oracle-native unique key column
information.</P>
<P>Return a list of all column name defined as unique key
for the given table.</P>
<P>
<H2><A NAME="_foreign_key table owner">_foreign_key TABLE OWNER</A></H2>
<P>This function implements a Oracle-native foreign key reference
information.</P>
<P>Return a list of hash of hash of array reference. Ouuf! Nothing very difficult.
The first hash is composed of all foreign key name. The second hash just have
two key known as 'local' and remote' corresponding to the local table where the
foreign key is defined and the remote table where the key refer.</P>
<P>The foreign key name is composed as follow:</P>
<PRE>
'local_table_name-&gt;remote_table_name'</PRE>
<P>Foreign key data consist in two array representing at the same indice the local
field and the remote field where the first one refer to the second.
Just like this:</P>
<PRE>
@{$link{$fkey_name}{local}} = @local_columns;
@{$link{$fkey_name}{remote}} = @remote_columns;</PRE>
<P>
<H2><A NAME="_get_users">_get_users</A></H2>
<P>This function implements a Oracle-native users information.</P>
<P>Return a hash of all users as an array.</P>
<P>
<H2><A NAME="_get_roles">_get_roles</A></H2>
<P>This function implements a Oracle-native roles
information.</P>
<P>Return a hash of all groups (roles) as an array of associated users.</P>
<P>
<H2><A NAME="_get_all_grants">_get_all_grants</A></H2>
<P>This function implements a Oracle-native user privilege
information.</P>
<P>Return a hash of all tables grants as an array of associated users.</P>
<P>
<H2><A NAME="_get_indexes table owner">_get_indexes TABLE OWNER</A></H2>
<P>This function implements a Oracle-native indexes information.</P>
<P>Return hash of array containing all unique index and a hash of
array of all indexes name which are not primary keys for the
given table.</P>
<P>
<H2><A NAME="_get_sequences">_get_sequences</A></H2>
<P>This function implements a Oracle-native sequences
information.</P>
<P>Return a hash of array of sequence name with MIN_VALUE, MAX_VALUE,
INCREMENT and LAST_NUMBER for the given table.</P>
<P>
<H2><A NAME="_get_views">_get_views</A></H2>
<P>This function implements a Oracle-native views information.</P>
<P>Return a hash of view name with the SQL query it is based on.</P>
<P>
<H2><A NAME="_alias_info">_alias_info</A></H2>
<P>This function implements a Oracle-native column information.</P>
<P>Return a list of array reference containing the following informations
for each alias of the given view</P>
<P>[(
column name,
column id
)]</P>
<P>
<H2><A NAME="_get_triggers">_get_triggers</A></H2>
<P>This function implements a Oracle-native triggers information.</P>
<P>Return an array of refarray of all triggers informations</P>
<P>
<H2><A NAME="_get_functions">_get_functions</A></H2>
<P>This function implements a Oracle-native functions information.</P>
<P>Return a hash of all function name with their PLSQL code</P>
<P>
<H2><A NAME="_get_packages">_get_packages</A></H2>
<P>This function implements a Oracle-native packages information.</P>
<P>Return a hash of all function name with their PLSQL code</P>
<P>
<H2><A NAME="_table_info">_table_info</A></H2>
<P>This function retrieve all Oracle-native tables information.</P>
<P>Return a handle to a DB query statement</P>
<P>
<HR>
<H1><A NAME="author">AUTHOR</A></H1>
<P>Gilles Darold &lt;<A HREF="mailto:gilles@darold.net">gilles@darold.net</A>&gt;</P>
<P>
<HR>
<H1><A NAME="copyright">COPYRIGHT</A></H1>
<P>Copyright (c) 2001 Gilles Darold - All rights reserved.</P>
<P>This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.</P>
<P>
<HR>
<H1><A NAME="bugs">BUGS</A></H1>
<P>This perl module is in the same state as my knowledge regarding database,
it can move and not be compatible with older version so I will do my best
to give you official support for Ora2Pg. Your volontee to help construct
it and your contribution are welcome.</P>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P><EM>DBI</EM>, <A HREF="/DBD/Oracle.html">the DBD::Oracle manpage</A>, <A HREF="/DBD/Pg.html">the DBD::Pg manpage</A></P>
<P>
<HR>
<H1><A NAME="acknowledgements">ACKNOWLEDGEMENTS</A></H1>
<P>Thanks to Jason Servetar who decided me to implement data extraction.</P>
</BODY>
</HTML>

View File

@ -1,72 +0,0 @@
#!/usr/bin/perl
#------------------------------------------------------------------------------
# Project : Oracle to Postgresql converter
# Name : ora2pg.pl
# Language : perl, v5.6.1
# OS : linux RedHat 7.3 kernel 2.4.18-17.7.xsmp
# Author : Gilles Darold, gilles@darold.net
# Copyright: Copyright (c) 2000-2002 : Gilles Darold - All rights reserved -
# Function : Script used to convert Oracle Database to PostgreSQL
#------------------------------------------------------------------------------
# Version : 2.0
#------------------------------------------------------------------------------
BEGIN {
$ENV{ORACLE_HOME} = '/usr/local/oracle/oracle816';
}
use strict;
use Ora2Pg;
# Initialyze the database connection
my $dbsrc = 'dbi:Oracle:host=localhost;sid=TEST';
my $dbuser = 'system';
my $dbpwd = 'manager';
# Create an instance of the Ora2Pg perl module
my $schema = new Ora2Pg (
datasource => $dbsrc, # Database DBD datasource
user => $dbuser, # Database user
password => $dbpwd, # Database password
debug => 1, # Verbose mode
# export_schema => 1, # Export Oracle schema to Postgresql 7.3 schema
# schema => 'APPS', # Extract only the given schema namespace
type => 'TABLE', # Extract table
# type => 'PACKAGE', # Extract PACKAGE information
# type => 'DATA', # Extract data with output as INSERT statement
# type => 'COPY', # Extract data with output as COPY statement
# type => 'VIEW', # Extract views
# type => 'GRANT', # Extract privileges
# type => 'SEQUENCE', # Extract sequences
# type => 'TRIGGER', # Extract triggers
# type => 'FUNCTION', # Extract functions
# type => 'PROCEDURE', # Extract procedures
# tables => [('TX_DATA')], # simple indexes
# tables => [('NDW_BROWSER_ATTRIBUTES')], # view
# tables => [('TRIP_DATA')], # Foreign key
# showtableid => 1, # Display only table indice during extraction
# min => 1, # Extract begin at indice 3
# max => 10, # Extract ended at indice 5
# data_limit => 1000, # Extract all data by dump of 1000 tuples
# data_limit => 0, # Extract all data in one pass. Be sure to have enougth memory.
);
# Just export data of the following fields from table 's_txcot'
#$schema->modify_struct('s_txcot','dossier', 'rub', 'datapp');
#### Function to use for extraction when type option is set to DATA or COPY
# Send exported data directly to a PostgreSQL database
#$schema->send_to_pgdb('dbi:Pg:dbname=test_db;host=localhost;port=5432','test','test');
# Output the data extracted from Oracle DB to a file or to STDOUT if no argument.
#$schema->export_data("output.sql");
#### Function to use for extraction of other type
# Create the POSTGRESQL representation of all objects in the database
$schema->export_schema("output.sql");
exit(0);