|
| 1 | +--- |
| 2 | +title: "Migrate from Azure Database for PostgreSQL Single Server to Flexible Server - Concepts" |
| 3 | +titleSuffix: Azure Database for PostgreSQL Flexible Server |
| 4 | +description: Concepts about migrating your Single server to Azure database for PostgreSQL Flexible server. |
| 5 | +author: shriram-muthukrishnan |
| 6 | +ms.author: shriramm |
| 7 | +ms.service: postgresql |
| 8 | +ms.topic: conceptual |
| 9 | +ms.date: 05/11/2022 |
| 10 | +ms.custom: "mvc, references_regions" |
| 11 | +--- |
| 12 | + |
| 13 | +# Migrate from Azure Database for PostgreSQL Single Server to Flexible Server (preview) |
| 14 | + |
| 15 | +[!INCLUDE[applies-to-postgres-single-flexible-server](../includes/applies-to-postgresql-single-flexible-server.md)] |
| 16 | + |
| 17 | +Azure Database for PostgreSQL Flexible Server provides zone-redundant high availability, control over price, and control over maintenance windows. You can use the available migration tool to move your databases from Single Server to Flexible Server. To understand the differences between the two deployment options, see [this comparison chart](../flexible-server/concepts-compare-single-server-flexible-server.md). |
| 18 | + |
| 19 | +By using the migration tool, you can initiate migrations for multiple servers and databases in a repeatable way. The tool automates most of the migration steps to make the migration journey across Azure platforms as seamless as possible. The tool is free for customers. |
| 20 | + |
| 21 | +>[!NOTE] |
| 22 | +> The migration tool is in public preview. |
| 23 | +> |
| 24 | +> Migration from Single Server to Flexible Server is enabled in preview in these regions: Central US, West US, South Central US, North Central US, East Asia, Switzerland North, Australia South East, UAE North, UK West and Canada East. |
| 25 | +
|
| 26 | +## Overview |
| 27 | + |
| 28 | +The migration tool provides an inline experience to migrate databases from Single Server (source) to Flexible Server (target). |
| 29 | + |
| 30 | +You choose the source server and can select up to eight databases from it. This limitation is per migration task. The migration tool automates the following steps: |
| 31 | + |
| 32 | +1. Creates the migration infrastructure in the region of the target server. |
| 33 | +2. Creates a public IP address and attaches it to the migration infrastructure. |
| 34 | +3. Adds the migration infrastructure's IP address to the allowlist on the firewall rules of both the source and target servers. |
| 35 | +4. Creates a migration project with both source and target types as Azure Database for PostgreSQL. |
| 36 | +5. Creates a migration activity to migrate the databases specified by the user from the source to the target. |
| 37 | +6. Migrates schemas from the source to the target. |
| 38 | +7. Creates databases with the same name on the Flexible Server target. |
| 39 | +8. Migrates data from the source to the target. |
| 40 | + |
| 41 | +The following diagram shows the process flow for migration from Single Server to Flexible Server via the migration tool. |
| 42 | + |
| 43 | +:::image type="content" source="./media/concepts-single-to-flexible/concepts-flow-diagram.png" alt-text="Diagram that shows the Migration from Single Server to Flexible Server." lightbox="./media/concepts-single-to-flexible/concepts-flow-diagram.png"::: |
| 44 | + |
| 45 | +The steps in the process are: |
| 46 | + |
| 47 | +1. Create a Flexible Server target. |
| 48 | +2. Invoke migration. |
| 49 | +3. Provision the migration infrastructure by using Azure Database Migration Service. |
| 50 | +4. Start the migration. |
| 51 | + 1. Initial dump/restore (online and offline) |
| 52 | + 1. Streaming the changes (online only) |
| 53 | +5. Cut over to the target. |
| 54 | + |
| 55 | +The migration tool is exposed through the Azure portal and through easy-to-use Azure CLI commands. It allows you to create migrations, list migrations, display migration details, modify the state of the migration, and delete migrations. |
| 56 | + |
| 57 | +## Comparison of migration modes |
| 58 | + |
| 59 | +The tool supports two modes for migration from Single Server to Flexible Server. The *online* option provides reduced downtime for the migration, with logical replication restrictions. The *offline* option offers a simple migration but might incur extended downtime, depending on the size of databases. |
| 60 | + |
| 61 | +The following table summarizes the differences between the migration modes. |
| 62 | + |
| 63 | +| Capability | Online | Offline | |
| 64 | +|:---------------|:-------------|:-----------------| |
| 65 | +| Database availability for reads during migration | Available | Available | |
| 66 | +| Database availability for writes during migration | Available | Generally not recommended, because any writes initiated after the migration are not captured or migrated | |
| 67 | +| Application suitability | Applications that need maximum uptime | Applications that can afford a planned downtime window | |
| 68 | +| Environment suitability | Production environments | Usually development environments, testing environments, and some production environments that can afford downtime | |
| 69 | +| Suitability for write-heavy workloads | Suitable but expected to reduce the workload during migration | Not applicable, because writes at the source after migration begins are not replicated to the target | |
| 70 | +| Manual cutover | Required | Not required | |
| 71 | +| Downtime required | Less | More | |
| 72 | +| Logical replication limitations | Applicable | Not applicable | |
| 73 | +| Migration time required | Depends on the database size and the write activity until cutover | Depends on the database size | |
| 74 | + |
| 75 | +Based on those differences, pick the mode that best works for your workloads. |
| 76 | + |
| 77 | +### Migration considerations for offline mode |
| 78 | + |
| 79 | +The migration process for offline mode entails a dump of the source Single Server database, followed by a restore at the Flexible Server target. |
| 80 | + |
| 81 | +The following table shows the approximate time for performing offline migrations for databases of various sizes. |
| 82 | + |
| 83 | +>[!NOTE] |
| 84 | +> Add about 15 minutes for the migration infrastructure to be deployed for each migration task. Each task can migrate up to eight databases. |
| 85 | +
|
| 86 | +| Database size | Approximate time taken (HH:MM) | |
| 87 | +|:---------------|:-------------| |
| 88 | +| 1 GB | 00:01 | |
| 89 | +| 5 GB | 00:05 | |
| 90 | +| 10 GB | 00:10 | |
| 91 | +| 50 GB | 00:45 | |
| 92 | +| 100 GB | 06:00 | |
| 93 | +| 500 GB | 08:00 | |
| 94 | +| 1,000 GB | 09:30 | |
| 95 | + |
| 96 | +### Migration considerations for online mode |
| 97 | + |
| 98 | +The migration process for online mode entails a dump of the Single Server database(s), a restore of that dump in the Flexible Server target, and then replication of ongoing changes. You capture change data by using logical decoding. |
| 99 | + |
| 100 | +The time for completing an online migration depends on the incoming writes to the source server. The higher the write workload is on the source, the more time it takes for the data to be replicated to Flexible Server. |
| 101 | + |
| 102 | +## Migration steps |
| 103 | + |
| 104 | +### Prerequisites |
| 105 | + |
| 106 | +Before you start using the migration tool: |
| 107 | + |
| 108 | +- [Create an Azure Database for PostgreSQL server](../flexible-server/quickstart-create-server-portal.md). |
| 109 | + |
| 110 | +- [Enable logical replication](../single-server/concepts-logical.md) on the source server. |
| 111 | + |
| 112 | + :::image type="content" source="./media/concepts-single-to-flexible/logical-replication-support.png" alt-text="Screenshot of logical replication support in the Azure portal." lightbox="./media/concepts-single-to-flexible/logical-replication-support.png"::: |
| 113 | + |
| 114 | + >[!NOTE] |
| 115 | + > Enabling logical replication will require a server restart for the change to take effect. |
| 116 | +
|
| 117 | +- [Set up an Azure Active Directory (Azure AD) app](./how-to-set-up-azure-ad-app-portal.md). An Azure AD app is a critical component of the migration tool. It helps with role-based access control as the migration tool accesses both the source and target servers. |
| 118 | + |
| 119 | +- If you are using any PostgreSQL extensions on the Single Server, it has to allow-listed on the Flexible Server before initiating the migration using the steps below: |
| 120 | + |
| 121 | + 1. Use select command in the Single Server environment to list all the extensions in use. |
| 122 | + |
| 123 | + ``` |
| 124 | + select * from pg_extension |
| 125 | + ``` |
| 126 | +
|
| 127 | + The output of the above command gives the list of extensions currently active on the Single Server |
| 128 | +
|
| 129 | + 2. Enable the list of extensions obtained from step 1 in the Flexible Server. Search for the 'azure.extensions' parameter by selecting the Server Parameters tab in the side pane. Select the extensions that are to be allow-listed and click Save. |
| 130 | +
|
| 131 | + :::image type="content" source="./media/concepts-single-to-flexible/single-to-flex-azure-extensions.png" alt-text="Screenshot of PG extension support in the Flexible Server Azure portal." lightbox="./media/concepts-single-to-flexible/single-to-flex-azure-extensions.png"::: |
| 132 | +
|
| 133 | +### Data and schema migration |
| 134 | +
|
| 135 | +After you finish the prerequisites, migrate the data and schemas by using one of these methods: |
| 136 | +
|
| 137 | +- [Migrate by using the Azure portal](../migrate/how-to-migrate-single-to-flexible-portal.md) |
| 138 | +- [Migrate by using the Azure CLI](../migrate/how-to-migrate-single-to-flexible-cli.md) |
| 139 | +
|
| 140 | +### Post-migration actions and considerations |
| 141 | +
|
| 142 | +- If you are using sequences, once the migration has successfully completed, ensure that you update the current value of sequences in target database to match the values in the source database. |
| 143 | +
|
| 144 | +- All the resources that the migration tool creates will be automatically cleaned up, whether the migration succeeds, fails, or is canceled. No action is required from you. |
| 145 | +
|
| 146 | +- If your migration fails, you can create a new migration task with a different name and retry the operation. |
| 147 | +
|
| 148 | +- If you have more than eight databases on your Single Server and you want to migrate them all, we recommend that you create multiple migration tasks. Each task can migrate up to eight databases. |
| 149 | +
|
| 150 | +- The migration does not move the database users and roles of the source server. You have to manually create these and apply them to the target server after migration. |
| 151 | +
|
| 152 | +- For security reasons, we highly recommended that you delete the Azure AD app after the migration finishes. |
| 153 | +
|
| 154 | +- After you validate your data and make your application point to Flexible Server, you can consider deleting your Single Server. |
| 155 | +
|
| 156 | +## Limitations |
| 157 | +
|
| 158 | +### Size |
| 159 | +
|
| 160 | +- You can migrate databases of sizes up to 1 TB by using this tool. To migrate larger databases or heavy write workloads, contact your account team or [contact us](mailto:[email protected]). |
| 161 | +
|
| 162 | +- In one migration attempt, you can migrate up to eight user databases from Single Server to Flexible Server. If you have more databases to migrate, you can create multiple migrations between the same Single Server and Flexible Server. |
| 163 | +
|
| 164 | +### Performance |
| 165 | +
|
| 166 | +- The migration infrastructure is deployed on a four-vCore virtual machine that might limit migration performance. |
| 167 | +
|
| 168 | +- The deployment of migration infrastructure takes 10 to 15 minutes before the actual data migration starts, regardless of the size of data or the migration mode (online or offline). |
| 169 | +
|
| 170 | +### Replication |
| 171 | +
|
| 172 | +- The migration tool uses a logical decoding feature of PostgreSQL to perform the online migration. The decoding feature has the following limitations. For more information about logical replication limitations, see the [PostgreSQL documentation](https://www.postgresql.org/docs/10/logical-replication-restrictions.html). |
| 173 | + - Data Definition Language (DDL) commands are not replicated. |
| 174 | + - Sequence data is not replicated. |
| 175 | + - Truncate commands are not replicated. |
| 176 | + |
| 177 | + To work around this limitation, use `DELETE` instead of `TRUNCATE`. To avoid accidental `TRUNCATE` invocations, you can revoke the `TRUNCATE` privilege from tables. |
| 178 | +
|
| 179 | + - Views, materialized views, partition root tables, and foreign tables are not migrated. |
| 180 | +
|
| 181 | +- Logical decoding will use resources in the Single Server. Consider reducing the workload, or plan to scale CPU/memory resources at the Single Server during the migration. |
| 182 | +
|
| 183 | +### Other limitations |
| 184 | +
|
| 185 | +- The migration tool migrates only data and schemas of the Single Server databases to Flexible Server. It does not migrate other features, such as server parameters, connection security details, firewall rules, users, roles, and permissions. In other words, everything except data and schemas must be manually configured in the Flexible Server target. |
| 186 | +
|
| 187 | +- The migration tool does not validate the data in the Flexible Server target after migration. You must do this validation manually. |
| 188 | +
|
| 189 | +- The migration tool migrates only user databases, including Postgres databases. It doesn't migrate system or maintenance databases. |
| 190 | +
|
| 191 | +- If migration fails, there is no option to retry the same migration task. You have to create a new migration task with a unique name. |
| 192 | +
|
| 193 | +- The migration tool does not include an assessment of your Single Server. |
| 194 | +
|
| 195 | +## Best practices |
| 196 | +
|
| 197 | +- As part of discovery and assessment, take the server SKU, CPU usage, storage, database sizes, and extensions usage as some of the critical data to help with migrations. |
| 198 | +- Plan the mode of migration for each database. For simpler migrations and smaller databases, consider offline mode. |
| 199 | +- Batch similar-sized databases in a migration task. |
| 200 | +- Perform large database migrations with one or two databases at a time to avoid source-side load and migration failures. |
| 201 | +- Perform test migrations before migrating for production: |
| 202 | + - Test migrations are an important for ensuring that you cover all aspects of the database migration, including application testing. |
| 203 | + |
| 204 | + The best practice is to begin by running a migration entirely for testing purposes. After a newly started migration enters the continuous replication (CDC) phase with minimal lag, make your Flexible Server target the primary database server. Use that target for testing the application to ensure expected performance and results. If you're migrating to a higher Postgres version, test for application compatibility. |
| 205 | +
|
| 206 | + - After testing is completed, you can migrate the production databases. At this point, you need to finalize the day and time of production migration. Ideally, there's low application use at this time. All stakeholders who need to be involved should be available and ready. |
| 207 | + |
| 208 | + The production migration requires close monitoring. For an online migration, the replication must be completed before you perform the cutover, to prevent data loss. |
| 209 | +
|
| 210 | +- Cut over all dependent applications to access the new primary database, and open the applications for production usage. |
| 211 | +- After the application starts running on the Flexible Server target, monitor the database performance closely to see if performance tuning is required. |
| 212 | +
|
| 213 | +## Next steps |
| 214 | +
|
| 215 | +- [Migrate to Flexible Server by using the Azure portal](../migrate/how-to-migrate-single-to-flexible-portal.md) |
| 216 | +- [Migrate to Flexible Server by using the Azure CLI](../migrate/how-to-migrate-single-to-flexible-cli.md) |
0 commit comments