> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bytebase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Synchronize Database Schemas

Database schema synchronization ensures consistency across multiple databases by replicating schema changes from a source to target databases. This eliminates manual SQL writing and reduces deployment errors.

Bytebase's **Sync Schema** feature enables:

* Replicating schemas to new databases
* Synchronizing changes across environments (dev → staging → prod)
* Rolling back to previous schema versions

This tutorial demonstrates three common synchronization scenarios using the Bytebase UI.

## Start Bytebase with sample data

1. Ensure Docker is running, then start the Bytebase container:

   ```bash theme={null}
   docker run --rm --init \
     --name bytebase \
     --publish 8080:8080 --pull always \
     --volume ~/.bytebase/data:/var/opt/bytebase \
     bytebase/bytebase:latest
   ```

   <img src="https://mintcdn.com/dbx/vw8BbfZhlW9y-cr_/content/docs/tutorials/shared/dk-bb-running.webp?fit=max&auto=format&n=vw8BbfZhlW9y-cr_&q=85&s=cf0be18b5f9bfc3ff7c06b8276cd2466" alt="dk-bb-running" width="1536" height="120" data-path="content/docs/tutorials/shared/dk-bb-running.webp" />

2. Open Bytebase in [localhost:8080](http://localhost:8080/), fill in the fields and click **Create admin account**. You'll be redirected to Workspace.

   <img src="https://mintcdn.com/dbx/vw8BbfZhlW9y-cr_/content/docs/tutorials/shared/account.webp?fit=max&auto=format&n=vw8BbfZhlW9y-cr_&q=85&s=89bfcf723a14ae15e941e00db24435b4" alt="account" width="3840" height="1936" data-path="content/docs/tutorials/shared/account.webp" />

3. During workspace setup, choose the built-in sample data.

   <img src="https://mintcdn.com/dbx/vw8BbfZhlW9y-cr_/content/docs/tutorials/shared/bb-setup-built-in-sample.webp?fit=max&auto=format&n=vw8BbfZhlW9y-cr_&q=85&s=8950dabf39d43da14c0e690c95084a48" alt="setup-built-in-sample-data" width="1024" height="664" data-path="content/docs/tutorials/shared/bb-setup-built-in-sample.webp" />

## Case 1 - Sync schema to a new database

Use this when setting up a new environment or scaling out your database infrastructure.

1. In `Sample Project`, navigate to **Database > Databases**. You'll see `hr_test` (Test) and `hr_prod` (Prod) databases.

2. Click **+ New DB** and configure:

   * **Name**: `hr_prod_2`
   * **Environment**: `Prod`
   * **Instance**: `Prod Sample Instance`
   * **Database owner name**: `bbsample`
     <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-new-db-prod-2.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=7b50f0a9be7a884b0751646ccb5fc778" alt="bb-new-db-prod-2" width="2280" height="1070" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-new-db-prod-2.webp" />

3. Click **Create**. An issue is created and executed automatically. Wait for it to complete.
   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/how-to-synchronize-database-schemas/bb-new-db-prod-2-issue.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=a2ec8979ea7fa46e4ef97081f24fa676" alt="bb-new-db-prod-2-issue" width="2542" height="1234" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-new-db-prod-2-issue.webp" />

4. Click **Sync Schema** in the left sidebar. Select `hr_prod` as the source and click **Next**.
   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-source.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=f6accb996e6477e5250fbb3990766ed6" alt="bb-sync-schema-source" width="2110" height="984" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-source.webp" />

5. Select `hr_prod_2` as the target database and click **Select**.
   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-all-selected.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=8046f8c2085157674fa151511a239f40" alt="bb-sync-schema-all-selected" width="2104" height="980" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-all-selected.webp" />

6. Review the calculated schema differences and generated DDL statements. Click **Preview Issue**.
   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-before-preview.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=9cf54ca8b141495b5e7f22c6fb832c8e" alt="bb-sync-schema-before-preview" width="2122" height="1122" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-before-preview.webp" />

7. Click **Create**, then **Ready for Review**. Navigate to **Rollout** and click **Run**. The schema is now synchronized to the new database.

## Case 2 - Sync schema from one to many

Use this for:

* Promoting changes across environments (dev → staging → prod)
* Multi-tenant SaaS deployments
* Multi-region database synchronization

1. Navigate to **CI/CD > Plans** and click **+ New Plan**.

2. Select **Schema Migration** and choose only `hr_test` as the target database.

3. Use the **Schema Editor** to add a new column:

   * **Name**: `email`
   * **Type**: `text`
   * **Default**: `Empty string`
   * **Not Null**: checked

   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-schema-editor-email.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=749d56b7879aee15c73f8f651807ba52" alt="bb-schema-editor-email" width="2464" height="1158" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-schema-editor-email.webp" />

4. Click **Create**, then **Ready for Review**. Go to **Rollout** and click **Run**. Wait for completion.

5. Click **Sync Schema** in the left sidebar. Select `hr_test` as the source and click **Next**.
   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-email-source.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=1433f04b0196c7a94bffd0ec5748b335" alt="bb-sync-schema-email-source" width="2392" height="888" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-email-source.webp" />

6. Select both `hr_prod` and `hr_prod_2` as targets. Review the schema differences and click **Preview issue**.
   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-add-email.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=5846788bce585330600119901e7cde87" alt="bb-sync-schema-add-email" width="2540" height="1232" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-add-email.webp" />

7. Click **Create**, then **Ready for Review**. Navigate to **Rollout** and click **Run** for each stage. The `email` column is now synchronized to both production databases.

## Case 3 - Rollback to previous schema versions

Use schema synchronization to roll back databases to any previous version from their migration history.

1. Navigate to **Sync Schema** and select `hr_test` as the source database.

2. Select a previous schema version from the dropdown and click **Next**.
   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-prev.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=03eb94d5bb34bd638de754b6c3a71dc7" alt="bb-sync-schema-prev" width="2344" height="980" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-schema-prev.webp" />

3. Select `hr_test` itself as the target (rolling back the same database) and click **Select**.
   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-rollback-target.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=3ec591f6741e223f57350789e5cebc30" alt="bb-sync-rollback-target" width="2348" height="988" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-rollback-target.webp" />

4. Review the rollback changes. The DDL will show what needs to be removed or modified. Click **Preview Issue**.
   <img src="https://mintcdn.com/dbx/L1emqLVGwC-B6xvQ/content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-rollback-preview.webp?fit=max&auto=format&n=L1emqLVGwC-B6xvQ&q=85&s=c1318eff79c8ba22569d24a6efb63dec" alt="bb-sync-rollback-preview" width="2566" height="1464" data-path="content/docs/tutorials/how-to-synchronize-database-schemas/bb-sync-rollback-preview.webp" />

5. Click **Create**, then **Ready for Review**. Navigate to **Rollout** and click **Run**. The schema successfully rolls back to the selected version.

## Summary

You've learned how to:

* Synchronize schemas to new databases
* Propagate changes across multiple environments
* Roll back to previous schema versions

## Next steps

* Learn about [batch changes](/change-database/batch-change/)
* Explore [GitOps integration](/gitops/overview/)
