How to migrate from Cloud SQL for PostgreSQL to self-hosted PostgreSQL
Teams leaving Cloud SQL for PostgreSQL for infrastructure they control usually move with native logical replication, which streams changes from the managed primary into a PostgreSQL server you run. The effort depends on database size, write volume, the extensions in use, and how many applications depend on sequences and large objects, because those are the parts that replication does not carry across for you. Plan the migration around those four factors before you choose a cutover window.
The source side needs the cloudsql.logical_decoding flag set to on on the Cloud SQL primary, which Google documents in its guide to setting up logical replication and decoding. Confirm that the flag can be changed on your instance type and version, and check whether the change requires a restart in your environment. The target is an external instance with wal_level=logical, and its major version must be one you can support on your own schedule. Check the Cloud SQL and target major versions side by side, and confirm the replication user, network path and TLS settings between the two environments before any data moves.
The target also has to be ready to receive the stream. Create the schema on the new server first, then define a publication on the source and a subscription on the target, and confirm that the copy and catch-up phases finish with the lag you expect. Sequences are not replicated by logical replication, so you need a documented step that sets each target sequence to the source value at cutover. Large objects also need a deliberate plan, because they are stored outside ordinary row replication. Ask your team which applications write them and whether they must move as part of the same window.
What maps cleanly from Cloud SQL to self-hosted PostgreSQL and what does not
This table compares each part of a Cloud SQL for PostgreSQL database with its equivalent on a server you run, and notes what changes during migration. Read it as a checklist: rows marked as needing separate steps are where cutover plans most often fail. Confirm each flag and behavior against the current PostgreSQL logical replication documentation and your Google Cloud configuration before you commit to a plan.
| Component | Self-hosted equivalent | Migration note |
|---|---|---|
| Table data | Tables and rows copied by initial sync, then streamed changes | Logical replication copies table data after the initial snapshot. Confirm which table types and row changes your version streams. |
| Primary keys | Same keys, recreated on the target schema | Replication needs a replica identity on tables without primary keys. Add keys or set replica identity before creating publications. |
| Indexes | Recreated on the target, not replicated | Create indexes on the target after the initial load to speed up copy. Verify index definitions match the source. |
| Roles and grants | Roles created with the server, grants applied by script | Cloud SQL manages some roles and privileges. Recreate application roles and grants explicitly; do not expect them to replicate. |
| Extensions | Installed by a superuser or extension owner on the target | Check each source extension is available and at the same version on your server. Cloud SQL-supported extensions may not all be packaged for your build. |
| Sequences | Created and set on the target separately | Logical replication does not carry sequence values. Set each sequence to the source value during cutover, after writes stop. |
| Large objects | Stored in pg_largeobject on the target | Large objects are not carried by logical replication without separate steps. Plan a dump and restore for them and confirm the method. |
| Publications and subscriptions | Publication on Cloud SQL, subscription on your server | The source needs logical decoding enabled and a publication. Your server needs a subscription pointing at the source with network and credential access. |
| Configuration flags | postgresql.conf and server settings you manage | Cloud SQL-specific flags, including cloudsql.logical_decoding, do not exist on your server. Review each flag and set equivalent wal_level and related parameters. |
| Managed features (backups, maintenance, HA) | Backups, failover and patching you design and run | Cloud SQL maintenance windows and automated backups stop applying. Set up backup, monitoring and failover before cutover. |
Documented tools and paths for moving data out of Cloud SQL
Moving a database out of Cloud SQL usually combines a source-side setting, a replication path and a set of role and object checks. The cards below cover the main documented options and the source-side reference, so you can match each tool to your downtime tolerance and database size before planning the cutover.
Native logical replication
Publications on the Cloud SQL primary stream row changes to a subscription on your external PostgreSQL server, so the copy stays current until you cut over. This is the primary path for databases where downtime must be short. Check that the source flag is enabled, that the target major version can receive the stream, and that every table you need has a replica identity or primary key before you create the publication.
Cloud SQL logical replication setupCloud SQL logical decoding flag
The source-side reference for turning on cloudsql.logical_decoding on a Cloud SQL primary, which is required before native logical replication can read changes. Changing this flag is an instance setting, so plan the change window and confirm with Google Cloud documentation how your instance applies it. Record the setting in your runbook so the source configuration is reproducible.
Subscriptions on your external server
A subscription on your self-hosted server connects to the publication, copies the initial table data and then applies ongoing changes. Your external instance needs wal_level=logical and network access from the target to the source. Verify replication lag, subscription errors and worker activity during the sync window, since the initial copy can run for a long time on large tables.
pg_dump and pg_restore for small or offline loads
pg_dump exports a single database in a custom or directory format, and pg_restore loads it into your new server. This fits small databases or a planned outage window where a consistent snapshot is acceptable. Expect the whole dump and restore to run inside the downtime window, and test restore time on a copy of production data before choosing this path.
pg_dumpall for roles and global objects
pg_dumpall with the global-only option captures roles and tablespace definitions that per-database dumps do not include. Review role memberships, passwords and ownership, since Cloud SQL manages some privileges through its own administrative role. Use the output as input to your review, not as a file to replay unchanged on a new server.
Sequences and large objects check
Logical replication does not carry sequence values, and large objects need separate handling, so both must be checked at cutover. Set each sequence to the source value after the final sync and confirm large object data was copied by your chosen method. Build this into the cutover checklist rather than discovering gaps after applications write to the new server.
How logical replication from Cloud SQL carries changes to your server
Replication out of Cloud SQL starts with two settings that must agree. On the source, set the database flag cloudsql.logical_decoding to on on the Cloud SQL primary, which lets it publish logical changes. On your side, the target server must run with wal_level=logical. Confirm both before anything else, because a Cloud SQL instance without the flag cannot act as a publisher, and changing a flag on a live primary is a planned change you should schedule and test first. The source setup is documented in the Google Cloud guide to logical replication and decoding, which you should follow for the exact steps in your Cloud SQL version.
Next, create a publication on the Cloud SQL primary that lists the tables to send, and a subscription on your server that points back to the source connection and subscribes to that publication. When the subscription is created, PostgreSQL first copies the existing rows of each published table, then streams subsequent inserts, updates and deletes as they commit. Your subscriber must already contain each target table with matching column names, types and key definitions, because the stream carries row data and does not create or alter tables for you. Check this with a schema comparison before the initial copy starts, not after.
Schema changes are not replicated automatically. An ALTER TABLE run on the Cloud SQL primary will not reach your server, so any DDL during the migration window must be applied to both sides by hand, in the same order, or replication will stop with errors. Plan a freeze on schema changes for the replicated tables, and record who owns that rule. Also confirm with Google Cloud which sequence values and large object data are handled outside the stream, since those are covered in the next section.
The sequence from inventory to decommissioning the Cloud SQL instance
This sequence moves a Cloud SQL for PostgreSQL workload onto self-hosted PostgreSQL in stages, so each stage produces evidence that the next one can rely on. The end state is a validated target, a documented cutover, a closed rollback window and a decommissioned source instance.
Inventory databases, extensions, roles and objects
Your team and DeployOpen list every database, schema, extension, role, publication-relevant table, sequence, large object and scheduled job on the Cloud SQL instance, and record which application uses each one. Extensions are matched against what the target server will install, and roles are mapped to the access model you intend to run. The step closes when the inventory is signed off by the application owners and every item has a named target or an explicit decision to drop it.
Run a pilot on a non-critical database
Choose a database with low business impact and move it end to end before any production data is touched. The pilot tests the replication setup, the target server build, backup configuration and the application connection changes, and it records real timings for the team to plan against. The step closes with a written pilot report listing defects found, fixes applied and the steps that still need a rehearsal. Durations from the pilot feed the written scope, not a generic estimate.
Prepare schema, sequences and large objects
Copy the schema definitions to the target and decide how each object type moves. Logical replication carries table data and row changes, so sequences, large objects and any DDL changes need a separate, explicit plan, and the team confirms which of these the chosen method handles in your PostgreSQL version. Each sequence is recorded with its current value so it can be resynchronized later. The step closes when the target schema matches the source for every object in scope and the sequence and large object plan has been reviewed.
Enable logical decoding on the source
Set the cloudsql.logical_decoding flag to on on the Cloud SQL primary, following the configuration steps in Google's documentation. Confirm the instance restarts as expected in a window your change process approves, and check that replication slots and the connection account have the privileges they need. Plan the change around your change control process, because the flag affects a production primary. The step closes when the flag is confirmed on and the replication role can connect from the target network.
Create publications and subscriptions
Create a publication on the Cloud SQL source for the tables in scope, then create a subscription on the self-hosted target that points at it. Initial table synchronization runs while the source keeps taking writes, and the team watches replication lag and slot growth on the source until the subscription reports steady state. The step closes when every table in the publication shows as synchronized and lag stays within the threshold agreed in the runbook.
Validate the parallel run with counts and checksums
Keep the target replicating while applications continue to use the source, and compare row counts and checksums table by table on a schedule agreed with the application owners. Differences are traced to their cause, such as in-flight transactions, excluded tables or type conversions, before anyone accepts them. The step closes with a validation report that lists each table, the comparison method used and any accepted exception with its owner.
Cut over with write freeze and sequence resync
Stop application writes to the Cloud SQL primary, wait for the subscription to catch up to the frozen position, and then resynchronize each sequence on the target to the source value plus a safe margin where your design calls for it. Point application connections, including any connection pooler, at the self-hosted endpoint and confirm the application can read and write. The cutover timing and rehearsal depend on your environment and the scope agreed in writing, so run this step at least once in a rehearsal first. The step closes when application smoke tests pass against the target and sequences are confirmed.
Hold a rollback window then decommission Cloud SQL
Keep the Cloud SQL instance available for an agreed rollback window, with a documented procedure for reversing the cutover if a serious defect appears. Back up the target from the first day it serves production, and confirm the restore works on a separate server. Once the window closes and the business owners sign off, remove the subscription, drop the publication, delete the logical decoding configuration if it is no longer needed, and decommission the instance. The step closes with a decommissioning record that lists the backup retention, access revocations and the date the source was removed.
How the Cloud SQL primary, your subscriber and the applications connect during the parallel run
The diagram starts with the Cloud SQL primary, where the cloudsql.logical_decoding flag must be on so that a publication can be created and streamed. Changes cross the trust boundary into your network, where a subscription on your self-hosted PostgreSQL server applies them. Applications keep writing to Cloud SQL until cutover, when their connections move to the new server. Check that the subscriber keeps up with the primary before that switch.
Changes flow from the Cloud SQL primary to your subscriber while applications still write to Cloud SQL.
What drives the cost and duration of this migration
This table lists the factors that change how much work a Cloud SQL to self-hosted PostgreSQL move takes, who carries each part, and whether the cost is one-time or recurring. Use it to read a partner's quote and to check whether each driver appears in the written scope.
| Driver | Why it changes cost or effort | Who pays and one-time or recurring | What to request in a quote |
|---|---|---|---|
| Total database size | Initial copy time, storage provisioning and the size of the backup and rehearsal restores all grow with data volume. | Partner and client infrastructure team, one-time for the copy, recurring for storage. | Assumed data volume per database, copy method and rehearsal restore timing. |
| Write rate on the Cloud SQL source | A high write rate increases replication lag to catch up and makes cutover timing harder to hold. | Partner for replication work, client for application freeze coordination, one-time. | Lag monitoring approach, catch-up assumptions and the cutover window the plan depends on. |
| Tables without primary keys | Logical replication needs a replica identity on each replicated table, so these tables need schema changes or a workaround before they can stream. | Client application team for schema decisions, partner for the change, one-time. | A list of affected tables, the chosen fix for each and who approves schema changes. |
| Sequences | Sequence values do not replicate through the publication, so each sequence must be set on the target during cutover. | Partner for scripting and checks, one-time per cutover. | How sequence values are synchronized, when, and the validation run before the switch. |
| Large objects | Large objects are not carried by normal table replication and need a separate copy and verification path. | Partner for the copy, client for confirming usage, one-time. | Whether large objects are in use, the transfer method and how references are checked. |
| Extensions in use | Each extension must exist on the target at a compatible version, and some may not be available on a self-hosted build without extra work. | Partner for compatibility review and install, client for approval, one-time. | An extension inventory, version match plan and any substitutes for unavailable extensions. |
| Applications and connection strings | Every service that points at the Cloud SQL instance needs new hosts, credentials, TLS settings and sometimes SQL fixes. | Client application teams for their code, partner for coordination and config changes, one-time. | A list of consuming services, the change per service and the test each owner signs off. |
| Network path between Google Cloud and the target | Private connectivity, firewall rules, routing and TLS for the replication stream depend on where the target runs. | Client network team for links and firewalls, partner for PostgreSQL settings, one-time plus recurring link costs. | The connectivity design, who owns each hop, and bandwidth and latency checks done before rehearsal. |
| Backup and monitoring rebuild | Cloud SQL backups and metrics do not move with the data, so backups, point-in-time recovery and alerts must be built on the target. | Partner for build, client for ongoing storage and monitoring tools, one-time build with recurring operation. | Backup tool choice, retention, restore test plan, alert set and who runs them after handover. |
| Number of rehearsals | Each full rehearsal repeats copy, catch-up, checks and timing, so more rehearsals raise effort but lower cutover risk. | Partner and client team time, one-time per rehearsal. | How many rehearsals are included, the pass criteria and what a failed rehearsal triggers. |
Questions buyers ask before moving off Cloud SQL for PostgreSQL
How much effort does moving off Cloud SQL for PostgreSQL take?
Effort depends mostly on database size, write volume, how many objects need to move, and how many applications connect to the database. The largest single driver is whether the team can replicate logically from the Cloud SQL primary into a server it runs, which requires the source to be configured for logical decoding and the target to be sized and secured before any data moves. Other drivers include extensions in use, the number of sequences and large objects, the application connection changes needed at cutover, and the volume of testing the team wants before switching traffic. Ask any partner for a written scope that lists each of these items, then compare the effort against the list of sources and targets your team already owns.
Can our own team run this migration without outside help?
Yes, if the team already operates PostgreSQL, has experience with logical replication and can run a rehearsal before production. The work breaks into four parts: enabling logical decoding on the source, building and securing the target server, creating publications and subscriptions, and planning the cutover. Teams without recent replication experience usually benefit from a review of the design before they start, and from a second pair of hands during the cutover window. An outside partner can work as a fixed-scope engagement with written deliverables, so the decision is about which skills you lack, not whether the migration is possible.
What do we need to provide, such as access and change windows?
You need administrative access to the Cloud SQL instance settings and the ability to set the cloudsql.logical_decoding flag, a network path from the target servers to the source, credentials for a replication role, and staff who can approve the cutover. Your change management process will also need time for the database restart that enabling logical decoding can require, which you should confirm in the Google Cloud documentation for your instance version. Plan for application owners to supply connection string changes, test cases and a rollback decision owner. Ask for this list in writing before the engagement starts, so access requests do not delay the first rehearsal.
How long does the cutover take, and why does it vary?
Cutover length depends on how far behind the replica is when you switch, how much write traffic continues during the switch, how many sequences must be reset, and how long your applications take to reconnect. Logical replication keeps the target synchronized while the source keeps serving traffic, so the cutover window is usually shorter than an offline dump and restore. The exact duration is specific to your environment, so measure it in a rehearsal on a copy of production data. Ask the partner to report the measured lag, the steps in the runbook and the rollback time, rather than accepting a generic figure.
Do sequences and large objects move automatically with logical replication?
No, logical replication does not carry the current value of sequences, so each sequence must be set on the target to a value above the last value used on the source before applications write to the new server. Large objects also need separate handling, because they are not replicated through the standard publication and subscription path in the same way as ordinary table rows. Check every table for large object references and every application for sequence-based keys during design. Ask for a written list of sequences and large objects, with the method used to move each one, and test that list against the rehearsal copy.
What happens to backups and high availability after the move?
Once the database runs on infrastructure you control, backups and high availability become your responsibility to design, run and test. Point-in-time recovery needs a base backup plus archived WAL files, and recent PostgreSQL releases can take incremental backups that pg_combinebackup reconstructs at restore time. High availability needs streaming replication, a decision between synchronous and asynchronous commit, and an external tool to detect failure and promote a standby, because PostgreSQL does not provide that detection itself. Before cutover, confirm that restores have been tested on the new platform, that backups are stored off site, and that someone owns the failover runbook.
Which PostgreSQL version should the new server run?
Choose a version that is still supported for the full life of the system you are building. PostgreSQL 18 was first released on September 25, 2025, and supports releases until November 14, 2030, while 17 is supported to November 8, 2029, and 16 to November 9, 2028. Versions 14 and 15 reach end of support in 2026 and 2027, so a new deployment on those versions would need an upgrade plan early. Match the target version to the source version you are replicating from, and confirm that every extension your applications use is available for that version before the rehearsal.
What usually goes wrong in a Cloud SQL to self-hosted move and how to prevent it
Most failed Cloud SQL exits do not fail at cutover day. They fail earlier, in tables that cannot replicate, objects that never moved, or servers that were never restored. Each card below names one failure and the check that prevents it before the parallel run begins.
Tables without primary keys
Logical replication in PostgreSQL needs a way to identify rows on the subscriber when updates and deletes arrive. Tables without a primary key, or with only a replica identity that cannot identify rows, will reject or block those changes. Before creating the publication, list every table without a primary key in the source and decide per table whether to add a key, set a replica identity, or move the table to a different load path.
Cloud SQL logical replication docsSequences left behind
Logical replication copies table rows but does not carry sequence current values to the new server. If the application keeps inserting after cutover, the target can hand out keys that already exist, producing duplicate key errors or silent conflicts with rows that arrived through replication. Plan a sequence sync step as part of cutover, set each sequence above the maximum value in its column, and confirm the application's identity columns and defaults are the same on both servers.
Large objects not copied
Large objects stored in the pg_largeobject catalog are referenced by OID rather than stored in ordinary table rows, so a publication over ordinary tables does not carry them. Applications that store files this way can cut over with missing data that no error reports. Inventory large object references from the source before planning, decide whether they will be exported separately, and verify counts and sample content on the target before the switch.
Schema drift during the parallel run
A parallel run can last weeks, and developers often apply schema changes to the Cloud SQL source while the new server is catching up. Replication does not propagate DDL, so a new column, index or dropped table on the source can break the subscription or leave the target with a different structure. Freeze schema changes for the parallel run, or route every DDL change through one migration process that applies it to both servers in the same order.
Extensions missing on the new server
Cloud SQL offers a set of supported extensions, and applications often rely on one of them without anyone writing it down. A self-hosted server starts with only the packages you install, so a missing extension can fail schema loads, stored functions or queries after cutover. Export the list of installed extensions and their versions from the source, install matching packages on the target, and run the application's test suite against the target before the parallel run starts.
Restores not tested on the new platform
A backup that runs on Cloud SQL does not prove that your own backup tooling, archive storage and restore procedure work on the new server. Teams often discover the gap during an incident, when the first real restore is attempted. Before cutover, restore a base backup and archived WAL files into a separate instance, run point-in-time recovery to a chosen time, and check row counts and application queries against the restored copy. Record how long the restore took so the recovery plan reflects measured time.
Continuous archiving docsWhat the self-hosted server needs after cutover: backups, failover and connections
Cloud SQL managed backups and recovery for your instance, so the self-hosted server needs its own backup design before the first production write arrives. PostgreSQL point-in-time recovery combines a base backup with archived WAL files. Without both, you can restore a copy of the data at the time of the base backup, but you cannot replay forward to a chosen moment just before an error. The design decisions are where archives are stored, how often base backups run, and how long WAL is kept.
- Base backup schedule: Set how often
pg_basebackupruns and confirm that each base backup is paired with the WAL needed to reach a recent point. - Archive location: Store WAL archives off the primary server, in storage separate from the database host and its failure domain.
- Incremental backups: Ask whether your tooling should use incremental backups, which
pg_combinebackupreconstructs at restore time. - Retention rules: Define how long base backups and WAL are kept, and who can delete them.
- Restore drills: Schedule restores into a separate environment and record how long they take.
Confirm your recovery point and recovery time targets with the application owners before you choose a backup tool, because those targets determine the archive frequency and the restore procedure.
A Cloud SQL instance with high availability is operated by Google, which handles detection and switchover for you. On a self-hosted server, PostgreSQL provides the replication itself. Hot standby servers can serve read-only queries, and you can choose synchronous replication, where a commit waits for standbys, or asynchronous replication. PostgreSQL does not provide the software that detects a primary failure and notifies the standby, so automatic failover needs external tools. Failover design is a separate decision from replication design.
- Replication mode: Choose synchronous or asynchronous replication based on how much data loss the business accepts when the primary fails.
- Failure detection: Select and configure an external tool to detect primary failure and promote a standby.
- Fencing: Plan how the old primary is prevented from accepting writes after promotion.
- Read traffic: Decide which applications may read from standbys and confirm they tolerate replication lag.
- Failover tests: Test planned and unplanned failovers in a non-production environment before go-live.
Confirm with your platform team who is paged during a failover and whether the chosen tool's behavior matches your change control process.
Applications that connected to Cloud SQL through its proxies or direct connections often assume a particular connection pattern. On your own server, connection limits, pooling and TLS settings are yours to set. PgBouncer is a lightweight connection pooler for PostgreSQL that sits between applications and the database. Pooling reduces the number of server-side connections that the database must handle, which matters when many application instances open connections at once. Pool mode changes what session features applications can rely on, so the choice must be tested against the application code.
- Pool mode: Choose session, transaction or statement pooling, and check each application for session-level features such as prepared statements, temporary tables and session variables.
- Connection limits: Set
max_connectionson the server and pool sizes in PgBouncer so the total stays within server capacity. - Client configuration: Update connection strings to point to the pooler and confirm TLS and authentication settings carry over.
- Pooler availability: Decide whether PgBouncer runs redundantly, since a single pooler becomes a single point of failure.
- Version currency: Track PgBouncer releases. Version 1.26.1 was released on October 14, 2026 with security fixes, so confirm the version you deploy includes current security fixes.
Run a load test with the production connection pattern before cutover, and confirm the pooler settings with the application owners.
How DeployOpen scopes and delivers a Cloud SQL to self-hosted PostgreSQL migration
DeployOpen plans and delivers the move from Cloud SQL for PostgreSQL into PostgreSQL servers you run, in your own cloud accounts, data centers or air-gapped networks. The work follows a written scope that covers replication setup, sequences, large objects, validation and cutover, with the same steps documented for your team to run later.
How we scope
- Inventory the Cloud SQL instance, its extensions, large objects, sequences and the applications that connect to it
- Confirm whether the source can enable cloudsql.logical_decoding and which tables lack primary keys
- Agree the target PostgreSQL version, network path, authentication method and cutover window in writing before work starts
- Engagements are fixed-scope, so deliverables and timelines are set in the written scope before any build begins
How we build
- Configure the external target server and create publications and subscriptions for the replicated tables
- Synchronize sequence values and move large objects with a documented check that row counts and checksums match
- Test the replication lag, application connection changes and rollback steps in a non-production copy first
- Record each step as a runbook so the cutover sequence is reproducible and reviewed by your team
How we hand over
- Deliver the target configuration, replication design, validation results and the cutover runbook as documentation
- Walk your database, security and operations staff through the replication state, monitoring and rollback procedure
- Document the decommissioning steps for the Cloud SQL source, including what to retain for audit and recovery
- Confirm with your team which evidence your compliance reviewers need before the source is shut down
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after the migration completes
- Support can cover minor release updates, backup and restore testing, and planning for later major version upgrades
- Ask for the support scope, response expectations and change process in the quote, since these are set per engagement
- Retainer terms are agreed in writing, so confirm what is included before the handover is signed off

