Skip to content

Import a database from elsewhere

When a database already runs somewhere else, on a managed service or on a server of your own, Flui can bring it over without a long stop. It copies the schema and the data into a PostgreSQL or MariaDB installed from the catalog, then keeps applying every change made on the old database while your application still uses it. When you are ready, you stop writing to the old one, switch, and point your application at Flui.

The import goes from PostgreSQL to PostgreSQL and from MariaDB to MariaDB. It does not convert between database engines, and it does not import from MySQL yet.

Before you start

On a PostgreSQL you import from:

  • wal_level is logical. On a managed service this is a parameter, such as rds.logical_replication on Amazon RDS, and changing it needs a restart.

  • The user you give Flui can replicate and create a publication for every table: a superuser, or rds_superuser on RDS.

  • One replication slot is free.

  • The version is between PostgreSQL 10 and 17. On a MariaDB you import from:

  • Binary logging is on (log_bin), with binlog_format set to ROW.

  • The user you give Flui has REPLICATION SLAVE, BINLOG MONITOR and RELOAD on every database, and can read the one you import.

Either way, the old database accepts connections from your cluster’s address, and the cluster’s outbound rules let its port out. Outbound traffic is open unless someone limited it; flui cluster egress <cluster> shows the rule.

On Flui, install a PostgreSQL or a MariaDB from the catalog and leave it empty. Flui refuses to import into a database that already holds tables, so nothing is ever overwritten.

Start the import

Open the Flui database. On its Overview, under Import from another PostgreSQL (or MariaDB), enter the host, port, database, user and password of the old database, choose how to use TLS, and select Start the import.

Flui checks the old database first and stops, with the reason, if something above is missing. Then it copies the schema and the data. A MariaDB copy is one consistent snapshot, streamed straight into the Flui database; replication then starts from the exact point the snapshot was taken, so nothing is lost or applied twice. The password is kept encrypted while the import runs and deleted when it ends.

Follow it

The import moves through these states:

StateMeaning
CheckingFlui reads the old database and copies the schema.
CopyingThe tables are being copied.
Copied, changes followEvery table is here, and each new change on the old database is applied within moments. You can switch.
SwitchingFlui waits for the last changes, then detaches.
ImportedDone. The two databases are no longer connected.

The dashboard and flui db import my-postgres show how many tables are copied and how far behind the copy is: in bytes for PostgreSQL, in seconds for MariaDB.

Switch

  1. Stop every write to the old database: stop your application, or put it in maintenance. Flui cannot stop the writes for you.
  2. Switch: Switch to Flui in the dashboard, or flui db import my-postgres --switch.
  3. Flui waits until nothing is left to apply and detaches. On PostgreSQL it also sets every sequence to the value it had on the old database, so new rows do not collide with copied ones; on MariaDB the auto-increment counters travel with the tables.
  4. Point your application at the Flui PostgreSQL (see Connect an application to PostgreSQL) and start it.

If changes keep arriving, the switch stops and says so. The import goes on, and you can switch again once the writes have stopped.

Cancel

Cancel the import, or flui db import my-postgres --cancel, stops following the old database. What was already copied stays in the Flui PostgreSQL.

What the import changes on the old database

On MariaDB, nothing: the Flui database reads the old one’s binary log like any replica would.

On PostgreSQL, only what it needs, all removed when it ends, whether it ends with a switch or a cancel:

  • a publication and a replication slot, both named flui_import_ followed by part of the import id;
  • on tables without a primary key, a full replica identity, so their updates and deletes can be copied. Flui lists those tables and sets them back at the end.

If the old database cannot be reached at the end, Flui says what is left there and how to remove it. An unused replication slot keeps the old database from freeing its write-ahead log, so remove it.

What is not copied

  • Changes to the schema made after the import started. Make them on both sides, or after the switch.
  • On MariaDB, other databases on the same server. Only the database you name is followed, even when a statement run from it writes elsewhere.
  • Large objects (lo_*). Tables, including bytea columns, are copied.
  • Roles and their passwords. The Flui PostgreSQL has its own user.