Migrating PostgreSQL from virtual machines to Kubernetes with CloudNativePG starts with one decision
Moving PostgreSQL from virtual machines to Kubernetes under CloudNativePG is a data and cutover project, not a container lift. Each database has to be copied, verified and switched over while applications keep writing, and the container image is the smallest part of that work. The first decision is how much write downtime the business will accept for each database, because that choice sets the import method and the amount of testing you need before cutover.
The short answer on effort depends on three things: how many databases you have, how much write downtime each one can tolerate, and whether the databases split cleanly into groups. CloudNativePG supports a microservice approach, where each cluster holds one application database, and a monolith approach, where one cluster holds several databases and users. An offline import with pg_dump and pg_restore is simpler, but writes to the source must stop before the final import. Databases that share roles, extensions or cross-database assumptions push you toward the monolith approach and more schema review. Ask your team to inventory every database, its owners, its write rate and its dependencies before choosing a path.
CloudNativePG is open source and released under the Apache License 2.0, so the operator itself carries no license fee. You still need a supported Kubernetes cluster with enough persistent storage, backup target and network policy for the database pods, and the cluster should be built and hardened before any data moves. Confirm the PostgreSQL major version you will run on the target, the CloudNativePG release you will deploy and the Kubernetes version it supports. The CloudNativePG import documentation describes the import options and should be read alongside your own test plan. Plan the migration as a rehearsal sequence, starting with a copy of production data in a non-production cluster, and treat the first complete run as the real measure of effort.
What maps cleanly from VM PostgreSQL to CloudNativePG and what does not
This table compares the main parts of a VM-hosted PostgreSQL setup with their CloudNativePG or Kubernetes equivalent and flags the items that need redesign. Read the rows marked as manual redesign first, because they are where cutover plans most often slip. Confirm each mapping against the CloudNativePG version you deploy before relying on it.
| Source item on a VM | CloudNativePG or Kubernetes equivalent | Migration note |
|---|---|---|
| Databases and schemas | Databases and owners declared in the Cluster custom resource or imported with pg_dump and pg_restore | Maps cleanly for logical content. Decide early whether each source database becomes its own microservice cluster or joins a monolith import. |
| Roles and privileges | Roles managed through the cluster configuration and secrets, with GRANT statements replayed after restore | Dump role definitions separately and review them. Passwords and role attributes may need to be recreated from Kubernetes Secrets. |
| Extensions | Only extensions included in the container image you build or use | Manual redesign. Confirm each extension and version is packaged in the image, and rebuild any host-level or compiled extension. |
| Streaming replication and standbys | Replicas managed by the operator inside the cluster | Replace hand-built standby configuration with operator-managed replicas. Confirm failover behavior in the CloudNativePG documentation for your version. |
| Base backups and WAL archiving | Backup and WAL archive settings declared for the cluster, with object storage as the target | Manual redesign for custom archive scripts. Rebuild retention and restore testing around the operator's backup features, and do not assume existing scripts carry over. |
| pg_hba.conf rules | Authentication rules set through cluster configuration, plus Kubernetes network policies for reachability | Manual redesign. Each host-based rule must be rewritten, and client networks change because application pods reach the database through cluster services. |
| postgresql.conf settings | Parameters declared in the cluster specification | Mostly maps, but memory and storage settings must fit container resource limits. Review settings that reference local file paths. |
| Local file paths and data directories | Persistent volumes claimed by each instance pod | Manual redesign. Any script, mount or tablespace that points at a fixed host path must be rebuilt against volume claims. |
| Connection pooling | Pooler resources in front of the cluster, typically PgBouncer | Maps with changes. Application connection strings change to the pooler service, and pool sizing must be retested. |
| Application connection endpoints | Kubernetes services for read-write and read-only traffic | Connection strings and DNS names change at cutover. Plan a single switch point and test rollback. |
Documented import and migration paths for PostgreSQL on Kubernetes
CloudNativePG documents several ways to bring an existing PostgreSQL database into a cluster, and each one moves a different set of objects. The cards below cover the offline import, the microservice and monolith approaches, and logical replication for online moves, along with what each path leaves behind for you to recreate and verify.
Offline import with pg_dump and pg_restore
CloudNativePG can pull a database from the source over the network with pg_dump and load it with pg_restore. Writes to the source must stop before the final import, so the outage lasts as long as the dump, transfer and restore take on your data volume. Test the timing on a copy of production before you schedule the cutover window.
CloudNativePG import docsMicroservice import for one application database
The microservice approach imports a single application database into its own cluster, with one owner for that database. It fits services that already keep their data isolated. Confirm that the application's connection strings, secret names and role names match what the operator creates in the target cluster before you change any configuration.
Monolith import for multiple databases
The monolith approach imports several databases and their users into one cluster. Shared roles, cross-database grants and per-database settings have to be checked after the restore, because a plain dump does not guarantee they carry over unchanged. List every role your applications depend on and confirm each one exists on the target before the first test run.
Logical replication for online moves
Logical replication copies changes from the source to the target while the source keeps serving traffic, so the cutover needs only a short write freeze. Replication moves table data and row changes, but schema changes made on the source after setup are not sent automatically. Confirm how your team will apply DDL changes during the replication window.
PostgreSQL upgrading docsRoles, sequences and extensions
Dumps and logical replication do not reliably carry every object type. Roles and their passwords are cluster-wide objects that a per-database dump may not include. Sequence values and extensions must also be checked on the target. Ask your team to confirm the extension list, the role list and the current sequence values in the target environment before cutover.
Testing the path before cutover
Run each import path against a copy of the source and compare row counts, checksums on critical tables, sequence values and application behavior. Record the time each step takes so the cutover plan uses measured numbers rather than estimates. Repeat the full rehearsal at least once with the same steps your team will run on the cutover night.
Choosing microservice or monolith import for each database
CloudNativePG gives you two import shapes, and the choice sets how many clusters you run, who owns which credentials and where applications connect. The microservice approach imports one application database per import, so each service gets its own database and its own owner role. The monolith approach imports several databases and users in one operation, which suits a legacy server that hosts many schemas for one application or tightly coupled apps that share a lifecycle. Start by listing every database on the source server, the application that uses it, the team that owns it and any cross-database queries, since those dependencies rule out splitting a set of databases apart. Decide grouping per application owner, not per server, because a single source instance often mixes unrelated workloads.
Each grouping decision carries through to roles and secrets. A microservice import means one role and one credential per service, which keeps rotation and revocation scoped to one team, but it multiplies Kubernetes Secrets that must be protected and reviewed. A monolith import keeps fewer credentials but gives a shared role access to more data, so review what each user can reach on the source before you copy grants across. Confirm in the CloudNativePG import documentation how ownership and roles are carried over for your chosen approach and version, because this is where many imports need manual fixes. Cluster count follows from these choices: one cluster per application group is common, but every extra cluster adds storage, backups, monitoring and an extra endpoint to route to. Plan connection routing (services and any pooler such as PgBouncer) per group before the import runs.
Whichever approach you choose, the pg_dump import is offline. Writes to the source must stop before the final import, or rows written after the dump will be missing from the new cluster. Plan a write freeze window for each group, and sequence groups so that a shared application does not start writing to a new cluster while its dependencies still write to the old one. Rehearse the freeze and the import on a copy of production data to measure how long the window must be, and record the source row counts and checksums so you can compare them after restore. If the outage window is not acceptable for a group, that group needs a logical replication plan instead of this import method, which the sibling sections cover.
How the offline and logical replication paths fit together
The diagram starts at the source PostgreSQL server on a virtual machine and shows two ways data reaches the CloudNativePG cluster. The offline path stops writes, moves a dump over the network with pg_dump and pg_restore, then cuts over. The logical replication path keeps the source live while changes stream into the cluster, and the application moves only after parallel validation confirms the copies match. Choose the path by how much downtime the application can tolerate, and confirm which databases and users the import approach will carry.
Offline import and logical replication paths into a CloudNativePG cluster, ending in cutover.
Sequence for moving databases from VMs into CloudNativePG
This sequence takes each PostgreSQL database from inventory through a tested import, a parallel run and cutover, and ends with the VM sources retired only after the retention period you agree.
Inventory databases, roles and extensions
Your team lists every database on each source VM, along with its owners, the roles that connect to it, installed extensions, and the applications that depend on it. Record the PostgreSQL major version and the size of each database, since the target must support the same extensions and the import method depends on size and write activity. Confirm which source versions are still supported under the PostgreSQL versioning policy, because a database on an unsupported version affects which upgrade path you choose. The step is done when the inventory is signed off by the application owners and every database is assigned to either the microservice or the monolith import approach.
Build the target cluster and prerequisites
Your platform team prepares the Kubernetes environment and the CloudNativePG cluster that will receive the data. Confirm the Kubernetes version you run is still within the project's support window, and check the control plane topology, etcd backup plan and how Secrets are encrypted at rest, since database credentials will be stored there. Define storage classes, resource limits, backup configuration and the pod security settings your standards require. The step closes when the empty cluster starts, passes a health check, and a restore test from a backup of the empty cluster succeeds, so the recovery path is proven before any production data arrives.
Run a pilot import on a non-production copy
Your team imports one representative database into the new cluster using pg_dump over the network and pg_restore, following the CloudNativePG import procedure for the chosen approach. Use a recent copy of the source rather than production, and record the elapsed time, errors, warnings about extensions or ownership, and any role or privilege differences. Compare object counts, sequence values and row counts against the source. The pilot is complete when the team has a repeatable runbook with the exact commands, the parameters that worked, and a list of manual fixes that a production import will need.
Run a parallel period with validation
Keep the VM source and the CloudNativePG cluster both available while the application team points a test environment at the new database. Run agreed validation queries, compare aggregates and key business records between the two systems, and check that application connection handling, pooling and authentication work with the new endpoints. Confirm how long the parallel run lasts and who signs off, because this period is where data drift and application defects appear. The step is done when the validation checklist passes for every database and the owners accept the results in writing.
Cut over with a write freeze for offline import
For an offline import, stop application writes to the source database, take the final pg_dump, restore it into the target cluster, and then repoint applications to the new service. Confirm before the window opens that no batch jobs or external writers will touch the source, and keep a tested rollback that returns traffic to the VM. Verify row counts and sequence values on the target immediately after restore, then run the smoke tests agreed in the parallel period. The cutover is done when applications write successfully to the cluster and the owners confirm the business checks.
Cut over logical replication after lag checks
For an online move, the team sets up logical replication from the source to the cluster, then monitors replication lag and confirms every table has caught up before any switch. Check that sequences, which logical replication does not carry over automatically, are synchronized at the cutover point, and that schema changes are blocked or replayed during the sync. Stop writes only for the final brief switch, confirm the subscriber has received all changes, and then repoint applications. The step is complete when lag is confirmed at zero for every publication, sequence values match, and the application is writing to the cluster.
Decommission VM sources after the retention period
After the cutover, keep the VM databases in a read-only state for the retention period your data governance and recovery requirements set, and confirm that backups of the CloudNativePG clusters run and restore successfully during that time. Then remove application access, take a final archival backup of the source if policy requires it, and shut down the VM. Record the decommission in your asset and access inventory, including revoked roles and deleted credentials. The sequence is complete when the retention period has ended, the archive is verified, and the source is removed from monitoring and backup schedules.
What drives effort and duration for this migration
This table lists the factors that most change the effort and calendar time of moving PostgreSQL from virtual machines into CloudNativePG clusters. Read each row for what pushes effort up, what brings it down, and what to ask a partner to put in a written quote.
| Driver | What increases effort | What to ask a partner to quote |
|---|---|---|
| Number of databases and users | Monolith imports with many databases, roles, extensions and grants each need mapping and checking. Each database adds a separate import and validation pass. | Itemized count of databases, roles and schemas in scope, and whether the import follows the microservice or monolith pattern. |
| Database size and import method | Larger databases lengthen the pg_dump and pg_restore window and the time to verify row counts. Offline import time grows with data volume. | Import method per database, expected offline window measured in a rehearsal, and who runs the timed trial. |
| Tolerance for write downtime | A short write freeze is simple but the freeze must cover the final import. Logical replication for a near-zero write pause adds setup, conflict checks and monitoring. | Whether the quote covers offline import, logical replication, or both, and the test evidence supplied before cutover. |
| Extensions and special objects | Extensions not packaged in the target image, large objects, sequences and custom types require image builds and compatibility checks before cutover. | List of extensions and object types found in the source, and who builds and tests the target image. |
| Applications and connection strings | Each application needs its connection string, credentials and pooler settings changed and retested. Shared services multiply this work. | Inventory of applications connecting to each database, the change list, and the test plan for each service. |
| Backup and recovery requirements | Required recovery point and recovery time targets drive backup design, restore tests and archive storage. Restores that must be proven on the new cluster add rehearsal time. | Backup and restore design on the new cluster, restore test scope, and evidence delivered to your team. |
| Kubernetes platform readiness | A cluster without storage classes, backup targets, identity integration, or secrets encryption needs platform work first. Missing platform pieces can outweigh the database work. | Confirmation of which platform pieces already exist in your environment and which the quote includes. |
| Team skills and ownership | Teams new to Kubernetes operators, or without PostgreSQL operations experience, need more training, pairing and handover time. Unclear ownership delays decisions. | Handover scope, runbooks delivered, training sessions included, and named owners on each side. |
| One-time versus recurring work | One-time work covers design, import, testing and cutover. Recurring work covers Kubernetes version upgrades, which follow the Kubernetes release and support cycle, and PostgreSQL minor and major upgrades. | Separate one-time and recurring line items, and whether a retainer covers upgrades and continuous testing after go-live. |
How to test restores and application behavior before cutover
Run at least one full rehearsal of the migration into the CloudNativePG cluster before any production cutover, and judge it against written pass criteria. Start with data. Compare row counts for every table in every migrated database, then compare checksums or hash aggregates on the large and business-critical tables, because matching counts alone can hide altered values, truncated text or wrong numeric precision. Check sequences separately: confirm each sequence's current value is at or above the highest id in its table, since an offline import can leave sequences behind and the first production inserts will fail or collide. Confirm that extensions, roles and grants came across, since a database can restore cleanly and still fail for the application's database user.
Next test application behavior against the new cluster, not only the data. Point a staging copy of each microservice at the rehearsal cluster, and run the queries your ORM and batch jobs issue, including the slowest ones from production logs. Compare execution plans with the source, because a new storage layer, different memory settings or changed statistics after restore can shift plans. Route traffic through PgBouncer in the same mode and pool sizes you plan to use in production, and test connection exhaustion and idle timeouts deliberately. Confirm the pooler's own version and security fixes are current before you rely on it, and check the PgBouncer site for the latest release notes.
Then test recovery and failover, which is where the design choice matters most. Take a backup from the new cluster, restore it into a separate namespace or cluster, and time the restore against your recovery time target. Verify that point-in-time recovery reaches a chosen timestamp and that the restored data matches your checks. For failover, stop the primary pod or its node in the rehearsal and measure how long clients take to reconnect. PostgreSQL does not include software that detects a primary failure and promotes a standby, so automatic failover depends on external tooling that you select, configure and test. Confirm which component performs promotion, how the application finds the new primary, and what happens to in-flight transactions. Record the results and sign off against them.
What usually goes wrong in VM to CloudNativePG moves and how to prevent it
Most failed moves from virtual machines to CloudNativePG do not fail during the data copy. They fail afterward, in the objects nobody listed, the restores nobody ran, and the control plane and secrets nobody backed up. The cards below cover each risk with a check to run before cutover.
Missed sequences and roles
A pg_dump of one database does not carry cluster-wide roles, and sequence values can lag behind the data if writes continue during the copy. Inventory roles, grants and sequences on the source and compare them after import. Confirm that each application login exists on the new cluster before the application is pointed at it.
CloudNativePG import docsUntested restores
A dump that completes without error does not prove the database is usable. Restore into a scratch CloudNativePG cluster, run row counts and application test suites against it, and time the full restore. Record the result so the cutover window is based on measured restore time, not an estimate.
Connection strings pointing at old hosts
Applications often hold hostnames, IP addresses or DSNs in configuration files, secrets and scheduled jobs that are easy to miss. Search every repository, config store and cron definition for the old host. Plan the cutover around a Kubernetes Service name, and keep the old server read-only for a rollback period.
Storage class and performance differences
A PersistentVolume from a different storage class can have different latency, IOPS and fsync behavior than the bare disk the database ran on before. Run the same benchmark and the slowest production queries on both platforms. Ask the platform team which storage class backs the cluster and whether it is suitable for WAL as well as data.
Kubernetes control plane upgrade drift
Nodes, the API server and the controller manager can drift apart when upgrades run in an unplanned order. The version skew policy requires kube-apiserver to be upgraded first, one minor version at a time, with kubelets allowed to lag only within a set range. Write the upgrade order into the runbook and check every node's kubelet version before a database cutover.
Version skew policyetcd backup gaps
The database backups created by CloudNativePG do not protect the Kubernetes objects that define the cluster. The control plane depends on etcd, which needs its own snapshot schedule taken with etcdctl and a tested restore path with etcdutl. Confirm who owns etcd backups, how often they run, and when a restore was last rehearsed.
Operating etcd clustersSecrets stored unencrypted in etcd
Kubernetes Secrets, including database passwords and the credentials used for backup storage, are stored unencrypted in etcd by default. Enable encryption at rest for Secrets, restrict list and watch access with least-privilege RBAC, and consider an external store through the Secrets Store CSI Driver. Verify this on the cluster itself, since an etcd snapshot would otherwise expose every password.
Kubernetes Secrets practicesQuestions teams ask before moving PostgreSQL to Kubernetes
How much does it cost to move PostgreSQL to CloudNativePG on Kubernetes?
The cost depends on the work involved, not on a fixed list price, so the answer comes from a written scope. The main components are the time to assess each database, build the target clusters, run the import or replication, test restores and perform the cutover. Recurring costs include the Kubernetes platform, storage, backup targets, monitoring and the staff who patch and upgrade the clusters. Ask any quote to separate one-time migration work from ongoing support, and to list which databases, extensions, applications and environments are covered. DeployOpen does not publish a price list, and a quote follows from the agreed scope.
How long does a PostgreSQL to Kubernetes migration take?
Duration is driven by database size, the number of databases and users, the number of applications that connect to them, and how much testing your change process requires. An offline import with pg_dump and pg_restore is simpler to plan but needs a downtime window that covers the dump, transfer and restore. Online moves with logical replication shorten the cutover but add setup, monitoring and validation time before the switch. No duration is given here because none was researched for this topic. Ask for a timeline that lists each phase and the test cycles it depends on.
What does the migration require from our team?
Your team supplies the knowledge that no import tool can infer. That includes who owns each database, which applications connect to it and with which roles, which extensions and custom objects are in use, acceptable downtime, and the recovery point and recovery time targets. Your platform team must provide the Kubernetes environment, storage classes, network paths between source and target, secrets handling and backup destinations. Application owners need to confirm connection string changes and test their own workloads. Plan for these people to be available during the test runs, not only at cutover.
Can our own team run the migration without a partner?
A team with Kubernetes operations experience and prior PostgreSQL administration can run the migration, provided it has time to rehearse the import and cutover. The hardest parts are usually not the commands but the decisions: whether to use one database per application or a monolith layout, how to stop writes at the source, how to prove the copy is complete, and how to roll back. Most teams that do this alone practice the full sequence on a copy several times before production. If you lack one of the skill sets, a fixed-scope engagement can cover the parts you cannot staff, and the written scope shows which tasks move to a partner.
When is an offline cutover acceptable, and when do we need online replication?
An offline cutover fits when the application can stop writing for the length of the dump, transfer and restore. CloudNativePG's import approach is offline in this sense: writes to the source should stop before the final import. Logical replication is the option when that window is too long. PostgreSQL logical replication can move data between servers, and it can reduce the switch to a short final step, but it needs primary key coverage on replicated tables, sequence handling and monitoring of lag. Decide per database, because a small reference database may suit an offline import while a large transactional one needs replication.
Does a Kubernetes platform have to exist before the database move?
Yes. The target CloudNativePG clusters run on a Kubernetes cluster you already operate, so the platform must be in place and tested first. Before importing data, confirm the control plane is highly available, etcd has a tested backup plan, and node and storage capacity fit the databases. Check the Kubernetes version against the supported releases, because the version skew policy governs how the control plane and nodes can be upgraded. Platform hardening, identity integration and Secrets encryption at rest should also be settled, since database credentials will be stored there. Treat the platform as a prerequisite workstream with its own acceptance criteria.
How do we test a PostgreSQL migration before cutover?
Test the whole path, not just the data copy. Run the import into a non-production CloudNativePG cluster, then compare row counts, checksums on critical tables, sequence values, extensions and roles. Run the application test suite and a realistic load against the target, and measure how long the full offline sequence takes so the cutover window is based on evidence. Rehearse backup and restore on the new clusters, because a migration that cannot be restored is not finished. Record each rehearsal, and repeat the cycle until the runbook runs without manual changes.
Which PostgreSQL version should the target cluster run?
Choose a version that is still supported for the life of the cluster. The PostgreSQL versioning policy lists supported major versions with end dates, and 13 and earlier are no longer supported. Version 14 is supported until November 12, 2026, so a target built on it would need an upgrade soon after cutover. Versions 15, 16, 17 and 18 have later end dates. Confirm the choice against your application's compatibility testing and against the CloudNativePG release you plan to run, since the operator's supported PostgreSQL images determine which versions you can deploy.
How DeployOpen scopes the move in writing
Most DeployOpen engagements are fixed-scope, which means the scope, deliverables and timeline for the move are agreed in writing before any work starts. For a migration into CloudNativePG, that document should name each source database, each target cluster, the import approach chosen for each one (microservice or monolith, offline pg_dump and pg_restore or logical replication), the list of application connection strings that will change, and the cutover window the business has accepted. A scope that leaves these items open tends to produce a quote that cannot be compared with another. Ask every bidder, including your own team, to state the same assumptions in writing.
At the end of the work, the client receives three records. The first is an inventory of every database, schema, role, extension and PostgreSQL version on the source, mapped to its target cluster and namespace. The second is a rehearsal record, showing each dry run with row counts, checksums or comparison results, timings and any errors fixed along the way. The third is a cutover runbook covering the write freeze, the final import or replication catch-up, the connection change, the rollback trigger and the owner of each step. Confirm with the provider the exact format of each record and whether the runbook is tested against the cluster before the production date.
A quote follows from the written scope, and DeployOpen does not publish a price list. Ask for the quote to separate one-time work (inventory, rehearsals, cutover support, documentation) from anything that recurs after cutover, such as backup verification, upgrades or retainer support. Cost moves with the number of databases, the size of the data that must be copied within the cutover window, how many applications must be retested, and whether the source needs changes to support logical replication. Confirm with the provider which of these items are included, and which would be handled as a change to the agreed scope.
How DeployOpen delivers and supports PostgreSQL migrations to CloudNativePG
DeployOpen works on this migration as a scoped engagement: we agree which databases move, which import path each one takes and how cutover is tested before any production write moves. The same written scope then governs the build, the handover to your platform team and the support that follows.
How we scope
- Inventory each source PostgreSQL database and classify it as microservice (one application database) or monolith (several databases and users).
- Record the PostgreSQL major version on the source and the target, and the extensions each database depends on.
- Agree in writing whether each database takes an offline pg_dump and pg_restore import or a logical replication move, with the acceptable write-stop window.
How we build
- Stand up the target CloudNativePG cluster in your Kubernetes environment with the storage, backup and network settings from the agreed scope.
- Run rehearsal imports into a non-production cluster and compare object counts, roles and sequences against the source.
- Configure the application connection path, including any connection pooler, and test it against the rehearsed data before cutover.
How we hand over
- Deliver a cutover runbook listing the freeze, import or replication steps, verification queries and rollback decision points.
- Document the cluster configuration, backup schedule and restore procedure so your team can run them without us.
- Walk your platform and database owners through the restore test results and record open items with owners and dates.
How we support
- Offer ongoing support, upgrades and continuous testing as a retainer after cutover, if your organization wants it.
- Plan the follow-on work to track Kubernetes and PostgreSQL support windows, with the current dates confirmed against the vendor pages.
- Confirm with your team which support responsibilities stay internal and which are covered by the retainer before handover.

