mirror of https://github.com/postgres/postgres
parent
911a498176
commit
904ba3ff69
@ -0,0 +1,17 @@ |
|||||||
|
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=>'VIEWS' |
||||||
|
- 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 |
||||||
|
|
||||||
@ -1,233 +1,297 @@ |
|||||||
Ora2Pg - Oracle to PostgreSQL database schema converter |
NAME |
||||||
|
Ora2Pg - Oracle to PostgreSQL database schema converter |
||||||
_________________________________________________________________ |
|
||||||
|
SYNOPSIS |
||||||
SYNOPSIS |
BEGIN { |
||||||
|
$ENV{ORACLE_HOME} = '/usr/local/oracle/oracle816'; |
||||||
BEGIN { |
} |
||||||
$ENV{ORACLE_HOME} = '/usr/local/oracle/oracle816'; |
|
||||||
} |
use strict; |
||||||
|
|
||||||
use strict; |
use Ora2Pg; |
||||||
|
|
||||||
use Ora2Pg; |
# Init the database connection |
||||||
|
my $dbsrc = 'dbi:Oracle:host=testdb.samse.fr;sid=TEST;port=1521'; |
||||||
# Init the database connection |
my $dbuser = 'system'; |
||||||
my $dbsrc = 'dbi:Oracle:host=testdb.samse.fr;sid=TEST;port=1521'; |
my $dbpwd = 'manager'; |
||||||
my $dbuser = 'system'; |
|
||||||
my $dbpwd = 'manager'; |
# Create an instance of the Ora2Pg perl module |
||||||
|
my $schema = new Ora2Pg ( |
||||||
# Create an instance of the Ora2Pg perl module |
datasource => $dbsrc, # Database DBD datasource |
||||||
my $schema = new Ora2Pg ( |
user => $dbuser, # Database user |
||||||
datasource => $dbsrc, # Database DBD datasource |
password => $dbpwd, # Database password |
||||||
user => $dbuser, # Database user |
); |
||||||
password => $dbpwd, # Database password |
|
||||||
); |
# Create the POSTGRESQL representation of all objects in the database |
||||||
|
$schema->export_schema("output.sql"); |
||||||
# Create the POSTGRESQL representation of all objects in the database |
|
||||||
$schema->export_schema("output.sql"); |
exit(0); |
||||||
|
|
||||||
exit(0); |
or if you only want to extract some tables: |
||||||
_________________________________________________________________ |
|
||||||
|
# Create an instance of the Ora2Pg perl module |
||||||
DESCRIPTION |
my @tables = ('tab1', 'tab2', 'tab3'); |
||||||
|
my $schema = new Ora2Pg ( |
||||||
Ora2Pg is a perl OO module used to export an Oracle database schema to |
datasource => $dbsrc, # Database DBD datasource |
||||||
a PostgreSQL compatible schema. |
user => $dbuser, # Database user |
||||||
|
password => $dbpwd, # Database password |
||||||
It simply connect to your Oracle database, extract its structure and |
tables => \@tables, # Tables to extract |
||||||
generate a SQL script that you can load into your PostgreSQL database. |
debug => 1 # To show somethings when running |
||||||
|
); |
||||||
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 |
or if you only want to extract the 10 first tables: |
||||||
me what is wrong and what can be better. |
|
||||||
|
# Create an instance of the Ora2Pg perl module |
||||||
It currently only dump the database schema, with primary, unique and |
my $schema = new Ora2Pg ( |
||||||
foreign keys. I've tried to excluded internal system tables but |
datasource => $dbsrc, # Database DBD datasource |
||||||
perhaps not enougt, please let me know. |
user => $dbuser, # Database user |
||||||
_________________________________________________________________ |
password => $dbpwd, # Database password |
||||||
|
max => 10 # 10 first tables to extract |
||||||
ABSTRACT |
); |
||||||
|
|
||||||
The goal of the Ora2Pg perl module is to cover all part needed to |
or if you only want to extract tables 10 to 20: |
||||||
export an Oracle database to a PostgreSQL database without other thing |
|
||||||
that provide the connection parameters to the Oracle database. |
# Create an instance of the Ora2Pg perl module |
||||||
|
my $schema = new Ora2Pg ( |
||||||
Features must include: |
datasource => $dbsrc, # Database DBD datasource |
||||||
|
user => $dbuser, # Database user |
||||||
- database schema export (done) |
password => $dbpwd, # Database password |
||||||
- grant export (done) |
min => 10 # Begin extraction at indice 10 |
||||||
- predefined function/trigger export (todo) |
max => 20 # End extraction at indice 20 |
||||||
- data export (todo) |
); |
||||||
- sql query converter (todo) |
|
||||||
|
To know at which indices table can be found during extraction use the |
||||||
My knowledge regarding database is really poor especially for Oracle |
option: |
||||||
so contribution is welcome. |
|
||||||
_________________________________________________________________ |
showtableid => 1 |
||||||
|
|
||||||
REQUIREMENT |
To extract all views set the option type as follow: |
||||||
|
|
||||||
You just need the DBI and DBD::Oracle perl module to be installed |
type => 'VIEW' |
||||||
_________________________________________________________________ |
|
||||||
|
Default is table schema extraction |
||||||
PUBLIC METHODS |
|
||||||
_________________________________________________________________ |
DESCRIPTION |
||||||
|
Ora2Pg is a perl OO module used to export an Oracle database schema to a |
||||||
new HASH_OPTIONS |
PostgreSQL compatible schema. |
||||||
|
|
||||||
Creates a new Ora2Pg object. |
It simply connect to your Oracle database, extract its structure and |
||||||
|
generate a SQL script that you can load into your PostgreSQL database. |
||||||
Supported options are: |
|
||||||
|
I'm not a Oracle DBA so I don't really know something about its internal |
||||||
- datasource : DBD datasource (required) |
structure so you may find some incorrect things. Please tell me what is |
||||||
- user : DBD user (optional with public access) |
wrong and what can be better. |
||||||
- password : DBD password (optional with public access) |
|
||||||
|
It currently only dump the database schema, with primary, unique and |
||||||
Attempt that this list should grow a little more because all |
foreign keys. I've tried to excluded internal system tables but perhaps |
||||||
initialization is done by this way. |
not enougt, please let me know. |
||||||
_________________________________________________________________ |
|
||||||
|
ABSTRACT |
||||||
export_sql FILENAME |
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 |
||||||
Print SQL conversion output to a filename or to STDOUT if no file is |
provide the connection parameters to the Oracle database. |
||||||
given. |
|
||||||
_________________________________________________________________ |
Features must include: |
||||||
|
|
||||||
PUBLIC METHODS |
- Database schema export, with unique, primary and foreign key. |
||||||
_________________________________________________________________ |
- Grants/privileges export by user and group. |
||||||
|
- Indexes and unique indexes export. |
||||||
_init HASH_OPTIONS |
- Table or view selection (by name and max table) export. |
||||||
|
- Predefined function/trigger export (todo) |
||||||
Initialize a Ora2Pg object instance with a connexion to the Oracle |
- Data export (todo) |
||||||
database. |
- Sql query converter (todo) |
||||||
_________________________________________________________________ |
|
||||||
|
My knowledge regarding database is really poor especially for Oracle so |
||||||
_tables |
contribution is welcome. |
||||||
|
|
||||||
This function is used to retrieve all table information. |
REQUIREMENT |
||||||
|
You just need the DBI and DBD::Oracle perl module to be installed |
||||||
Set the main hash of the database structure $self->{tables}. Keys are |
|
||||||
the names of all tables retrieved from the current database. Each |
PUBLIC METHODS |
||||||
table information compose an array associated to the table_info key as |
new HASH_OPTIONS |
||||||
array reference. In other way: |
|
||||||
|
Creates a new Ora2Pg object. |
||||||
$self->{tables}{$class_name}{table_info} = [(OWNER,TYPE)]; |
|
||||||
|
Supported options are: |
||||||
TYPE Can be TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL |
|
||||||
TEMPORARY, ALIAS, SYNONYM or a data source specific type identifier. |
- datasource : DBD datasource (required) |
||||||
|
- user : DBD user (optional with public access) |
||||||
It also get the following informations in the DBI object to affect the |
- password : DBD password (optional with public access) |
||||||
main hash of the database structure : |
- type : Type of data to extract, can be TABLE (default) or VIEW |
||||||
|
- debug : Print the current state of the parsing |
||||||
$self->{tables}{$class_name}{field_name} = $sth->{NAME}; |
- tables : Extract only the given tables (arrayref) |
||||||
$self->{tables}{$class_name}{field_type} = $sth->{TYPE}; |
- showtableid : Display only the table indice during extraction |
||||||
|
- min : Indice to begin extraction. Default to 0 |
||||||
It also call these other private subroutine to affect the main hash of |
- max : Indice to end extraction. Default to 0 mean no limits |
||||||
the database structure : |
|
||||||
|
Attempt that this list should grow a little more because all |
||||||
@{$self->{tables}{$class_name}{column_info}} = &_column_info($self, $class_ |
initialization is done by this way. |
||||||
name); |
|
||||||
@{$self->{tables}{$class_name}{primary_key}} = &_primary_key($self, $class_ |
export_sql FILENAME |
||||||
name); |
|
||||||
@{$self->{tables}{$class_name}{unique_key}} = &_unique_key($self, $class_n |
Print SQL conversion output to a filename or to STDOUT if no file is |
||||||
ame); |
given. |
||||||
@{$self->{tables}{$class_name}{foreign_key}} = &_foreign_key($self, $class_ |
|
||||||
name); |
PUBLIC METHODS |
||||||
_________________________________________________________________ |
_init HASH_OPTIONS |
||||||
|
|
||||||
_get_sql_data |
Initialize a Ora2Pg object instance with a connexion to the Oracle |
||||||
|
database. |
||||||
Returns a string containing the entire SQL Schema definition |
|
||||||
compatible with PostgreSQL |
_tables |
||||||
_________________________________________________________________ |
|
||||||
|
This function is used to retrieve all table information. |
||||||
_sql_type INTERNAL_TYPE LENGTH |
|
||||||
|
Set the main hash of the database structure $self->{tables}. Keys are |
||||||
This function return the PostgreSQL datatype corresponding to the |
the names of all tables retrieved from the current database. Each table |
||||||
Oracle internal type. |
information compose an array associated to the table_info key as array |
||||||
_________________________________________________________________ |
reference. In other way: |
||||||
|
|
||||||
_column_info TABLE |
$self->{tables}{$class_name}{table_info} = [(OWNER,TYPE)]; |
||||||
|
|
||||||
This function implements a Oracle-native column information. |
DBI TYPE can be TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL |
||||||
|
TEMPORARY, ALIAS, SYNONYM or a data source specific type identifier. |
||||||
Return a list of array reference containing the following informations |
This only extract TABLE type. |
||||||
for each column the given a table |
|
||||||
|
It also get the following informations in the DBI object to affect the |
||||||
[( column name, column type, column length, nullable column, default |
main hash of the database structure : |
||||||
value )] |
|
||||||
_________________________________________________________________ |
$self->{tables}{$class_name}{field_name} = $sth->{NAME}; |
||||||
|
$self->{tables}{$class_name}{field_type} = $sth->{TYPE}; |
||||||
_primary_key TABLE |
|
||||||
|
It also call these other private subroutine to affect the main hash of |
||||||
This function implements a Oracle-native primary key column |
the database structure : |
||||||
information. |
|
||||||
|
@{$self->{tables}{$class_name}{column_info}} = &_column_info($self, $class_name); |
||||||
Return a list of all column name defined as primary key for the given |
@{$self->{tables}{$class_name}{primary_key}} = &_primary_key($self, $class_name); |
||||||
table. |
@{$self->{tables}{$class_name}{unique_key}} = &_unique_key($self, $class_name); |
||||||
_________________________________________________________________ |
@{$self->{tables}{$class_name}{foreign_key}} = &_foreign_key($self, $class_name); |
||||||
|
|
||||||
_unique_key TABLE |
_views |
||||||
|
|
||||||
This function implements a Oracle-native unique key column |
This function is used to retrieve all views information. |
||||||
information. |
|
||||||
|
Set the main hash of the views definition $self->{views}. Keys are the |
||||||
Return a list of all column name defined as unique key for the given |
names of all views retrieved from the current database values are the |
||||||
table. |
text definition of the views. |
||||||
_________________________________________________________________ |
|
||||||
|
It then set the main hash as follow: |
||||||
_foreign_key TABLE |
|
||||||
|
# Definition of the view |
||||||
This function implements a Oracle-native foreign key reference |
$self->{views}{$table}{text} = $view_infos{$table}; |
||||||
information. |
# Grants defined on the views |
||||||
|
$self->{views}{$table}{grants} = when I find how... |
||||||
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 |
_get_sql_data |
||||||
second hash just have two key known as 'local' and remote' |
|
||||||
corresponding to the local table where the foreign key is defined and |
Returns a string containing the entire SQL Schema definition compatible |
||||||
the remote table where the key refer. |
with PostgreSQL |
||||||
|
|
||||||
The foreign key name is composed as follow: |
_sql_type INTERNAL_TYPE LENGTH |
||||||
|
|
||||||
'local_table_name->remote_table_name' |
This function return the PostgreSQL datatype corresponding to the Oracle |
||||||
|
internal type. |
||||||
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 |
_column_info TABLE |
||||||
second. Just like this: |
|
||||||
|
This function implements a Oracle-native column information. |
||||||
@{$link{$fkey_name}{local}} = @local_columns; |
|
||||||
@{$link{$fkey_name}{remote}} = @remote_columns; |
Return a list of array reference containing the following informations |
||||||
_________________________________________________________________ |
for each column the given a table |
||||||
|
|
||||||
_get_privilege |
[( column name, column type, column length, nullable column, default |
||||||
|
value )] |
||||||
This function implements a Oracle-native tables grants information. |
|
||||||
|
_primary_key TABLE |
||||||
Return a hash of all groups (roles) with associated users and a hash |
|
||||||
of arrays of all grants on related tables. |
This function implements a Oracle-native primary key column information. |
||||||
_________________________________________________________________ |
|
||||||
|
Return a list of all column name defined as primary key for the given |
||||||
AUTHOR |
table. |
||||||
|
|
||||||
Gilles Darold <gilles@darold.net> |
_unique_key TABLE |
||||||
_________________________________________________________________ |
|
||||||
|
This function implements a Oracle-native unique key column information. |
||||||
COPYRIGHT |
|
||||||
|
Return a list of all column name defined as unique key for the given |
||||||
Copyright (c) 2001 Gilles Darold - All rights reserved. |
table. |
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify |
_foreign_key TABLE |
||||||
it under the same terms as Perl itself. |
|
||||||
_________________________________________________________________ |
This function implements a Oracle-native foreign key reference |
||||||
|
information. |
||||||
BUGS |
|
||||||
|
Return a list of hash of hash of array reference. Ouuf! Nothing very |
||||||
This perl module is in the same state as my knowledge regarding |
difficult. The first hash is composed of all foreign key name. The |
||||||
database, it can move and not be compatible with older version so I |
second hash just have two key known as 'local' and remote' corresponding |
||||||
will do my best to give you official support for Ora2Pg. Your volontee |
to the local table where the foreign key is defined and the remote table |
||||||
to help construct it and your contribution are welcome. |
where the key refer. |
||||||
_________________________________________________________________ |
|
||||||
|
The foreign key name is composed as follow: |
||||||
SEE ALSO |
|
||||||
|
'local_table_name->remote_table_name' |
||||||
DBI, DBD::Oracle |
|
||||||
|
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_table_privilege TABLE |
||||||
|
|
||||||
|
This function implements a Oracle-native table grants information. |
||||||
|
|
||||||
|
Return a hash of array of all users and their grants on the given table. |
||||||
|
|
||||||
|
_get_roles |
||||||
|
|
||||||
|
This function implements a Oracle-native roles/users information. |
||||||
|
|
||||||
|
Return a hash of all groups (roles) as an array of associated users. |
||||||
|
|
||||||
|
_get_indexes TABLE |
||||||
|
|
||||||
|
This function implements a Oracle-native indexes information. |
||||||
|
|
||||||
|
Return an array of all indexes name which are not primary keys for the |
||||||
|
given table. |
||||||
|
|
||||||
|
Note: Indexes name must be created like this tablename_fieldname else |
||||||
|
they will not be retrieved or if tablename false in the output |
||||||
|
fieldname. |
||||||
|
|
||||||
|
_get_sequences TABLE |
||||||
|
|
||||||
|
This function implements a Oracle-native sequence information. |
||||||
|
|
||||||
|
Return a hash of array of sequence name with MIN_VALUE, MAX_VALUE, |
||||||
|
INCREMENT and LAST_NUMBER for the given table. |
||||||
|
|
||||||
|
Not working yet. |
||||||
|
|
||||||
|
_get_views |
||||||
|
|
||||||
|
This function implements a Oracle-native views information. |
||||||
|
|
||||||
|
Return a hash of array of sequence name with MIN_VALUE, MAX_VALUE, |
||||||
|
INCREMENT and LAST_NUMBER for the given table. |
||||||
|
|
||||||
|
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 |
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,6 @@ |
|||||||
|
- Extract sequences on tables. Seem to be difficult, can't find the way to link |
||||||
|
a sequence with one or more column. So problably just dump and edit manually |
||||||
|
- More precision in type conversion based on length (I've no good DB to do that) |
||||||
|
- Extract triggers and internal function. |
||||||
|
- Extract datas. |
||||||
|
- SQL queries converter. |
||||||
Loading…
Reference in new issue