Skip to main content
This page describes best practices for using MOLT Fetch to ensure reliable, secure, and performant data migration to CockroachDB.

Test and validate

To verify that your connections and configuration work properly, run MOLT Fetch in a staging environment before migrating any data in production. Use a test or development environment that closely resembles production.

Configure the source database and connection

  • To prevent connections from terminating prematurely during the data export phase, set the following to high values on the source database:
    • Maximum allowed number of connections. MOLT Fetch can export data across multiple connections. The number of connections it will create is the number of shards (--export-concurrency) multiplied by the number of tables (--table-concurrency) being exported concurrently.
      With the default numerical range sharding, only tables with primary key types of INT, FLOAT, or UUID can be sharded. PostgreSQL users can enable --use-stats-based-sharding to use statistics-based sharding for tables with primary keys of any data type. For details, refer to Table sharding.
    • Maximum lifetime of a connection.
  • If a PostgreSQL database is set as a source, ensure that idle_in_transaction_session_timeout on PostgreSQL is either disabled or set to a value longer than the duration of the data export phase. Otherwise, the connection will be prematurely terminated. To estimate the time needed to export the PostgreSQL tables, you can perform a dry run and sum the value of molt_fetch_table_export_duration_ms for all exported tables.

Memory requirements

  • MOLT Fetch buffers data in memory before flushing to files or the target database, regardless of which data path you use. To prevent memory outages during data export, estimate the amount of memory used to export tables:
    If you are exporting multiple tables concurrently (i.e., --table-concurrency is set higher than 1), estimate the memory requirement using the table with the largest average row size. For details on how concurrency and sharding interact, refer to Table sharding. Insufficient memory can cause degraded throughput, process crashes, or migration failures. To prevent memory issues:

Optimize performance

  • To optimize data load performance, drop all non-PRIMARY KEY constraints and indexes on the target CockroachDB database before migrating:
    Do not drop PRIMARY KEY constraints.
    You can recreate constraints and indexes after loading the data.
  • For PostgreSQL sources using --use-stats-based-sharding, run ANALYZE on source tables before migration to ensure optimal shard distribution. This is especially important for large tables where even distribution can significantly improve export performance.
  • If a table in the source database is much larger than the other tables, filter and export the largest table in its own molt fetch task. Repeat this for each of the largest tables. Then export the remaining tables in another task.
  • Ensure that the machine running MOLT Fetch is equipped to handle the amount of data being migrated. Fetch performance can sometimes be limited by available resources, but should always be making progress. To identify possible resource constraints, observe the molt_fetch_rows_exported metric for decreases in the number of rows being processed. You can use the sample Grafana dashboard to view metrics. For details on optimizing export performance through sharding, refer to Table sharding.

Docker performance

MOLT Fetch is likely to run more slowly in a Docker container than on a local machine. To improve performance, increase the memory or compute resources, or both, on your Docker container.

Import and continuation handling

  • When using IMPORT INTO during the data import phase to load tables into CockroachDB, if the fetch task terminates before the import job completes, the hanging import job on the target database will keep the table offline. To make this table accessible again, manually resume or cancel the job. Then resume molt fetch using continuation, or restart the task from the beginning.

Security

Cockroach Labs strongly recommends the following security practices.

Connection security

  • To keep your database credentials out of shell history and logs, follow these best practices when specifying your source and target connection strings:
    • Avoid plaintext connection strings.
    • Provide your connection strings in the MOLT_SOURCE and MOLT_TARGET environment variables, which MOLT Fetch and MOLT Verify read in place of --source and --target. For Oracle multitenant sources, MOLT_SOURCE_CDB replaces --source-cdb. For example:
      Afterward, omit --source and --target from MOLT commands. Unlike connection strings passed as flags, the environment variables do not appear in the process list. If you set both a flag and its environment variable, the flag takes precedence.
    • If possible, use an external secrets manager to load the environment variables from stored secrets.
  • Use TLS-enabled connection strings to encrypt data in transit from MOLT to the database. When using TLS certificates, ensure certificate files are accessible to the MOLT binary on the same machine. For example, a PostgreSQL connection string with TLS certificates:
    MySQL source connection strings use the MySQL names for TLS parameters: ssl-mode (DISABLED, PREFERRED, REQUIRED, VERIFY_CA, or VERIFY_IDENTITY), ssl-ca, ssl-cert, and ssl-key. MOLT rejects the PostgreSQL names (sslmode, sslrootcert, sslcert, and sslkey) in a MySQL connection string. For example, a MySQL connection string with TLS certificates:
  • URL-encode connection strings for the source database and CockroachDB so special characters in passwords are handled correctly.
    • Given a password a$52&, pass it to the molt escape-password command with single quotes:
      Use the encoded password in your connection string. For example:
  • Remove sslmode=disable from production connection strings.
By default, insecure connections (i.e., sslmode=disable on PostgreSQL; ssl-mode not set or ssl-mode=DISABLED on MySQL) are disallowed. When using an insecure connection, molt fetch returns an error. To override this check, you can enable the --allow-tls-mode-disable flag. Do this only when testing, or if a secure SSL/TLS connection to the source or target database is not possible.

Connect to Oracle over TLS (TCPS)

By default, connections to Oracle use plain TCP with a standard connection string, and no wallet is needed. TLS-encrypted connections to Oracle use the TCPS protocol and require an Oracle wallet. A wallet is recommended for production deployments and required when the Oracle database listener accepts only TCPS connections. The wallet directory must contain the following three files:
tnsnames.ora must define a TCPS alias. The alias name (in this example, MY_ORACLE_TLS) must match the @{alias} in your connection string:
sqlnet.ora must point the Oracle client at the wallet directory:
The following requirements apply when connecting to Oracle over TCPS:
  • A TNS alias is required. The oracle://{host}:{port}/{service_name} URL form uses plain-TCP EZCONNECT and fails against a TCPS listener with ORA-12537: TNS:connection closed. Always connect via the @{alias} defined in tnsnames.ora.
  • Auto-login wallets only. The Oracle client driver has no wallet-password option, so use an auto-login wallet (cwallet.sso). Because the wallet contains credentials, store it in a directory that only the user running the tool can read.
  • Oracle Instant Client basic variant required. TLS requires the full basic client; basiclite may be missing the required TLS libraries.
How you obtain or create the wallet depends on your Oracle deployment. Refer to the documentation for your Oracle environment or managed service provider. Pass the wallet directory to MOLT Fetch with --source-oracle-wallet-location. For Oracle Multitenant databases, a single wallet location applies to both --source (PDB) and --source-cdb (CDB); define TCPS aliases for both endpoints in the wallet’s tnsnames.ora. For example, to load data from an Oracle database over TCPS, connect via the TNS alias and pass the wallet directory:

Cloud storage security

Ensure that access control is properly configured for Amazon S3, Google Cloud Storage, or Azure Blob Storage.
Amazon S3
  • Set the following environment variables in the terminal running molt fetch:
    • To run molt fetch in a containerized environment (e.g., Docker), pass the required environment variables using -e. If your authentication method relies on local credential files, you may also need to volume map the host path to the appropriate location inside the container using -v. For example:
  • Alternatively, set --use-implicit-auth to use implicit authentication. When using assume role authentication, specify the service account with --assume-role. For example:
  • Set --import-region to specify an AWS_REGION (e.g., --import-region 'ap-south-1').
  • By default, MOLT Fetch does not get credentials from the AWS EC2 instance metadata service (IMDS). This prevents long delays on hosts outside AWS. If you run MOLT Fetch on EC2 and use the instance profile for credentials, set AWS_EC2_METADATA_DISABLED=false. Other credential sources, such as environment variables and the shared credentials file, are not affected.
  • Ensure the S3 bucket is created and accessible by authorized roles and users only.

See also