Documentation

esc
    Move to Pantech / Import databases

    Import databases

    Copy a PostgreSQL or MySQL database into a Pantech managed database through the Pantech Migrate agent, once or with low-downtime replication for PostgreSQL, with a readiness check before and verification after.

    A database import copies one database from your other cloud, or from your own servers, into a Pantech managed database. The Pantech Migrate agent, running inside your network, reads the source with a login that stays on it. Pantech applies what it sends inside your Pantech database, then counts and checks every table on both sides.

    ModeWhat it doesEngines
    dumpCopies the database once. Stop writes to the source firstPostgreSQL, MySQL, MariaDB
    replicateCopies the database, then keeps applying the source's changes until you cut over, so the downtime is only the cutoverPostgreSQL only

    Low-downtime replication for MySQL and MariaDB is not available yet: a replicate import of one is blocked with mode_not_available. Use dump.

    You need:

    • a plan with the database as a database item (scan and plan). RDS and Aurora, Cloud SQL, Azure Database, Huawei Cloud RDS, DigitalOcean, Linode and Vultr databases are planned from a scan;
    • a Pantech database to import into, with the same engine family as the source (MySQL into MySQL, MariaDB into MariaDB), on the same or a newer major version, with room for the data. Create it first: it bills as usual, and the import itself is free. Databases created before imports were available cannot take one (destination_not_supported): create a new one;
    • the Pantech Migrate agent program running where it can reach the source database, enrolled for the plan's connection (any connection: on AWS, Google Cloud, Azure and Huawei Cloud too), on a host with the database's dump tools;
    • to be an Owner or Admin, and allowed to change the destination database (databases:Update).

    1. Tell the agent about the source

    The source's address, user and password are configured on the agent, under a name of your choice: its source_ref, 1 to 64 letters, digits, ., _ and -. Add it under database_sources in the agent's configuration file, with the connection string in an environment variable (dsn_env) or in a file only the agent's user can read (dsn_file):

    config.json
    {
      "database_sources": {
        "orders-prod": {"engine": "postgres", "dsn_env": "ORDERS_DSN"},
        "shop":        {"engine": "mysql", "dsn_file": "/etc/pantech-migrate/shop.dsn"}
      }
    }

    engine is postgres, mysql or mariadb. The connection string is read only when an import runs, and only on the agent's machine. Pantech stores only the name, and every job names the source by it: no host, user or password is ever sent to Pantech. The agent refuses a dsn_file other users can read (chmod 600 it), and a configuration file other users can change.

    Give the agent a login that can read every table to copy. For replicate it also needs to replicate (see the readiness check). The agent runs pg_dump or mysqldump locally to read the schema, so run the agent program (not the container, which has neither) on a host with the client tools installed, at least as new as the source server.

    Then check that the agent can open each source, without sending anything to Pantech:

    Terminal
    $ ORDERS_DSN=… pantech-migrate-agent checkdatabase source orders-prod: ok (postgres)

    Restart the agent after changing its configuration. It takes imports only while its configuration names at least one source.

    2. Start the import

    Terminal
    $ curl -X POST https://api.pantechdynamics.com/public/v1/migrations/mig_06gk3x9tq7m2v8r4y1c5d0zp8w/database-imports \    -H "Authorization: Bearer $PANTECH_API_KEY" \    -H "Idempotency-Key: $(uuidgen)" \    -H "Content-Type: application/json" \    -d '{"item_key": "database:us-east-1:orders-db", "destination_database_id": "db_06gk3x9tq7m2v8r4y1c5d0zp8w", "mode": "replicate", "source_ref": "orders-prod"}'
    FieldWhat it is
    item_keyOne of the plan's database items
    destination_database_idYour Pantech database, with the same engine as the source
    target_databaseThe database to create and fill on the destination. It must be empty. Defaults to the source's name, made valid: 1 to 63 lowercase letters, digits and underscores, starting with a letter
    modedump or replicate
    source_refThe source's name in the agent's configuration

    The import is awaiting agent until the agent picks it up. An agent whose configuration has no source by that name fails the import with source_not_configured. One database can have one import in progress.

    3. The readiness check

    The agent measures the source and Pantech measures your database, then the import compares them and lists what it found in readiness.issues. A blocking issue stops the import (blocked) until you fix it and ask for the check again with POST /database-imports/{import_id}/readiness. Each issue has a message, and where your provider has one, a copy-paste fix.

    IssueBlockingWhat it means
    engine_family_mismatch✓The source and your Pantech database run different engines. Choose a Pantech database with the same engine
    source_version_newer✓The source runs a newer major version than your Pantech database. Import into a database on the same or a newer version
    version_upgradeYour Pantech database runs a newer major version. Test your application against it before going live
    version_not_measuredOne side did not report its version, so they were not compared
    extension_unavailable✓A PostgreSQL extension the source uses is not available on your Pantech database
    size_exceeds_storage✓The source holds more than the free space on your Pantech database. Grow its storage first
    size_near_storageThe source holds over 70% of the free space. Indexes are rebuilt during the import and need room
    size_not_measured, destination_space_not_measuredOne side's size was not measured, so it was not checked
    table_without_primary_key✓ for replicateTables without a primary key. Replication needs one on every table; a dump copies them whole, starting again if the copy is interrupted
    too_many_tables✓An import takes at most 2,000 tables
    replication_check_failed✓ for PostgreSQL replicateA replication setting is missing on the source: see below
    mode_not_available✓Low-downtime import is not available yet for MySQL and MariaDB. Use dump
    target_not_empty✓The target database already has tables. Import into an empty database
    destination_not_ready✓Your Pantech database has not reported back yet. Check readiness again in a minute
    destination_not_supported✓Your Pantech database was created before imports were available. Create a new database for the import

    What the agent measured is in readiness.source (engine, version, provider, size, extensions, table count), and what your database reported in destination (its version, free and total disk, existing tables, trusted extensions). A value that could not be measured is null, never a guess.

    Setting up the source for replicate

    For a PostgreSQL replicate import, the readiness check gives the fix for the provider it detected:

    RequirementAWS RDS and AuroraGoogle Cloud SQLAzure Database for PostgreSQLSelf-hosted
    Logical replicationIn the DB parameter group, set rds.logical_replication = 1, then rebootSet the flag cloudsql.logical_decoding = onSet the server parameter wal_level = logical, then restartALTER SYSTEM SET wal_level = logical; then restart
    A login that can replicateGRANT rds_replication TO <user>;ALTER USER <user> WITH REPLICATION;ALTER ROLE <user> WITH REPLICATION;ALTER ROLE <user> WITH REPLICATION;
    A free slot and senderRaise max_replication_slots and max_wal_senders so one of each is free, then rebootRaise the same flagsRaise the same parameters, then restartRaise the same settings, then restart
    A primary key on every tableALTER TABLE … ADD PRIMARY KEY …The sameThe sameThe same

    For MySQL and MariaDB the check already reports the binary log settings replication will need (log_bin on, binlog_format = ROW, binlog_row_image = FULL, and a login with REPLICATION SLAVE, REPLICATION CLIENT), so you can prepare the source now.

    4. The copy

    Once nothing blocks it, the import copies. For replicate, the agent first creates a publication and a logical replication slot on the source (pantech_migrate_…), so every change from then on is kept for the import.

    • Schema first, then rows, then indexes. Tables are created, rows are copied a page at a time by primary key from one consistent snapshot, then indexes, constraints and triggers are added, as a restore orders them. Sequences are set at the end.
    • Rows are values. Rows travel as data and are loaded as data, never as SQL. Only the schema arrives as SQL, and it is checked first (below).
    • It resumes. Every page can be sent again without making duplicates, so an interruption on any side costs a re-send of the last page.
    • Per-table progress is in tables: each table's status (pending, copying, copied, verified or verify_failed), pages, rows and bytes.

    A replicate import moves on to replicating: it applies each change the source commits, one transaction at a time, and lag_bytes shows how far behind it is.

    5. Cut over, or finish

    • dump: once every table is copied, POST /database-imports/{import_id}/cutover. Sequences are set and every table is verified.
    • replicate: stop writes to the source, then cut over. The import applies the remaining changes until there is no lag, verifies, removes its access, and the agent drops the replication slot and publication on the source.

    Then point your application at the Pantech database's hostname with your own login.

    Verification

    For each table, the row count is compared exactly on both sides, and up to 8 ranges of rows (the first, the last and others chosen the same way on both sides) are checksummed value by value. A table that does not match leaves the import verifying_failed, with the table named: nothing is removed automatically, so you can look into it, then revoke access or cancel.

    How Pantech reaches your database

    Your Pantech database has no public address, and an import does not give it one. The data goes from the agent to Pantech over encrypted connections, and Pantech writes it into your database over an encrypted, private connection.

    For the import, Pantech creates a temporary login on your database, pantech_import: its password is generated for the import and never shown or stored; it holds no more than your own admin login, on the target database only; and every object it creates belongs to your admin login. The engine also expires it after a day. It is removed when the import completes, is cancelled or fails, or when you remove it yourself:

    Terminal
    $ curl -X POST https://api.pantechdynamics.com/public/v1/database-imports/dbi_06gk3x9tq7m2v8r4y1c5d0zp8w/revoke-access \    -H "Authorization: Bearer $PANTECH_API_KEY" \    -H "Idempotency-Key: $(uuidgen)"

    revoke-access keeps the data; an import still copying stops. destination.access_state shows where the login is: not_prepared, requested, active, revoking, revoked or failed.

    What the schema may not do

    The schema is the only SQL an import sends, and the agent and Pantech both check every statement before it runs. An import stops with statement_refused for statements that manage roles, users or grants, create or drop databases or tablespaces, change server settings or replication, read or write files on the server, load code (C or untrusted languages, plugins), create event triggers, publications or subscriptions, or create an extension your Pantech database does not offer as trusted. In MySQL and MariaDB, DEFINER clauses are removed by the agent before the schema is sent. Everything runs as a login with no superuser rights, so even a statement that slipped past could not leave the target database.

    Cancel

    POST /database-imports/{import_id}/cancel stops the import and removes its access to your database. What was already copied stays. The agent drops its replication slot and publication on the source. If the agent is gone, drop the slot yourself, or it keeps holding the source's write-ahead log: SELECT pg_drop_replication_slot('<slot name>');.

    Statuses

    awaiting_agent → preflight → ready or blocked → copying → replicating (replicate only) → cutting_over → verifying → completed. From any of them, cancelling → cancelled, or failed with a failure.code. verifying_failed keeps the import's access until you revoke it or cancel. Troubleshooting explains every failure.

    Limits

    • 3 imports in progress per organization, and one per destination database.
    • 2,000 tables per import.
    • The move is free; the destination database bills as usual.

    Was this page helpful?

    Updated