Skip to main content

Migrate a Postgres database to Lakebase

Beta

This feature is in Beta.

A one-time migration copies an existing Postgres database into a branch in a Lakebase project. You choose the target project and branch, and Lakebase copies the source database's roles, schema, and data into it.

When to use a migration​

Migrate your database when you want a single, complete copy of it and you can cut over at one point in time.

Use a different method in these cases:

To compare all the ways to move data in and out of Lakebase, see Move data in and out of Lakebase.

How a migration works​

You can create and manage migrations in the Lakebase App, or programmatically with the Python SDK, Java SDK, Databricks CLI, curl, or Go SDK. Where an operation is available more than one way, this page shows the instructions together as tabs. Migrations don't require a separate enablement step.

The programmatic examples require Python SDK 0.163.0, Java SDK 0.177.0, or Databricks CLI 1.26.0 (or above). The migration commands are hidden from the databricks postgres --help list, but databricks postgres <command> --help shows each command's usage.

A migration runs in these stages:

Stage

What happens

Create

You name the migration, choose a Unity Catalog connection to the source database, and list the databases to copy. Creating the migration starts the first assessment.

Assess

Lakebase runs a set of checks against the source. Each check passes, raises a warning, or blocks the migration. See Lakebase migration assessment checks.

Resolve

You fix blockers on the source and re-run the assessment, or acknowledge the warnings.

Start

You choose the target project and branch, and then start the migration. Lakebase loads the roles and schema, and then copies the data one database at a time.

Finish

You set role passwords, re-apply ownership and privileges, and point your applications at Lakebase.

Stage

What happens

Create

You name the migration, choose a Unity Catalog connection to the source database, and list the databases to copy. Creating the migration starts the first assessment.

Assess

Lakebase runs a set of checks against the source. Each check passes, raises a warning, or blocks the migration. See Lakebase migration assessment checks.

Resolve

You fix blockers on the source and re-run the assessment, or acknowledge the warnings.

Start

You choose the target project and branch, and then start the migration. Lakebase loads the roles and schema, and then copies the data one database at a time.

Finish

You set role passwords, re-apply ownership and privileges, and point your applications at Lakebase.

A migration is a one-time copy, not continuous replication. It brings most of your database across automatically and leaves a few things for you to set up on the target:

Copied automatically

You configure manually

Roles (names and memberships)

Role passwords

Schema, table data, and sequence values

Object ownership and privileges (GRANTs)

Copied automatically

You configure manually

Roles (names and memberships)

Role passwords

Schema, table data, and sequence values

Object ownership and privileges (GRANTs)

For the complete list of what is and isn't copied, see What a migration copies.

Prerequisites​

  • A workspace in a region where migrations are available. See Region availability.
  • A Unity Catalog connection of type PostgreSQL to the source database that uses username and password authentication, and the USE CONNECTION privilege on it. In the Lakebase App, you can create the connection while you create the migration. The connection uses TLS with full certificate verification. See Run federated queries on PostgreSQL.
  • The CAN MANAGE permission on the target Lakebase project. See Manage project permissions.
  • A target project that runs PostgreSQL 17 or above, with a branch that has at least one compute. See Manage projects.
  • Target database names that don't already exist on the target branch. By default, each target database uses the name of its source database.

For the source requirements that the assessment checks, such as supported PostgreSQL versions and the 500 GB limit on each source database, see Lakebase migration assessment checks.

Step 1: Create a migration​

Creating a migration saves its configuration and starts the first assessment. Each migration copies between 1 and 10 databases from one source.

  1. In the Lakebase App, click Migrations in the sidebar.

  2. Click Create migration. If you don't have any migrations yet, click Create new migration.

  3. On the Connect to source step, enter a name for the migration. The name must be 1 to 63 characters, start with a lowercase letter, and contain only lowercase letters, numbers, and hyphens.

  4. For the migration type, select One-time copy.

  5. Connect to the source database:

    • To create a Unity Catalog connection, select Create new connection, and then enter the connection name, host, port, user, and password.
    • To use a Unity Catalog connection that already exists, select the option to use an existing connection, and then select the connection. Only PostgreSQL connections are listed.

    The following image shows the Connect to source step with One-time copy and an existing connection selected.

    Connect to source step of the Create new migration wizard, with One-time copy and an existing connection selected.

  6. On the Map databases step, enter the name of the first database to copy in Source database name. To copy more databases, click Add database for each one. To give a copy a different name, enter the name in Lakebase database name. Leave the field empty to keep the original name.

  7. On the Review step, confirm the source connection and databases, and then click Create migration & start assessment.

Step 2: Review the assessment​

A migration assessment runs a check for each source requirement and returns one of these verdicts for each check: Pass, Warning, Blocker, Unsupported, or Error. Any Blocker, Unsupported, or Error result blocks the migration. For the full list of checks, see Lakebase migration assessment checks.

To review an assessment in the Lakebase App:

  1. Click Migrations in the sidebar and select the migration.

  2. On the Overview tab, review the Assessments card. It shows the number of blockers, warnings, and passes, and lists the checks with the most severe results first. To see every check, click See more or open the Assessments tab.

    The following image shows the Assessments card for an assessment that found two warnings and no blockers.

    Assessments card with the summary of blockers, warnings, and passes, and the check results with warnings listed first.

  3. If the assessment found blockers, fix them on the source database, and then click Re-run assessment.

  4. If the assessment found only warnings, click Review warnings. Select I have reviewed and acknowledge all warnings., and then click Acknowledge warnings.

After every check passes, or after you acknowledge the warnings, the migration's status changes to Ready to start.

An assessment expires 24 hours after it completes. If the latest assessment expired, re-run it before you start the migration. After the first assessment completes, you can't change the migration's source connection or database mappings. To copy different databases, create a new migration.

To get assessment results, re-run an assessment, or acknowledge warnings programmatically, use the following. Assessments are listed newest first, and each one is named migrations/{migration_id}/assessments/{n}, where n is the attempt number.

To print the result of each check in an assessment, run the following. Each check has a check_id, a verdict, and, for checks that don't pass, a reason:

Python
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

assessment = w.postgres.get_assessment(name="migrations/my-migration/assessments/1")
for check in assessment.checks or []:
print(check.check_id, check.verdict, check.reason)

for assessment in w.postgres.list_assessments(parent="migrations/my-migration"):
print(assessment.name)

To re-run the assessment and wait for it to finish, run the following:

Python
w.postgres.assess_migration(name="migrations/my-migration").wait()

To acknowledge the warnings on an assessment, run the following. The call completes immediately:

Python
w.postgres.acknowledge_assessment_warnings(name="migrations/my-migration/assessments/1")

Step 3: Start a migration​

When you start a migration, Lakebase loads the roles and schema into the target branch, then copies data one database at a time. At the start of each database's data copy, Lakebase takes a consistent snapshot of its table rows. The copy excludes row changes from transactions that commit after that snapshot. Databases in the same migration can reflect different points in time.

A branch can be the target of only one migration. Lakebase creates a role named migration-assistant on the target branch to run the migration.

If the target project doesn't allow password connections, starting the migration turns them on for the whole project. They stay on after the migration ends. See Manage password connections.

  1. Click Migrations in the sidebar, and select a migration whose status is Ready to start.

  2. Click Start migration.

  3. On the Lakebase Project step, choose the target project. The project must run PostgreSQL 17 or above.

    • To use an existing project, select Use existing project, choose the project, and click Next. On the Branch step, select the target branch, and then click Next.
    • To create a project, select Create new project, enter a name, and select PostgreSQL 17 or above as the Postgres version. Review the region and the production branch that the migration uses, and then click Create and continue.
  4. On the Review step, review the target, and then click Start migration.

    The following image shows the Review step with the migration type, the source, the destination branch, the database mappings, and the notice about password connections.

    Review step of the Start migration drawer, showing the migration type, source, destination branch, database mappings, and a notice that starting the migration turns on password login for the target project.

Step 4: Monitor the migration​

In the Lakebase App, click Migrations in the sidebar to see each migration's name, source, status, and creation time. Select a migration to follow its progress through these steps: Assess source data, Choose Lakebase target, Schema load, Data load, and Complete.

Migration states​

The Lakebase App shows each migration's status. The API returns the same information in the migration's state field.

Status

API value

Meaning

Draft

MIGRATION_STATE_DRAFT

The migration is saved, and no assessment is running.

Assessing

MIGRATION_STATE_ASSESSING

An assessment is running.

Action required

MIGRATION_STATE_ASSESSMENT_NEEDS_ACTION

The latest assessment found blockers to fix or warnings to acknowledge.

Ready to start

MIGRATION_STATE_READY_TO_START

Every check passed, or you acknowledged the warnings.

Loading schema

MIGRATION_STATE_SCHEMA_LOAD

Lakebase is loading roles and schemas into the target branch.

Copying data

MIGRATION_STATE_INITIAL_DATA_LOAD

Lakebase is copying the data, one database at a time.

Completed

MIGRATION_STATE_COMPLETED

The copy finished.

Failed

MIGRATION_STATE_FAILED

The schema load or the data copy didn't complete.

Status

API value

Meaning

Draft

MIGRATION_STATE_DRAFT

The migration is saved, and no assessment is running.

Assessing

MIGRATION_STATE_ASSESSING

An assessment is running.

Action required

MIGRATION_STATE_ASSESSMENT_NEEDS_ACTION

The latest assessment found blockers to fix or warnings to acknowledge.

Ready to start

MIGRATION_STATE_READY_TO_START

Every check passed, or you acknowledged the warnings.

Loading schema

MIGRATION_STATE_SCHEMA_LOAD

Lakebase is loading roles and schemas into the target branch.

Copying data

MIGRATION_STATE_INITIAL_DATA_LOAD

Lakebase is copying the data, one database at a time.

Completed

MIGRATION_STATE_COMPLETED

The copy finished.

Failed

MIGRATION_STATE_FAILED

The schema load or the data copy didn't complete.

Creating, assessing, and starting a migration return long-running operations. To poll one of these operations, use its name, which has the form migrations/{migration_id}/operations/{operation_id}. For more about long-running operations, see Long-running operations (LROs).

To get a migration's state and list your migrations, run the following. list_migrations follows page tokens for you:

Python
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

migration = w.postgres.get_migration(name="migrations/my-migration")
print(migration.state)

for migration in w.postgres.list_migrations():
print(migration.name, migration.state)

Step 5: Prepare the target after the migration​

After the migration's status changes to Completed, prepare the target databases for your applications:

  1. Set a password for each migrated role that signs in with a password, or switch the role to OAuth authentication. Role passwords aren't copied. See Reset a password and About authentication.
  2. Re-apply object ownership and privileges. The migrated objects are owned by the migration-assistant role, and the source's GRANTs aren't copied. Use ALTER ... OWNER TO and GRANT statements to restore the ownership and privileges that your applications need.
  3. Update your applications to connect to the target branch. See Connection strings.

Delete or restore a migration​

Deleting a migration removes the migration and its assessments. It doesn't delete the target databases or any data copied into them. You can't delete a migration while one of its operations is running.

You can restore a deleted migration for 30 days. After 30 days, the migration is permanently deleted. A deleted migration keeps its target branch until it's permanently deleted, so you can't use that branch as the target of another migration during that time.

To delete a migration in the Lakebase App, click Migrations in the sidebar, open the menu for the migration, and click Delete. To restore a deleted migration, use the API.

To delete a migration and then restore it, run the following. Both calls complete immediately:

Python
from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

w.postgres.delete_migration(name="migrations/my-migration")
w.postgres.undelete_migration(name="migrations/my-migration")

What a migration copies​

This is the complete reference for what a migration does and doesn't copy. Use it to confirm whether a specific object type comes across before you start a migration.

A migration copies the following from each source database:

  • Roles and role memberships
  • Schemas and table definitions
  • Table data, including sequence values
  • Indexes, constraints, triggers, and row-level security policies
  • Materialized views, which are refreshed on the target
  • Extensions on the supported list, installed at the version that Lakebase provides

After the data is copied, Lakebase runs ANALYZE (to refresh the query planner's statistics) on the target databases.

A migration doesn't copy the following:

  • Role passwords. The SUPERUSER, REPLICATION, and BYPASSRLS attributes aren't granted on the target, and roles that the source's hosting provider manages are skipped.
  • Object ownership and privileges (GRANTs). Lakebase creates the target databases and their objects as the migration-assistant role.
  • Tablespace placement.
  • Large objects, publications, and subscriptions.
  • Extensions that aren't on the supported list. The assessment reports each one as a warning.
  • Row changes from transactions that commit after Lakebase takes the snapshot for that source database. The migration doesn't replicate later changes.

Region availability​

Migrations are available wherever Lakebase Autoscaling is available, except in the following regions:

  • ap-southeast-3 (Asia Pacific - Jakarta)
  • us-west-2 (US West - Oregon)

Limitations​

  • Migrations require a workspace in a supported region.
  • Migrations support only the one-time copy type.
  • Each migration copies between 1 and 10 databases from one source.
  • The target project must run PostgreSQL 17 or above, and the target databases must not already exist on the target branch.
  • A branch can be the target of only one migration.
  • Some objects and attributes aren't copied. See What a migration copies.
  • Terraform doesn't support migrations.

Additional resources​