Invoking Migration Toolkit
==========================

.. container:: registered_link
   :name: invoking_mtk

After installing Migration Toolkit and specifying connection properties
for the source and target databases in the :ref:`toolkit.properties file <Specifying connection properities>`  , Migration
Toolkit is ready to perform migrations.

The Migration Toolkit executable is named ``runMTK.sh`` on Linux systems
and ``runMTK.bat`` on Windows systems. On a Linux system, the executable
is located in:

``/usr/edb/migrationtoolkit/bin``

On Windows, the executable is located in:

``C:\Program Files\edb\mtk\bin``

See :ref:`Migration Toolkit command options <Migration Toolkit command options>`  for information on controlling details of the
migration.

..  Note::
   If the following error appears upon invoking the Migration Toolkit, check the file permissions of the `toolkit.properties`  file.

.. code:: text

   MTK-11015: The connection credentials file ../etc/toolkit.properties is
   not secure and accessible to group/others users. This file contains
   plain passwords and should be restricted to Migration Toolkit owner user
   only.

The operating system user account running the Migration Toolkit must be
the owner of the ``toolkit.properties`` file with a minimum of read
permission on the file. In addition, there must be no permissions of any
kind for group and other users. The following is an example of the
recommended file permissions, where user enterprisedb is running the
Migration Toolkit.

``-rw------- 1 enterprisedb enterprisedb 191 Aug 1 09:59 toolkit.properties``

Importing character data with embedded binary zeros (NULL characters)
---------------------------------------------------------------------

Migration Toolkit supports importing a column with a value of NULL.
However, Migration Toolkit doesn’t support importing NULL character
values (embedded binary zeros 0x00) with the JDBC connection protocol.
If you’re importing data that includes the NULL character, use the
``-replaceNullChar`` option to replace the NULL character with a single,
non-NULL, replacement character.

..  Note::
   -   MTK implicitly replaces NULL characters with an empty string. -   The `-replaceNullChar`  option doesn't work with the `-copyViaDBLinkOra`  option.

Once the data is migrated, use a SQL statement to replace the character
specified by ``-replaceNullChar`` with binary zeros.

Migrating a schema from Oracle
------------------------------

Unless specified in the command line, Migration Toolkit expects the
source database to be Oracle and the target database to be EDB Postgres
Advanced Server. To migrate a complete schema on Linux, navigate to the
executable and invoke the following command:

``$ ./runMTK.sh <schema_name>``

To migrate a complete schema on Windows, navigate to the executable and
invoke the following command:

``> .\runMTK.bat <schema_name>``

Where:

``<schema_name>`` is the name of the schema in the source database
specified in the ``toolkit.properties`` file that you want to migrate.
You must include at least one ``schema_name`` value.

..  Note::
   - When the default database user of a migrated schema is automatically migrated, the custom profile of the default database user is also migrated if a custom profile exists. A custom profile is a user-created profile. For example, custom profiles exclude Oracle profiles `DEFAULT`  and `MONITORING_PROFILE` . - PostgreSQL default rows are limited to 8 KB in size. This means that each table row must fit into a single 8 KB block, Otherwise, an error occurs indicating, for example, that we can create a table with 1600 columns of INT and insert data for all the columns. However, we can't do the same with BIGINT columns because INT is stored as 4 bytes, but each BIGINT requires more space (8 bytes). For more information, see  `PostgreSQL Limits <https://www.postgresql.org/docs/14/limits.html>`_  in the PostgreSQL documentation.

You can migrate multiple schemas by following the command name with a
comma-delimited list of schema names.

On Linux, execute the following command:

``$ ./runMTK.sh <schema_name1>,<schema_name2>,<schema_name3>``

On Windows, execute the following command:

``> .\runMTK.bat <schema_name1>,<schema_name2>,<schema_name3>``

.. container:: registered_link
   :name: migrate_non_oracle

Migrating from a non-Oracle source database
-------------------------------------------

If you don’t specify a source database type and a target database type,
Postgres assumes the source database is Oracle and the target database
is EDB Postgres Advanced Server.

To invoke Migration Toolkit, open a command window, navigate to the
executable, and invoke the following command:

``$ ./runMTK.sh -sourcedbtype <source_type> -targetdbtype <target_type> [options, …] <schema_name>;``

``-sourcedbtype <source_type>``

``<source_type>`` specifies the server type of the source database.
``<source_type>`` isn’t case sensitive. By default, ``<source_type>`` is
oracle. ``source_type`` can be one of the following values:

.. csv-table::
  :header: To migrate from:,Specify:
  :widths: 10,30
  :align: left
  :class: longtable

  Oracle,oracle (the default value)
  MySQL,mysql
  SQL Server,sqlserver
  Sybase,sybase
  PostgreSQL,postgres or postgresql
  EDB Postgres Advanced Server,enterprisedb

``-targetdbtype <target_type>``

``<target_type>`` specifies the server type of the target database.
``<target_type>`` isn’t case sensitive. By default, ``<target_type>`` is
``enterprisedb`` . ``<target_type>`` can be one of the following values:

.. csv-table::
  :header: To migrate to:,Specify:
  :widths: 10,30
  :align: left
  :class: longtable

  EDB Postgres Advanced Server,enterprisedb
  PostgreSQL,postgres or postgresql

``<schema_name>``

``<schema_name>`` is the name of the schema in the source database
specified in the ``toolkit.properties`` file that you want to migrate.
You must include at least one ``<schema_name>`` value.

The following example migrates a schema (table definitions and table
content) named ``HR`` from a MySQL database on a Linux system to an EDB
Postgres Advanced Server host. The command includes the
``‑sourcedbtype`` and ``-targetdbtype`` options.

On Linux, use the following command:

``$ ./runMTK.sh -sourcedbtype mysql -targetdbtype enterprisedb HR``

On Windows, use the following command:

``> .\runMTK.bat -sourcedbtype mysql -targetdbtype enterprisedb HR``

You can migrate multiple schemas from a source database by including a
comma-delimited list of schemas at the end of the Migration Toolkit
command. The following example migrates multiple schemas (named HR and
ACCTG) from a MySQL database to a PostgreSQL database.

On Linux, use the following command:

``$ ./runMTK.sh -sourcedbtype mysql -targetdbtype postgres HR,ACCTG``

On Windows, use the following command:

``> .\runMTK.bat -sourcedbtype mysql -targetdbtype postgres HR,ACCTG``

.. toctree::
  :maxdepth: 3

  07_08_mtk_command_options