This page describes how to convert your SQL Server database to
PostgreSQL syntax and migrate the data to AlloyDB for PostgreSQL
with Database Migration Service.

The migration process involves the following tasks:

1. Configuring your source database for migration connectivity and preparing
   the data for conversion to PostgreSQL.

2. Creating the destination AlloyDB for PostgreSQL cluster.

3. Converting your SQL Server schema and other objects to
   PostgreSQL syntax with a Database Migration Service conversion workspace.

4. Creating and running the migration job in Database Migration Service.

5. Monitoring the migration job progress with Database Migration Service observability
   features.

6. Promoting the migration job after the data is fully migrated.

## Costs

In this document, you use the following billable components of
Google Cloud:

- AlloyDB for PostgreSQL (See [AlloyDB for PostgreSQL pricing](https://docs.cloud.google.com/alloydb/pricing).)
- If used for storing Customer-managed Encryption Keys (CMEK): Cloud Storage (See [Cloud Storage pricing](https://docs.cloud.google.com/storage/pricing).)

To generate a cost estimate based on your projected usage, use the
[pricing calculator](https://docs.cloud.google.com/products/calculator).

## Before you begin

1. Verify if this migration path can fully support your scenario. See the following pages:
   - [Supported sources and destinations](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/scenario-overview.md.txt#supported-src-and-dest) on the *Scenario overview* page lists all supported source and destination versions.
   - [Known limitations](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/known-limitations.md.txt) describes supported data types, database sizes, and other limitations.
   - [Networking overview](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/networking-overview.md.txt) describes available network connectivity solutions.

     To migrate your data, Database Migration Service needs to establish a network
     connection to your source and destination clusters. Depending on
     your architecture, you might need additional preparation to facilitate
     network connectivity.
2. *Optional*: Database Migration Service supports failback replication.
   Consider if you want to run failback replication after you complete the
   standard migration job. You can prepare for failback replication as you
   plan your migration job, or do it before you promote the standard migration job.
   For more information on failback migrations, see the following pages:

   - [Failback migrations overview](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/failback-migration.md.txt).
   - [Failback migrations guide](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/guide-failback-migration.md.txt).
3. *For one-time migrations*: Consider the schedule for your migration. One-time migrations perform only a full dump and load operation without subsequent change data capture. We recommend that you disable writes on your source database for the migration process to avoid losing data.
4. Consider in which region you want to create the destination database. Database Migration Service is a fully-regional product, meaning all entities related to your migration (source and destination connection profiles, migration jobs, destination databases, conversion workspaces) must be saved in a single region.
5. In the Google Cloud console, on the project selector page, select or [create a Google Cloud project](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt).

   [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)
6. Enable the Database Migration Service, Compute Engine, Cloud Storage, and AlloyDB for PostgreSQL Admin APIs. [Enable the APIs](https://console.cloud.google.com/apis/enableflow?apiid=compute.googleapis.com,datamigration.googleapis.com,alloydb.googleapis.com,storage.googleapis.com)

### Required roles

To get the permissions that you need to perform heterogeneous SQL Server
migrations with Database Migration Service, ask your administrator to grant you the
required IAM roles on your project:

- [Database Migration Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/datamigration.md.txt#datamigration.admin) (`roles/datamigration.admin`)
- [AlloyDB Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/alloydb.md.txt#alloydb.admin) (`roles/alloydb.admin`)

For more information about granting roles, see
[Manage access](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt) in the Identity and Access Management documentation.

These predefined roles contain the permissions required to perform
heterogeneous SQL Server migrations with Database Migration Service. To see the exact
permissions that are required, expand the
**Required permissions** section:

#### Required permissions

The following permissions are required to perform heterogeneous SQL Server
migrations with Database Migration Service:

- `datamigration.*`
- `cloudaicompanion.entitlements.get`

  This permission is included in the `roles/datamigration.admin`
  role. It is required for the
  [Gemini-enhanced conversion features](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/code-conversion-with-gemini.md.txt).
- `alloydb.clusters.create`
- `alloydb.clusters.get`
- `alloydb.clusters.list`
- `alloydb.clusters.update`
- `alloydb.clusters.delete`
- `alloydb.instances.create`
- `alloydb.instances.get`
- `alloydb.instances.list`
- `alloydb.instances.update`
- `alloydb.instances.delete`
- `alloydb.operations.get`
- `alloydb.users.list`
- `alloydb.users.get`
- `alloydb.users.create`
- `alloydb.users.update`
- `alloydb.users.delete`

You might also be able to get these permissions with
[custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or other
[predefined roles](https://docs.cloud.google.com/iam/docs/roles-permissions.md.txt).

## Step 1. Prepare your source database

To prepare your source data for migration, follow these steps:

1. Set up source database connectivity. Do the following:
   1. Optional: Consider if you want to use SSL/TLS certificates to secure the source network connection. For more information, see [Secure network connections with TLS](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/encrypt-connections-with-certificates.md.txt).

      Database Migration Service offers different TLS variants to secure network
      connections: basic or TLS. Depending on which variant
      you want to use, you might need to perform additional configuration
      steps on your source database.
   2. [Choose and configure your source network connectivity method](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/networking-methods-source.md.txt).
2. [Configure your source database instance](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/configure-source-database.md.txt).

   In this step, you create a dedicated migration database user account
   and enable the necessary replication features: snapshot isolation,
   and table-level change data capture (CDC).
3. [Create a source connection profile](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/create-source-connection-profile.md.txt).

   Connection profiles contain information necessary for Database Migration Service
   to establish the connection to your source database. Connection
   details vary depending on which
   [source network connectivity method](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/networking-methods-source.md.txt) you use.

## Step 2. Prepare your AlloyDB for PostgreSQL destination cluster

To configure your destination AlloyDB for PostgreSQL instance, perform the following steps:

1. [Choose and configure your destination network connectivity method](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/networking-methods-destination.md.txt).
2. [Create and configure your AlloyDB for PostgreSQL destination cluster](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/configure-destination-database.md.txt).

   Make sure you use enough compute and memory resources to cover your migration
   needs. For more information, see
   [Migration recommendations](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/known-limitations.md.txt#recommendations).
3. [Create a destination connection profile](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/create-destination-connection-profile.md.txt).

   Connection profiles contain information necessary for Database Migration Service
   to establish the connection to your destination database. Connection
   details vary depending on which
   [destination network connectivity method](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/networking-methods-destination.md.txt) you use.

## Step 3. Convert SQL Server objects to PostgreSQL syntax

Databases can often have thousands of objects. Converting them all in a single
session might be a challenging process. With conversion workspaces, you can divide
the conversion process into multiple phases where you add new objects to the
conversion, fix the issues, and then test them in your destination database.

To convert objects from your source database, do the following:

1. [Create the conversion workspace and run the initial conversion](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/create-conversion-workspace.md.txt).
2. [Fix conversion issues and apply the schema to your destination database](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/convert-sql.md.txt).

   > [!TIP]
   > **Tip:** You can use [Gemini-assisted conversion features](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/about-conversion-workspaces.md.txt#ai-conversion) to expedite the conversion process.

## Step 4. Create and run the migration job

To configure and run your migration, perform the following steps:

1. Optional: If you want to manage your own certificates for the migration job, [prepare the necessary encryption keys](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/cmek-for-migration-jobs.md.txt).
2. [Create and run the migration job](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/create-migration-job.md.txt).

   The destination AlloyDB for PostgreSQL database is writable during the migration
   to allow DML changes to be applied if needed. Take care not to make any
   changes to the database configuration or table structures which might break
   the migration process or impact data integrity.

   You can monitor the migration progress, as well as your destination cluster
   health with Database Migration Service observability
   features. See
   [Migration job metrics](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/migration-job-metrics.md.txt).

## Step 5. Finalize the migration

When you decide to switch your application to the new AlloyDB for PostgreSQL
cluster, finalize the migration by following these steps:

### One-time migrations

When Database Migration Service completes the full dump phase, your migration
job status changes to **Ready for promote**.

1. Optional: [Verify migration data](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/verify-migration.md.txt) for completeness.
2. [Promote the migration job](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/finalize-migration.md.txt).

### Continuous migrations

1. *Optional*: Database Migration Service supports failback replication.
   We recommend that you configure and run the failback migration
   before you promote the standard migration job.
   For more information on failback migrations, see the following pages:

   - [Failback migrations overview](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/failback-migration.md.txt).
   - [Failback migrations guide](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/guide-failback-migration.md.txt).
2. Stop all write operations on your source database. You can switch them to read-only mode to retain operational functionality.
3. Optional: [Verify migration data](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/verify-migration.md.txt) for completeness.
4. [Promote the migration job](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/finalize-migration.md.txt).

You can now clean up all Database Migration Service entities such as connection profiles,
migration jobs, and conversion workspaces. You can also choose to retain them
and reuse these entities for another migration.

## What's next

- Learn more about Google Cloud features for AlloyDB for PostgreSQL. See [AlloyDB for PostgreSQL features](https://docs.cloud.google.com/sql/docs/postgres/features.md.txt).
- Consider configuring a failback migration job. See [Failback migrations overview](https://docs.cloud.google.com/database-migration/docs/sqlserver-to-alloydb/failback-migration.md.txt).