|
| 1 | +--- |
| 2 | +title: How to set up Azure CLI for migration service in Azure Database for PostgreSQL - Flexible Server |
| 3 | +description: Learn how to set up Azure CLI for migration service in Azure Database for PostgreSQL - Flexible Server and begin migrating your data. |
| 4 | +author: markingmyname |
| 5 | +ms.author: maghan |
| 6 | +ms.date: 06/13/2024 |
| 7 | +ms.service: postgresql |
| 8 | +ms.subservice: flexible-server |
| 9 | +ms.topic: how-to |
| 10 | +ms.custom: |
| 11 | + - devx-track-azurecli |
| 12 | +--- |
| 13 | + |
| 14 | +# How to set up Azure CLI for migration service in Azure Database for PostgreSQL - Flexible Server |
| 15 | + |
| 16 | +To begin migrating using Azure CLI, you need to install the Azure CLI on your local machine. |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- [Choose the right command line tool](/CLI/azure/choose-the-right-azure-command-line-tool) |
| 21 | +- [Install Azure CLI](/cli/azure/install-azure-cli) |
| 22 | +- [Review the az postgresql commands](/cli/azure/postgres) |
| 23 | + |
| 24 | +## Migrate commands |
| 25 | + |
| 26 | +Migrating with the Azure CLI uses the following commands: |
| 27 | + |
| 28 | +- [az postgres flexible-server migration create](/cli/azure/postgres/flexible-server/migration#az-postgres-flexible-server-migration-create) |
| 29 | +- [az postgres flexible-server migration list](/cli/azure/postgres/flexible-server/migration#az-postgres-flexible-server-migration-list) |
| 30 | +- [az postgres flexible-server migration show](/cli/azure/postgres/flexible-server/migration#az-postgres-flexible-server-migration-show) |
| 31 | + |
| 32 | +The following table defines the parameters and the commands that use them: |
| 33 | + |
| 34 | +| Parameter | Relevant commands | Description | |
| 35 | +| --- | --- | --- | |
| 36 | +| `subscription` | Create, List, Show | Subscription ID of PostgreSQL Flexible server | |
| 37 | +| `resource-group` | Create, List, Show | Resource group of PostgreSQL Flexible server | |
| 38 | +| `name` | Create, List, Show | Name of the PostgreSQL Flexible server | |
| 39 | +| `migration-name` | Create, Show | Unique identifier to migrations attempted to Flexible Server. This field accepts only alphanumeric characters and doesn't accept any special characters except a hyphen (-). The name can't start with -, and no two migrations to a Flexible Server target can have the same name. | |
| 40 | +| `filter` | List | To filter migrations, two values are supported – Active and All |
| 41 | +| `help` | Create, List, Show | Provides information about each command. | |
| 42 | +| `migration-mode` | Create | This is an optional parameter. Default value: Offline. Offline migration involves copying your source databases to your target server at a point in time. | |
| 43 | +| `migration-option` | Create | Allows you to perform validations before triggering a migration. Default is ValidateAndMigrate. Allowed values are - Migrate, Validate, ValidateAndMigrate. |
| 44 | +| `properties` | Create | Absolute path to a JSON file that has the information about the source server | |
| 45 | + |
| 46 | +The **create** command requires a JSON file, which contains the following information: |
| 47 | + |
| 48 | +| Property Name | Description | |
| 49 | +| --- | --- | |
| 50 | +| `sourceDbServerResourceId` | Source server details in the format for on-premises, Azure virtual machines (VMs), AWS - `<<hostname or IP address>>:<<port>>@<<username>>` | |
| 51 | +| `AdminCredentials` | This parameter lists passwords for admin users for both the source server and the target PostgreSQL flexible server. These passwords help to authenticate against the source and target servers | |
| 52 | +| `targetServerUserName` | The default value is the admin user created during the creation of the flexible server, and the password provided is used for authentication against this user. If you aren't using the default user, this parameter is the user or role on the target server for migration. This user should be a member of azure_pg_admin, pg_read_all_settings, pg_read_all_stats, and pg_stat_scan_tables roles and should have the Create role, Create DB attributes | |
| 53 | +| `dbsToMigrate` | Specify the list of databases that you want to migrate to Flexible Server. You can include a maximum of eight database names at a time. Providing the list of DBs in array format. | |
| 54 | +| `OverwriteDBsInTarget` | When set to true (default), if the target server happens to have an existing database with the same name as the one you're trying to migrate, the migration tool automatically overwrites the database | |
| 55 | +| `MigrationMode` | Mode of the migration. The supported value is "Offline" | |
| 56 | +| `sourceType` | Required parameter. Values can be - on-premises, AWS, AzureVM, PostgreSQLSingleServer | |
| 57 | +| `sslMode` | SSL modes for migration. SSL mode for PostgreSQLSingleServer is VerifyFull and Prefer/Require for other source types | |
| 58 | + |
| 59 | +## Cutover the migration |
| 60 | + |
| 61 | +After the base data migration is complete, the migration task moves to the `WaitingForCutoverTrigger` substate. In this state, users can trigger the cutover from the portal by selecting the migration name in the migration grid or through the CLI using the command below. |
| 62 | + |
| 63 | +For example: |
| 64 | + |
| 65 | +```azurecli-interactive |
| 66 | +az postgres flexible-server migration update --subscription 11111111-1111-1111-1111-111111111111 --resource-group my-learning-rg --name myflexibleserver --migration-name CLIMigrationExample --cutover |
| 67 | +``` |
| 68 | + |
| 69 | +Before initiating cutover, it's important to ensure that: |
| 70 | + |
| 71 | +- Writes to the source are stopped |
| 72 | +- `latency` value decreases to 0 or close to 0 |
| 73 | +- `latency` value indicates when the target last synced with the source. At this point, writes to the source can be stopped and cutover initiated. In case there's heavy traffic at the source, it's recommended to stop writes first so that `Latency` can come close to 0, and then a cutover is initiated. |
| 74 | +- The Cutover operation applies all pending changes from the Source to the Target and completes the migration. If you trigger a "Cutover" even with nonzero `Latency`, the replication stops until that point in time. All the data on source until the cutover point is then applied on the target. Say a latency was 15 minutes at the cutover point, so all the changed data in the last 15 minutes applies to the target. |
| 75 | + |
| 76 | +Time depends on the backlog of changes occurring in the last 15 minutes. Hence, it's recommended that the latency go to zero or near zero before triggering the cutover. |
| 77 | + |
| 78 | +The `latency` information can be obtained using the migration show command. |
| 79 | +Here's a snapshot of the migration before initiating the cutover: |
| 80 | + |
| 81 | +After the cutover is initiated, pending data captured during CDC is written to the target, and migration is now complete. |
| 82 | + |
| 83 | +If the cutover isn't successful, the migration moves to the `Failed` state. |
| 84 | + |
| 85 | +For more information about this command, use the `help` parameter. |
| 86 | + |
| 87 | +## Cancel the migration |
| 88 | + |
| 89 | +To cancel the migration task, use the following command: |
| 90 | + |
| 91 | +```azurecli |
| 92 | +az postgres flexible-server migration update cancel [--subscription] |
| 93 | + [--resource-group] |
| 94 | + [--name] |
| 95 | + [--migration-name] |
| 96 | +``` |
| 97 | + |
| 98 | +## The --help command |
| 99 | + |
| 100 | +For more information about this command, use the `help` parameter: |
| 101 | + |
| 102 | +```azurecli-interactive |
| 103 | +az postgres flexible-server migration update cancel -- help |
| 104 | +``` |
| 105 | + |
| 106 | +## Related content |
| 107 | + |
| 108 | +- [Migration service in Azure Database for PostgreSQL](overview-migration-service-postgresql.md) |
| 109 | +- [Migrate from Single Server to Flexible Server](tutorial-migration-service-single-to-flexible.md) |
| 110 | +- [Migrate offline from AWS RDS PostgreSQL](tutorial-migration-service-aws-offline.md) |
| 111 | +- [Migrate online from AWS RDS PostgreSQL](tutorial-migration-service-aws-online.md) |
| 112 | +- [Migrate offline from on-premises or an Azure VM hosted PostgreSQL](tutorial-migration-service-iaas-offline.md) |
| 113 | +- [Migrate online from on-premises or an Azure VM hosted PostgreSQL](tutorial-migration-service-iaas-online.md) |
0 commit comments