Key Considerations for Migrating Databases to CloudNativePG (CNPG)
Migrating databases is rarely simple. Achieving zero or minimal downtime while avoiding data loss demands careful planning. Moving to CloudNativePG (CNPG)—the Kubernetes-native PostgreSQL operator—introduces additional factors tied to containerized environments, Kubernetes storage, and operator-specific features.
While no guide can cover every scenario, the following considerations provide a strong starting point for a smooth transition.
1. Database Size
PostgreSQL databases consist of interconnected objects—schemas, tables, indexes, roles, and more—stored in a specific file structure managed by the server. Data movement typically relies on SQL operations, with backups (via pg_dump) being a common method. CNPG provides other methods, including direct access to the migration source, but that is not always feasible.
Small databases (a few MB or GB) are straightforward to transfer. Large ones—think tens or hundreds of terabytes—require much more planning around storage, time, and bandwidth.
Actionable first step:
Query your current PostgreSQL server to understand the footprint:
SELECT datname, pg_size_pretty(pg_database_size(datname)) AS size
FROM pg_database
ORDER BY pg_database_size(datname) DESC;
This returns a clear, human-readable table of database sizes. Note that pg_dump files are usually compressed, so they may be smaller than the live database. Always provision extra headroom on the target side to accommodate growth.
Pro tip: Before migrating, run cleanup jobs on the source. Remove old, unused data, temporary tables, or orphaned records. Every DBA knows how clutter accumulates—there is no reason to carry it forward.
2. Database Type (Source Compatibility)
Your source may not be PostgreSQL. Many applications support multiple backends, such as MySQL, MariaDB, or others. In these cases, you will need schema conversion, data type mapping, and possibly query adjustments.
Popular tools include:
- pgloader — Excellent for migrating from MySQL or other systems to PostgreSQL.
- mysqldump with compatibility flags, followed by manual tweaks.
Plan for differences in features, stored procedures, and data types early in the process.
3. Query and I/O Patterns
Size alone does not tell the full story. A modest database under heavy load can stress CPU, memory, storage IOPS, and network resources more than a large but quiet one.
Key steps:
- Profile current workloads using tools like pg_stat_statements, pg_stat_io (available in PostgreSQL 16+), or external monitoring.
- Benchmark the expected load on the target Kubernetes environment.
- Leverage CNPG’s built-in replication: add multiple read-only replicas (typically three or more instances per cluster) to offload read traffic from the primary.
Understanding IOPS and file system behavior versus actual PostgreSQL activity is complex and often warrants dedicated testing. A well-provisioned CNPG cluster with proper storage classes can handle demanding workloads effectively.
4. High Availability (HA) Requirements
Traditional PostgreSQL HA solutions (e.g., Patroni) work well but require manual management. CNPG provides native, automated HA with replicas and failover capabilities, plus integrated PgBouncer support for connection pooling.
This setup suits most applications using a primary for writes and replicas for reads. However, it is not an active-active configuration with multiple writable nodes. If your application demands true multi-master writes, conduct deeper research or consider additional patterns.
5. Backup and Restore Strategies
Backups are only as good as your last successful restore. Many organizations discover gaps only during a crisis.
Best practices:
- Validate existing backup procedures and adapt them for CNPG.
- CNPG offers built-in support for continuous archiving and recovery, often using object storage like S3.
- For smaller databases or extra safety, combine this with traditional
pg_dump/pg_restore. - Test restores regularly—ideally onto new clusters—to confirm end-to-end recoverability.
6. Data Transport
Moving data from on-premises to cloud (or between data centers) introduces logistical challenges.
- Network constraints: Private networks, firewalls, and bandwidth limits can complicate large transfers.
- Physical media: For very large databases, shipping drives is sometimes necessary, but many data centers restrict external USB/storage devices due to security policies.
- Alternatives: Logical replication (via CNPG’s native PostgreSQL support) enables near-zero-downtime migrations by streaming changes in real time.
Plan the transport method early and account for security, compliance, and downtime windows.
7. Application Connectivity
Migration affects more than just the database. Consider:
- Whether the application moves with the database or connects remotely.
- Updated connection strings, service discovery in Kubernetes, and network policies.
- New RBAC roles, secrets management, and security configurations.
Test connectivity thoroughly in a staging environment, paying special attention to Kubernetes networking and service exposure.
8. One Cluster or Many? (CNPG Architecture Decisions)
CNPG strongly recommends one PostgreSQL cluster per database (or per microservice) for isolation, security, and operational simplicity.
Important storage consideration: Decide whether to place Write-Ahead Log (WAL) files on the same volume as data or on a dedicated volume. WAL can grow rapidly, especially under heavy load or during replication lag. Using a separate walStorage volume prevents one from starving the other.
Evaluate your disk space, I/O patterns, and resource availability. Some teams run many databases in a single large CNPG cluster successfully; others prefer multiple smaller clusters on dedicated nodes. Choose based on validated requirements rather than convenience alone.
Final Thoughts
Migrating to CloudNativePG offers powerful Kubernetes-native PostgreSQL capabilities—automated HA, declarative management, and excellent operator integration—but success depends on thoughtful preparation.
Start with assessment (size, load, compatibility), design for isolation and performance, validate backups and connectivity, and test thoroughly. Tools like logical replication can minimize disruption, while proper storage configuration prevents nasty surprises with WAL growth.
With careful planning, you can achieve a reliable, scalable PostgreSQL environment that leverages the full power of Kubernetes. Good luck with your migration!
Have you migrated to CNPG? Share your experiences or specific challenges in the comments.
Did you find this post helpful? You can support me.
Related posts
- Databases – Postgresql – Pilot
- Databases – Postgresql – Gitea and PGBouncer
- Databases – Postgresql – PGbouncer
- CNPG – Cloud Native Postgresql – Pilot
Author Profile
Latest entries
blog24.06.2026CNPG – considerations for migrating databases
blog14.06.2026CNPG – Cloud Native Postgresql – Pilot
blog18.04.2026ConfDroid Puppet Modules – java
blog18.04.2026ConfDroid Puppet Modules – SSH



