darold / ora2pg

Ora2Pg is a free tool used to migrate an Oracle database to a PostgreSQL compatible schema. It connects your Oracle database, scan it automatically and extracts its structure or data, it then generates SQL scripts that you can load into PostgreSQL.
http://www.ora2pg.com/
GNU General Public License v3.0
991 stars 342 forks source link

Using the COPY Option using DSN with no host or port #1632

Closed daviesluke closed 1 year ago

daviesluke commented 1 year ago

When using the COPY option that optionally creates a Oracle Foreign Data Wrapper (FDW) and then using a ORACLE_DSN value such as -> dbi:Oracle:TEST where the TEST is a TNS alias then the svroptions in the pg_foreign_server table are incorrectly input as {dbserver=//COPY:COPY/}

This is due to the code in the function _create_foreign_server in the Ora2Pg.pm file which does not account for the host or port NOT being there

This is the troublesome code

20466                 my $sql = '';
20467                 my $extension = 'oracle_fdw';
20468                 if (!$self->{fdw_server}) {
20469                         $self->logit("FATAL: a foreign server name must be set using FDW_SERVER\n", 0, 1);
20470                 }
20471                 if (!$self->{is_mysql} && $self->{oracle_dsn} =~ /(\/\/.*\/.*)/)
20472                 {
20473                         $self->{oracle_fwd_dsn} = "dbserver '$1'";
20474                 }
20475                 else
20476                 {
20477                         $self->{oracle_dsn} =~ /host=([^;]+)/;
20478                         my $host = $1 || 'localhost';
20479                         $self->{oracle_dsn} =~ /port=(\d+)/;
20480                         my $port = $1 || ((!$self->{is_mysql}) ? 1521 : 3306);
darold commented 1 year ago

Commit 14a3020 might fix this issue.