<refentry id="app-ora2pgpro">
 <indexterm zone="app-ora2pgpro">
  <primary>ora2pgpro</primary>
 </indexterm>

 <refmeta>
  <refentrytitle><application>ora2pgpro</application></refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo>Application</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>ora2pgpro</refname>
  <refpurpose>migrate an Oracle database to Postgres Pro</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
  <cmdsynopsis>
   <command>ora2pgpro</command>
   <arg choice="opt" rep="repeat">
    <replaceable class="parameter">option</replaceable>
   </arg>
  </cmdsynopsis>

  <cmdsynopsis>
   <command>ora2pgpro</command>
   <arg choice="opt">
    <option>-c</option> <replaceable class="parameter">config_file</replaceable>
   </arg>
   <arg choice="opt">
    <option>-t</option> <replaceable class="parameter">export_type</replaceable>
   </arg>
   <arg choice="opt">
    <option>-o</option> <replaceable class="parameter">output_file</replaceable>
   </arg>
  </cmdsynopsis>

  <cmdsynopsis>
   <command>ora2pgpro</command>
   <arg choice="opt">
    <option>-s</option> <replaceable class="parameter">dsn</replaceable>
   </arg>
   <arg choice="opt">
    <option>-u</option> <replaceable class="parameter">user</replaceable>
   </arg>
   <arg choice="opt">
    <option>-w</option> <replaceable class="parameter">password</replaceable>
   </arg>
  </cmdsynopsis>

  <cmdsynopsis>
   <command>ora2pgpro</command>
   <arg choice="plain">
    <option>-i</option> <replaceable class="parameter">input_file</replaceable>
   </arg>
   <arg choice="opt">
    <option>-p</option>
   </arg>
  </cmdsynopsis>

  <cmdsynopsis>
   <command>ora2pgpro</command>
   <arg choice="plain">
    <option>--project_base</option> <replaceable class="parameter">directory</replaceable>
   </arg>
   <arg choice="plain">
    <option>--init_project</option> <replaceable class="parameter">project_name</replaceable>
   </arg>
  </cmdsynopsis>

  <cmdsynopsis>
   <command>ora2pgpro</command>
   <group choice="req">
    <arg choice="plain"><option>-h</option></arg>
    <arg choice="plain"><option>--help</option></arg>
    <arg choice="plain"><option>-v</option></arg>
    <arg choice="plain"><option>--version</option></arg>
   </group>
  </cmdsynopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Configuration</title>

  <para>
    <application>ora2pgpro</application> configuration can be as simple as
    choosing the Oracle database
    to export and choosing the export type.
  </para>
  <para>
    The full control of the Oracle database
    migration is managed in a single configuration file named
    <filename>ora2pgpro.conf</filename>. The format of this file
    consists of a directive name in upper case followed by a tab character
    and a value. Comments are lines beginning with a <literal>#</literal>.
    There is no specific order to place the configuration directives, they
    are set at the time they are read in the configuration file.
  </para>
  <para>
    For configuration directives that just take a single value, you can
    use them multiple times in the configuration file but only the last
    occurrence found in the file will be used. For configuration
    directives that allow a list of values, you can use it multiple times,
    the values will be appended to the list. If you use the
    <xref linkend="ora2pgpro-import"/> directive to load a custom
    configuration file, directives defined in this file will be stored
    from the place the <varname>IMPORT</varname> directive is
    found, so it is better to put it at the end of the configuration
    file.
  </para>
  <para>
    Values set in the command-line options override values from the
    configuration file.
  </para>
  <para>
      First of all, make sure that libraries and binaries path include the
      <application>Oracle Instant Client</application> installation:
    </para>
<programlisting>
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
export PATH="/usr/lib/oracle/11.2/client64/bin:$PATH"
</programlisting>
    <para>
      By default, <application>ora2pgpro</application> looks for
      <filename>/etc/ora2pgpro/ora2pgpro.conf</filename> configuration file,
      if the file exists, you can simply execute:
    </para>
<programlisting>
/usr/local/bin/ora2pgpro
</programlisting>
    <para>
      If you want to call another configuration file, give the path
      as the command-line argument:
    </para>
<programlisting>
/usr/local/bin/ora2pgpro -c /etc/ora2pgpro/new_ora2pgpro.conf
</programlisting>

  <refsect2>
  <title>Command-Line Options</title>

  <para>
   The following command-line options are available for
   <application>ora2pgpro</application>:
  </para>

  <variablelist>
    <varlistentry>
      <term><option>-a</option></term>
      <term><option>--allow</option></term>
      <listitem>
      <para>
      Comma-separated list of objects to allow from export. Can be used
      with <literal>SHOW_COLUMN</literal> too.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-b</option></term>
      <term><option>--basedir</option></term>
      <listitem>
      <para>
      Set the default output directory where files resulting from exports
      will be stored.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-c</option></term>
      <term><option>--conf</option></term>
      <listitem>
      <para>
      Set an alternative configuration file other than the default
      <filename>/etc/ora2pgpro/ora2pgpro.conf</filename>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-C</option></term>
      <term><option>--cdc_file</option></term>
      <listitem>
      <para>
      File used to store/read SCN per table during export.
      Default: <filename>TABLES_SCN.log</filename> in the current directory.
      This is the file written by the <option>--cdc_ready</option> option.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-d</option></term>
      <term><option>--debug</option></term>
      <listitem>
      <para>
      Enable verbose output.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-D</option></term>
      <term><option>--data_type</option></term>
      <listitem>
      <para>
      Allow custom type replacement in command line.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-e</option></term>
      <term><option>--exclude</option></term>
      <listitem>
      <para>
      Comma-separated list of objects to exclude from export.
      Can be used with <varname>SHOW_COLUMN</varname> too.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-h</option></term>
      <term><option>--help</option></term>
      <listitem>
      <para>
      Print this short help.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-g</option></term>
      <term><option>--grant_object</option></term>
      <listitem>
      <para>
      Extract privilege for the given object type. See possible values
      in <xref linkend="ora2pgpro-grant-object"/> configuration.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-i</option></term>
      <term><option>--input</option></term>
      <listitem>
      <para>
      File containing Oracle
      <application>PL/SQL</application> code to convert with
      no Oracle database connection initiated.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-j</option></term>
      <term><option>--jobs</option></term>
      <listitem>
      <para>
      Number of parallel processes to send data to Postgres Pro.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-J</option></term>
      <term><option>--copies</option></term>
      <listitem>
      <para>
      Number of parallel connections to extract data from Oracle.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-l</option></term>
      <term><option>--log</option></term>
      <listitem>
      <para>
      Set a log file. Default is <systemitem>stdout</systemitem>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-L</option></term>
      <term><option>--limit</option></term>
      <listitem>
      <para>
      Number of tuples extracted from Oracle
      and stored in memory before writing, default: 10000.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-n</option></term>
      <term><option>--namespace</option></term>
      <listitem>
      <para>
      Set the Oracle schema to extract from.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-N</option></term>
      <term><option>--pg_schema</option></term>
      <listitem>
      <para>
      Set Postgres Pro <varname>search_path</varname>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-o</option></term>
      <term><option>--out</option></term>
      <listitem>
      <para>
      Set the path to the output file where SQL will
      be written. Default: <filename>output.sql</filename> in running directory.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-p</option></term>
      <term><option>--plsql</option></term>
      <listitem>
      <para>
      Enable <application>PL/SQL</application> to
      <application>PL/pgSQL</application> code conversion.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-P</option></term>
      <term><option>--parallel</option></term>
      <listitem>
      <para>
      Number of parallel tables to extract at the same time.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-q</option></term>
      <term><option>--quiet</option></term>
      <listitem>
      <para>
      Disable progress bar.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-r</option></term>
      <term><option>--relative</option></term>
      <listitem>
      <para>
      Use <option>\ir</option> instead of <option>\i</option> in
      the <application>psql</application> scripts generated.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-s</option></term>
      <term><option>--source</option></term>
      <listitem>
      <para>
      Set the Oracle DBI data source.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-S</option></term>
      <term><option>--scn</option></term>
      <listitem>
      <para>
      Set the Oracle System Change
      Number (SCN) to use to export data. It will be used in
      the <literal>WHERE</literal> clause to get the data. It is used
      with <literal>COPY</literal> or <literal>INSERT</literal>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-t</option></term>
      <term><option>--type</option></term>
      <listitem>
      <para>
      Set the export type. It will override the one
      given in the configuration file (<literal>TYPE</literal>).
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-T</option></term>
      <term><option>--temp_dir</option></term>
      <listitem>
      <para>
      Set a distinct temporary directory when two or more
      <application>ora2pgpro</application> instances run in parallel.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-u</option></term>
      <term><option>--user</option></term>
      <listitem>
      <para>
      Set the Oracle database connection user.
      <envar>ORA2PG_USER</envar> environment variable can be used instead.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-v</option></term>
      <term><option>--version</option></term>
      <listitem>
      <para>
      Show <application>ora2pgpro</application> version and exit.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-w</option></term>
      <term><option>--password</option></term>
      <listitem>
      <para>
      Set the password of the Oracle database user.
      <envar>ORA2PG_PASSWD</envar> environment variable can be used instead.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>-W</option></term>
      <term><option>--where</option></term>
      <listitem>
      <para>
      Set the <literal>WHERE</literal> clause to apply to the
      Oracle query to retrieve data.
      Can be used multiple times.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--forceowner</option></term>
      <listitem>
      <para>
      Force <application>ora2pgpro</application> to set tables and
      sequences owner like in Oracle database.
      If the value is set to a username, this one
      will be used as the objects owner. By default it is the user
      used to connect to the Postgres Pro database that will be the owner.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--nls_lang</option></term>
      <listitem>
      <para>
      Set the Oracle <varname>NLS_LANG</varname>
      client encoding.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--client_encoding</option></term>
      <listitem>
      <para>
      Set the Postgres Pro client encoding.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--view_as_table</option></term>
      <listitem>
      <para>
      Comma-separated list of views to export as table.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--estimate_cost</option></term>
      <listitem>
      <para>
        Enable migration cost estimation assistance with <literal>SHOW_REPORT</literal>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--cost_unit_value</option></term>
      <listitem>
      <para>
      Number of minutes for a cost evaluation unit.
      Default: 5 minutes, corresponds to a migration conducted by a
      Postgres Pro expert.
      Set it to 10 if this is your first migration.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--dump_as_html</option></term>
      <listitem>
      <para>
      Force <application>ora2pgpro</application> to dump report in HTML,
      used only with <literal>SHOW_REPORT</literal>. Default is to dump
      report as simple text.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--dump_as_csv</option></term>
      <listitem>
      <para>
      As above but force <application>ora2pgpro</application>
      to dump report in <acronym>CSV</acronym>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--dump_as_sheet</option></term>
      <listitem>
      <para>
      Report migration assessment with one <acronym>CSV</acronym> line per database.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--init_project</option></term>
      <listitem>
      <para>
      Initialize a typical <application>ora2pgpro</application> project tree.
      Top directory will be created under the project base directory.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--project_base</option></term>
      <listitem>
      <para>
      Define the base directory for <application>ora2pgpro</application>
      project trees. Default is the current directory.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--print_header</option></term>
      <listitem>
      <para>
      Used with <option>--dump_as_sheet</option> to print
      the <acronym>CSV</acronym> header, especially for the first
      run of <application>ora2pgpro</application>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--human_days_limit</option></term>
      <listitem>
      <para>
      Set the number of man-days limit where the migration
      assessment level switches from B to C. Default is set to
      5 man-days.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--audit_user</option></term>
      <listitem>
      <para>
      Comma-separated list of usernames to filter queries in
      the <xref linkend="ora2pgpro-audit-user"/> table. Used only
      with <literal>SHOW_REPORT</literal> and <literal>QUERY</literal> export type.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--pg_dsn</option></term>
      <listitem>
      <para>
      Set the data source to Postgres Pro for direct import.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--pg_user</option></term>
      <listitem>
      <para>
      Set the Postgres Pro user to be used.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--pg_pwd</option></term>
      <listitem>
      <para>
      Set the Postgres Pro password to be used.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--count_rows</option></term>
      <listitem>
      <para>
      Force <application>ora2pgpro</application> to perform a real row
      count in <literal>TEST</literal>, <literal>TEST_COUNT</literal>,
      and <literal>SHOW_TABLE</literal> actions.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--no_header</option></term>
      <listitem>
      <para>
      Do not append <application>ora2pgpro</application> header to output file.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--oracle_speed</option></term>
      <listitem>
      <para>
      Use to know at which speed Oracle is able
      to send data. No data will be processed or written.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--ora2pg_speed</option></term>
      <listitem>
      <para>
      Use to know at which speed <application>ora2pgpro</application> is able
      to send transformed data. Nothing will be written.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--blob_to_lo</option></term>
      <listitem>
      <para>
      Export BLOBs as large objects, can only be used with
      action <literal>SHOW_COLUMN</literal>, <literal>TABLE</literal>,
      and <literal>INSERT</literal>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--cdc_ready</option></term>
      <listitem>
      <para>
      Use current SCN per table to export data and register
      them into a file named <filename>TABLES_SCN.log</filename> by default. It
      can be changed using <option>-C</option>|<option>--cdc_file</option>.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--lo_import</option></term>
      <listitem>
      <para>
      Use <application>psql</application> <command>\lo_import</command>
      command to import BLOBs as large
      objects. Can be used to import data with <literal>COPY</literal>
      and import the large object manually in a second pass. It is required
      for BLOBs larger than 1GB.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--mview_as_table</option></term>
      <listitem>
      <para>
      Comma-separated list of materialized views to export
      as regular tables.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--drop_if_exists</option></term>
      <listitem>
      <para>
      Drop the object before creation if it exists.
      </para>
      </listitem>
    </varlistentry>

    <varlistentry>
      <term><option>--offline</option></term>
      <listitem>
      <para>
       Convert exported data without the connection to the Oracle database.
      </para>
      </listitem>
    </varlistentry>
  </variablelist>

  <para>
    <application>ora2pgpro</application> returns 0 on success,
    1 on error. It returns 2 when a child process has been interrupted
    and you received the warning message: <quote>WARNING: an error occurs
    during data export. Please check what's happen.</quote> Most of the time
    this is an OOM issue, first try reducing
    <xref linkend="ora2pgpro-data-limit"/> value.
  </para>
  <para>
    Note that performance might be improved by updating stats on
    Oracle:
  </para>
<programlisting>
DBMS_STATS.GATHER_SCHEMA_STATS
DBMS_STATS.GATHER_DATABASE_STATS
DBMS_STATS.GATHER_DICTIONARY_STATS
</programlisting>
  <para>
    The two options <option>--project_base</option> and
    <option>--init_project</option>, when used, indicate that
    <application>ora2pgpro</application> has to create a project template
    with a work tree, a configuration file and a script to export all objects
    from the Oracle database. Here is a sample
    of the command usage:
  </para>
<programlisting>
ora2pgpro --project_base /app/migration/ --init_project test_project
	Creating project test_project.
	/app/migration/test_project/
		schema/
			dblinks/
			directories/
			functions/
			grants/
			mviews/
			packages/
			partitions/
			procedures/
			sequences/
			synonyms/
			tables/
			tablespaces/
			triggers/
			types/
			views/
		sources/
			functions/
			mviews/
			packages/
			partitions/
			procedures/
			triggers/
			types/
			views/
		data/
		config/
		reports/

	Generating generic configuration file
	Creating script export_schema.sh to automate all exports.
	Creating script import_all.sh to automate all imports.
</programlisting>

  <para>
    It creates a generic configuration file where you define
    the Oracle database connection and a shell
    script called <filename>export_schema.sh</filename>.
    The <filename>sources/</filename> directory will contain
    the Oracle code,
    the <filename>schema/</filename> will contain the code ported
    to Postgres Pro. The
    <filename>reports/</filename> directory will contain the HTML reports
    to help assess the migration cost.
  </para>
  <para>
    If you want to use your own default configuration file, use
    the <option>-c</option> option to give the path to that file.
    Rename it with the <literal>.dist</literal> suffix if you
    want <application>ora2pgpro</application> to apply the generic
    configuration values, the configuration file will be copied untouched
    otherwise.
  </para>
  <para>
    Once you have set the connection to the Oracle
    database, you can execute the script <filename>export_schema.sh</filename>
    that will export all object type from your Oracle
    database and output DDL files into the schema subdirectories.
    At end of the export, it will give you the command to export data
    later when the import of the schema will be done and verified.
  </para>
  <para>
    You can choose to load the DDL files generated manually or use the
    second script <filename>import_all.sh</filename> to import those
    files interactively. If this kind of migration is not currently in progress
    for you, it is recommended you to use those scripts.
  </para>
  </refsect2>
  </refsect1>

  <refsect1 id="pbk-authors">
   <title>Authors</title>
    <para>
     Postgres Professional, Moscow, Russia.
    </para>
  </refsect1>
</refentry>
