Migrate from Azure Database for PostgreSQL to self-hosted PostgreSQL

A move off Azure Database for PostgreSQL flexible server is mostly a replication, extension and cutover problem. This page explains the documented paths, what does not map, and what drives effort.

On this page

How to migrate from Azure Database for PostgreSQL to self-hosted PostgreSQL

Most teams leaving Azure Database for PostgreSQL flexible server move their data with native logical replication or pglogical into PostgreSQL servers they operate themselves, then cut over the application in a planned window. The source stays online during the copy, so the work is less about moving files and more about preparing the source, building the target, and proving that the two databases agree before any traffic moves. Microsoft documents that flexible server supports native logical replication, logical decoding and the pglogical extension, and that pglogical adds an initial schema copy, TRUNCATE support and DDL replication. Confirm the current configuration steps and parameter names in the Microsoft Learn guide on logical replication before you plan the source changes, because they differ by server tier and version.

Effort depends on four things: the size of the database, how fast it changes, which extensions it relies on, and how much downtime the application can tolerate. A small database with light write traffic and a generous outage window is a different project from a large, write-heavy system that must stay near current during the copy. Ask every candidate to inventory the extensions in use, the tables without primary keys, large objects, sequences, and any DDL that runs during business hours, because each of these changes the replication design. Logical replication copies row changes, so it does not carry the full schema or every object by itself, and sequences need an explicit cutover step. Expect to plan around the source's replication slot retention and the target's version, since the target version should be one that is still supported, as listed in the PostgreSQL versioning policy.

The cost components are the source and target infrastructure you run during the overlap, the engineering time to configure replication and validate data, the application changes if any, and the testing and rollback rehearsals. Costs that recur after cutover are the self-hosted servers, backups, monitoring and patching, which you take on from the Azure service. One-time costs are the replication build, validation and cutover. When you request a quote, ask for the written list of extensions checked, the validation method for row counts and checksums, the rollback plan, and the downtime assumptions for the cutover window.

What maps cleanly from Azure to self-hosted PostgreSQL and what does not

This table compares Azure Database for PostgreSQL flexible server with a self-hosted PostgreSQL deployment, area by area. Read the left column as the question to answer, then check the cells for what carries over directly and what your team must build or confirm. The main takeaway is that the database engine and SQL carry over, while Azure-managed backups, patching, failover and identity do not and need replacements designed before cutover.

AreaAzure flexible serverSelf-hosted PostgreSQL
Schema and dataStandard PostgreSQL schemas, tables and data typesSame SQL and data types; confirm the target major version supports every feature you use
Logical replicationNative logical replication, logical decoding and pglogical are supportedPublications and subscriptions work between servers you run; confirm source settings and network paths
Roles and loginEntra ID logins can be used alongside PostgreSQL rolesEntra ID logins must be replaced by PostgreSQL roles and an authentication method you choose and document
ExtensionsOnly extensions Azure offers on the flexible serverInstall extensions yourself; confirm each one exists for the target major version and your OS packages
High availabilityManaged zone-redundant or standby option with managed failoverStreaming replicas and an external failover tool you select, configure and test
Backups and point-in-time recoveryManaged backups and point-in-time restore within a configured retention windowBase backups plus archived WAL, with restore tests you run and record; no managed restore button
Connection poolingManaged pooling option where offered by the service tierDeploy and size a pooler such as PgBouncer, then tune its settings for your workload
Patching and maintenance windowsAzure schedules minor updates within a maintenance windowYour team schedules minor releases, which replace executables and need a restart
Major version upgradesAzure-managed upgrade pathPlan pg_upgrade or logical replication yourself, with a rollback path and a version support date in view

Choosing native logical replication or pglogical for the source

Native logical replication is built into PostgreSQL and works with publications on the source and subscriptions on the target. On Azure Database for PostgreSQL flexible server, it depends on logical decoding being enabled on the source, which is a server parameter you set and then restart the server to apply. The publication lists the tables to send, and the subscription on your server pulls those changes. Because the feature is part of core PostgreSQL, it is the option most teams already know how to operate.

  • Source setting: Enable logical decoding through the server parameters in the Azure portal or CLI, then restart the server so the change takes effect.
  • Publications: Create a publication on the source for each set of tables you want to move, and confirm that every table has a primary key or a replica identity, since updates and deletes depend on it.
  • Subscriptions: Create subscriptions on your self-hosted target that point at the source connection string. The target must run a major version that the replication protocol supports for your plan.
  • Initial copy: The subscription copies existing rows at creation time, but it does not copy the table definitions, so you create the schema on the target first.
  • Schema changes: New tables, columns and most DDL are not replicated, so every structural change during the move must be applied on both sides by hand.

Confirm the logical decoding setting and the replication role permissions with Azure before you plan the window, and read the current limits in the Microsoft Learn page on logical replication in Azure Database for PostgreSQL.

Documented tools and paths for moving the data

Moving off Azure Database for PostgreSQL flexible server is mostly a choice among a few documented paths, each with different limits on what it carries. The cards below set out what each tool moves, what it leaves behind, and which checks belong in the plan before a cutover date is set.

Native logical replication

Native logical replication uses a publication on the source and a subscription on your target to stream row changes after an initial copy. It suits a low-downtime move when the source exposes logical decoding and your tables have primary keys or replica identity settings. Sequences are not replicated, so advance them on the target during cutover. Confirm the source settings with Microsoft's logical replication guidance before you plan the window.

Azure logical replication docs

pglogical extension

pglogical is an extension that adds an initial schema copy, TRUNCATE support and DDL replication on top of logical replication. It can reduce manual setup when the source supports it and you need schema changes to flow during the move. Check that the extension is available on your Azure tier and that the target server runs a compatible version. Test DDL replication against a copy before relying on it in production.

pg_dump and pg_restore

pg_dump and pg_restore copy one database at a time as a logical snapshot, which makes them suitable for smaller databases or an offline load during a maintenance window. The dump captures schema and data for the database you name but not cluster-wide roles or tablespaces. Large objects need the custom or directory format to be included. Plan the window from a timed test restore, not from the dump size alone.

pg_dumpall for roles and globals

pg_dumpall is the documented route for cluster-wide objects such as roles, role memberships and tablespace definitions, which pg_dump skips. Run it with the global-only option to capture roles, then restore them before the database restore so ownership and grants resolve. Azure-managed roles such as azure_superuser and admin roles may not map to your target, so review every role before import. Passwords and their hashes may need to be reset.

pg_upgrade or logical replication for version changes

Use pg_upgrade or logical replication only when the target major version differs from the source. pg_upgrade works in place on the same platform and is faster for large data sets, while logical replication allows a move across major versions with short downtime. Choose the supported target line first, since PostgreSQL 14 reaches end of life on November 12, 2026. Test extension compatibility for each major version before cutover.

Upgrading PostgreSQL docs

Sequence from inventory to decommissioning the Azure server

This sequence moves a production PostgreSQL workload off Azure Database for PostgreSQL flexible server onto servers you run, with each stage closed by a check that gates the next. The end state is a validated new environment, a short cutover window, and an Azure server kept until a restore on the new side has been tested.

  1. Inventory databases, extensions and connections

    The platform team, with the application owners, lists every database, schema, role, extension, publication-relevant table, sequence, large object and client connection string on the Azure server. Confirm which extensions the source runs and whether your target builds offer the same versions, since an extension missing on the new side blocks the cutover. Record connection counts, peak write rates and tables without primary keys, because these decide how replication is configured. Done when the inventory is signed off by the application owners and every extension has a confirmed target.

  2. Build target servers with backups and a pooler

    Your infrastructure team provisions the self-hosted primary, any standbys, the backup repository and a connection pooler such as PgBouncer in front of the database. Confirm the PostgreSQL major version you will run, using the supported version list, and check current PgBouncer release notes before deployment. Configure authentication, TLS and the pooler so applications can connect without changing their credentials model. Done when a test application connects through the pooler and a base backup and archive push complete on the new servers.

  3. Enable logical decoding and create publications

    On the Azure server, the database owner enables logical replication through the server parameters that Microsoft documents for flexible server, then restarts within the maintenance behavior your organization accepts. The team creates a publication for each set of tables to replicate, and decides whether pglogical is needed for initial schema copy, TRUNCATE or DDL replication. Confirm the replication role's privileges and the network path from Azure to your servers. Done when the publications exist, the replication slot is visible on the source, and the connection test from the target succeeds.

  4. Load initial data and catch up

    Schema is created on the target first, then the subscription performs the initial table copy while changes accumulate in the slot. Watch replication lag and slot retention on the source, since a stalled subscriber makes the source hold WAL. Sequences are not replicated by logical replication, so they are set during cutover. Done when every subscribed table reports a ready state and lag returns to a steady low value under normal write load.

  5. Run parallel validation with row counts and checksums

    Run the source and target side by side for a period agreed with the application owners while replication continues. Compare row counts for every replicated table, and compare checksums or hashes on sampled and business-critical tables, noting that checksums on large tables need a planned window. Check sequences, extension objects, permissions and any tables excluded from publications. Done when every mismatch is explained and fixed, and the owners sign the validation report.

  6. Cut over applications with a short write freeze

    The team stops writes at the application or pooler level, waits for the subscriber to reach the source's final position, then sets sequence values on the target to match the source. The pooler or DNS entry is switched to the new primary and the application connection strings are verified. Confirm the freeze duration with the application owners before the window, and agree a rollback decision point. Done when the new primary accepts writes, the applications pass their smoke tests, and the old source is set read-only.

  7. Prove a restore on the new side before decommissioning

    After the new environment has run in production, the team restores a recent backup to a separate host, applies archived WAL to a chosen point in time, and runs the application validation suite against the restored copy. Keep the Azure server running in read-only mode until this restore succeeds and the retention needs of your compliance owners are confirmed. Done when the restore test is documented with its recovery point and the data owners accept the new backup policy. Only then is the Azure server deleted, after confirming any export or retention obligations are met.

Cutover moves traffic from the Azure publisher to your subscriber

The diagram starts at the Azure Database for PostgreSQL flexible server, which acts as the publisher. Logical replication or pglogical carries changes to the self-hosted subscriber in your infrastructure. The subscriber also feeds a standby server for high availability and a backup archive for point-in-time recovery, so the target is protected before any traffic moves. During the parallel run, the application still connects to the source. At cutover, the application connects through PgBouncer to the target. The reverse path shows the rollback route: changes written on the target must flow back to the source if you need to return, so confirm that this path is designed and tested before cutover.

Replication stream, standby, backups and cutover path for the Azure migration.

What drives the effort and cost of this move

This table lists the factors that change how much work the migration takes and what it costs, with whether each is one-time or recurring and what to ask for in a quote. Read it before requesting a scope, because most of these drivers are only visible once the source server has been inventoried.

DriverWhy it changes effort or costOne-time or recurringWhat to ask for in a quote
Total database size and write rateInitial copy time grows with data volume, and a high write rate means more change data to replay before cutoverOne-timeAssumed copy method, measured source size and write profile, and the replication lag target
Tables without primary keysLogical replication needs a replica identity on each replicated table, so keyless tables need a fix or a special setting before they can replicateOne-timeList of affected tables and the agreed fix for each, with who approves schema changes
Extensions on the source and their availability on your targetEach extension must exist on the self-hosted server at a compatible version, and some Azure-provided extensions may have no direct equivalentOne-timeExtension inventory compared against the target build, with a decision for every extension that cannot be carried over
Sequences and identity columnsSequence values do not replicate in the same way as table rows, so values must be set during cutover or the application may insert duplicate keysOne-timeSequence list and the cutover step that resynchronizes each value
Downtime toleranceA short cutover window needs rehearsed steps and tighter monitoring than a planned maintenance window, which raises test and staffing effortOne-timeAgreed cutover window, rollback point and the number of rehearsal runs included
Number of client applications and connection stringsEach application needs its connection string, driver settings, TLS configuration and retry behavior checked against the new endpointOne-timeApplication inventory, owners for each application and the test scope for each one
Target high availability and backup designReplicas, automatic failover tooling, WAL archiving and restore testing add build and test work that Azure managed features previously coveredOne-time to build, recurring to operateDesign decisions for replication, failover, backup retention and restore test frequency, plus who runs them after handover
Connection pooling and network pathMoving off a managed endpoint means setting up pooling, firewall rules, private networking and DNS changes yourselfOne-time to build, recurring to operatePooler design, network diagram and the owner of firewall and DNS changes
Team skills in Azure and Linux operationsStaff who already run Azure and Linux can own the new estate sooner, while gaps add training, documentation and external supportRecurringSkills assessment, named operators and the handover and training plan included in the scope

What usually goes wrong in an Azure to self-hosted PostgreSQL move

Most failed cutovers from Azure Database for PostgreSQL trace back to a short list of gaps: state that replication never carried, objects that exist only on one side, and settings that still point at the old server. Each card below names one of these gaps and the check that prevents it.

Sequences not advanced at cutover

Logical replication copies row data but does not keep sequence values moving on the target. If the application resumes inserts on the new server while sequence counters sit at old values, the result is primary key collisions or silent gaps. Before cutover, compare each sequence's last value on the source and target, set the target to a value above the source, and confirm this happens after writes stop on Azure, not before.

Azure logical replication docs

Missing primary keys block updates

Logical replication identifies rows to update or delete by their replica identity, which is normally the primary key. Tables without a primary key or a usable unique index can replicate inserts but fail on updates and deletes, or need a full replica identity that is slow and wide. Query the catalog for tables lacking a primary key before you create publications, and add keys or a deliberate replica identity to each table that needs one.

Extensions missing or mismatched

Azure flexible server only loads extensions it allows, and the versions on your self-hosted server may differ. A table that uses a type or index from an extension will fail to restore if the extension is absent, or behave differently if the version changed. List every installed extension and its version on the source, install the same versions on the target, and run the application's extension-dependent queries against the target before the cutover window.

Roles and privileges not recreated

Logical replication moves data and schema objects in the replicated set, but it does not carry the login roles, group memberships and grants that the application depends on. Azure administrative roles also have no direct equivalent on a self-hosted server. Export role definitions and grants from the source, recreate them on the target with the authentication method you chose, and test each application account with a real connection before the cutover.

Unsupported DDL during replication

Native logical replication does not replicate schema changes, so a column added on Azure during the sync period will not appear on the target unless someone applies it there too. Teams that run deployments continuously often miss this until a subscriber fails on an unknown column. Freeze schema changes for the migration window, record every DDL change made during it, and apply each one to the target before the subscription resumes. Where the team needs DDL replication, confirm what pglogical supports before choosing it.

No tested restore before decommissioning

Teams often shut down the Azure server once the new one accepts traffic, which removes the only fallback. A backup that has never been restored is not evidence of recovery. Before decommissioning, take a base backup of the target, restore it to a separate host, run row counts and checksums against the source, and confirm point-in-time recovery to a known timestamp. Keep the Azure server available for a period you set in advance.

Connection strings still pointing to Azure

Applications, batch jobs, reporting tools and scheduled scripts often hold connection strings in config files, secrets stores or environment variables that are easy to miss. Some keep writing to Azure after cutover, which splits data between two servers. Inventory every consumer that reaches the Azure hostname, switch them in one controlled change, and watch the Azure server's connection count until it stays at zero for the agreed period.

Questions buyers ask before moving off Azure PostgreSQL

What drives the cost of moving off Azure Database for PostgreSQL?

The cost is driven by the amount of work the move requires, not by the database size alone. Your internal team pays in staff time to inventory extensions, configure the source and target, build the replication path, test the application and run the cutover. A partner, if you use one, is paid for the scope agreed in writing. Recurring costs move to your side: the virtual machines or Kubernetes capacity, storage, backups, monitoring, patching and on-call coverage that Azure previously handled as part of the managed service. Ask any quote to separate one-time migration work from ongoing operations, and to list which Azure-managed functions (backups, patching, failover, monitoring) are being replaced and by what. Overlap costs also matter, because the source and target usually run side by side until validation finishes.

How long does an Azure PostgreSQL migration take?

Duration depends on the number of databases, total change volume, the extensions and features in use, how much application code depends on Azure-specific behavior, and how many test cycles your validation requires. Schema and extension inventory is usually quick compared with application testing and cutover rehearsal. Initial data copy time grows with database size and network throughput between Azure and your target, and the backlog of changes that build up during the copy must be drained before cutover. Ask for a timeline that lists each phase and its exit criteria, and confirm which Azure settings and maintenance windows constrain you. No duration is given here because it depends on your environment.

What must our internal team provide before the work starts?

Your team needs to supply access and decisions that only you can make. Typically this includes:

  • Azure subscription and server access for an account allowed to change server parameters and create replication objects
  • An inventory of databases, schemas, extensions, roles, and application connection strings
  • Network paths between Azure and the target environment, plus firewall and DNS change approval
  • A named owner for application testing, data validation sign-off, and the cutover go or no-go decision
  • Target infrastructure, backup storage, and monitoring that meet your security and compliance requirements

Missing items usually show up as delays in the first two weeks, so list them in the statement of work.

Can our team migrate off Azure PostgreSQL using the documented tools?

Often yes, if your team has PostgreSQL administration skills and time to test. The PostgreSQL project documents logical replication and pg_dump-based approaches, and Microsoft documents how logical replication and the pglogical extension behave on Azure. The harder parts are rarely the commands. They are verifying that every extension and feature has a target equivalent, rehearsing the cutover until its timing is predictable, validating data, and running the new platform's backups, failover and monitoring after go-live. Teams without this experience often choose a fixed-scope engagement for the cutover and handover, and keep the routine work in house.

How is downtime kept low during the cutover?

Downtime is kept low by replicating continuously rather than copying the database once while applications are stopped. The usual pattern is to load the initial data, let a replication stream carry changes until the target is current, then pause writes briefly, confirm the lag is zero, and repoint applications. The length of the write pause depends on how far the target has fallen behind and how quickly your connection changes can be made. Rehearse the sequence on a copy of production, time each step, and agree rollback conditions in advance. Sequences, large objects and DDL changes need explicit handling, because logical replication does not carry every object type automatically.

Which Azure logical replication settings should we confirm before starting?

Confirm the settings on the Azure side before scheduling any work. Check that logical replication is enabled on the flexible server, that the server parameters needed for logical decoding are set and that a restart has been planned for them, and that the replication user has the required privileges. Verify whether you intend to use native logical replication, logical decoding or the pglogical extension, because Microsoft documents that pglogical adds initial schema copy, TRUNCATE support and DDL replication. Confirm the replication slot and WAL retention limits, since unconsumed slots can grow storage. Read the Microsoft Learn logical replication guide and confirm each setting against your server's current version and configuration.

What extensions and features should we check on the source?

Start with an inventory of every extension installed on the source and every feature your applications rely on. For each extension, confirm that the target server has the same extension at a compatible version, or that you have a documented replacement. Also check roles and grants, custom types, sequences, large objects, triggers, and any use of Azure-specific administration functions. Replication does not carry every object type in the same way, so each item needs an explicit owner and a test. Ask your partner or internal team to produce this inventory as the first deliverable, because it determines the target design and the effort estimate.

Who owns security and compliance controls after we leave Azure?

After the move, your organization owns the controls Azure previously operated for the managed service, including network isolation, TLS configuration, authentication methods, encryption at rest, audit logging, access reviews and backup retention. PostgreSQL documents authentication methods such as SCRAM, certificates and directory-based login that you can configure, but you must choose and test them. DeployOpen can prepare systems and evidence for compliance assessments, but it does not issue audit reports or certifications, which independent auditors and certification bodies provide. Ask your compliance team to map each Azure-provided control to its replacement before cutover.

What a scoped migration engagement covers

A DeployOpen migration engagement starts with a written scope that is agreed before any work begins. The scope names the databases, schemas and extensions in the Azure Database for PostgreSQL flexible server instance, and it sets out each phase: inventory, target design, replication setup, validation, cutover runbook and rollback. The inventory phase records database sizes, write rates, sequences, large objects, installed extensions and the server parameters that affect logical replication. The target design phase covers the self-hosted PostgreSQL version, storage, high availability, backups, connection pooling and network paths between the two environments. Ask for the scope document to list which of these items are included, which are assumed to be already in place, and which are excluded, so the quote can be compared line by line with an internal estimate.

Your team keeps ownership of the Azure subscription, the Azure server resources and the target infrastructure throughout the work. DeployOpen works in accounts and servers that you grant access to, and the scope should say which roles are needed, for example who changes the source server settings that enable logical decoding and who approves the change window. The runbook and rollback plan belong to your operations team after handover, so the written deliverables should include the replication monitoring steps, the criteria for stopping a cutover and the exact steps to point applications back to Azure. Confirm with your Microsoft account team and against the Azure documentation which replication settings your server tier supports before the scope is signed, because those settings decide what the source side of the migration can do.

How DeployOpen scopes, delivers and supports the migration

DeployOpen approaches a move off Azure Database for PostgreSQL flexible server as a written, fixed-scope engagement covering the source configuration, the target self-hosted PostgreSQL servers, replication, validation and cutover. The work runs inside your own cloud accounts, data centers or air-gapped networks, with each phase documented for your team to keep.

How we scope

  • Inventory the source server settings, databases, extensions and replication needs before any change is made to Azure.
  • Agree in writing whether native logical replication or pglogical is the replication path, with the reasons recorded.
  • Define the cutover window, rollback conditions and acceptance checks in the written scope before work starts.

How we build

  • Prepare the target PostgreSQL servers, network paths and TLS settings in your infrastructure, matched to the source major version.
  • Set up publications, subscriptions and the initial copy, then test replication lag and extension behavior on a rehearsal copy.
  • Run the cutover rehearsal end to end, including application connection string changes and a documented rollback path.

How we hand over

  • Deliver a runbook covering source changes, replication steps, validation queries, cutover actions and rollback steps.
  • Document the target configuration, authentication settings, backup setup and the list of source features that were replaced.
  • Walk your database, security and operations teams through the handover so they can run and verify the new environment.

How we support

  • Offer post-cutover support for a defined period as part of the written scope, with the period agreed before work starts.
  • Make ongoing upgrades, testing and operational support available through a retainer once the migration is complete.
  • Ask for a quote built from the written scope, which sets out the work, deliverables and timeline for your environment.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.